Skip to content

Commit b3d169d

Browse files
committed
Updating error messages and path fixes
1 parent 56eb31a commit b3d169d

5 files changed

Lines changed: 28 additions & 31 deletions

File tree

skdaccess/astro/kepler/data_fetcher.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@
3232
from skdaccess.astro.kepler.data_wrapper import DataWrapper
3333
from skdaccess.utilities import data_util
3434

35-
# 3rd party package imports
36-
import pandas as pd
37-
import numpy as np
35+
# Standard library imports
3836
from collections import OrderedDict
3937
import re
4038
import glob
4139
import os
40+
41+
# 3rd party package imports
42+
import pandas as pd
43+
import numpy as np
4244
from astropy.table import Table
4345
from astropy.io import fits
4446

4547

46-
4748
class DataFetcher(DataFetcherBase):
4849
''' Data Fetcher for Kepler light curve data '''
4950
def __init__(self, ap_paramList, normalize=False, drop_on_quality=False, filter_window=None, quarter_list=None, wrapper_type = 'series'):
@@ -71,7 +72,8 @@ def output(self):
7172
7273
@return DataWrapper
7374
'''
74-
data_location = data_util.getDataLocation('kepler')
75+
76+
data_location = data_util.getDataLocation('kepler', raise_exception = False)
7577

7678
if data_location == None:
7779
data_location = os.path.join(os.path.expanduser('~'), '.skdaccess', 'kepler')

skdaccess/geo/grace/data_fetcher.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ def output(self):
6363
'''
6464

6565
data_file = getDataLocation('grace')
66-
if data_file is None:
67-
print("No data available")
68-
return None
6966

7067
geo_point = self.ap_paramList[0]()
7168
store = pd.HDFStore(data_file, 'r')

skdaccess/geo/groundwater/data_fetcher.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ def output(self):
6767
@return Groundwater Data Wrapper
6868
'''
6969

70-
data_file = getDataLocation('groundwater')
71-
if data_file is None:
72-
print("No data available")
73-
return None
70+
71+
data_file = getDataLocation('groundwater')
7472

7573

7674
if self.ap_paramList == []:
@@ -127,9 +125,6 @@ def __str__(self):
127125

128126
def getStationMetadata():
129127
data_file = getDataLocation('groundwater')
130-
if data_file is None:
131-
print('Dataset not available')
132-
return None
133128

134129
store = pd.HDFStore(data_file,'r')
135130
meta_data = store['meta_data']

skdaccess/geo/pbo/data_fetcher.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from skdaccess.utilities import pbo_util
3232
from skdaccess.utilities import data_util
3333

34-
#IGNORE THIS LINE
34+
# Import datawrapper
3535
from skdaccess.geo.pbo.data_wrapper import DataWrapper
3636

3737
# 3rd party package imports
@@ -82,6 +82,7 @@ def __init__(self, start_time, end_time, lat_range, lon_range, ap_paramList, mdy
8282

8383
def setStationList(self, station_list):
8484
self.station_list = station_list
85+
8586

8687
def stationCheck(self):
8788
'''
@@ -115,10 +116,7 @@ def stabilize(self):
115116

116117
storeName = self.meta_data
117118

118-
storeData_fn = data_util.getDataLocation('pbo')
119-
if storeData_fn is None:
120-
print('Dataset not available')
121-
return None
119+
storeData_fn = data_util.getDataLocation('pbo')
122120

123121
storeData = pd.HDFStore(storeData_fn)
124122

@@ -147,10 +145,7 @@ def rawData(self):
147145
storeName = self.meta_data
148146

149147
storeData_fn = data_util.getDataLocation('pbo')
150-
if storeData_fn is None:
151-
print('Dataset not available')
152-
return None
153-
148+
154149
storeData = pd.HDFStore(storeData_fn)
155150

156151
mdyratio = self._mdyratio
@@ -243,9 +238,6 @@ def getStationMetadata():
243238
'''
244239

245240
storeData_fn = data_util.getDataLocation('pbo')
246-
if storeData_fn is None:
247-
print('Dataset not available')
248-
return None
249241

250242
store = pd.HDFStore(storeData_fn, 'r')
251243
meta_frame = store['meta_data']

skdaccess/utilities/data_util.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from io import BytesIO
4848

4949
import configparser
50+
from configparser import NoSectionError, NoOptionError
5051
import os
5152

5253
def getConfig():
@@ -55,7 +56,7 @@ def getConfig():
5556
5657
@return configParser.ConfigParser object of configuration
5758
'''
58-
config_location = os.path.expanduser('~') + '/.skdaccess.conf'
59+
config_location = os.path.join(os.path.expanduser('~'), '.skdaccess.conf')
5960

6061
conf = configparser.ConfigParser()
6162
conf.read(config_location)
@@ -68,13 +69,13 @@ def writeConfig(conf):
6869
6970
@param configparser.ConfigParser object
7071
'''
71-
config_location = os.path.expanduser('~') + '/.skdaccess.conf'
72+
config_location = os.path.join(os.path.expanduser('~'), '.skdaccess.conf')
7273
config_handle = open(config_location, "w")
7374
conf.write(config_handle)
7475
config_handle.close()
7576

7677

77-
def getDataLocation(data_name):
78+
def getDataLocation(data_name, raise_exception = True):
7879
'''
7980
Get the location of data set
8081
@@ -85,7 +86,17 @@ def getDataLocation(data_name):
8586
data_name = str.lower(data_name)
8687

8788
conf = getConfig()
88-
return conf.get(data_name, 'data_location', fallback=None)
89+
90+
try:
91+
return conf.get(data_name, 'data_location')
92+
except (NoOptionError, NoSectionError) as e:
93+
print("Data unavailable. In a terminal, please run: skdaccess", data_name)
94+
95+
if raise_exception:
96+
raise e
97+
else:
98+
return None
99+
89100

90101
def setDataLocation(data_name, location):
91102
'''

0 commit comments

Comments
 (0)