def check_remote_netcdf(self, ds_str): if netcdf.is_remote_netcdf(ds_str): response = requests.get(ds_str, allow_redirects=True, timeout=60) try: return MemoizedDataset(urlparse(response.url).path, memory=response.content) except OSError as e: # 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)
def load_remote_dataset(self, ds_str): """ Returns a dataset instance for the remote resource, either OPeNDAP or SOS :param str ds_str: URL to the remote resource """ 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: # 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) # Check if the HTTP response is XML, if it is, it's likely SOS so # we'll attempt to parse the response as SOS # 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))