API Reference#

APIs for Developers#

Below is a list of APIs available in pcmdi_metrics (> v3.6.1) for developers.

Data load#

io.xcdat_open(infile[, data_var, decode_times])

Open input file (netCDF, or xml generated by cdscan)

Land-sea mask#

utils.create_land_sea_mask(obj[, lon_key, ...])

Generate a land-sea mask (1 for land, 0 for sea) for a given xarray Dataset or DataArray.

utils.apply_landmask(obj[, data_var, ...])

Apply a land-sea mask to a given DataArray or Dataset.

utils.apply_oceanmask(obj[, data_var, ...])

Apply an ocean mask to a given DataArray or Dataset.

Grid and regrid#

utils.create_target_grid([lat1, lat2, lon1, ...])

Generate a uniform grid for given latitude/longitude ranges and resolution

utils.regrid(ds, data_var, target_grid[, ...])

Regrid the dataset to a given grid.

Custom calendars#

utils.custom_season_average(ds, data_var, season)

Calculates the average of a user defined season in each year.

utils.custom_season_departure(ds, data_var, ...)

Calculate the departure from a reference seasonal climatology for each season in a given year.

Region handling#

io.region_subset(ds, region[, data_var, ...])

Subset a dataset or data array based on a specified region.

io.region_from_file

Retrieve data from xarray Dataset#

io.get_grid(d)

Get grid information

io.get_axis_list(ds)

Retrieve coordinate key names from the dataset or data array.

io.get_data_list(ds)

Retrieve data variable names from the dataset or data array.

io.get_latitude(ds)

Extract latitude coordinate data.

io.get_latitude_bounds(ds)

Extract latitude bounds data.

io.get_latitude_key(ds)

Get the key for the latitude dimension.

io.get_longitude(ds)

Extract longitude coordinate data.

io.get_longitude_bounds(ds)

Extract longitude bounds data.

io.get_longitude_key(ds)

Get the key for the longitude dimension.

io.get_time(ds)

Extract time coordinate data.

io.get_time_bounds(ds)

Extract time bounds data.

io.get_time_bounds_key(ds)

Get the key for the time bounds.

io.get_time_key(ds)

Get the key for the time dimension.

io.select_subset(ds[, lat, lon, time])

Select a subset of the given xarray dataset based on specified latitude, longitude, and time ranges.

Quality control (QC) and repair#

utils.check_daily_time_axis(ds[, time_key])

Check if the time axis in an xarray dataset follows a correct daily sequence, considering all CFTime calendars.

utils.check_monthly_time_axis(ds[, time_key])

Check if the time axis of a dataset follows a correct monthly sequence.

utils.regenerate_time_axis(ds[, start_str, ...])

Regenerate the time axis and bounds for an xarray Dataset.

Miscellaneous tools#

utils.sort_human(input_list)

Sort a list of strings in natural order.

utils.fill_template(template, **kwargs)

Fill in a template string with keyword values.

utils.tree()

Create a nested defaultdict with infinite depth.