API

The PyPROS module

Functions to calculate the precipitation type. For a point or numpy arrays

class pypros.pros.PyPros(variables_file, method='ks', threshold=None, data_format=None)[source]

Main project class. Discriminates precipitation type considering different methodologies using surface observations.

__init__(variables_file, method='ks', threshold=None, data_format=None)[source]
Parameters
  • variables_file (str, list) – The file paths containing air temperature, dew point temperature and (digital elevation model) fields.

  • method (str) –

    The precipitation type discrimination method to use. Defaults to ks.

    Available:
    • ks : Koistinen and Saltikoff method

    • single_tw: A single wet bulb temperature

      threshold

    • single_ta: A single air temperature threshold

    • dual_tw : A dual wet bulb temperature thresholds

    • dual_ta : A dual air temperature threshold

    • linear_tr: Linear transition between rain

      and snow

  • threshold (float, list) –

    Threshold value(s) to use in the different methods available.

    Defaults to:
    • static_tw: 1.5

    • static_ta: 0.0

    • linear_tr: [0, 3]

  • data_format (dict, optional) –

    Defaults to None. The order of the variables in the variables files. Defaults to: {‘vars_files’: [‘tair’,

    ’tdew’, ‘dem’]}

Raises

ValueError – Raised when the method is not valid

__weakref__

list of weak references to the object (if defined)

refl_mask(refl)[source]

Calculates the precipitation type masked. The output classification is as follows:

rain

  • 1dBZ : 1

  • 5dBZ: 2

  • 10dBZ : 3

  • 15dBZ: 4

  • 25dBZ : 5

sleet

  • 1dBZ: 6

  • 5dBZ : 7

  • 10dBZ: 8

  • 15dBZ : 9

  • 25dBZ: 10

snow

  • 1dBZ : 11

  • 5dBZ: 12

  • 10dBZ : 13

  • 15dBZ: 14

  • 25dbZ: 15

Parameters

refl (numpy.array) – Array with reflectivity values

Raises

IndexError – Raised if the types don’t match in size or type

Returns

The precipitation type classification value

Return type

float, numpy array

save_file(field, file_name)[source]

Saves the calculate field data into a file

Parameters

file_name (str) – The output file path

Psychrometric calculations

Psychrometric calculations

pypros.psychrometrics.get_tw_sadeghi(tair, tdew, z)[source]

Gets the wet bulb temperature from air temperature, dew point temperature and pressure. Formula taken from: https://journals.ametsoc.org/doi/pdf/10.1175/JTECH-D-12-00191.1

Results close to trhp2tw, but computationally efficient

Parameters
  • tair (float, numpy array) – The air temperature in Celsius

  • tdew (float, numpy array) – The dew point temperature in Celsius

  • z (float, numpy array) – The altitude in metres

Returns

The wet bulb temperature in Celsius

Return type

float, numpy array

pypros.psychrometrics.hr2td(temp, r_h)[source]

Returns the dew point from the relative humidity and the temperature Formula from: https://www.aprweather.com/pages/calc.htm

Both float values or numpy matrices can be passed as input and get as output

Parameters
  • temp (float, numpy array) – The temperature in Celsius

  • r_h (float, numpy array) – The relative humidity in %

Returns

The dew point in Celsius

Return type

float, numpy array

pypros.psychrometrics.td2hr(temp, tempd)[source]

Returns the relative humidity from the temperature and the dew point Formula from: https://www.aprweather.com/pages/calc.htm

Both float values or numpy matrices can be passed as input and get as output

Parameters
  • temp (float, numpy array) – The temperature in Celsius

  • tempd (float, numpy array) – The dew point in Celsius

Returns

The relative humidity in %

Return type

float, numpy array

pypros.psychrometrics.trhp2tw(temp, rh, z)[source]

Gets the wet bulb temperature from the temperature, relative humidity and pressure. Formula taken from: https://www.weather.gov/epz/wxcalc_wetbulb (Brice and Hall, 2003)

Parameters
  • temp (float, numpy array) – The temperature in Celsius

  • rh (float, numpy array) – The relative humidity in [0,1]

  • z (float, numpy array) – The altitude in metres

Returns

The wet bulb temperature in Celsius

Return type

float, numpy array

pypros.psychrometrics.ttd2tw(temp, tempd)[source]

Gets the wet bulb temperature from the temperature and the dew point Formula taken from: https://journals.ametsoc.org/doi/full/10.1175/JAMC-D-11-0143.1

TODO: Take altitude in account (should change algorithm)

Parameters
  • temp (float, numpy array) – The temperature in Celsius

  • tempd (float, numpy array) – The dew point in Celsius

Returns

The wet bulb temperature in Celsius

Return type

float, numpy array

Rain or snow methodologies

Implements several rain or snow methodologies.

pypros.ros_methods.calculate_dual_threshold(field, th_s, th_r)[source]

Calculates the precipitation type based on two threshold values, one for rain and one for snow. If value >= th_r –> rain –> 0 If value <= th_s –> snow –> 1 If th_s < value < th_r –> mixed –> 0.5

Parameters
  • field (float, numpy array) – Meteorological variable field

  • th_s (float) – Snow threshold. Values below this threshold classified as snow.

  • th_r (float) – Rain threshold. Values above this threshold classified as rain.

Raises

ValueError – Raised if th_r is smaller than th_s.

Returns

Precipitation type field

Return type

float, numpy array

pypros.ros_methods.calculate_koistinen_saltikoff(temp, tempd)[source]

Returns the Koistinen-Saltikoff value.

Koistinen J., Saltikoff E. (1998): Experience of customer products of accumulated snow, sleet and rain, COST 75 Final Seminar on Advanced Weather Radar Systems, Locarno, Switzerland. EUR 18567 EN, 397-406.

The formula values are

  • prob < 0.3 –> rain

  • 0.3 < prob < 0.7 –> sleet

  • prob > 0.7 –> snow

Both float values or numpy matrices can be passed as input and get as output

Parameters
  • temp (float, numpy array) – The temperature in Celsius

  • tempd (float, numpy array) – The dew point in Celsius

Returns

The Koistinen J., Saltikoff E. formula value

Return type

float, numpy array

pypros.ros_methods.calculate_linear_transition(field, th_s, th_r)[source]

Calculates the probability of precipitation type based on two threshold values, one for rain and one for snow. Assumes a linear transition between them. If value >= th_r –> rain –> 0 If value <= th_s –> snow –> 1 If th_s < value < th_r –> mixed –> (0, 1)

Parameters
  • field (float, numpy array) – Meteorological variable field

  • th_s (float) – Snow threshold. Values below this threshold classified as snow.

  • th_r (float) – Rain threshold. Values above this threshold classified as rain.

Raises

ValueError – Raised if th_r is smaller than th_s.

Returns

Probability of precipitation type field

Return type

float, numpy array

pypros.ros_methods.calculate_single_threshold(field, th)[source]

Calculates the precipitation type based on a threshold value. If value > threshold –> rain –> 0 If value <= threshold –> snow –> 1

Parameters
  • field (float, numpy array) – Meteorological variable field

  • th (float) – Threshold from which precipitation type is discriminated

Returns

Precipitation type field

Return type

float, numpy array