cdasws 1.8.5__py3-none-any.whl → 1.8.7__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.
cdasws/__init__.py CHANGED
@@ -137,7 +137,7 @@ except ImportError:
137
137
  CDF_XARRAY_AVAILABLE = False
138
138
 
139
139
 
140
- __version__ = "1.8.5"
140
+ __version__ = "1.8.7"
141
141
 
142
142
 
143
143
  #
@@ -282,7 +282,8 @@ class CdasWs:
282
282
  self._user_agent += ' (' + user_agent + ')'
283
283
 
284
284
  self._request_headers = {
285
- 'Content-Type' : 'application/json',
285
+ #'Content-Type' : 'application/json',
286
+ 'Content-Type' : 'application/xml',
286
287
  'Accept' : 'application/xml',
287
288
  'User-Agent' : self._user_agent,
288
289
  #'Accept-Encoding' : 'gzip' # only beneficial for icdfml responses
@@ -729,17 +730,21 @@ class CdasWs:
729
730
  interval. See module note about timezone value. If this
730
731
  parameter is omitted, the time interval will end infinitely
731
732
  in the future.<br>
733
+ <b>id</b> - a dataset identifier. The value may be a CDAS
734
+ (e.g., AC_H2_MFI), DOI (e.g., 10.48322/fh85-fj47), or SPASE
735
+ [ResourceID] (e.g., spase://NASA/NumericalData/ACE/MAG/L2/PT1H)
736
+ identifier. If specified, all other keywords are ignored.<br>
732
737
  <b>idPattern</b> - a java.util.regex compatible regular
733
- expression that must match the dataset's identifier value.
738
+ expression that must match the dataset's CDAS identifier value.
734
739
  Omitting this parameter is equivalent to `.*`.<br>
735
740
  <b>labelPattern</b> - a java.util.regex compatible regular
736
- expression that must match the dataset's label text.
741
+ expression that must match the dataset's CDAS label text.
737
742
  Omitting this parameter is equivalent to `.*`. Embedded
738
743
  matching flag expressions (e.g., `(?i)` for case insensitive
739
744
  match mode) are supported and likely to be useful in this
740
745
  case.<br>
741
746
  <b>notesPattern</b> - a java.util.regex compatible regular
742
- expression that must match the dataset's notes text.
747
+ expression that must match the dataset's CDAS notes text.
743
748
  Omitting this parameter is equivalent to `.*`. Embedded
744
749
  matching flag expressions (e.g., `(?s)` for dotall match mode)
745
750
  are supported and likely to be useful in this case.<br>
@@ -793,6 +798,10 @@ class CdasWs:
793
798
  url = url + 'stopDate=' \
794
799
  + urllib.parse.quote(keywords['stopDate']) + '&'
795
800
 
801
+ if 'id' in keywords:
802
+ url = url + 'id=' \
803
+ + urllib.parse.quote(keywords['id']) + '&'
804
+
796
805
  if 'idPattern' in keywords:
797
806
  url = url + 'idPattern=' \
798
807
  + urllib.parse.quote(keywords['idPattern']) + '&'
@@ -1324,12 +1333,14 @@ class CdasWs:
1324
1333
  CdasWs.get_data
1325
1334
  """
1326
1335
 
1327
- self.logger.debug('data_request = %s', data_request.json())
1336
+ #self.logger.debug('data_request = %s', data_request.json())
1337
+ self.logger.debug('data_request = %s', data_request.xml_str())
1328
1338
 
1329
1339
  url = self._endpoint + 'datasets'
1330
1340
 
1331
1341
  for retries in range(RETRY_LIMIT):
1332
- response = self._session.post(url, data=data_request.json(),
1342
+ #response = self._session.post(url, data=data_request.json(),
1343
+ response = self._session.post(url, data=data_request.xml_str(),
1333
1344
  timeout=self._timeout)
1334
1345
 
1335
1346
  if response.status_code == 200:
cdasws/__main__.py CHANGED
@@ -202,7 +202,7 @@ def example(
202
202
  # 'interpolateMissingValues': True,
203
203
  # 'sigmaMultiplier': 4,
204
204
  # 'overrideDefaultBinning': True
205
- #}
205
+ #},
206
206
  dataRepresentation=DataRepresentation.SPACEPY
207
207
  )
208
208
  # cdas.get_data('10.21978/P8PG8V', ['BT'],
cdasws/datarequest.py CHANGED
@@ -44,8 +44,10 @@ the United States under Title 17, U.S.Code. All Other Rights Reserved.
44
44
 
45
45
  import enum
46
46
  import json
47
+ import xml.etree.ElementTree as ET
47
48
  from typing import List, Union # when python 3.8 , TypedDict
48
49
  from abc import ABCMeta, abstractmethod
50
+ #from cdasws import NS
49
51
  from cdasws.timeinterval import TimeInterval
50
52
 
51
53
 
@@ -117,6 +119,14 @@ class DataRequest(metaclass=ABCMeta): # pylint: disable=too-few-public-methods
117
119
  Creates an object representing a DataRequestEntity from
118
120
  <https://cdaweb.gsfc.nasa.gov/WebServices/REST/CDAS.xsd>.
119
121
 
122
+ Notes
123
+ -----
124
+ This class was originally written with serialization to JSON
125
+ in mind so some dict key values are the JSON representations.
126
+ For example, Start/End key values are strings instead of
127
+ datetimes. These value data type choices cause extra code
128
+ for serialization to XML.
129
+
120
130
  Parameters
121
131
  ----------
122
132
  request_type
@@ -180,6 +190,170 @@ class DataRequest(metaclass=ABCMeta): # pylint: disable=too-few-public-methods
180
190
  bin_data['overrideDefaultBinning']
181
191
 
182
192
 
193
+ # pylint: disable=too-many-locals
194
+ # pylint: disable=too-many-branches
195
+ # pylint: disable=too-many-statements
196
+ def xml_element(self) -> ET:
197
+ """
198
+ Produces the XML Element representation of this object.
199
+
200
+ Returns
201
+ -------
202
+ ET
203
+ XML Element representation of this object.
204
+ """
205
+
206
+ #attrs = {'xmlns': NS}
207
+ attrs = {'xmlns': 'http://cdaweb.gsfc.nasa.gov/schema'}
208
+
209
+ builder = ET.TreeBuilder()
210
+ builder.start('DataRequest', attrs)
211
+ request_name = next(iter(self._data_request))
212
+ builder.start(request_name, {})
213
+ data_request = self._data_request[request_name]
214
+ time_intervals = data_request['TimeInterval']
215
+ if isinstance(time_intervals, list):
216
+ for time_interval in time_intervals:
217
+ start = time_interval['Start']
218
+ end = time_interval['End']
219
+ TimeInterval(start, end).xml_element(builder)
220
+ else:
221
+ start = time_intervals['Start']
222
+ end = time_intervals['End']
223
+ TimeInterval(start, end).xml_element(builder)
224
+
225
+ builder.start('DatasetRequest', {})
226
+ dataset_request = data_request['DatasetRequest']
227
+ builder.start('DatasetId', {})
228
+ builder.data(dataset_request['DatasetId'])
229
+ builder.end('DatasetId')
230
+ variable_names = dataset_request['VariableName']
231
+ if isinstance(variable_names, list):
232
+ for variable_name in variable_names:
233
+ builder.start('VariableName', {})
234
+ builder.data(variable_name)
235
+ builder.end('VariableName')
236
+ else:
237
+ builder.start('VariableName', {})
238
+ builder.data(variable_names)
239
+ builder.end('VariableName')
240
+ builder.end('DatasetRequest')
241
+ if 'CdfVersion' in data_request:
242
+ builder.start('CdfVersion', {})
243
+ builder.data(str(data_request['CdfVersion']))
244
+ builder.end('CdfVersion')
245
+ if 'CdfFormat' in data_request:
246
+ builder.start('CdfFormat', {})
247
+ builder.data(data_request['CdfFormat'])
248
+ builder.end('CdfFormat')
249
+ if 'Compression' in data_request:
250
+ builder.start('Compression', {})
251
+ builder.data(data_request['Compression'])
252
+ builder.end('Compression')
253
+ if 'Format' in data_request:
254
+ builder.start('Format', {})
255
+ builder.data(data_request['Format'])
256
+ builder.end('Format')
257
+ if 'Thumbnail' in data_request:
258
+ builder.start('Thumbnail', {})
259
+ builder.data(str(data_request['Thumbnail']))
260
+ builder.end('Thumbnail')
261
+ if 'ThumbnailId' in data_request:
262
+ builder.start('ThumbnailId', {})
263
+ builder.data(data_request['ThumbnailId'])
264
+ builder.end('ThumbnailId')
265
+ if 'GraphOptions' in data_request:
266
+ graph_options = data_request['GraphOptions']
267
+ builder.start('GraphOptions', {})
268
+ if 'CoarseNoiseFilter' in graph_options:
269
+ builder.start('CoarseNoiseFilter', {})
270
+ builder.data(graph_options['CoarseNoiseFilter'])
271
+ builder.end('CoarseNoiseFilter')
272
+ if 'XAxisWidthFactor' in graph_options:
273
+ builder.start('XAxisWidthFactor', {})
274
+ builder.data(str(graph_options['XAxisWidthFactor']))
275
+ builder.end('XAxisWidthFactor')
276
+ if 'YAxisHeightFactor' in graph_options:
277
+ builder.start('YAxisHeightFactor', {})
278
+ builder.data(str(graph_options['YAxisHeightFactor']))
279
+ builder.end('YAxisHeightFactor')
280
+ if 'Combine' in graph_options:
281
+ builder.start('Combine', {})
282
+ builder.data(str(graph_options['Combine']).lower())
283
+ builder.end('Combine')
284
+ if 'Overplot' in graph_options:
285
+ builder.start('Overplot', {})
286
+ builder.data(str(graph_options['Overplot']))
287
+ builder.end('Overplot')
288
+ builder.end('GraphOptions')
289
+ if 'GraphOption' in data_request:
290
+ graph_options = data_request['GraphOption']
291
+ if isinstance(graph_options, list):
292
+ for graph_option in graph_options:
293
+ builder.start('GraphOption', {})
294
+ builder.data(graph_option)
295
+ builder.end('GraphOption')
296
+ else:
297
+ builder.start('GraphOption', {})
298
+ builder.data(graph_option)
299
+ builder.end('GraphOption')
300
+ if 'ImageFormat' in data_request:
301
+ image_formats = data_request['ImageFormat']
302
+ if isinstance(image_formats, list):
303
+ for image_format in image_formats:
304
+ builder.start('ImageFormat', {})
305
+ builder.data(image_format)
306
+ builder.end('ImageFormat')
307
+ else:
308
+ builder.start('ImageFormat', {})
309
+ builder.data(data_request['ImageFormat'])
310
+ builder.end('ImageFormat')
311
+ if 'BinData' in data_request:
312
+ bin_data = data_request['BinData']
313
+ builder.start('BinData', {})
314
+ if 'Interval' in bin_data:
315
+ builder.start('Interval', {})
316
+ builder.data(str(bin_data['Interval']))
317
+ builder.end('Interval')
318
+ if 'InterpolateMissingValues' in bin_data:
319
+ builder.start('InterpolateMissingValues', {})
320
+ builder.data(str(bin_data['InterpolateMissingValues']).lower())
321
+ builder.end('InterpolateMissingValues')
322
+ if 'SigmaMultiplier' in bin_data:
323
+ builder.start('SigmaMultiplier', {})
324
+ builder.data(str(bin_data['SigmaMultiplier']))
325
+ builder.end('SigmaMultiplier')
326
+ if 'OverrideDefaultBinning' in bin_data:
327
+ builder.start('OverrideDefaultBinning', {})
328
+ builder.data(str(bin_data['OverrideDefaultBinning']).lower())
329
+ builder.end('OverrideDefaultBinning')
330
+ builder.end('BinData')
331
+ builder.end(request_name)
332
+ builder.end('DataRequest')
333
+ xml_element = builder.close()
334
+
335
+ return xml_element
336
+ # pylint: enable=too-many-locals
337
+ # pylint: enable=too-many-branches
338
+ # pylint: enable=too-many-statements
339
+
340
+
341
+ def xml_str(self) -> str:
342
+ """
343
+ Produces an str xml representation of this object matching the
344
+ XML representation of a DataRequestEntity from
345
+ <https://cdaweb.gsfc.nasa.gov/WebServices/REST/CDAS.xsd>.
346
+
347
+ Returns
348
+ -------
349
+ str
350
+ string XML representation of this object.
351
+ """
352
+
353
+ #return ET.tostring(self.xml_element(), encoding="utf-8", method='xml', xml_declaration=True)
354
+ return ET.tostring(self.xml_element(), encoding="utf-8", method='xml')
355
+
356
+
183
357
  def json(self, **keywords) -> str:
184
358
  """
185
359
  Produces a JSON representation of this object matching the
@@ -632,6 +806,7 @@ class ThumbnailRequest(DataRequest): # pylint: disable=too-few-public-methods
632
806
  i_format.value)
633
807
 
634
808
 
809
+
635
810
  class AudioRequest(DataRequest): # pylint: disable=too-few-public-methods
636
811
  """
637
812
  Class representing an AudioRequest from
cdasws/timeinterval.py CHANGED
@@ -41,6 +41,8 @@ the United States under Title 17, U.S.Code. All Other Rights Reserved.
41
41
  """
42
42
 
43
43
 
44
+ import xml.etree.ElementTree as ET
45
+ from xml.etree.ElementTree import TreeBuilder
44
46
  from datetime import datetime, timezone
45
47
  from typing import Tuple, Union
46
48
  import dateutil.parser
@@ -132,6 +134,53 @@ class TimeInterval:
132
134
  self._end = TimeInterval.get_datetime(value)
133
135
 
134
136
 
137
+ def xml_element(self,
138
+ builder: TreeBuilder = None) -> ET:
139
+ """
140
+ Produces the XML Element representation of this object.
141
+
142
+ Parameters
143
+ ----------
144
+ builder
145
+ The TreeBuilder to use.
146
+
147
+ Returns
148
+ -------
149
+ ET
150
+ XML Element representation of this object.
151
+ """
152
+
153
+ if builder is None:
154
+ builder = ET.TreeBuilder()
155
+
156
+ builder.start('TimeInterval', {})
157
+ builder.start('Start', {})
158
+ builder.data(self._start.isoformat().replace('+00:00', '.000Z'))
159
+ builder.end('Start')
160
+ builder.start('End', {})
161
+ builder.data(self._end.isoformat().replace('+00:00', '.000Z'))
162
+ builder.end('End')
163
+
164
+ return builder.end('TimeInterval')
165
+
166
+
167
+ def xml_str(self) -> str:
168
+ """
169
+ Produces an str xml representation of this object matching the
170
+ XML representation of a DataRequestEntity from
171
+ <https://cdaweb.gsfc.nasa.gov/WebServices/REST/CDAS.xsd>.
172
+
173
+ Returns
174
+ -------
175
+ str
176
+ string XML representation of this object.
177
+ """
178
+
179
+ #return ET.tostring(self.xml_element(), encoding="utf-8", method='xml',
180
+ # xml_declaration=True)
181
+ return ET.tostring(self.xml_element(), encoding="utf-8", method='xml')
182
+
183
+
135
184
  def __str__(self):
136
185
  return self._start.isoformat() + ' ' + self._end.isoformat()
137
186
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cdasws
3
- Version: 1.8.5
3
+ Version: 1.8.7
4
4
  Summary: NASA's Coordinated Data Analysis System Web Service Client Library
5
5
  Home-page: https://cdaweb.gsfc.nasa.gov/WebServices/REST
6
6
  Author: Bernie Harris
@@ -14,9 +14,8 @@ Classifier: Environment :: Web Environment
14
14
  Classifier: Intended Audience :: End Users/Desktop
15
15
  Classifier: Intended Audience :: Developers
16
16
  Classifier: Intended Audience :: System Administrators
17
- Classifier: Operating System :: MacOS :: MacOS X
18
- Classifier: Operating System :: Microsoft :: Windows
19
- Classifier: Operating System :: POSIX
17
+ Classifier: License :: OSI Approved :: NASA Open Source Agreement v1.3 (NASA-1.3)
18
+ Classifier: Operating System :: OS Independent
20
19
  Classifier: Programming Language :: Python
21
20
  Classifier: Topic :: Scientific/Engineering :: Physics
22
21
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
@@ -0,0 +1,13 @@
1
+ cdasws/__init__.py,sha256=8__wjJd-f5a8EE_k3Q9kWyPuwEdlK0TSOjkw1IJIJpU,91733
2
+ cdasws/__main__.py,sha256=9-S-Zh4sRMtcJRg-YELX_HjN8Q74cZiekZ1MLF51bls,12553
3
+ cdasws/cdasws.py,sha256=755mLWlMFXknNP3f8g_W9An6niAmksqcb1NdgiAybj0,29552
4
+ cdasws/datarepresentation.py,sha256=kKgAKCA4uzGoBQ8r8jbXstBg8SCg_EQtsoGhO8kIpco,2164
5
+ cdasws/datarequest.py,sha256=fQVroT8RXYhJLG7_y-HO3ABnJUQJjWGFPeLNrtwbWtk,29080
6
+ cdasws/timeinterval.py,sha256=ajWPkjBnUppFRXMLQiF5L1L3RYYjRqbUGThXIi9YKg8,7815
7
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ tests/test_cdasws.py,sha256=DsKesU19_9zUIO1a7oyWWtywBGN7gjdQHFLMGUZ4X8c,24395
9
+ cdasws-1.8.7.dist-info/LICENSE,sha256=og42scUY42lPLGBg0wHt6JtrbeInVEr5xojyrguPqrQ,12583
10
+ cdasws-1.8.7.dist-info/METADATA,sha256=iE_iYWN2sybYeMn8LlzSVVZVyLwLOi0x1A5GyuE66kU,5733
11
+ cdasws-1.8.7.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
12
+ cdasws-1.8.7.dist-info/top_level.txt,sha256=GyIvHk5F6ysnTdDfnQsjZbTBt_EYrKyC0oeiIt9l-AE,7
13
+ cdasws-1.8.7.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- cdasws/__init__.py,sha256=GSsIndi0QVibnlnrScOpV66LVstYcvZluNsHpU8ebRc,91107
2
- cdasws/__main__.py,sha256=odblrsfHMXcovTQQ50xdYM3ubxOH6IMaiurjUDWsOS0,12552
3
- cdasws/cdasws.py,sha256=755mLWlMFXknNP3f8g_W9An6niAmksqcb1NdgiAybj0,29552
4
- cdasws/datarepresentation.py,sha256=kKgAKCA4uzGoBQ8r8jbXstBg8SCg_EQtsoGhO8kIpco,2164
5
- cdasws/datarequest.py,sha256=mRzQKAld1O-8O83IT6XBXnRmKbpf5K_oLi3sOmQzeVs,21737
6
- cdasws/timeinterval.py,sha256=677SULpzclE4XqFuU4_SjZLVCZKlQKa2ekvswnmDVkU,6392
7
- tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- tests/test_cdasws.py,sha256=DsKesU19_9zUIO1a7oyWWtywBGN7gjdQHFLMGUZ4X8c,24395
9
- cdasws-1.8.5.dist-info/LICENSE,sha256=og42scUY42lPLGBg0wHt6JtrbeInVEr5xojyrguPqrQ,12583
10
- cdasws-1.8.5.dist-info/METADATA,sha256=oc9FXpYcLYKuHpYEu-gQMaBjS8yOT9sB1jiNvAJKuO0,5744
11
- cdasws-1.8.5.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
12
- cdasws-1.8.5.dist-info/top_level.txt,sha256=GyIvHk5F6ysnTdDfnQsjZbTBt_EYrKyC0oeiIt9l-AE,7
13
- cdasws-1.8.5.dist-info/RECORD,,
File without changes