geospacelab 0.11.4__py3-none-any.whl → 0.12.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. geospacelab/__init__.py +1 -1
  2. geospacelab/datahub/sources/cdaweb/dmsp/ssusi/downloader.py +103 -0
  3. geospacelab/datahub/sources/cdaweb/dmsp/ssusi/edr_aur/__init__.py +17 -7
  4. geospacelab/datahub/sources/cdaweb/dmsp/ssusi/edr_aur/downloader.py +13 -62
  5. geospacelab/datahub/sources/cdaweb/dmsp/ssusi/sdr_disk/__init__.py +317 -0
  6. geospacelab/datahub/sources/cdaweb/dmsp/ssusi/sdr_disk/downloader.py +44 -0
  7. geospacelab/datahub/sources/cdaweb/dmsp/ssusi/sdr_disk/loader.py +198 -0
  8. geospacelab/datahub/sources/cdaweb/dmsp/ssusi/sdr_disk/variable_config.py +149 -0
  9. geospacelab/datahub/sources/cdaweb/downloader.py +396 -97
  10. geospacelab/datahub/sources/cdaweb/downloader_backup.py +93 -0
  11. geospacelab/datahub/sources/cdaweb/omni/__init__.py +26 -14
  12. geospacelab/datahub/sources/cdaweb/omni/downloader.py +97 -84
  13. geospacelab/datahub/sources/esa_eo/swarm/advanced/efi_tct02/__init__.py +1 -1
  14. geospacelab/datahub/sources/esa_eo/swarm/advanced/efi_tct02/downloader.py +1 -1
  15. geospacelab/datahub/sources/gfz/hpo/__init__.py +1 -1
  16. geospacelab/datahub/sources/gfz/hpo/variable_config.py +3 -1
  17. geospacelab/datahub/sources/madrigal/isr/pfisr/fitted/loader.py +1 -1
  18. geospacelab/datahub/sources/madrigal/satellites/dmsp/downloader.py +2 -1
  19. geospacelab/datahub/sources/tud/champ/dns_acc/__init__.py +24 -7
  20. geospacelab/datahub/sources/tud/champ/dns_acc/downloader.py +29 -36
  21. geospacelab/datahub/sources/tud/champ/dns_acc/loader.py +28 -2
  22. geospacelab/datahub/sources/tud/champ/wnd_acc/__init__.py +68 -10
  23. geospacelab/datahub/sources/tud/champ/wnd_acc/downloader.py +29 -36
  24. geospacelab/datahub/sources/tud/champ/wnd_acc/loader.py +36 -7
  25. geospacelab/datahub/sources/tud/champ/wnd_acc/variable_config.py +3 -3
  26. geospacelab/datahub/sources/tud/downloader.py +288 -113
  27. geospacelab/datahub/sources/tud/goce/dns_acc/__init__.py +354 -0
  28. geospacelab/datahub/sources/tud/goce/dns_acc/downloader.py +42 -0
  29. geospacelab/datahub/sources/tud/goce/dns_acc/loader.py +66 -0
  30. geospacelab/datahub/sources/tud/goce/dns_acc/variable_config.py +139 -0
  31. geospacelab/datahub/sources/tud/goce/dns_wnd_acc/__init__.py +3 -3
  32. geospacelab/datahub/sources/tud/goce/dns_wnd_acc_v01/__init__.py +339 -0
  33. geospacelab/datahub/sources/tud/goce/dns_wnd_acc_v01/downloader.py +42 -0
  34. geospacelab/datahub/sources/tud/goce/dns_wnd_acc_v01/loader.py +84 -0
  35. geospacelab/datahub/sources/tud/goce/dns_wnd_acc_v01/variable_config.py +212 -0
  36. geospacelab/datahub/sources/tud/goce/wnd_acc/__init__.py +339 -0
  37. geospacelab/datahub/sources/tud/goce/wnd_acc/downloader.py +42 -0
  38. geospacelab/datahub/sources/tud/goce/wnd_acc/loader.py +65 -0
  39. geospacelab/datahub/sources/tud/goce/wnd_acc/variable_config.py +188 -0
  40. geospacelab/datahub/sources/tud/grace/dns_acc/__init__.py +6 -3
  41. geospacelab/datahub/sources/tud/grace/dns_acc/downloader.py +29 -37
  42. geospacelab/datahub/sources/tud/grace/wnd_acc/__init__.py +21 -4
  43. geospacelab/datahub/sources/tud/grace/wnd_acc/downloader.py +29 -39
  44. geospacelab/datahub/sources/tud/grace/wnd_acc/loader.py +5 -1
  45. geospacelab/datahub/sources/tud/grace/wnd_acc/variable_config.py +74 -0
  46. geospacelab/datahub/sources/tud/grace_fo/dns_acc/__init__.py +6 -3
  47. geospacelab/datahub/sources/tud/grace_fo/dns_acc/downloader.py +35 -40
  48. geospacelab/datahub/sources/tud/grace_fo/wnd_acc/__init__.py +20 -4
  49. geospacelab/datahub/sources/tud/grace_fo/wnd_acc/downloader.py +29 -44
  50. geospacelab/datahub/sources/tud/grace_fo/wnd_acc/loader.py +4 -0
  51. geospacelab/datahub/sources/tud/grace_fo/wnd_acc/variable_config.py +73 -0
  52. geospacelab/datahub/sources/tud/swarm/dns_acc/__init__.py +27 -5
  53. geospacelab/datahub/sources/tud/swarm/dns_acc/downloader.py +29 -38
  54. geospacelab/datahub/sources/tud/swarm/dns_pod/__init__.py +24 -5
  55. geospacelab/datahub/sources/tud/swarm/dns_pod/downloader.py +29 -38
  56. geospacelab/datahub/sources/tud/swarm/dns_pod/loader.py +3 -0
  57. geospacelab/datahub/sources/wdc/asysym/downloader.py +2 -2
  58. geospacelab/visualization/mpl/panels.py +7 -3
  59. {geospacelab-0.11.4.dist-info → geospacelab-0.12.0.dist-info}/METADATA +1 -1
  60. {geospacelab-0.11.4.dist-info → geospacelab-0.12.0.dist-info}/RECORD +63 -45
  61. {geospacelab-0.11.4.dist-info → geospacelab-0.12.0.dist-info}/WHEEL +1 -1
  62. {geospacelab-0.11.4.dist-info → geospacelab-0.12.0.dist-info}/licenses/LICENSE +0 -0
  63. {geospacelab-0.11.4.dist-info → geospacelab-0.12.0.dist-info}/top_level.txt +0 -0
