xoa.cf.CFSpecs

class xoa.cf.CFSpecs(cfg=None, default=True, user=True, name=None, cache=None)[source]

Manager for CF specifications

CF specifications are defined here an extension of a subset of CF conventions: known variables and coordinates are described through a generic name, a specialized name, alternates names, some properties and attributes like standard_name, long_name, axis.

Have a look to the default specifications and to the Naming conventions with xoa.cf section.

Parameters:
  • cfg (str, list, CFSpecs, dict) – A config file name or string or dict or CF Specs, or a list of them. It may contain the “data_vars”, “coords” and “sglocator” sections. When a list is provided, specs are merged with the firsts having priority over the lasts.

  • default (bool) – Load also the default internal specs

  • user (bool) – Load also the user specs stored in USER_CF_FILE

  • name (str, None) – Assign a shortcut name. It defaults the the [register] name option of the specs.

  • cache (bool) – Use in-memory cache system?

__init__(cfg=None, default=True, user=True, name=None, cache=None)[source]

Methods

auto_format(obj, **kwargs)

Rename variables and coordinates and fill their attributes

copy()

decode(obj, **kwargs)

Auto format, infer coordinates and rename to generic names

encode(obj, **kwargs)

Same as decode() but rename with the specialized name

fill_attrs(obj, **kwargs)

Fill missing attributes of a xarray.Dataset or xarray.DataArray

format_coord(da[, cf_name, loc, copy, ...])

Format a coordinate array

format_data_var(da[, cf_name, loc, copy, ...])

Format a data_var array

format_dataset(ds[, cf_names, copy, ...])

Format a whole dataset

get(obj, cf_name[, get])

A shortcut to search() with an explicit generic CF name

get_axis(coord[, lower])

Get the dimension type, either from axis attr or from match Cf coord

get_category(da)

Guess if a dataarray belongs to data_vars or coords

get_dim_type(dim[, da, lower])

Get the type of a dimension

get_dim_types(da[, unknown, asdict])

Get a tuple of the dimension types of an array

get_dims(da, cf_args[, allow_positional, ...])

Get the data array dimensions names from their type or generic CF name

get_loc(da)

Get the staggered grid location from name and standard_name

get_loc_mapping(obj[, cf_names, loc, categories])

Associate a location to each identified variables, coordinates and dimensions of obj

get_location(da)

Get the staggered grid location from name and standard_name

get_name()

infer_coords(ds)

Search for known coords and make sure they are set as coords

load_cfg([cfg, cache])

Load a single or a list of configurations

match(da[, loc])

Check if an array matches any data_var or coord specs

match_coord(da[, cf_name, loc])

Check if an array matches a given or any coord specs

match_data_var(da[, cf_name, loc])

Check if an array matches given or any data_var specs

match_dim(dim[, cf_name, loc])

Check if a dimension name matches given or any coord specs

parse_dims(dims, obj)

Convert from generic dim names to specialized names

pprint(**kwargs)

Pretty print the specs as dict using pprint.pprint()

reloc(obj, **locs)

Convert given staggered grid locations to other locations

search(obj[, cf_name, loc, get, single, ...])

Search for a dataarray with data_vars and/or coords

search_coord(obj[, cf_name, loc, get, ...])

Search for a coord that maches given or any specs

search_coord_from_dim(da, dim[, errors])

Search a dataarray for a coordinate from a dimension name

search_data_var(obj[, cf_name, loc, get, ...])

Search for a data_var that maches given or any specs

search_dim(da[, cf_arg, loc, errors])

Search a dataarray/dataset for a dimension name according to its generic name or type

set_name(name)

set_specs(category, name, **specs)

Update or create specs for an item

set_specs_from_cfg(cfg)

Update or create specs from a config

to_loc(obj, **locs)

Set the staggered grid location for specified names

Attributes

categories

List of cf specs categories

cfgspecs

coords

Specifications for coords CFCoordSpecs

data_vars

Specification for data_vars CFVarSpecs

dict

Dictionary copy of the specs

dims

Dictionary of dims per dimension type within x, y, z, t and f

name

Name

sglocator

SGLocator instance