|
17 | 17 |
|
18 | 18 | Warnings
|
19 | 19 | --------
|
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. |
21 | 22 |
|
22 | 23 | Note
|
23 | 24 | ----
|
|
41 | 42 | import functools
|
42 | 43 | import numpy as np
|
43 | 44 |
|
| 45 | +import pysat |
44 | 46 | from pysat.instruments.methods import general as ps_gen
|
45 | 47 | from pysat.utils.io import load_netcdf
|
46 | 48 |
|
|
87 | 89 | list_files = functools.partial(ps_gen.list_files,
|
88 | 90 | supported_tags=supported_tags)
|
89 | 91 |
|
| 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 | + |
90 | 103 | # 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 | + |
93 | 131 |
|
94 | 132 | # 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 |
97 | 176 |
|
98 | 177 |
|
99 | 178 | def load(fnames, tag='', inst_id=''):
|
@@ -165,14 +244,24 @@ def load(fnames, tag='', inst_id=''):
|
165 | 244 | elif tag == 'o2den':
|
166 | 245 | epoch_name = 'nevents'
|
167 | 246 |
|
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') |
173 | 262 |
|
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 |
176 | 265 | time = [dt.datetime.strptime(str(val), "b'%Y-%m-%dT%H:%M:%SZ'")
|
177 | 266 | for val in data['scan_start_time'].values]
|
178 | 267 |
|
|
0 commit comments