cdasws 1.8.9__py3-none-any.whl → 1.8.11__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
@@ -24,7 +24,7 @@
24
24
  #
25
25
  # NOSA HEADER END
26
26
  #
27
- # Copyright (c) 2018-2024 United States Government as represented by
27
+ # Copyright (c) 2018-2025 United States Government as represented by
28
28
  # the National Aeronautics and Space Administration. No copyright is
29
29
  # claimed in the United States under Title 17, U.S.Code. All Other
30
30
  # Rights Reserved.
@@ -35,7 +35,7 @@
35
35
  Package for accessing the Coordinate Data Analysis System (CDAS)
36
36
  web services <https://cdaweb.gsfc.nasa.gov/WebServices/REST/>.<br>
37
37
 
38
- Copyright &copy; 2018-2024 United States Government as represented by the
38
+ Copyright &copy; 2018-2025 United States Government as represented by the
39
39
  National Aeronautics and Space Administration. No copyright is claimed in
40
40
  the United States under Title 17, U.S.Code. All Other Rights Reserved.
41
41
 
@@ -102,7 +102,7 @@ try:
102
102
  except ImportError:
103
103
  try:
104
104
  import cdflib as cdf
105
- import xarray as xr
105
+ import xarray as xr # pylint: disable=ungrouped-imports
106
106
  CDF_XARRAY_AVAILABLE = True
107
107
  def cdf_to_xarray(filename, to_datetime=False, to_unixtime=False,
108
108
  fillval_to_nan=False):
@@ -130,14 +130,21 @@ except ImportError:
130
130
  xarray.dataset
131
131
  An XArray Dataset object.
132
132
  """
133
- return cdf.cdf_to_xarray(filename, to_datetime=to_datetime,
133
+ return cdf.cdf_to_xarray(filename, to_datetime=to_datetime, # pylint: disable=no-member
134
134
  to_unixtime=to_unixtime,
135
135
  fillval_to_nan=fillval_to_nan)
136
136
  except ImportError:
137
137
  CDF_XARRAY_AVAILABLE = False
138
138
 
139
139
 
140
- __version__ = "1.8.9"
140
+ try:
141
+ import requests_cache
142
+ CACHE_AVAILABLE = True
143
+ except ImportError:
144
+ CACHE_AVAILABLE = False
145
+
146
+
147
+ __version__ = "1.8.11"
141
148
 
142
149
 
143
150
  #
@@ -231,7 +238,8 @@ class CdasWs:
231
238
  proxy=None,
232
239
  ca_certs=None,
233
240
  disable_ssl_certificate_validation=False,
234
- user_agent=None):
241
+ user_agent=None,
242
+ disable_cache=False):
235
243
  """
236
244
  Creates an object representing the CDAS web services.
237
245
 
@@ -259,6 +267,8 @@ class CdasWs:
259
267
  Flag indicating whether to validate the SSL certificate.
260
268
  user_agent
261
269
  A value that is appended to the HTTP User-Agent value.