@@ -100,6 +100,8 @@ class Dataset(datahub.DatasetSourced):
100
100
  self.omni_res = kwargs.pop('omni_res', '1min')
101
101
  self.data_file_type = kwargs.pop('data_file_type','')
102
102
  self.allow_download = kwargs.pop('allow_download', True)
103
+ self.force_download = kwargs.pop('force_download', False)
104
+ self.download_dry_run = kwargs.pop('download_dry_run', False)
103
105
 
104
106
  self.metadata = None
105
107
 
@@ -165,7 +167,18 @@ class Dataset(datahub.DatasetSourced):
165
167
  '{:4d}'.format(thismonth.year)
166
168
  file_patterns = [
167
169
  self.omni_res,
168
- thismonth.strftime('%Y%m%d')
170
+ thismonth.strftime('%Y%m')
171
+ ]
172
+ elif self.omni_res == '1h':
173
+ initial_file_dir = kwargs.pop('initial_file_dir', None)
174
+ if initial_file_dir is None:
175
+ initial_file_dir = self.data_root_dir / \
176
+ 'OMNI2_low_res_1h' / \
177
+ '{:4d}'.format(thismonth.year)
178
+ file_patterns = [
179
+ 'omni2',
180
+ 'mrg1hr',
181
+ thismonth.strftime('%Y')
169
182
  ]
