Filters¶
Filters select, crop, sort and rename data after a source opens it.
Filter
pydantic-model
¶
Filter(**data: Any)
Bases: RompyBaseModel
Filters applied to a dataset after a source opens it.
Each field holds the keyword arguments of the filter function with the same
name in this module (sort_filter, subset_filter, crop_filter,
timenorm_filter, rename_filter, derived_filter). Calling the filter on a
dataset applies them in that order, skipping those left empty.
Fields:
-
sort(Optional[dict]) -
subset(Optional[dict]) -
crop(Optional[dict]) -
timenorm(Optional[dict]) -
rename(Optional[dict]) -
derived(Optional[dict])
Validators:
check_for_typos
classmethod
¶
Suggest the closest field name for an unknown input key.
A field can be given by its name or, like in pydantic, by its alias.
derived_filter
¶
Add derived variable to Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Input dataset to add derived variables to. |
required | |
derived_variables
|
Mapping { |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ds |
Dataset
|
Input dataset with extra derived variables. |
Example
import xarray as xr ds = xr.DataArray([-10, -11], coords={"x": [0, 1]}).to_dataset(name="elevation") ds = derived_filter(ds, {"depth": "ds.elevation * -1"})
subset_filter
¶
subset_filter(ds, data_vars=None) -> Dataset
Subset data variables from dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Input dataset to transform. |
required | |
data_vars
|
Variables to subset from ds. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ds |
Dataset
|
|
crop_filter
¶
crop_filter(ds, **data_slice) -> Dataset
Crop dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Input dataset to transform. |
required | |
data_slice
|
Data slice to crop |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ds |
Dataset
|
|