Skip to content

Commit

Permalink
BUG: Fix NCEI NCSS access (fixes Unidata#215)
Browse files Browse the repository at this point in the history
Adds support for NetcdfServer, when available, to be used for NCSS.
  • Loading branch information
dopplershift committed Apr 9, 2018
1 parent 9f7bf0f commit 43a7c40
Show file tree
Hide file tree
Showing 3 changed files with 349 additions and 6 deletions.
21 changes: 15 additions & 6 deletions siphon/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ class Dataset(object):
"""

ncssServiceNames = ('NetcdfSubset', 'NetcdfServer')

def __init__(self, element_node, catalog_url=''):
"""Initialize the Dataset object.
Expand Down Expand Up @@ -540,18 +542,25 @@ def subset(self, service=None):
Parameters
----------
service : str, optional
The name of the service for subsetting the dataset. Defaults to 'NetcdfSubset'.
The name of the service for subsetting the dataset. Defaults to 'NetcdfSubset'
or 'NetcdfServer', in that order, depending on the services listed in the
catalog.
Returns
-------
a client for communicating using ``service``
"""
if service is None:
service = 'NetcdfSubset'

if service not in ('NetcdfSubset',):
raise ValueError(service + ' is not a valid service for subset')
for serviceName in self.ncssServiceNames:
if serviceName in self.access_urls:
service = serviceName
break
else:
raise RuntimeError('Subset access is not available for this dataset.')
elif service not in self.ncssServiceNames:
raise ValueError(service + ' is not a valid service for subset. Options are: '
+ ', '.join(self.ncssServiceNames))

return self.access_with_service(service)

Expand Down Expand Up @@ -581,7 +590,7 @@ def access_with_service(self, service):
provider = NC4Dataset
except ImportError:
raise ImportError('OPENDAP access requires netCDF4-python to be installed.')
elif service == 'NetcdfSubset':
elif service in self.ncssServiceNames:
from .ncss import NCSS
provider = NCSS
elif service == 'HTTPServer':
Expand Down
Loading

0 comments on commit 43a7c40

Please sign in to comment.