170
183
  else:
171
184
  raise NotImplementedError
@@ -181,28 +194,27 @@ class Dataset(datahub.DatasetSourced):
181
194
 
182
195
  # Validate file paths
183
196
 
184
- if not done and self.allow_download:
197
+ if (not done and self.allow_download) or (self.force_download):
185
198
  done = self.download_data()
186
199
  if done:
187
200
  done = super().search_data_files(
188
201
  initial_file_dir=initial_file_dir, search_pattern=search_pattern)
189
202
  else:
190
203
  print('Cannot find files from the online database!')
191
-
204
+ if list(self.data_file_paths):
205
+ self.data_file_paths = list(set(self.data_file_paths))
206
+ self.data_file_paths.sort()
192
207
  return done
193
208
 
194
209
  def download_data(self):
195
- if self.data_file_type == 'hres-cdf':
196
- if self.omni_type.upper() == 'OMNI':
197
- new_omni = False
198
- elif self.omni_type.upper() == 'OMNI2':
199
- new_omni = True
200
- download_obj = self.downloader(dt_fr=self.dt_fr, dt_to=self.dt_to,
201
- res=self.omni_res, new_omni=new_omni,
202
- data_file_root_dir=self.data_root_dir)
203
- else:
204
- raise NotImplementedError
205
- return download_obj.done
210
+
211
+ download_obj = self.downloader(
212
+ dt_fr=self.dt_fr, dt_to=self.dt_to,
213
+ time_res=self.omni_res, product=self.omni_type,
214
+ root_dir_local=self.data_root_dir,
215
+ force_download=self.force_download,
216
+ dry_run=self.download_dry_run,)
217
+ return any(download_obj.done)
206
218
 
207
219
  # _validate_IMF_cs = staticmethod(_validate_IMF_cs)
208
220
 
@@ -13,102 +13,115 @@ import datetime
13
13
  import requests
14
14
  import bs4
15
15
  import re
16
+ import pathlib
16
17
 
17
18
  import geospacelab.toolbox.utilities.pydatetime as dttool
18
19
  import geospacelab.toolbox.utilities.pylogging as mylog
19
20
  from geospacelab.config import prf
20
21
 
21
-
22
- class Downloader(object):
23
- def __init__(self, dt_fr, dt_to, res='1min', new_omni=True, data_file_root_dir=None, version=None):
24
- if res == '1h':
25
- new_omni = True
26
- self.dt_fr = dt_fr
27
- self.dt_to = dt_to
28
- self.res = res
29
- self.new_omni = new_omni
22
+ from geospacelab.datahub.sources.cdaweb.downloader import CDAWebHTTPDownloader as DownloaderBase
23
+
24
+
25
+ class Downloader(DownloaderBase):
26
+
27
+ def __init__(
28
+ self,
29
+ dt_fr, dt_to,
30
+ time_res='1min',
31
+ product='OMNI2',
32
+ version='',
33
+ root_dir_local=None,
34
+ direct_download=True,
35
+ force_download=False,
36
+ dry_run=False,
37
+ ):
38
+
39
+ self.time_res = time_res
40
+ self.product = product
30
41
  self.version = version
31
- self.done = False
32
- if data_file_root_dir is None:
33
- self.data_file_root_dir = prf.datahub_data_root_dir / "CDAWeb" / 'OMNI'
34
- else:
35
- self.data_file_root_dir = data_file_root_dir
36
-
37
- self.url_base = "https://cdaweb.gsfc.nasa.gov/pub/data/omni/omni_cdaweb/"
38
-
39
- self.download()
40
-
41
- def download(self):
42
- if self.res in ['1min', '5min']:
43
- self.download_high_res_omni()
44
- elif self.res == '1h':
45
- self.download_low_res_omni()
46
-
47
- def download_high_res_omni(self):
48
- if self.new_omni:
49
- omni_type = "hro2"
50
- omni_dir_name = 'OMNI2'
42
+
43
+ if root_dir_local is None:
44
+ root_dir_local = prf.datahub_data_root_dir / "CDAWeb" / 'OMNI'
51
45
  else:
