-
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
Conversation
Issues an HTTP HEAD request and handles "Content-Type: application/x-netcdf" headers by attempting to open a netCDF file in memory. Opening in memory will require the netCDF-C library to be compiled with that feature.
Use the content-type request header to inform how a dataset should be created. Remote NetCDF resources can be created via fetching the raw bytes and instantiating a MemoizedDataset object. Extend this capability to fetch TableDAP datasets by simply adding the .ncCF extension and the string of variables to the dataset URL.
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.
Good call @benjwadams, I'll implement that |
Use a try-catch routine to first attempt creating an in-memory netCDF4-python Dataset. If the netcdf-c lib was compiled without in-memory options, an OSError will be thrown; this is excepted and a NamedTemporaryFile is used to hold the raw bytes.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
@@ -20,3 +23,30 @@ class MemoizedDataset(Dataset): | |||
@lru_cache(128) | |||
def get_variables_by_attributes(self, **kwargs): | |||
return super(MemoizedDataset, self).get_variables_by_attributes(**kwargs) | |||
|
|||
@contextmanager | |||
def tempnc(data: BinaryIO) -> Generator[str, None, None]: |
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.
Take elements of #799 and #800 to fetch remote NetCDF resources and uses this capability to fetch ERDDAP TableDAP datasets with the .ncCF extension.