270
+ disable_cache
271
+ Flag indicating whether to disable HTTP caching.
262
272
  """
263
273
 
264
274
  self.logger = logging.getLogger(type(self).__name__)
@@ -268,6 +278,7 @@ class CdasWs:
268
278
  self.logger.debug('ca_certs = %s', ca_certs)
269
279
  self.logger.debug('disable_ssl_certificate_validation = %s',
270
280
  disable_ssl_certificate_validation)
281
+ self.logger.debug('disable_cache = %s', disable_cache)
271
282
 
272
283
  if endpoint is None:
273
284
  self._endpoint = 'https://cdaweb.gsfc.nasa.gov/WS/cdasr/1/dataviews/sp_phys/'
@@ -288,7 +299,12 @@ class CdasWs:
288
299
  'User-Agent' : self._user_agent,
289
300
  #'Accept-Encoding' : 'gzip' # only beneficial for icdfml responses
290
301
  }
291
- self._session = requests.Session()
302
+ if CACHE_AVAILABLE and disable_cache is not True:
303
+ self._session = requests_cache.CachedSession('cdasws_cache',
304
+ cache_control=True)
305
+ else:
306
+ self._session = requests.Session()
307
+
292
308
  self._session.headers.update(self._request_headers)
293
309
  self._session.auth = NullAuth()
294
310
 
@@ -961,7 +977,8 @@ class CdasWs:
961
977
 
962
978
  url = 'https://doi.org/' + doi
963
979
  headers = {'Accept': 'text/x-bibliography; style=apa'}
964
- response = requests.get(url, headers=headers)
980
+ response = requests.get(url, headers=headers,
981
+ timeout=30)
965
982
 
966
983
  return response.text
967
984
 
cdasws/__main__.py CHANGED
@@ -24,7 +24,7 @@
24
24
  #
25
25
  # NOSA HEADER END
26
26
  #
27
- # Copyright (c) 2018-2024 United States Government as represented by
27
+ # Copyright (c) 2018-2025 United States Government as represented by
28
28
  # the National Aeronautics and Space Administration. No copyright is
29
29
  # claimed in the United States under Title 17, U.S.Code. All Other
30
30
  # Rights Reserved.
@@ -34,7 +34,7 @@
34
34
  Example Coordinate Data Analysis System (CDAS) web service client.
35
35
  Includes example calls to most of the web services.
36
36
 
37
- Copyright &copy; 2018-2024 United States Government as represented by the
37
+ Copyright &copy; 2018-2025 United States Government as represented by the
38
38
  National Aeronautics and Space Administration. No copyright is claimed in
39
39
  the United States under Title 17, U.S.Code. All Other Rights Reserved.
40
40
  """
@@ -42,6 +42,7 @@ the United States under Title 17, U.S.Code. All Other Rights Reserved.
42
42
  import sys
43
43
  import getopt
44
44
  import json
45
+ import time
45
46
  import logging
46
47
  import logging.config
47
48
  from typing import List
@@ -56,7 +57,7 @@ from cdasws.datarepresentation import DataRepresentation
56
57
  logging.basicConfig()
57
58
  LOGGING_CONFIG_FILE = 'logging_config.json'
58
59
  try:
59
- with open(LOGGING_CONFIG_FILE, 'r') as fd:
60
+ with open(LOGGING_CONFIG_FILE, 'r', encoding='utf-8') as fd:
60
61
  logging.config.dictConfig(json.load(fd))
61
62
  except BaseException as exc: # pylint: disable=broad-except
62
63
  if not isinstance(exc, FileNotFoundError):
@@ -85,9 +86,10 @@ def print_usage(
85
86
  -------
86
87
  None
87
88
  """
88
- print('USAGE: {name} [-e url][-d][-c cacerts][-h]'.format(name=name))
89
+ print(f'USAGE: {name} [-e url][-d][-c cacerts][-n][-h]')
89
90
  print('WHERE: url = CDAS web service endpoint URL')
90
91
  print(' -d disables TLS server certificate validation')
92
+ print(' -n disables the use of http caching')
91
93
  print(' cacerts = CA certificate filename')
92
94
 
93
95
 
@@ -108,13 +110,14 @@ def example(
108
110
  containing the CA certificates to use.<br>
109
111
  -d or --disable-cert-check to disable verification of the server's
110
112
  certificate
113
+ -n or --nocache disables the use of http caching
111
114
  -h or --help prints help information.
112
115
  """
113
116
 
114
117
  try:
115
- opts = getopt.getopt(argv[1:], 'he:c:d',
118
+ opts = getopt.getopt(argv[1:], 'he:c:dn',
116
119
  ['help', 'endpoint=', 'cacerts=',
117
- 'disable-cert-check'])[0]
120
+ 'disable-cert-check', 'nocache'])[0]
118
121
  except getopt.GetoptError:
