pylawr.field#
|
RadarField is a xarray.DataArray accessor to extend xarray for radar processing. |
|
Check if an array has a given tag |
|
Get a verified grid from the array and given grid. |
|
Attempt to |
|
Remove a tag from an array with |
- class pylawr.RadarField(data)[source]#
Bases:
objectRadarField is a xarray.DataArray accessor to extend xarray for radar processing. The accessor is called with xarray.DataArray.lawr.
- Parameters
data (
xarray.DataArray) – This accessor is valid for this given data array.
- grid#
The grid of this RadarField. The grid is used for localization, interpolation and plotting purpose.
- Type
child of
BaseGrid
- _decibel(x, dbzmin=-32.5)[source]#
Converts to decibel unit.
\[\mathrm{decibel} = 10 \cdot \log_{10}(\mathrm{linear})\]Note
Due to conventions: Linear reflectivities smaller than or equal to \(0\,\mathrm{mm^6\,m^{-3}}\) will be transformed to \(-32.5\,\mathrm{dBZ}\) in decibel unit.
- Parameters
x (
xarray.DataArray) – The radar field with linear non-decibel unit.- Returns
The radar field with decibel unit.
- _linear(x, dbzmin=-32.5)[source]#
Converts to linear unit.
\[\mathrm{linear} = 10^{\frac{\mathrm{decibel}}{10}}\]Note
Due to conventions: Reflectivities in decibel unit smaller than or equal to \(-32\,\mathrm{dBZ}\) will be transformed to \(0\,\mathrm{mm^6\,m^{-3}}\) in linear unit.
- Parameters
x (
xarray.DataArray) – The radar field with decibel unit.- Returns
The radar field with linear non-decibel unit.
- _rainrate(x, a=200.0, b=1.6)[source]#
Converts to rain rate r via Z/R relationship.
\[r = \sqrt[b]{\frac{z}{a}}\]- Parameters
x (int, float or array (radar reflectivity factor, mm**6/m**3)) –
a (float, optional) – Parameter a of the Z/R relationship. This is the scale factor of the Z/R relationship. Default is 200.0 from Marshall-Palmer.
b (float, optional) – Parameter b of the Z/R relationship. This is the polynomial grade factor of the Z/R relationship. Default is 1.6 from Marshall-Palmer.
- Return type
converted x in rain rate (mm/h)
- _reflectivity(x, a=200.0, b=1.6)[source]#
Converts to radar reflectivity factor via Z/R relationship.
- Parameters
a (float, optional) – Parameter a of the Z/R relationship. This is the scale factor of the Z/R relationship. Default is 200.0 from Marshall-Palmer.
b (float, optional) – Parameter b of the Z/R relationship. This is the polynomial grade factor of the Z/R relationship. Default is 1.6 from Marshall-Palmer.
- Return type
converted x in radar reflectivity factor (mm**6/mm**3)
- property data#
Get the data for this accessor.
- Returns
The data for this
xarray.DataArrayaccessor.- Return type
- db_to_linear(inverse=False)[source]#
Transform this rain field from decibel units to linear units.
\[ \begin{align}\begin{aligned}\mathrm{linear} &= 10^{\frac{\mathrm{decibel}}{10}}\\\mathrm{decibel} &= 10 \cdot \log_{10}(\mathrm{linear})\end{aligned}\end{align} \]Note
Due to conventions: Linear reflectivities smaller than or equal to \(0\,\mathrm{mm^6\,m^{-3}}\) will be transformed to \(-32.5\,\mathrm{dBZ}\) in decibel unit and vice versa.
- Parameters
inverse (bool, optional) – Default is False.
- Returns
converted_field – The converted rain field with Gaussian decibel or linear non-decibel units. The field has the same grid as this DataArray. The target variable is determined automatically. If name is None, the target variable will be either linear_reflectivity or reflectivity.
- Return type
- filter(filter_class, *args, **kwargs)[source]#
Method to apply a filter to this class.
- Parameters
filter_class (Python obj) – This instance of a python class is used to filter the data. The class needs a transform method with data as first argument and grid as keyword argument. The return value of the transform method should be a xarray.DataArray. A possible second return value is interpreted as new grid.
*args – The variable length argument list is passed to the transform method of the filter_class.
**kwargs – The variable keyword argument dictionary is passed to the transform method of the filter_class. This argument could be used if another array is necessary to transform this array with the given filter class.
- Returns
filtered_data – The filtered data array, with the set grid.
- Return type
- property grid#
- grid_to_array()[source]#
Convert the array to a
DataArraywith the grid as attributes and variables.- Returns
combined_ds – The
DataArraywith the added grid.- Return type
- classmethod load(load_path)[source]#
The RadarField is loaded from a NetCDF-file. This method should be only used if the field is saved with the ‘to_netcdf’ method.
- Parameters
load_path (str) – Path where the file is saved. The file need to be a NetCDF.file.
- Returns
loaded_field – The loaded radar field.k
- Return type
- remove_tag(tag)[source]#
Remove a tag (and any duplicates) from
tags. Don’t complain if the tag doesn’t exist.- Parameters
tag (str) – The tag to remove
- set_grid_coordinates(grid)[source]#
Set the grid coordinates for this DataArray. The coordinates of this DataArray are replaced by the coordinates of the grid.
- set_metadata(other_array)[source]#
Set the metadata for this array based on the given other array. The metadata is the name, the attributes and the grid.
- Parameters
other_array (
xarray.DataArray) – The other_array is used to extract the metadata for the data of this class.- Returns
attributed_array – This array with replaced name, attributes and grid from other_array.
- Return type
- set_variable(name)[source]#
Set the variable name of this DataArray to the given name. The unit, long name and short name are set according to the naming convention defined in utilities/conventions.py.
- Parameters
name (str) – The name of the variable. This name needs to be defined in the naming convention.
- Returns
named_array – The DataArray with the set name, unit, long name and short name. All other attributes will be also set. If a grid is defined for this DataArray it will be carried over.
- Return type
- property tags#
Tags describing what has already happened to this field
- Type
- Getter
Converts the
RadarField.dataxarray.DataArray.attrs"tags"to alist- Setter
Sets the
RadarField.dataxarray.DataArray.attrs"tags"key
- to_dbz()[source]#
Convert the rain field to reflectivity in decibel from any arbitrary variable. If no variable is specified in the attributes, it is assumed that the rain field is the reflectivity in decibel. If the variable of this DataArray is rain_rate zr_convert with default values will be used.
- Returns
converted_field – The converted rain field as reflectivity in dB. The field has the same grid and attributes (except for the variable unit and names) as this DataArray.
- Return type
- to_netcdf(save_path)[source]#
Save the RadarField to given save path as NetCDF-file. The grid is added to the attributes such that it can be restored from the attributes.
- Parameters
save_path (str) – Path where the file should be saved. If the path is a directory the file name is inferred by the radar and grid.
- to_z()[source]#
Convert the rain field to linear reflectivity from any arbitrary variable. If no variable is specified in the attributes, it is assumed that the rain field is the reflectivity in decibel. If the variable of this DataArray is rain_rate zr_convert with default values will be used.
- Returns
converted_field – The converted rain field as linear reflectivity. The field has the same grid and attributes (except for the variable unit and names) as this DataArray.
- Return type
- zr_convert(a=200.0, b=1.6, inverse=False)[source]#
Convert from z to r via Z/R relationship. The Z/R relationship is calculated with
\[r = \sqrt[b]{\frac{z}{a}}\]for conversion from z to r. If inverse is chosen, then the unit will be converted from r to z with:
\[z = a \cdot r^{b}\]- Parameters
a (float, optional) – Parameter a of the Z/R relationship. This is the scale factor of the Z/R relationship. Default is 200.0 from Marshall-Palmer.
b (float, optional) – Parameter b of the Z/R relationship. This is the polynomial grade factor of the Z/R relationship. Default is 1.6 from Marshall-Palmer.
inverse (bool, optional) – If the reflectivity should be calculated based on a rain rate field (True) or if the rain rate should be calculated based on the reflectivity (False). Default is False.
- Returns
converted_field – The converted rain field with r or z as unit and the same grid as this DataArray.
- Return type
Warning
- UserWarning :
An UserWarning will be raised if the rain field is already the right variable or if the field is in decibel units.
- pylawr.field.get_verified_grid(array, grid=None)[source]#
Get a verified grid from the array and given grid.
- Parameters
array (
xarray.DataArray) – If no grid is given, this array will be used to determine the grid. The grid is verified to this array.grid (child of
BaseGridor None) – This grid is verified within this method. If no grid is given, the grid from the array is used.
- Returns
verified_grid – The verified and inferred grid. If a grid is given and verified, this will be the same grid as given.
- Return type
child of
BaseGrid- Raises
AttributeError – An AttributeError is raised if no grid was specified and no grid is set for the array.
TypeError – A TypeError is raised if the given grid is not a valid grid.
ValueError – A ValueError is raised if the given grid does not have the same shape as the given array.
- pylawr.field.untag_array(array, tag)[source]#
Remove a tag from an array with
remove_tag()