52
- omni_type = "hro"
53
- omni_dir_name = "OMNI"
54
-
55
- num_month = (self.dt_to.year - self.dt_fr.year) * 12 + self.dt_to.month - self.dt_fr.month + 1
56
- dt0 = datetime.datetime(self.dt_fr.year, self.dt_fr.month, 1)
57
- for nm in range(num_month):
58
- dt1 = dttool.get_next_n_months(dt0, nm)
59
- url = self.url_base + omni_type + '_' + self.res + '/' + '{:4d}'.format(dt1.year) + '/'
60
-
61
- r = requests.get(url)
62
-
63
- soup = bs4.BeautifulSoup(r.text, 'html.parser')
64
- a_tags = soup.find_all('a', href=True)
65
- hrefs = []
66
- for a_tag in a_tags:
67
- href = a_tag['href']
68
- pattern = omni_type + '_' + self.res + '_' + dt1.strftime("%Y%m%d")
69
- if pattern in href:
70
- hrefs.append(href)
71
- if len(hrefs) == 0:
72
- mylog.StreamLogger.info("Cannot find the queried data file!")
73
- return
74
- if len(hrefs) > 1:
75
- mylog.StreamLogger.warning("Find multiple matched files!")
76
- print(hrefs)
77
- return
78
-
79
- href = hrefs[0]
80
- ma = re.search('v[0-5][0-9]', href)
81
- version = ma.group(0)
82
- if self.version is None:
83
- self.version = version
84
- elif self.version != version:
85
- mylog.StreamLogger.info("Cannot find the queried data file! Version={}.".format(version))
86
-
87
- r_file = requests.get(url + href, allow_redirects=True)
88
- file_name = href
89
- file_path = self.data_file_root_dir / (omni_dir_name + '_high_res_' + self.res)
90
- file_path = file_path / '{:4d}'.format(dt1.year) / file_name
91
- if file_path.is_file():
92
- mylog.simpleinfo.info(
93
- "The file {} exists in the directory {}.".format(file_path.name, file_path.parent.resolve()))
94
- else:
95
- file_path.parent.resolve().mkdir(parents=True, exist_ok=True)
96
- with open(file_path, "wb") as omni:
97
- mylog.simpleinfo.info(
98
- "Downloading {} to the directory {} ...".format(file_path.name, file_path.parent.resolve())
99
- )
100
- omni.write(r_file.content)
101
- mylog.simpleinfo.info("Done")
102
- self.done = True
103
-
104
- def download_low_res_omni(self):
105
- raise NotImplemented
46
+ root_dir_local = pathlib.Path(root_dir_local)
47
+ root_dir_remote = '/'.join([
48
+ self.root_dir_remote, 'omni', 'omni_cdaweb'
49
+ ])
50
+ super().__init__(
51
+ dt_fr, dt_to,
52
+ root_dir_local=root_dir_local,
53
+ root_dir_remote=root_dir_remote,
54
+ direct_download=direct_download,
55
+ force_download=force_download,
56
+ dry_run=dry_run,
57
+ )
58
+
59
+ def search_from_http(self, *args, **kwargs):
60
+ dt_fr_1 = self.dt_fr
61
+ dt_to_1 = self.dt_to
62
+ diff_months = (dt_to_1.year - dt_fr_1.year) * 12 + dt_to_1.month - dt_fr_1.month
63
+ file_paths_remote = []
64
+ for nm in range(diff_months + 1):
65
+ this_month = dttool.get_next_n_months(dt_fr_1, nm)
66
+
67
+ subdirs = []
68
+
69
+ if self.time_res in ['1min', '5min']:
70
+ subdirs.append(f'{omni_product_dict[self.product]}_{self.time_res}')
71
+ elif self.time_res == '1h':
72
+ subdirs.append('hourly')
73
+ subdirs.append('{:4d}'.format(this_month.year))
74
+
75
+ if self.time_res in ['1min', '5min',]:
76
+ file_name_patterns = [
77
+ 'omni', omni_product_dict[self.product], self.time_res, this_month.strftime("%Y%m")
78
+ ]
79
+ elif self.time_res == '1h':
80
+ file_name_patterns = [
81
+ 'omni2', 'mrg1hr', this_month.strftime("%Y")
82
+ ]
83
+ if str(self.version):
84
+ file_name_patterns.append(self.version)
85
+
86
+ paths = super().search_from_http(subdirs=subdirs, file_name_patterns=file_name_patterns)
87
+
88
+ if len(paths) > 1 and self.time_res != '1h':
89
+ mylog.StreamLogger.error("Find multiple matched files!")
90
+ print(paths)
91
+
92
+ file_paths_remote.extend(paths)
93
+
94
+ return list(set(file_paths_remote))
95
+
96
+ def save_files_from_http(self, file_paths_local=None, root_dir_remote=None):
97
+
98
+ if file_paths_local is None:
99
+ file_paths_local = []
100
+ for fp_remote in self.file_paths_remote:
101
+ if self.time_res in ['1min', '5min']:
102
+ subdir = f'{self.product}_high_res_{self.time_res}'
103
+ elif self.time_res == '1h':
104
+ subdir = 'OMNI2_low_res_1h'
105
+
106
+ fp_local = fp_remote.replace(self.base_url + '/' + self.root_dir_remote + '/', '')
107
+ pattern_replaced = fp_local.split('/')[0]
108
+ fp_local = fp_local.replace(
109
+ pattern_replaced, subdir, 1
110
+ )
111
+ file_paths_local.append(self.root_dir_local / fp_local)
112
+ return super().save_files_from_http(file_paths_local, root_dir_remote)
113
+
114
+
115
+ omni_product_dict = {
116
+ 'OMNI': 'hro',
117
+ 'OMNI2': 'hro2',
118
+ }
106
119
 
