Skip to content

Commit 7040e79

Browse files
authored
Merge pull request #163 from pysat/inst/gold_pr
BUG/STY: fix GOLD updates
2 parents f3aa4ab + 73d2d56 commit 7040e79

File tree

2 files changed

+101
-13
lines changed

2 files changed

+101
-13
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1212
* DE2 Vector Electric Field Instrument (VEFI) and magnetometer
1313
* DMSP SSUSI EDR-Aurora data
1414
* IGS GPS (TEC and ROTI)
15-
* TIMED GUVI
1615
* SES-14 GOLD -- tdisk, tlimb and o2den data products added
1716
* TIMED GUVI
1817
* Add TIMED GUVI platform to support L1C intensity datasets.

pysatNASA/instruments/ses14_gold.py

Lines changed: 101 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
1818
Warnings
1919
--------
20-
The cleaning parameters for the instrument are still under development.
20+
- The cleaning parameters for the instrument are still under development.
21+
- Loading multiple days of data requires a bugfix in pysat 3.1.0 or higher.
2122
2223
Note
2324
----
@@ -41,6 +42,7 @@
4142
import functools
4243
import numpy as np
4344

45+
import pysat
4446
from pysat.instruments.methods import general as ps_gen
4547
from pysat.utils.io import load_netcdf
4648

@@ -87,13 +89,90 @@
8789
list_files = functools.partial(ps_gen.list_files,
8890
supported_tags=supported_tags)
8991

92+
# Set download tags. Note that tlimb uses the general implementation, while
93+
# other tags use the cdasws implementation.
94+
download_tags = {'': {'tlimb': {'remote_dir': ''.join(('/pub/data/gold/',
95+
'level2/tlimb',
96+
'/{year:4d}/')),
97+
'fname': supported_tags['']['tlimb']},
98+
'nmax': 'GOLD_L2_NMAX',
99+
'o2den': 'GOLD_L2_O2DEN',
100+
'tdisk': 'GOLD_L2_TDISK'}}
101+
102+
90103
# Set the download routine
91-
download_tags = {'': {'nmax': 'GOLD_L2_NMAX'}}
92-
download = functools.partial(cdw.cdas_download, supported_tags=download_tags)
104+
def download(date_array, tag='', inst_id='', data_path=None):
105+
"""Download NASA GOLD data.
106+
107+
This routine is intended to be used by pysat instrument modules supporting
108+
a particular NASA CDAWeb dataset.
109+
110+
Parameters
111+
----------
112+
date_array : array-like
113+
Array of datetimes to download data for. Provided by pysat.
114+
tag : str
115+
Data product tag (default='')
116+
inst_id : str
117+
Instrument ID (default='')
118+
data_path : str or NoneType
119+
Path to data directory. If None is specified, the value previously
120+
set in Instrument.files.data_path is used. (default=None)
121+
122+
"""
123+
124+
if tag == 'tlimb':
125+
cdw.download(date_array, tag=tag, inst_id=inst_id,
126+
supported_tags=download_tags, data_path=data_path)
127+
else:
128+
cdw.cdas_download(date_array, tag=tag, inst_id=inst_id,
129+
supported_tags=download_tags, data_path=data_path)
130+
93131

94132
# Set the list_remote_files routine
95-
list_remote_files = functools.partial(cdw.cdas_list_remote_files,
96-
supported_tags=download_tags)
133+
def list_remote_files(tag='', inst_id='', start=None, stop=None,
134+
series_out=True):
135+
"""Return a list of every file for chosen remote data.
136+
137+
This routine is intended to be used by pysat instrument modules supporting
138+
a particular NASA CDAWeb dataset.
139+
140+
Parameters
141+
----------
142+
tag : str
143+
Data product tag (default='')
144+
inst_id : str
145+
Instrument ID (default='')
146+
start : dt.datetime or NoneType
147+
Starting time for file list. A None value will start with the first
148+
file found.
149+
(default=None)
150+
stop : dt.datetime or NoneType
151+
Ending time for the file list. A None value will stop with the last
152+
file found.
153+
(default=None)
154+
series_out : bool
155+
boolean to determine output type. True for pandas series of file names,
156+
and False for a list of the full web address.
157+
(default=True)
158+
159+
Returns
160+
-------
161+
file_list : list
162+
A list containing the verified available files
163+
164+
"""
165+
166+
if tag == 'tlimb':
167+
file_list = cdw.list_remote_files(tag=tag, inst_id=inst_id,
168+
start=start, stop=stop,
169+
supported_tags=download_tags)
170+
else:
171+
file_list = cdw.cdas_list_remote_files(tag=tag, inst_id=inst_id,
172+
start=start, stop=stop,
173+
supported_tags=download_tags,
174+
series_out=series_out)
175+
return file_list
97176

98177

99178
def load(fnames, tag='', inst_id=''):
@@ -165,14 +244,24 @@ def load(fnames, tag='', inst_id=''):
165244
elif tag == 'o2den':
166245
epoch_name = 'nevents'
167246

168-
data, meta = load_netcdf(fnames, pandas_format=pandas_format,
169-
epoch_name=epoch_name, labels=labels,
170-
meta_translation=meta_translation,
171-
combine_by_coords=False,
172-
drop_meta_labels='FILLVAL')
247+
# TODO(#165): remove try/except notation once pysat 3.1.0 is released
248+
try:
249+
data, meta = load_netcdf(fnames, pandas_format=pandas_format,
250+
epoch_name=epoch_name, labels=labels,
251+
meta_translation=meta_translation,
252+
combine_by_coords=False,
253+
drop_meta_labels='FILLVAL')
254+
except TypeError:
255+
pysat.logger.warn(' '.join(("Loading multiple days of data may error.",
256+
"Upgrade to pysat 3.1.0 or higher to",
257+
"resolve this issue.")))
258+
data, meta = load_netcdf(fnames, pandas_format=pandas_format,
259+
epoch_name=epoch_name, labels=labels,
260+
meta_translation=meta_translation,
261+
drop_meta_labels='FILLVAL')
173262

174-
if tag == ['nmax', 'tdisk', 'tlimb']:
175-
# Add time coordinate from scan_start_time.
263+
if tag in ['nmax', 'tdisk', 'tlimb']:
264+
# Add time coordinate from scan_start_time
176265
time = [dt.datetime.strptime(str(val), "b'%Y-%m-%dT%H:%M:%SZ'")
177266
for val in data['scan_start_time'].values]
178267

0 commit comments

Comments
 (0)