-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remote NetCDF TableDAP #801
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def is_tabledap(url): | ||
""" | ||
Identify a dataset as an ERDDAP TableDAP dataset. | ||
|
||
Parameters | ||
---------- | ||
url (str) : URL to dataset | ||
|
||
Returns | ||
------- | ||
bool | ||
""" | ||
|
||
return "tabledap" in url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,13 @@ | |
from netCDF4 import Dataset | ||
from owslib.sos import SensorObservationService | ||
from owslib.swe.sensor.sml import SensorML | ||
from compliance_checker.protocols import opendap, netcdf, cdl, erddap | ||
from datetime import datetime | ||
from pkg_resources import working_set | ||
|
||
from compliance_checker import MemoizedDataset | ||
from compliance_checker import MemoizedDataset, tempnc | ||
from compliance_checker.base import BaseCheck, GenericFile, Result, fix_return_value | ||
from compliance_checker.cf.cf import CFBaseCheck | ||
from compliance_checker.protocols import cdl, netcdf, opendap | ||
|
||
|
||
# Ensure output is encoded as Unicode when checker output is redirected or piped | ||
|
@@ -765,20 +766,39 @@ def load_remote_dataset(self, ds_str): | |
:param str ds_str: URL to the remote resource | ||
""" | ||
|
||
if opendap.is_opendap(ds_str): | ||
if "tabledap" in ds_str: # ERDDAP TableDAP request | ||
# modify ds_str to contain the full variable request | ||
variables_str = opendap.create_DAP_variable_str(ds_str) | ||
|
||
# join to create a URL to an .ncCF resource | ||
ds_str = "{}.ncCF?{}".format(ds_str, variables_str) | ||
|
||
if netcdf.is_remote_netcdf(ds_str): | ||
response = requests.get(ds_str, allow_redirects=True, | ||
timeout=60) | ||
try: | ||
return MemoizedDataset(response.content, memory=response.content) | ||
except OSError as e: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
# handle case when netCDF C libs weren't compiled with | ||
# in-memory support by using tempfile | ||
with tempnc(response.content) as _nc: | ||
return MemoizedDataset(_nc) | ||
|
||
elif opendap.is_opendap(ds_str): | ||
return Dataset(ds_str) | ||
else: | ||
# Check if the HTTP response is XML, if it is, it's likely SOS so | ||
# we'll attempt to parse the response as SOS | ||
response = requests.get(ds_str, allow_redirects=True) | ||
if "text/xml" in response.headers["content-type"]: | ||
return self.process_doc(response.content) | ||
|
||
raise ValueError( | ||
"Unknown service with content-type: {}".format( | ||
response.headers["content-type"] | ||
) | ||
) | ||
|
||
# some SOS servers don't seem to support HEAD requests. | ||
# Issue GET instead if we reach here and can't get the response | ||
response = requests.get(ds_str, allow_redirects=True, | ||
timeout=60) | ||
content_type = response.headers.get("content-type") | ||
if content_type == "text/xml": | ||
return self.process_doc(response.content) | ||
else: | ||
raise ValueError("Unknown service with content-type: {}".format(content_type)) | ||
|
||
def load_local_dataset(self, ds_str): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename this to
create_temporary_ncfile
or something more explicit.