arctichoke.dataset.trim_dataset

Attributes

cdo

cdo

Functions

trim_latlon(dataset[, map_bbox, precise_trim, ...])

Trim the given dataset.

trim_files(files_to_trim[, name_prefix, ...])

Trim the specified files and save them as new files.

Module Contents

arctichoke.dataset.trim_dataset.cdo
arctichoke.dataset.trim_dataset.cdo
arctichoke.dataset.trim_dataset.trim_latlon(dataset: str, xarray.Dataset, xarray.DataArray, map_bbox: [float, float, float, float] = sps.NWP_BBOX, precise_trim: bool = False, save_as: str = None, verbose: bool = False)

Trim the given dataset.

Select only the data within the given bounding box of latitude and longitude coordinates from the given dataset.

Parameters:
  • dataset (str, xarray.Dataset, xarray.DataArray) – The dataset to plot.

  • map_bbox (Array of float, optional) –

    An array of coordinates defining the bounding box of the map in the following format:
    • [LAT_MAX, LAT_MIN, LON_MAX, LON_MIN]

    Default is arctichoke.params.latlon_params.NWP_BBOX.

  • precise_trim (bool, optional) – Whether to precisely trim an irregular grid to the bounding box, making all values outside the bounding box null. Default is False.

  • save_as (str, None, optional) – The file name to which to save the modified dataset. Default is None, which doesn’t save the dataset to a file.

  • verbose (bool, optional) – Whether to verbosely output information as the function executes. Default is False.

Returns:

xr_data_trimmed – The dataset trimmed to the latitude and longitude ranges provided.

Return type:

xarray.Dataset

Examples

>>>
arctichoke.dataset.trim_dataset.trim_files(files_to_trim: [str], name_prefix: str = 'trim_', use_cdo_python: bool = True, overwrite: bool = False, **kwargs)

Trim the specified files and save them as new files.

For each given file, load the data, trim the dataset, then save that trimmed dataset as a new file in the same location with a new filename.

Parameters:
  • files_to_trim (List of str) – A list of paths of the data files to trim.

  • name_prefix (str, optional) – The prefix to be prepended to each file name when saving. Default is trim_.

  • use_cdo_python (bool, optional) – Whether to tell trim_latlon() to use the Python implementation of cdo or use subprocess to run a shell command. Default is True which uses the Python implementation of cdo.

  • overwrite (bool, optional) – Whether to overwrite an existing file if it exists. Default is False.

  • **kwargs – Keyword arguments to pass to trim_latlon().

Return type:

None

Examples

>>> from arctichoke.path.find_data import list_variable_files
>>> list_of_files = list_variable_files('EC-Earth3P-HR', 'siage', variant_label='r3i1p2f1')
>>> from arctichoke.dataset.trim_dataset import trim_files
>>> trim_files(list_of_files)
(trim_files) `name_prefix`: trim_NWP_
(trim_latlon) `save_as`: /arctichoke_data/bergybits/data/CMIP6/HighResMIP/EC-Earth-Consortium/EC-Earth3P-HR/hist-1950/r3i1p2f1/SImon/siage/gn/v20190214/trim_NWP_siage_SImon_EC-Earth3P-HR_hist-1950_r3i1p2f1_gn_195001-195012.nc
...
(trim_latlon) `save_as`: /arctichoke_data/bergybits/data/CMIP6/HighResMIP/EC-Earth-Consortium/EC-Earth3P-HR/hist-1950/r3i1p2f1/SImon/siage/gn/v20190214/trim_NWP_siage_SImon_EC-Earth3P-HR_hist-1950_r3i1p2f1_gn_201401-201412.nc