-
Notifications
You must be signed in to change notification settings - Fork 7
/
cat.py
76 lines (67 loc) · 2.33 KB
/
cat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from intake.catalog import Catalog
from intake.catalog.local import LocalCatalogEntry
class ThreddsCatalog(Catalog):
name = 'thredds_cat'
def __init__(self, url, driver='opendap', **kwargs):
self.url = url
self.driver = driver
super().__init__(**kwargs)
def _load(self):
from siphon.catalog import TDSCatalog
if 'simplecache::' in self.url:
if self.driver == 'netcdf':
self.cache = True
self.url_no_simplecache = self.url.replace('simplecache::', '')
self.metadata.update({'fsspec_pre_url': 'simplecache::'})
else:
raise ValueError(
f'simplecache requires driver="netcdf", found driver="{self.driver}".'
)
else:
self.cache = False
self.url_no_simplecache = self.url
self.cat = TDSCatalog(self.url_no_simplecache)
self.name = self.cat.catalog_name
self.metadata.update(self.cat.metadata)
# sub-cats
self._entries = {
r.title: LocalCatalogEntry(
r.title,
'THREDDS cat',
'thredds_cat',
True,
{'url': r.href},
[],
[],
self.metadata,
None,
catalog=self,
)
for r in self.cat.catalog_refs.values()
}
def access_urls(ds, self):
if self.driver == 'opendap':
driver_for_access_urls = 'OPENDAP'
elif self.driver == 'netcdf':
driver_for_access_urls = 'HTTPServer'
url = ds.access_urls[driver_for_access_urls]
if 'fsspec_pre_url' in self.metadata.keys():
url = f'{self.metadata["fsspec_pre_url"]}{url}'
return url
self._entries.update(
{
ds.name: LocalCatalogEntry(
ds.name,
'THREDDS data',
self.driver,
True,
{'urlpath': access_urls(ds, self), 'chunks': None},
[],
[],
{},
None,
catalog=self,
)
for ds in self.cat.datasets.values()
}
)