utils¶
Module utils contains ...
set_xr_units(x, units)
¶
Sets the units attribute of an xr.DataArray. No effect if x is not a dataarray
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
xr.DataArray
|
data array |
required |
units |
str
|
units descriptor |
required |
Source code in uchronia/utils.py
xr_concat(series, new_coord_names, new_dim_name=None, units=None)
¶
concatenate DataArrays - helper function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
series |
Sequence[xr.DataArray]
|
arrays to concatenate. These should have the same coordinates. |
required |
new_coord_names |
Sequence[str]
|
Names of the concatenated cases |
required |
new_dim_name |
str
|
Name of the new dimension for concatenated cases. Defaults to None. |
None
|
units |
str
|
units. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
xr.DataArray
|
xr.DataArray: concatenated arrays with one added dimension compared to inputs |
Examples:
>>> before = mk_test_season_minmax(min_x=1.0, max_x=2.0, kharif=False, units='MAF')
>>> after = before * 1.1
>>> xr_concat([before, after], new_coord_names=['before','after'], new_dim_name='case', units='MAF')
<xarray.DataArray (case: 2, minmax: 2, ten_day_id: 18)>
array([[[1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. ,
1. , 1. , 1. , 1. , 1. , 1. ],
[2. , 2. , 2. , 2. , 2. , 2. , 2. , 2. , 2. , 2. , 2. , 2. ,
2. , 2. , 2. , 2. , 2. , 2. ]],
[[1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1,
1.1, 1.1, 1.1, 1.1, 1.1, 1.1],
[2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2, 2.2,
2.2, 2.2, 2.2, 2.2, 2.2, 2.2]]])
Coordinates:
* minmax (minmax) <U3 'min' 'max'
* ten_day_id (ten_day_id) int64 19 20 21 22 23 24 25 ... 30 31 32 33 34 35 36
* case (case) object 'before' 'after'
Attributes:
units: MAF