Skip to content

Commit 0e42b49

Browse files
committed
Restored data_util as it was overrwitten by an old version in 0784a24
1 parent f182649 commit 0e42b49

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

skdaccess/utilities/data_util.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ def setDataLocation(data_name, location):
106106

107107

108108
def downloadPBO(out_file = 'pbo_data.h5', use_file=None):
109+
'''
110+
Download and parse data from the Plate Boundary Observatory
111+
112+
@param out_file: Output filename for parsed data
113+
@param use_file: Use already downloaded data. If None, data will be downloaded.
114+
115+
@return Absolute path of parsed data
116+
'''
109117

110118
def convert_timedelta(in_number):
111119
time_string = str(in_number)
@@ -191,10 +199,19 @@ def convert_timedelta(in_number):
191199
return os.path.abspath(out_file)
192200

193201
def downloadGRACE(out_file = 'grace.h5', local_data = None):
202+
'''
203+
Download and parse data from the Gravity Recovery and Climate Experiment.
204+
205+
@param out_file: Output filename for parsed data
206+
@param local_data: Use already downloaded data. If None, data will be downloaded.
194207
208+
@return Absolute path of parsed data
209+
'''
210+
# Get date of grace data from filename
195211
def getDate(filename):
196212
return pd.to_datetime(re.search('[0-9]{8}',filename).group())
197213

214+
# Check if two dates are within 10 days of eachother
198215
def dateMismatch(date1,date2):
199216
if np.abs(date1 - date2) > pd.to_timedelta(10, 'D'):
200217
return True
@@ -257,6 +274,7 @@ def roundDay(timestamp):
257274
data = {}
258275
u_dict = {}
259276

277+
print('Parsing Grace data')
260278
for file_list in tqdm.tqdm(zip(jpl_files, csr_files, gfz_files), total=min_length):
261279

262280
# Check for date mismatch
@@ -314,6 +332,14 @@ def roundDay(timestamp):
314332
return os.path.abspath(out_file)
315333

316334
def downloadGW(out_file = 'gw_data.h5', local_data = None):
335+
'''
336+
Download and parse California groundwater data provided by USGS
337+
338+
@param out_file: Output filename for parsed data
339+
@param local_data: Use already downloaded data. If None, data will be downloaded.
340+
341+
@return Absolute path of parsed data
342+
'''
317343

318344
# If using local data metadata name is assumed
319345
metadata_filename = 'gw_metadata.rdb'
@@ -330,7 +356,7 @@ def downloadGW(out_file = 'gw_data.h5', local_data = None):
330356

331357

332358
# Download meta data
333-
data_file = open('gw_metadata.rdb', 'wb')
359+
data_file = open(metadata_filename, 'wb')
334360
copyfileobj(urlopen('http://waterservices.usgs.gov/nwis/site/?format=rdb&stateCd=ca&startDT=1800-01-01&endDT=2020-12-31&parameterCd=72019&siteType=GW&hasDataTypeCd=dv'),
335361
data_file)
336362
data_file.close()
@@ -369,7 +395,7 @@ def downloadGW(out_file = 'gw_data.h5', local_data = None):
369395

370396

371397
#Read metadata
372-
meta_data = pd.read_table('gw_metadata.rdb', skiprows=31, names = ['Agency', 'Site Number', 'Site Name', 'Site Type',
398+
meta_data = pd.read_table(metadata_filename, skiprows=31, names = ['Agency', 'Site Number', 'Site Name', 'Site Type',
373399
'Lat', 'Lon', 'LatLon Accuracy', 'LatLon Datum',
374400
'Altitude', 'Altitude Accuracy', 'Altitude Datum',
375401
'Hydrologic Code'], index_col=1)
@@ -387,6 +413,13 @@ def downloadGW(out_file = 'gw_data.h5', local_data = None):
387413
return os.path.abspath(out_file)
388414

389415
def downloadKeplerData(kid_list):
416+
'''
417+
Download and parse Kepler data for a list of kepler id's
418+
419+
@param kid_list: List of Kepler ID's to download
420+
421+
@return dictionary of kepler data
422+
'''
390423

391424
return_data = dict()
392425

0 commit comments

Comments
 (0)