NetCDF๏ƒ

static read_file.NetCDF(path_or_dataset, parameter=None, coords=None, crs_key=None, data_crs=None, sel=None, isel=None, set_data=None, mask_and_scale=False)๏ƒ

Read all relevant information necessary to add a NetCDF to the map.

Parameters
  • path_or_dataset (str, pathlib.Path or xar.Dataset) โ€“

    • If str or pathlib.Path: The path to the file.

    • If xar.Dataset: The xarray.Dataset instance to use

  • parameter (str) โ€“ The name of the variable to use as parameter. If None, the first variable of the NetCDF file will be used. The default is None.

  • coords (tuple of str) โ€“ The names of the variables to use as x- and y- coordinates. (e.g. (โ€˜latโ€™, โ€˜lonโ€™)) The default is None in which case the coordinate-dimensions defined in the NetCDF will be used.

  • crs_key (str, optional) โ€“

    The attribute-name that holds the crs-information.

    By default the following options are tried: - <crs_key> = โ€œspatial_refโ€, โ€œcrsโ€, โ€œcrs_wktโ€

    • crs = file.attrs.<crs_key>

  • data_crs (None, optional) โ€“ Optional way to specify the crs of the data explicitly. (โ€œcrs_keyโ€ will be ignored if โ€œdata_crsโ€ is provided!)

  • sel (dict, optional) โ€“ A dictionary of keyword-arguments passed to xarray.Dataset.sel() (see https://xarray.pydata.org/en/stable/generated/xarray.Dataset.sel.html) The default is None.

  • isel (dict, optional) โ€“ A dictionary of keyword-arguments passed to xarray.Dataset.isel(). (see https://xarray.pydata.org/en/stable/generated/xarray.Dataset.isel.html) The default is {โ€œbandโ€ : 0} (if sel is None).

  • set_data (None or eomaps.Maps) โ€“ Indicator if the dataset should be returned None or assigned to the provided Maps-object (e.g. by using m.set_data(โ€ฆ)). The default is None.

  • mask_and_scale (bool) โ€“

    Indicator if the data should be masked and scaled with respect to the file-attributes _FillValue, scale_factor and add_offset.

    • If False: the data will only be scaled โ€œon demandโ€, avoiding costly initialization of very large float-arrays. Masking will still be applied in case a _FillValue attribute has been found. (a masked-array is returned to avoid dtype conversions) The encoding is accessible via m.data_specs.encoding

    • If True: all data will be masked and scaled after reading. For more details see xarray.open_dataset.

    NOTE: using mask_and_scale=True results in a conversion of the data-values to floats!! For very large datasets this can cause a huge increase in memory-usage! EOmaps handles the scaling internally to show correct values for callbacks and colorbars, even if mask_and_scale=False!

    The default is False.

Returns

A dict that contains the data required for plotting.

Return type

dict (if set_data is False) or None (if set_data is True)

Examples

# to just read the data use one of the following:

>>> path = r"C:/folder/file.tiff"
>>> data = m.read_file.NetCDF(path)
>>> file = xar.open_dataset(path)
>>> data = m.read_file.NetCDF(file)
>>> with xar.open_dataset(path) as file:
>>>     data = m.read_file.NetCDF(file)

# to assign the data directly to the Maps-object, use set_data=<Maps object>:

>>> m.read_file.NetCDF(path, set_data=m)