119
122
  print('ERROR: invalid option')
120
123
  print_usage(argv[0])
@@ -125,6 +128,7 @@ def example(
125
128
  endpoint = ENDPOINT
126
129
  ca_certs = None
127
130
  disable_ssl_certificate_validation = False
131
+ disable_cache = False
128
132
 
129
133
  for opt, arg in opts:
130
134
  if opt in ('-e', '--endpoint'):
@@ -134,6 +138,8 @@ def example(
134
138
  elif opt in ('-d', '--disable-cert-check'):
135
139
  disable_ssl_certificate_validation = True
136
140
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
141
+ elif opt in ('-n', '--nocache'):
142
+ disable_cache = True
137
143
  elif opt in ('-h', '--help'):
138
144
  print_usage(argv[0])
139
145
  sys.exit()
@@ -141,7 +147,8 @@ def example(
141
147
 
142
148
  cdas = CdasWs(endpoint=endpoint, ca_certs=ca_certs,
143
149
  disable_ssl_certificate_validation=
144
- disable_ssl_certificate_validation, user_agent='Example')
150
+ disable_ssl_certificate_validation,
151
+ disable_cache = disable_cache, user_agent='Example')
145
152
 
146
153
  print(cdas.get_observatory_groups(
147
154
  instrumentType='Magnetic Fields (Balloon)'))
@@ -163,14 +170,30 @@ def example(
163
170
 
164
171
  print('citation = ' + cdas.get_citation('10.48322/541v-1f57'))
165
172
 
166
- mms_brst_inventory = cdas.get_inventory('MMS1_FPI_BRST_L2_DES-MOMS',
173
+ dataset = 'MMS1_FPI_BRST_L2_DES-MOMS'
174
+ t0 = time.perf_counter()
175
+ mms_brst_inventory = cdas.get_inventory(dataset,
167
176
  timeInterval=TimeInterval(
168
177
  '2018-08-30T08:09:53Z',
169
178
  '2018-08-30T08:52:00Z'))
170
- print('MMS1_FPI_BRST_L2_DES-MOMS inventory:')
179
+ t1 = time.perf_counter()
180
+ print(f'{dataset} inventory took {t1 - t0}s')
181
+ print(f'{dataset} inventory:')
171
182
  for interval in mms_brst_inventory:
172
183
  print(' ' + str(interval))
173
184
 
185
+ t0 = time.perf_counter()
186
+ mms_brst_inventory = cdas.get_inventory(dataset,
187
+ timeInterval=TimeInterval(
188
+ '2018-08-30T08:09:53Z',
189
+ '2018-08-30T08:52:00Z'))
190
+ t1 = time.perf_counter()
191
+ print(f'second {dataset} inventory took {t1 - t0}s')
192
+ print(f'second {dataset} inventory:')
193
+ for interval in mms_brst_inventory:
194
+ print(' ' + str(interval))
195
+
196
+
174
197
  doi_inventory = cdas.get_inventory('10.21978/P8T923')
175
198
  print('10.21978/P8T923 inventory:')
176
199
  for interval in doi_inventory:
cdasws/timeinterval.py CHANGED
@@ -24,7 +24,7 @@
24
24
  #
25
25
  # NOSA HEADER END
26
26
  #
27
- # Copyright (c) 2018-2024 United States Government as represented by
27
+ # Copyright (c) 2018-2025 United States Government as represented by
28
28
  # the National Aeronautics and Space Administration. No copyright is
29
29
  # claimed in the United States under Title 17, U.S.Code. All Other
30
30
  # Rights Reserved.
@@ -35,7 +35,7 @@
35
35
  Package defining a class to represent the TimeInterval class from
36
36
  <https://cdaweb.gsfc.nasa.gov/WebServices/REST/CDAS.xsd>.<br>
37
37
 
38
- Copyright &copy; 2018-2024 United States Government as represented by the
38
+ Copyright &copy; 2018-2025 United States Government as represented by the
39
39
  National Aeronautics and Space Administration. No copyright is claimed in
40
40
  the United States under Title 17, U.S.Code. All Other Rights Reserved.
41
41
  """
@@ -155,10 +155,10 @@ class TimeInterval:
155
155
 
156
156
  builder.start('TimeInterval', {})
157
157
  builder.start('Start', {})
158
- builder.data(self._start.isoformat().replace('+00:00', '.000Z'))
158
+ builder.data(self._start.isoformat().replace('+00:00', 'Z'))
159
159
  builder.end('Start')
160
160
  builder.start('End', {})
161
- builder.data(self._end.isoformat().replace('+00:00', '.000Z'))
161
+ builder.data(self._end.isoformat().replace('+00:00', 'Z'))
162
162
  builder.end('End')
163
163
 
164
164
  return builder.end('TimeInterval')
@@ -252,13 +252,13 @@ class TimeInterval:
252
252
  """
253
253
  try:
254
254
  start_datetime = TimeInterval.get_datetime(start)
255
- except ValueError:
256
- raise ValueError('unrecognized start datetime value')
255
+ except ValueError as exc:
256
+ raise ValueError('unrecognized start datetime value') from exc
257
257
 
258
258
  try:
259
259
  end_datetime = TimeInterval.get_datetime(end)
260
- except ValueError:
261
- raise ValueError('unrecognized end datetime value')
260
+ except ValueError as exc:
261
+ raise ValueError('unrecognized end datetime value') from exc
262
262
 
263
263
  return start_datetime, end_datetime
264
264
 
@@ -1,13 +1,12 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: cdasws
3
- Version: 1.8.9
3
+ Version: 1.8.11
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
7
7
  Author-email: NASA-SPDF-Support@nasa.onmicrosoft.com
8
8
  License: NOSA
9
9
  Keywords: heliophysics,coordinated data analysis,multi-mission,multi-instrument,space physics,spdf,cdaweb
10
- Platform: UNKNOWN
11
10
  Classifier: Development Status :: 5 - Production/Stable
12
11
  Classifier: Environment :: Console
13
12
  Classifier: Environment :: Web Environment
@@ -20,13 +19,28 @@ Classifier: Programming Language :: Python
20
19
  Classifier: Topic :: Scientific/Engineering :: Physics
21
20
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
21
  Description-Content-Type: text/markdown
23
- Requires-Dist: python-dateutil (>=2.8.0)
24
- Requires-Dist: requests (>=2.20)
25
- Requires-Dist: urllib3 (>=1.24.1)
22
+ License-File: LICENSE
23
+ Requires-Dist: python-dateutil>=2.8.0
24
+ Requires-Dist: requests>=2.20
25
+ Requires-Dist: urllib3>=1.24.1
26
26
  Provides-Extra: spdm
27
- Requires-Dist: spacepy (>=0.5.0) ; extra == 'spdm'
27
+ Requires-Dist: spacepy>=0.5.0; extra == "spdm"
28
28
  Provides-Extra: xarray
29
- Requires-Dist: cdflib (>=0.4.4) ; extra == 'xarray'
29
+ Requires-Dist: cdflib>=0.4.4; extra == "xarray"
30
+ Provides-Extra: cache
31
+ Requires-Dist: requests-cache>=1.2.1; extra == "cache"
32
+ Dynamic: author
33
+ Dynamic: author-email
34
+ Dynamic: classifier
35
+ Dynamic: description
36
+ Dynamic: description-content-type
37
+ Dynamic: home-page
38
+ Dynamic: keywords
39
+ Dynamic: license
40
+ Dynamic: license-file
41
+ Dynamic: provides-extra
42
+ Dynamic: requires-dist
43
+ Dynamic: summary
30
44
 
31
45
 
32
46
  ## Synopsis
@@ -78,9 +92,13 @@ full ISTP/SPDF metadata).
78
92
 
79
93
  ## Dependencies
80
94
 
81
- The only required dependencies are python-dateutil and requests. If you
82
- call the get_data method then **one** of the following two sets of additional
83
- dependencies are required:
95
+ The only required dependencies are the following:
96
+
97
+ 1. [python-dateutil](https://pypi.org/project/python-dateutil/).
98
+ 2. [requests](https://pypi.org/project/requests/).
99
+
100
+ If you call the get_data method then **one** of the following two sets
101
+ of additional dependencies are required:
84
102
 
85
103
  1. To have get_data return the data in the SpacePy data model.
86
104
  * [SpacePy](https://spacepy.github.io/). Refer to the SpacePy
@@ -89,6 +107,11 @@ dependencies are required:
89
107
  * [cdflib](https://pypi.org/project/cdflib/).
90
108
  * [xarray](https://pypi.org/project/xarray/).
91
109
 
110
+ If you want to take advantage of HTTP caching, then install the following:
111
+
112
+ 1. [requests-cache](https://pypi.org/project/requests-cache/).
113
+
114
+
92
115
  ## Installation
93
116
 
94
117
  As noted in the dependencies above, if you intend to call the get_data
@@ -107,6 +130,10 @@ Then, to install this package
107
130
 
108
131
  $ pip install -U cdasws
109
132
 
133
+ or to include the optional cache package
134
+
135
+ $ pip install -U cdasws[cache]
136
+
110
137
 
111
138
  ## API Reference
112
139
 
@@ -133,5 +160,3 @@ Bernie Harris.
133
160
 
134
161
  This code is licensed under the
135
162
  [NASA Open Source Agreement](https://cdaweb.gsfc.nasa.gov/WebServices/NASA_Open_Source_Agreement_1.3.txt) (NOSA).
136
-
137
-
@@ -0,0 +1,13 @@
1
+ cdasws/__init__.py,sha256=0pB64-kPdpLdMptyZIbyXSZmqADfG6PGwGyIxYmmrv0,92358
2
+ cdasws/__main__.py,sha256=d8GJwd6EJK1JBS71q6h_1LYVUUj1IlRLpylQCi1SRGM,13466
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=UcKB-rFSk2eeaw0a29gOQQq7rNY0ab4Qwfz4iwJFelg,7839
7
+ cdasws-1.8.11.dist-info/licenses/LICENSE,sha256=og42scUY42lPLGBg0wHt6JtrbeInVEr5xojyrguPqrQ,12583
8
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ tests/test_cdasws.py,sha256=DsKesU19_9zUIO1a7oyWWtywBGN7gjdQHFLMGUZ4X8c,24395
10
+ cdasws-1.8.11.dist-info/METADATA,sha256=UT8MZ4EYgYEdtEvZZPKwgh0P9NFfT8_ka04emp-HdvQ,6926
11
+ cdasws-1.8.11.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
12
+ cdasws-1.8.11.dist-info/top_level.txt,sha256=GyIvHk5F6ysnTdDfnQsjZbTBt_EYrKyC0oeiIt9l-AE,7
13
+ cdasws-1.8.11.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.37.1)
2
+ Generator: setuptools (80.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,13 +0,0 @@
1
- cdasws/__init__.py,sha256=zugl_smMeupjG7Kvb9GrUsg2lyv4HkT4a8_PAE3DQOk,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.9.dist-info/LICENSE,sha256=og42scUY42lPLGBg0wHt6JtrbeInVEr5xojyrguPqrQ,12583
10
- cdasws-1.8.9.dist-info/METADATA,sha256=_vRqNZDerIUktDt3UhorZdwfdmbdBpIa7XVnPjCtUSo,6287
11
- cdasws-1.8.9.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
12
- cdasws-1.8.9.dist-info/top_level.txt,sha256=GyIvHk5F6ysnTdDfnQsjZbTBt_EYrKyC0oeiIt9l-AE,7
13
- cdasws-1.8.9.dist-info/RECORD,,