107
120
 
108
121
  def test():
109
122
  dt_fr = datetime.datetime(2020, 3, 4)
110
123
  dt_to = datetime.datetime(2020, 5, 3)
111
- download_obj = Downloader(dt_fr, dt_to)
124
+ download_obj = Downloader(dt_fr, dt_to, force_download=True, time_res='1h')
112
125
  pass
113
126
 
114
127
 
@@ -170,7 +170,7 @@ class Dataset(datahub.DatasetSourced):
170
170
  def add_GEO_LST(self):
171
171
  lons = self['SC_GEO_LON'].flatten()
172
172
  uts = self['SC_DATETIME'].flatten()
173
- lsts = [ut + datetime.timedelta(hours=lon / 15.) for ut, lon in zip(uts, lons)]
173
+ lsts = [ut + datetime.timedelta(seconds=int(lon / 15. * 3600)) for ut, lon in zip(uts, lons)]
174
174
  lsts = [lst.hour + lst.minute / 60. + lst.second / 3600. for lst in lsts]
175
175
  var = self.add_variable(var_name='SC_GEO_LST')
176
176
  var.value = np.array(lsts)[:, np.newaxis]
@@ -33,7 +33,7 @@ class Downloader(DownloaderModel):
33
33
  raise NotImplementedError
34
34
 
35
35
  if ftp_data_dir is None:
36
- ftp_data_dir = f'Advanced/Plasma_Data/{frq_str}_TII_Cross-track_Dataset/Sat_{sat_id.upper()}'
36
+ ftp_data_dir = f'Advanced/Plasma_Data/{frq_str}_TII_Cross-track_Dataset/New_version/Sat_{sat_id.upper()}'
37
37
 
38
38
  if data_file_root_dir is None:
39
39
  data_file_root_dir = prf.datahub_data_root_dir / "ESA" / "SWARM" / "Advanced" / "EFI-TII" / data_type
