API Reference

APIs

Below is a list of Application Programming Interfaces (APIs) available in pcmdi_metrics (> v3.6.1).

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.

utils.replace_date_pattern(filename, replacement)

Replace the 'YYYYMM-YYYYMM' pattern in a filename with a specified replacement.

Data load

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

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

Date

utils.date_to_str(date_obj)

Convert a date object to a string in 'YYYY-MM-DD' format.

utils.extract_date_components(ds[, index])

Extract year, month, and day from a dataset's time dimension.

utils.find_overlapping_dates(ds, start_date, ...)

Find the overlapping period between given dates and a dataset's time range.

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.

Graphics

Example usages of the following plotting functions are available in the demo notebooks.

graphics.parallel_coordinate_plot(data, ...)

Create a parallel coordinate plot for visualizing multi-dimensional data.

graphics.portrait_plot(data, xaxis_labels, ...)

Create a portrait plot for visualizing 2D data arrays.

graphics.TaylorDiagram(stddev, corrcoef, refstd)

Create a Taylor diagram.

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.

Region handling

io.load_regions_specs()

Load predefined geographic region specifications for climate data analysis.

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

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

io.region_from_file(data, rgn_path, attr, ...)

Return data masked from a feature in the input 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.