opendap
- make_opendap_url(base_url, order)
_summary_
- Parameters
base_url (str) – URL to OPeNDAP database
order (dict) – Keys are OPeNDAP variables, values are dictionaries specifying the indices to download for a dimension. Give an empty dictionary to not do any slicing.
- Returns
URL to download a subset.
- Return type
str
Example
base_url = “https://ladsweb.modaps.eosdis.nasa.gov/opendap/RemoteResources/laads/allData/5200/VNP02IMG/2023/060/VNP02IMG.A2023060.1106.002.2023061191604.nc” order = {
- ‘/observation_data/I05_quality_flags’: {
‘number_of_lines’: [1610, 1711], ‘number_of_pixels’: [2920, 3013]},
- ‘/observation_data/I05’: {
‘number_of_lines’: [1610, 1711], ‘number_of_pixels’: [2920, 3013]},
‘/observation_data/I05_brightness_temperature_lut’: {} }
- download(fp, product_name, coords, variables, post_processors, fn_func, url_func, un_pw=None, tiles=None, data_source_crs=None, parallel=False, spatial_tiles=True, request_dims=True, timedelta=None)
Download data from a OPENDaP server.
- Parameters
fp (str) – Path to file in which to download.
product_name (str) – Name of product.
coords (dict) – Coordinate names and boundaries.
variables (dict) – Keys are variable names, values are additional settings.
post_processors (dict) – Processors to apply to specific variables.
url_func (function) – Function that takes product_name as input and return a url.
un_pw (tuple, optional) – Username and password to use, by default None.
tiles (list, optional) – Tiles to download, by default None.
data_source_crs (rasterio.CRS.crs, optional) – CRS of datasource, by default None.
parallel (bool, optional) – Download files in parallel (currently not implemented), by default False.
spatial_tiles (bool, optional) – Whether the tiles are spatial or temporal, by default True.
request_dims (bool, optional) – Include dimension settings in the OPENDaP request, by default True.
timedelta (datetime.datetime.timedelta, optional) – Shift the time coordinates by tdelta, by default None.
- Returns
Dataset with downloaded data.
- Return type
xr.Dataset
- setup_session(uri, username=None, password=None, check_url=None, session=None, verify=True, username_field='username', password_field='password')
A general function to set-up requests session with cookies using beautifulsoup and by calling the right url.
- raise_if_form_exists(url, session)
This function raises a UserWarning if the link has forms
- download_xarray(url, fp, coords, variables, post_processors, data_source_crs=None, timedelta=None)
Download a OPENDaP dataset using xarray directly.
- Parameters
url (str) – URL to dataset.
fp (str) – Path to file to download into.
coords (dict) – Coordinates to request.
variables (dict) – Variables to request.
post_processors (dict) – Additional functions to apply to variables.
data_source_crs (rasterio.CRS.crs, optional) – CRS of the data source, by default None.
timedelta (datetime.datetime.timedelta, optional) – Shift the time coordinates by tdelta, by default None.
- Returns
Downloaded dataset.
- Return type
xr.Dataset
- create_selection(coords, target_crs=None, source_crs=CRS.from_epsg(4326))
Create a dictionary that can be given to xr.Dataset.sel.
- Parameters
coords (dict) – Dictionary describing the different dimensions over which to select. Possible keys are “x” for latitude, “y” for longitude and “t” for time, but other selections keys are also allowed (e.g. so select a band). Values are tuples with the first value the respective dimension names in the ds and the second value the selector.
target_crs (rasterio.crs.CRS, optional) – crs of the dataset on which the selection will be applied, by default None.
source_crs (rasterio.crs.CRS, optional) – crs of the x and y limits in coords, by default epsg:4326.
- Returns
Dimension names with slices to apply to each dimension.
- Return type
dict