2
2
# Distributed under the terms of the MIT License.
3
3
# SPDX-License-Identifier: MIT
4
4
"""
5
- This module contains code to support reading and parsing
6
- catalog files from a THREDDS Data Server (TDS). They help identifying
7
- the latest dataset and finding proper URLs to access the data.
5
+ Code to support reading and parsing catalog files from a THREDDS Data Server (TDS).
6
+
7
+ They help identifying the latest dataset and finding proper URLs to access the data.
8
8
"""
9
9
10
10
from collections import OrderedDict
26
26
27
27
class TDSCatalog (object ):
28
28
r"""
29
- An object for holding information from a THREDDS Client Catalog.
29
+ Parse information from a THREDDS Client Catalog.
30
30
31
31
Attributes
32
32
----------
@@ -44,6 +44,7 @@ class TDSCatalog(object):
44
44
catalog ref title.
45
45
46
46
"""
47
+
47
48
def __init__ (self , catalog_url ):
48
49
r"""
49
50
Initialize the TDSCatalog object.
@@ -52,6 +53,7 @@ def __init__(self, catalog_url):
52
53
----------
53
54
catalog_url : str
54
55
The URL of a THREDDS client catalog
56
+
55
57
"""
56
58
# top level server url
57
59
self .catalog_url = catalog_url
@@ -159,8 +161,7 @@ def _process_datasets(self):
159
161
160
162
class CatalogRef (object ):
161
163
r"""
162
- An object for holding Catalog References obtained from a THREDDS Client
163
- Catalog.
164
+ An object for holding catalog references obtained from a THREDDS Client Catalog.
164
165
165
166
Attributes
166
167
----------
@@ -170,7 +171,9 @@ class CatalogRef(object):
170
171
url to the :class:`CatalogRef`'s THREDDS Client Catalog
171
172
title : str
172
173
Title of the :class:`CatalogRef` element
174
+
173
175
"""
176
+
174
177
def __init__ (self , base_url , element_node ):
175
178
r"""
176
179
Initialize the catalogRef object.
@@ -191,12 +194,13 @@ def __init__(self, base_url, element_node):
191
194
self .href = urljoin (base_url , href )
192
195
193
196
def follow (self ):
194
- r""" Follow the catalog reference, returning a new :class:`TDSCatalog`
197
+ r"""Follow the catalog reference and return a new :class:`TDSCatalog`.
195
198
196
199
Returns
197
200
-------
198
201
TDSCatalog
199
202
The referenced catalog
203
+
200
204
"""
201
205
return TDSCatalog (self .href )
202
206
@@ -215,10 +219,11 @@ class Dataset(object):
215
219
A dictionary of access urls whose keywords are the access service
216
220
types defined in the catalog (for example, "OPENDAP", "NetcdfSubset",
217
221
"WMS", etc.
222
+
218
223
"""
224
+
219
225
def __init__ (self , element_node , catalog_url = '' ):
220
- r"""
221
- Initialize the Dataset object.
226
+ r"""Initialize the Dataset object.
222
227
223
228
Parameters
224
229
----------
@@ -229,7 +234,7 @@ def __init__(self, element_node, catalog_url=''):
229
234
230
235
"""
231
236
self .name = element_node .attrib ['name' ]
232
- if ( 'urlPath' in element_node .attrib ) :
237
+ if 'urlPath' in element_node .attrib :
233
238
self .url_path = element_node .attrib ['urlPath' ]
234
239
else :
235
240
self .url_path = None
@@ -248,8 +253,7 @@ def __init__(self, element_node, catalog_url=''):
248
253
'the latest.xml dataset!' )
249
254
250
255
def resolve_url (self , catalog_url ):
251
- r"""
252
- Resolve the url of the dataset when reading latest.xml
256
+ r"""Resolve the url of the dataset when reading latest.xml.
253
257
254
258
Parameters
255
259
----------
@@ -283,9 +287,7 @@ def resolve_url(self, catalog_url):
283
287
log .warning ('no dataset url path found in latest.xml!' )
284
288
285
289
def make_access_urls (self , catalog_url , all_services , metadata = None ):
286
- r"""
287
- Make fully qualified urls for the access methods enabled on the
288
- dataset.
290
+ r"""Make fully qualified urls for the access methods enabled on the dataset.
289
291
290
292
Parameters
291
293
----------
@@ -295,8 +297,8 @@ def make_access_urls(self, catalog_url, all_services, metadata=None):
295
297
list of :class:`SimpleService` objects associated with the dataset
296
298
metadata : TDSCatalogMetadata
297
299
Metadata from the :class:`TDSCatalog`
298
- """
299
300
301
+ """
300
302
all_service_dict = {service .name : service for service in all_services }
301
303
service_name = None
302
304
if metadata :
@@ -335,15 +337,14 @@ def make_access_urls(self, catalog_url, all_services, metadata=None):
335
337
self .access_urls = access_urls
336
338
337
339
def add_access_element_info (self , access_element ):
340
+ """Create an access method from a catalog element."""
338
341
service_name = access_element .attrib ['serviceName' ]
339
342
url_path = access_element .attrib ['urlPath' ]
340
343
self .access_element_info [service_name ] = url_path
341
344
342
345
343
346
class SimpleService (object ):
344
- r"""
345
- An object for holding information about an access service enabled on a
346
- dataset.
347
+ r"""Hold information about an access service enabled on a dataset.
347
348
348
349
Attributes
349
350
----------
@@ -355,7 +356,9 @@ class SimpleService(object):
355
356
A dictionary of access urls whose keywords are the access service
356
357
types defined in the catalog (for example, "OPENDAP", "NetcdfSubset",
357
358
"WMS", etc.)
359
+
358
360
"""
361
+
359
362
def __init__ (self , service_node ):
360
363
r"""
361
364
Initialize the Dataset object.
@@ -373,8 +376,7 @@ def __init__(self, service_node):
373
376
374
377
375
378
class CompoundService (object ):
376
- r"""
377
- An object for holding information about compound services.
379
+ r"""Hold information about compound services.
378
380
379
381
Attributes
380
382
----------
@@ -385,10 +387,11 @@ class CompoundService(object):
385
387
"COMPOUND")
386
388
services : list[SimpleService]
387
389
A list of :class:`SimpleService` objects
390
+
388
391
"""
392
+
389
393
def __init__ (self , service_node ):
390
- r"""
391
- Initialize a :class:`CompoundService` object.
394
+ r"""Initialize a :class:`CompoundService` object.
392
395
393
396
Parameters
394
397
----------
@@ -410,8 +413,7 @@ def __init__(self, service_node):
410
413
411
414
412
415
def _find_base_tds_url (catalog_url ):
413
- """
414
- Identify the base URL of the THREDDS server from the catalog URL.
416
+ """Identify the base URL of the THREDDS server from the catalog URL.
415
417
416
418
Will retain URL scheme, host, port and username/password when present.
417
419
"""
@@ -423,9 +425,7 @@ def _find_base_tds_url(catalog_url):
423
425
424
426
425
427
def _get_latest_cat (catalog_url ):
426
- r"""
427
- Get the latest dataset catalog from the supplied top level dataset catalog
428
- url.
428
+ r"""Get the latest dataset catalog from the supplied top level dataset catalog url.
429
429
430
430
Parameters
431
431
----------
@@ -448,10 +448,10 @@ def _get_latest_cat(catalog_url):
448
448
449
449
450
450
def get_latest_access_url (catalog_url , access_method ):
451
- r"""
452
- Get the data access url, using a specified access method, to the latest
453
- data available from a top level dataset catalog (url). Currently only
454
- supports the existence of one "latest" dataset.
451
+ r"""Get the data access url to the latest data using a specified access method.
452
+
453
+ These are available for a data available from a top level dataset catalog (url).
454
+ Currently only supports the existence of one "latest" dataset.
455
455
456
456
Parameters
457
457
----------
@@ -466,8 +466,8 @@ def get_latest_access_url(catalog_url, access_method):
466
466
Data access URL to be used to access the latest data available from a
467
467
given catalog using the specified `access_method`. Typically a single string,
468
468
but not always.
469
- """
470
469
470
+ """
471
471
latest_cat = _get_latest_cat (catalog_url )
472
472
if latest_cat != '' :
473
473
if len (list (latest_cat .datasets .keys ())) > 0 :
0 commit comments