@@ -104,7 +104,7 @@ class Dataset(datahub.DatasetSourced):
104
104
  import matplotlib.dates as mdates
105
105
  self._variables['Hp'].visual.plot_config.bar['width'] = \
106
106
  (mdates.date2num(datetime.datetime(2000, 1, 1,) + datetime.timedelta(minutes=self.data_res)) \
107
- - mdates.date2num(datetime.datetime(2000, 1, 1))) * 0.9
107
+ - mdates.date2num(datetime.datetime(2000, 1, 1))) * 1
108
108
  self._variables['ap'].config(name=f'Hp{self.data_res}', label=f'ap{self.data_res}')
109
109
  # self.select_beams(field_aligned=True)
110
110
  if self.time_clip:
@@ -60,7 +60,9 @@ plot_config.bar = {
60
60
  'vmin': 0,
61
61
  'vmax': 10,
62
62
  'colormap': cm.cmap_for_kp(),
63
- 'width': mdates.date2num(datetime.datetime(1971, 1, 1, 0, 25)) - mdates.date2num(datetime.datetime(1971, 1, 1, 0))
63
+ 'align': 'center',
64
+ 'width': 1.
65
+ # 'width': mdates.date2num(datetime.datetime(1971, 1, 1, 0, 25)) - mdates.date2num(datetime.datetime(1971, 1, 1, 0))
64
66
  }
65
67
  # set axis attrs
66
68
  axis = var.visual.axis
@@ -183,7 +183,7 @@ class Loader:
183
183
  if var_name == 'nel':
184
184
  vars_fh5['ne'] = 10**np.array(fh5_vars_2d[var_name]).T
185
185
  elif var_name == 'dnel':
186
- vars_fh5['dne'] = 10 ** np.array(fh5_vars_2d[var_name]).T
186
+ vars_fh5['dne'] = 10**np.array(fh5_vars_2d[var_name]).T
187
187
  else:
188
188
  arr = np.array(fh5_vars_2d[var_name]).T
189
189
 
@@ -36,7 +36,8 @@ data_type_dict = {
36
36
  's4': 'plasma temp',
37
37
  'e': 'flux/energy',
38
38
  'ssies2': 'SSIES-2',
39
- 'hp': 'Hemispherical power'
39
+ 'hp': 'Hemispherical power',
40
+ 'ssies3': 'SSIES-3'
40
41
  }
41
42
 
42
43
 
@@ -25,7 +25,7 @@ default_dataset_attrs = {
25
25
  'instrument': 'ACC',
26
26
  'product': 'DNS-ACC',
27
27
  'data_file_ext': 'txt',
28
- 'product_version': 'v01',
28
+ 'product_version': 'v02',
29
29
  'data_root_dir': prf.datahub_data_root_dir / 'TUD' / 'CHAMP',
30
30
  'allow_load': True,
31
31
  'allow_download': True,
@@ -47,7 +47,19 @@ default_variable_names_v01 = [
47
47
  'SC_GEO_LST',
48
48
  'rho_n',
49
49
  ]
50
- default_variable_names_v02 = []
50
+ default_variable_names_v02 = [
51
+ 'SC_DATETIME',
52
+ 'SC_GEO_LAT',
53
+ 'SC_GEO_LON',
54
+ 'SC_GEO_ALT',
55
+ 'SC_ARG_LAT',
56
+ 'SC_GEO_LST',
57
+ 'rho_n',
58
+ 'rho_n_MEAN',
59
+ 'FLAG',
60
+ 'FLAG_MEAN',
61
+ ]
62
+
51
63
 
52
64
  # default_data_search_recursive = True
53
65
 
@@ -64,10 +76,12 @@ class Dataset(datahub.DatasetSourced):
64
76
  self.facility = kwargs.pop('facility', 'CHAMP')
65
77
  self.instrument = kwargs.pop('instrument', 'ACC')
66
78
  self.product = kwargs.pop('product', 'DNS-ACC')
67
- self.product_version = kwargs.pop('product_version', 'v01')
79
+ self.product_version = kwargs.pop('product_version', 'v02')
68
80
  self.local_latest_version = ''
69
81
  self.allow_download = kwargs.pop('allow_download', False)
70
82
  self.force_download = kwargs.pop('force_download', False)
83
+ self.download_dry_run = kwargs.pop('download_dry_run', False)
84
+
71
85
  self.add_AACGM = kwargs.pop('add_AACGM', False)
72
86
  self.add_APEX = kwargs.pop('add_APEX', False)
73
87
  self._data_root_dir = self.data_root_dir # Record the initial root dir
@@ -195,7 +209,9 @@ class Dataset(datahub.DatasetSourced):
195
209
  file_patterns = [
196
210
  'CH',
197
211
  self.product.upper().replace('-', '_'),
198
- this_day.strftime('%Y_%m'),
212
+ this_day.strftime('%Y'),
213
+ this_day.strftime('%m'),
214
+ self.product_version,
199
215
  ]
200
216
  # remove empty str
201
217
  file_patterns = [pattern for pattern in file_patterns if str(pattern)]
@@ -217,7 +233,7 @@ class Dataset(datahub.DatasetSourced):
217
233
  search_pattern=search_pattern,
218
234
  allow_multiple_files=False
219
235
  )
