Generic class for LIVVkit Extensions.
This supplies several common methods for plotting and data analysis.
| Class | LEX |
Define a LIVVkit extension. |
| Function | annotate |
Add land / ocean, gridlines, colourbar. |
| Function | area |
Compute a masked and weighted area average of some field. |
| Function | check |
Check that longitudes are -180 - +180. |
| Function | closest |
Determine closest model points to set of observation x/y points. |
| Function | compute |
Compute reasonable min / max levels for one to three arrays which are comparable. |
| Function | gen |
Generate a list of files to be loaded for a particular dataset climatology. |
| Function | gen |
Similar to gen_file_list but for timeseries data. Generate list of files to load. |
| Function | get |
Get the name of which type of averaging is used (annual, seasonal, monthly). |
| Function | get |
Determine season bounds for climatology files. |
| Function | img |
Convert the module name into a file prefix for the image output. |
| Function | load |
Load observational (or reanalysis) data. |
| Function | load |
Load data for timeseries. |
| Function | parse |
Parse a data_var formula or name. |
| Function | parse |
Parse a LIVVext data_var formula or native netCDF field name string. |
| Function | plot |
Undocumented |
| Function | plot |
Undocumented |
| Function | proc |
Process the climatology file to maintain backward compatibility with standalone LEX. |
| Function | summarize |
Provides a snapshot of the extension's results to be provided on the summary webpage and printed to STDOUT via the print_summary method |
| Function | var |
Fill in a LIVVext defined string template for a particular variable, season, and run. |
| Constant | DAYS |
np.ndarray of number of days per month. |
| Constant | DAYS |
Map seasonal (MMM) abbreviations to number of days per season. |
| Constant | MON |
List of short month names (Jan, Feb, ...). |
| Constant | SEASON |
Map seasonal (MMM) abbreviations to human-readable names for seasons. |
| Constant | TFORM |
Transform for data on a regular lat / lon grid. |
xr.DataArray | np.ndarray, config: dict, area_file: Path, area_var: str, mask_file: Path = None, mask_var: str = None, sum_out: bool = False, land_only: bool = False):
(source)
¶
Compute a masked and weighted area average of some field.
- data : array_like
- Array of data to be averaged
- config : dict
- LIVVkit configuration dictionary, at least contains the variable maskv if mask_var is not set
- area_file : Path
- Path to a netCDF file containing the grid cell area which matches data
- area_var : str
- Name of the netCDF variable which contains the area data
- mask_file : Path, optional
- Path to a netCDF file containing the ice sheet mask whose shape matches data. If not set, the mask is assumed to be in the area_file file
- mask_var : str, optional
- Name of the netCDF variable which contains the ice sheet mask data, if not set, then use maskv from config
- sum_out: bool, optional
- Return the weighted sum rather than average. Defualt is False
- land_only: bool, optional
- Return the average or sum over grid cells which are 100% land so no ocean cells are included. Default is False
| Returns | |
|
np.ndarray, model_y: np.ndarray, obs_x: np.ndarray, obs_y: np.ndarray) -> tuple[ np.ndarray]:
(source)
¶
Determine closest model points to set of observation x/y points.
| Parameters | |
modelnp.ndarray | Model x coordinate array (lon) |
modelnp.ndarray | Model y coordinate array (lat) |
obsnp.ndarray | Observation x locations (lon) |
obsnp.ndarray | Observation y locations (lat) |
| Returns | |
tuple[np.ndarray] | Array of closest points, Array of indicies for observations on the model mesh (nobs, ny, nx) |
Compute reasonable min / max levels for one to three arrays which are comparable.
| Parameters | |
data:dict | Masked array of data for which to compute contour levels |
bnds:tuple, optional | Upper / lower percentiles to use for bounds (default: (5%, 95%)) |
even:bool, optional | Use an even interval about 0 (default: False) |
| round | Undocumented |
keys:list, optional | List of keys within data for which bounds will be computed, default is all keys in data |
| Returns | |
float | bnd_l, bnd_h - Lower, upper bounds for contouring |
dict, var_name: list | tuple | str, overs: str, sea: list | tuple | str, cycle: str) -> list[ Path]:
(source)
¶
Generate a list of files to be loaded for a particular dataset climatology.
| Parameters | |
config:dict |
|
varlist | tuple | str | Name or list/tuple of names of fields to be loaded, each in a separate file |
overs:str | Observation version (dset_a, dset_b, ..., or model) |
sea:list | tuple | str | Season or list/tuple of seasons to be loaded |
cycle:str | Climatology averaging period (e.g. ann, sea, mon) |
| Returns | |
list[Path] | List of full file paths to be loaded |
Similar to gen_file_list but for timeseries data. Generate list of files to load.
| Parameters | |
config:dict | LIVVext configuratrion dictionary. |
varlist | tuple | str | Field name or list/tuple of field names to be loaded |
overs:str | "Observational" dataset version (e.g. dset_a, dset_b, ..., or model) |
| Returns | |
list[Path] | List of absolute paths to input dataset files |
str | int | float, year_s: int, year_e: int, mon_s: int = None, mon_e: int = None) -> tuple[ str]:
(source)
¶
Determine season bounds for climatology files.
Load observational (or reanalysis) data.
| Parameters | |
config:dict |
|
sea:str, optional | Season or month (e.g. ANN, DJF, '01', 1), by default "ANN" |
mode:str, optional | Climatology mode, for sum (climoS), average (climoA), by default "climoS" |
singlestr, optional | Load only one dataset, by default None, load all datasets in config["in_dirs"] |
expectbool, optional | Assume dataset has a single time per file, by default True |
| Returns | |
dict[xr.Dataset] | Dictionary of xr.Dataset s, one for each dataset in config["in_dirs"]. |
Load data for timeseries.
| Parameters | |
config:dict |
|
| Returns | |
dict[xr.Dataset] | Dictionary of datasets for each dataset in config["timeseries_dirs"] |
list | tuple | str, dataset: xr.Dataset, scale: float | int | str) -> xr.DataArray:
(source)
¶
Parse a data_var formula or name.
| Parameters | |
datalist | tuple | str | data_var definition, if a list or tuple, this is a formula for
computing a derived field, if a string, this is a native output
field from the dataset. See livvext.utils.extract_ds for more details. |
dataset:xr.Dataset | Input xr.Dataset |
scale:float | int | str | Scale the data_var field after computation by scale. Can be
numeric or a string representation (e.g. 1e-6, 32.5, or "365 * 24").
See livvext.utils.eval_expr for more details. |
| Returns | |
xr.DataArray | Xarray DataArray of the field of intrest |
Process the climatology file to maintain backward compatibility with standalone LEX.
| Parameters | |
config:dict | LIVVkit /LEX configuration dict |
filestr | Configuration item which points to climatology filename to be formatted, usually climo or climo_remap |
sea:str | Season identifier |
| Returns | |
str | climo_file - Formatted name of climatology file |
Provides a snapshot of the extension's results to be provided on the summary webpage and printed to STDOUT via the print_summary method
Fill in a LIVVext defined string template for a particular variable, season, and run.
| Parameters | |
filestr | Filename template with spots for variable, icesheet, and season start / end |
_var:str | Model or observational field name |
isheet:str | Icesheet name (gis or ais) |
_sea:str | Season name or month number (e.g. ANN, DJF,..., '01' or 1) |
yearint | Start year of climatology |
yearint | End year of climatology |
sep:str, optional | Separator within the template, if defined. By default "_" |
| Returns | |
str | Formatted filename |
np.ndarray of number of days per month.
| Value |
|
Map seasonal (MMM) abbreviations to number of days per season.
| Value |
|
List of short month names (Jan, Feb, ...).
| Value |
|