pylawr.utilities#

pylawr.utilities.decorators.lazy_property(fn)

Decorator that makes a property lazy-evaluated.

pylawr.utilities.decorators.log_decorator(...)

pylawr.utilities.decorators.tuplesetter(prop)

This decorator can be used to make sure that the set attribute is a tuple.

pylawr.utilities.helpers.polar_padding(...)

Utility function for polar padding.

pylawr.utilities.helpers.create_array(grid)

Create a testing array based on given grid.

pylawr.utilities.decorators#

pylawr.utilities.decorators.lazy_property(fn)[source]#

Decorator that makes a property lazy-evaluated. Based on: http://stevenloria.com/lazy-evaluated-properties-in-python/

pylawr.utilities.decorators.log_decorator(fn_logger)[source]#
pylawr.utilities.decorators.tuplesetter(prop, len_tuple=2, valid_types=None)[source]#

This decorator can be used to make sure that the set attribute is a tuple. The decorated method needs to return the value, which should be set. If the value is an iterable, it will be converted into a tuple and shortened to the given tuple length starting from the beginning. If the value is None, then the attribute will be set to None. For any other type the value is converted into a tuple with len_tuple times the value as elements.

Parameters
  • prop (property) – the property

  • len_tuple (int) – The length of the set tuple. If the return value of the decorated method is an iterable it will be shortened to this length. Default is 2.

  • valid_types (python type, tuple(python types) or None) – The tuple elements will be tested against these valid types with :py:func:isinstance. If this is None, the test will be skipped. Default is None.

Returns

The decorated callable

Return type

callable

pylawr.utilities.padding#

pylawr.utilities.helpers.create_array(grid, const_val=0, timestamp=datetime.datetime(2023, 7, 25, 10, 43, 52, 769309), tag='testing', var='dbz')[source]#

Create a testing array based on given grid. The array is initialized with given constant value.

Parameters
  • grid (child of pylawr.grid.BaseGrid) – The array will be created based on these grid coordinates.

  • const_val (float, optional) – The grid will have this constant value.

  • timestamp (datetime.datetime, optional) – Value of time coordinate.

  • tag (str, optional) – This tag is added to the array.

  • var (str, optional) – Variable of array following naming conventions.

Returns

array – This array has the shape of the grid coordinates and an additional time axis as first dimension. The time is initialized as 01/01/1970. The grid is appended to this array with set_grid_coordinates.

Return type

xarray.DataArray

pylawr.utilities.helpers.polar_padding(reflectivity, pad_size=(5, 5))[source]#

Utility function for polar padding. In polar padding, the lower boundary is wrapped, while the upper boundary is reflected. The left and right boundaries are connected.

array([[1, 2, 3, 4],
       [5, 6, 7, 8],
       [9, 10, 11, 12]])

with a field size of (3,3) will be padded to:

array([[2, 3, 4, 1, 2, 3],
       [4, 1, 2, 3, 4, 1],
       [8, 5, 6, 7, 8, 5],
       [12, 9, 10, 11, 12, 9],
       [12, 9, 10, 11, 12, 9]])
Parameters
  • reflectivity (numpy.ndarray) – This reflectivity field will be padded. The last two dimension should be (azimuth, range).

  • pad_size (tuple(int, int), optional) – The padding of (azimuth, range).

Returns

padded_refl – The padded reflectivity field.

Return type

numpy.ndarray