220
-
236
+ self.data_file_paths = np.unique(self.data_file_paths)
221
237
  return done
222
238
 
223
239
  def download_data(self, dt_fr=None, dt_to=None):
@@ -229,10 +245,11 @@ class Dataset(datahub.DatasetSourced):
229
245
  dt_fr, dt_to,
230
246
  product=self.product,
231
247
  version=self.product_version,
232
- force=self.force_download
248
+ force_download=self.force_download,
249
+ dry_run=self.download_dry_run
233
250
  )
234
251
 
235
- return download_obj.done
252
+ return any(download_obj.done)
236
253
 
237
254
  @property
238
255
  def database(self):
@@ -8,42 +8,35 @@ __license__ = "BSD-3-Clause License"
8
8
  __email__ = "lei.cai@oulu.fi"
9
9
  __docformat__ = "reStructureText"
10
10
 
11
+ import datetime
11
12
  from geospacelab.config import prf
12
13
 
13
- from geospacelab.datahub.sources.tud.downloader import Downloader as DownloaderModel
14
-
15
-
16
- class Downloader(DownloaderModel):
17
-
18
- def __init__(
19
- self, dt_fr, dt_to,
20
- product='DNS-ACC',
21
- version='v01',
22
- force=True, direct_download=True, **kwargs
23
- ):
24
- if version == 'v01':
25
- v_str = "version_01"
26
- elif version == 'v02':
27
- raise NotImplementedError
28
- else:
29
- raise NotImplementedError
30
- data_file_root_dir = prf.datahub_data_root_dir / "TUD" / "CHAMP" / product.upper() / version
31
- ftp_data_dir = f'{v_str}/CHAMP_data'
32
- file_name_patterns = ['CH', product.replace('-', '_')]
33
- super(Downloader, self).__init__(
34
- dt_fr, dt_to,
35
- data_file_root_dir=data_file_root_dir, ftp_data_dir=ftp_data_dir, force=force,
36
- direct_download=direct_download, file_name_patterns=file_name_patterns, **kwargs
14
+ from geospacelab.datahub.sources.tud.downloader import TUDownloader as DownloaderBase
15
+
16
+
17
+ class Downloader(DownloaderBase):
18
+
19
+ def __init__(self,
20
+ dt_fr, dt_to,
21
+ mission='CHAMP',
22
+ sat_id='',
23
+ version='v02',
24
+ product='DNS-ACC',
25
+ direct_download=True,
26
+ force_download=False,
27
+ dry_run=False,
28
+ ):
29
+ self.mission = mission
30
+ self.version = version
31
+
32
+ super().__init__(
33
+ dt_fr, dt_to,
34
+ mission=mission,
35
+ sat_id=sat_id,
36
+ version=version,
37
+ product=product,
38
+ direct_download=direct_download,
39
+ force_download=force_download,
40
+ dry_run=dry_run
37
41
  )
38
-
39
- def download(self, **kwargs):
40
-
41
- done = super(Downloader, self).download(**kwargs)
42
- return done
43
-
44
- def search_files(self, **kwargs):
45
-
46
- file_list = super(Downloader, self).search_files(**kwargs)
47
-
48
- return file_list
49
- # version control
42
+
@@ -30,7 +30,7 @@ class Loader(object):
30
30
  if self.version == 'v01':
31
31
  self.load_v01()
32
32
  elif self.version == 'v02':
33
- raise NotImplementedError
33
+ self.load_v02()
34
34
  else:
35
35
  raise NotImplementedError
36
36
 
@@ -57,4 +57,30 @@ class Loader(object):
57
57
  self.variables['SC_GEO_LST'] = np.array(results[5]).astype(np.float32).reshape(num_rec, 1)
58
58
  self.variables['SC_ARG_LAT'] = np.array(results[6]).astype(np.float32).reshape(num_rec, 1)
59
59
  self.variables['rho_n'] = np.array(results[7]).astype(np.float32).reshape(num_rec, 1)
60
-
60
+
61
+ def load_v02(self):
62
+ with open(self.file_path, 'r') as f:
63
+ text = f.read()
64
+ results = re.findall(
65
+ r"^(\d{4}-\d{2}-\d{2}\s*\d{2}\:\d{2}\:\d{2}\.\d{3})\s*(\w{3})\s*"
66
+ + r"([\-\d.]+)\s*([\-\d.]+)\s*([\-\d.]+)\s*([\-\d.]+)\s*([\-\d.]+)\s*([+\-\d.Ee]+)\s*([+\-\d.Ee]+)\s*([\-\d.]+)\s*([\-\d.]+)",
67
+ text,
68
+ re.M)
69
+ results = list(zip(*results))
70
+ dts = [datetime.datetime.strptime(dtstr + '000', "%Y-%m-%d %H:%M:%S.%f") for dtstr in results[0]]
71
+ num_rec = len(dts)
72
+ if results[1][0] == 'GPS':
73
+ self.variables['SC_GPSTIME'] = np.array(dts).reshape(num_rec, 1)
74
+ t_gps = [(dt - dttool._GPS_DATETIME_0).total_seconds() for dt in dts]
75
+ dts = dttool.convert_gps_time_to_datetime(t_gps, weeks=None)
76
+
77
+ self.variables['SC_DATETIME'] = np.array(dts).reshape(num_rec, 1)
78
+ self.variables['SC_GEO_ALT'] = np.array(results[2]).astype(np.float32).reshape(num_rec, 1) * 1e-3 # in km
79
+ self.variables['SC_GEO_LON'] = np.array(results[3]).astype(np.float32).reshape(num_rec, 1)
80
+ self.variables['SC_GEO_LAT'] = np.array(results[4]).astype(np.float32).reshape(num_rec, 1)
81
+ self.variables['SC_GEO_LST'] = np.array(results[5]).astype(np.float32).reshape(num_rec, 1)
82
+ self.variables['SC_ARG_LAT'] = np.array(results[6]).astype(np.float32).reshape(num_rec, 1)
83
+ self.variables['rho_n'] = np.array(results[7]).astype(np.float32).reshape(num_rec, 1)
84
+ self.variables['rho_n_MEAN'] = np.array(results[8]).astype(np.float32).reshape(num_rec, 1)
85
+ self.variables['FLAG'] = np.array(results[9]).astype(np.float32).reshape(num_rec, 1)
86
+ self.variables['FLAG_MEAN'] = np.array(results[10]).astype(np.float32).reshape(num_rec, 1)