swirlspy.utils.conversion package

Data conversion methods

swirlspy.utils.conversion.acc_rainfall_depth(frames, start_time, end_time, result_step_size=Timedelta('0 days 00:30:00'), acc_interval=Timedelta('0 days 01:00:00'), time_axis='time')

Obtain accumulated rainfall over a time period from a start_time to an end_time at certain times. For example, to generate past 60 minute rainfall every 30 minutes from start_time = x to end_time = y (inclusive).

Parameters
  • frames (xarray.DataArray) – Contains observed and/or forecasted rainfall every n minutes, n being the interval (in minutes) between two timestamps.

  • start_time (pandas.Timestamp) – The first base time of accumulation.

  • end_time (pandas.Timestamp) – The last base time of accumulation.

  • result_step_size (pandas.Timedelta) – Times at which accumulated rainfall are to be calculated. Defaults to every 30 minutes.

  • acc_interval (pandas.Timedelta) – Rainfall accumulation period. Defaults to 1 hour.

  • time_axis (str) – Name of time axis. (Default: ‘time’)

Returns

macc_rf – Contains accumulated rainfall over acc_interval every times.

Return type

xarray,DataArray

swirlspy.utils.conversion.temporal_interpolate(frames, start_time, end_time, result_step_size=Timedelta('0 days 00:06:00'), interp_type='linear')

Interpolate xarray data values such as rainrates along the time dimension.

Parameters
  • frames (xarray.DataArray) – Contains data values to be temporally interpolated.

  • start_time (pandas.Timestamp) – User defined start-time.

  • end_time (pandas.Timestamp) – The user-defined end time.

  • result_step_size (pandas.Timedelta) – The time interval between interpolated data. Defaults to 6 minutes.

  • interp_type (str) – The interpolation type for interpolating data in the time axis. Options include: ‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’, ‘previous’, ‘next’. Interpolation based on scipy.interpolate.interp1d. Default is linear.

Returns

interp_da – Contains data interpolated along the time axis.

Return type

xarray.DataArray

swirlspy.utils.conversion.to_hko_earth_format(data: DataArray, coords_dp: int = 3, values_dp: int = 2, uv_mode: bool = False, version: int = 1, error: int = 0, **kwargs) DataArray

Format data to HKO Earth format.

Parameters
  • data (xarray.DataArray) – Input data.

  • coords_dp (int, optional) – Decimal place of coordinates, e.g. 3 means coordinates related values will correct to 3 decimal place. Default : 3

  • values_dp (int, optional) – Decimal place of values, e.g. 2 means all data point values stored with correct to 2 decimal place. Default : 2

  • uv_mode (bool, optional) – If set to true, data will be parsed in UV mode. Default : False

  • version (int, optional) – Data version number. Default : 1

  • error (int, optional) – Error flag, set to 1 means it is a dummy image to acknowledge HKO earth something wrong with raw data. Default : 0

  • y_step (float, optional) – vertical step size between each pixels, if not set it will be calculated from data Default : Calculate from y coordinate, (y[-1] - y[0]) / len(y)

  • x_step (float, optional) – horizontal step size between each pixels, if not set it will be calculated from data Default : Calculate from x coordinate, (x[-1] - x[0]) / len(x)

swirlspy.utils.conversion.to_rainfall_depth(frames: DataArray, **kwargs)

Convert data frames’ value to accumulated rainfall. If Z-R relationship is used, default a & b are Marshall-Plalmer. You may wish to refer to the Z-R relationship page for more information on the choice of a & b.

Parameters
  • frames (xarray.DataArray) – data frames to be convert

  • a (float) – a in Z = aR^b relationship

  • b (float) – b in Z = aR^b relationship

Returns

r – xarray containing the accumulated rainfall depth relationship return frames no need to do any conversion

Return type

xarray.DataArray

swirlspy.utils.conversion.to_rainfall_rate(frames: DataArray, logarithmic: bool, **kwargs)

Convert data frames’ value to rainfall rate. If Z-R relationship is used, default a & b are Marshall-Plalmer. You may wish to refer to the Z-R relationship page for more information on the choice of a & b.

Parameters
  • frames (xarray.DataArray) – data frames to be convert

  • a (float) – a in Z = aR^b relationship

  • b (float) – b in Z = aR^b relationship

Returns

r – xarray containing the rainfall rate relationship return frames no need to do any conversion

Return type

xarray.DataArray

swirlspy.utils.conversion.to_reflectivity(frames: DataArray, logarithmic: bool, **kwargs)

Convert data frames’ value to radar reflectivity factor. If Z-R relationship is used, default a & b are Marshall-Plalmer. You may wish to refer to the Z-R relationship page for more information on the choice of a & b.

Parameters
  • frames (xarray.DataArray) – data frames to be convert

  • a (float) – a in Z = aR^b relationship

  • b (float) – b in Z = aR^b relationship

Returns

r – xarray containing the radar reflectivity factor relationship return frames no need to do any conversion

Return type

xarray.DataArray

swirlspy.utils.conversion.to_rgb_data(data: DataArray, uv_mode: bool = False, **kwargs) ndarray

Create rgba data from data array. If meta data is included in data array attribute, it will be prepended to at the start of data. Assumed it will have matched width with input data.

Parameters
  • data (xarray.DataArray) – Input data.

  • uv_mode (bool, optional) – If set to True, input data will be assumed with shape (y, x, 2) where last dimension is (U, V). Otherwise, it should be (y, x) Default : False

  • zero_value (integer, optional) – the value assigned to the pixel if that point is unknown value. Default : 0

swirlspy.utils.conversion.tz2naive(timestamp)

Convert timezone-aware pandas.Timestamp to timezone-naive pandas.Timestamp in local time