def TR_calculation(arr, fill_val=None, threshold=20, out_unit="days"): """ Calculates the TR indice: number of tropical nights (i.e. days with daily minimum temperature > 20 degrees Celsius) [days]. :param arr: daily min temperature (e.g. "tasmin") in Kelvin :type arr: numpy.ndarray (3D) or numpy.ma.MaskedArray (3D) :param fill_val: fill value :type fill_val: float :param threshold: user defined temperature threshold in degrees Celsius (default: threshold=20) :type threshold: float :rtype: numpy.ndarray (2D) (if "arr" is numpy.ndarray) or numpy.ma.MaskedArray (2D) (if "arr" is numpy.ma.MaskedArray) .. warning:: Units of "arr" must be Kelvin. .. warning:: Units of "threshold" must be in Celsius. .. warning:: If "arr" is a masked array, the parameter "fill_val" is ignored, because it has no sense in this case. """ T = threshold + 273.15 TR = calc.get_nb_events(arr, logical_operation="gt", thresh=T, fill_val=fill_val, out_unit=out_unit) return TR
def TX90p_calculation(arr, dt_arr, percentile_dict, fill_val=None, out_unit="days"): """ Calculate the TX90p indice: number of warm days-times (i.e. days with daily max temperature > 90th percentile of daily max temperature in the base period). :param arr: daily max temperature (e.g. "tasmax") :type arr: numpy.ndarray (3D) or numpy.ma.MaskedArray (3D) :param dt_arr: corresponding time steps vector :type dt_arr: numpy.ndarray (1D) of datetime objects :param percentile_dict: 90th percentile of daily max temperature :type percentile_dict: dict :param fill_val: fill value :type fill_val: float :rtype: numpy.ndarray (2D) (if "arr" is numpy.ndarray) or numpy.ma.MaskedArray (2D) (if "arr" is numpy.ma.MaskedArray) .. warning:: Units of "arr" and percentile values of "percentile_dict" must be the same. .. warning:: If "arr" is a masked array, the parameter "fill_val" is ignored, because it has no sense in this case. """ TX90p = calc.get_nb_events( arr, logical_operation="gt", thresh=percentile_dict, fill_val=fill_val, out_unit=out_unit, dt_arr=dt_arr ) return TX90p
def R99p_calculation(arr, percentile_arr, fill_val=None, out_unit="days"): """ Calculate the R99p indice: number of extremely wet days (i.e. days with daily precipitation amount > 99th percentile of daily amount in the base period). :param arr: daily precipitation flux (liquid form) (e.g. "pr") in mm/day :type arr: numpy.ndarray (3D) or numpy.ma.MaskedArray (3D) :param dt_arr: corresponding time steps vector :type dt_arr: numpy.ndarray (1D) of datetime objects :param percentile_dict: 99th percentile of daily precipitation amount at wet days in mm/day :type percentile_dict: dict :param fill_val: fill value :type fill_val: float :rtype: numpy.ndarray (2D) (if "arr" is numpy.ndarray) or numpy.ma.MaskedArray (2D) (if "arr" is numpy.ma.MaskedArray) .. warning:: If "arr" is a masked array, the parameter "fill_val" is ignored, because it has no sense in this case. """ wet_arr = calc.get_wet_days(arr=arr, fill_val=fill_val) # masked array R99p = calc.get_nb_events( wet_arr, logical_operation="gt", thresh=percentile_arr, fill_val=fill_val, out_unit=out_unit ) return R99p
def SU_calculation(arr, fill_val=None, threshold=25, out_unit="days"): ''' Calculates the SU indice: number of summer days (i.e. days with daily maximum temperature > 25 degrees Celsius) [days]. :param arr: daily maximum temperature (e.g. "tasmax") in Kelvin :type arr: numpy.ndarray (3D) or numpy.ma.MaskedArray (3D) :param fill_val: fill value :type fill_val: float :param threshold: user defined temperature threshold in degrees Celsius (default: threshold=25) :type threshold: float :rtype: numpy.ndarray (2D) (if "arr" is numpy.ndarray) or numpy.ma.MaskedArray (2D) (if "arr" is numpy.ma.MaskedArray) .. warning:: Units of "arr" must be Kelvin. .. warning:: Units of "threshold" must be in Celsius. .. warning:: If "arr" is a masked array, the parameter "fill_val" is ignored, because it has no sense in this case. ''' T = threshold + 273.15 SU = calc.get_nb_events(arr, logical_operation='gt', thresh=T, fill_val=fill_val, out_unit=out_unit) return SU
def R20mm_calculation(arr, fill_val=None, threshold=20.0, out_unit="days"): """ Calculates the R20mm indice: number of very heavy precipitation days (i.e. days with daily precipitation amount > = 20 mm) [days] :param arr: daily precipitation (liquid form) flux (e.g. "pr") in mm/day :type arr: numpy.ndarray (3D) or numpy.ma.MaskedArray (3D) :param fill_val: fill value :type fill_val: float :rtype: numpy.ndarray (2D) (if "arr" is numpy.ndarray) or numpy.ma.MaskedArray (2D) (if "arr" is numpy.ma.MaskedArray) .. warning:: Units of "arr" must be mm/day. .. warning:: If "arr" is a masked array, the parameter "fill_val" is ignored, because it has no sense in this case. """ R20mm = calc.get_nb_events(arr, logical_operation="get", thresh=threshold, fill_val=fill_val, out_unit=out_unit) return R20mm
def SD50cm_calculation(arr, fill_val=None, threshold=50.0, out_unit="days"): """ Calculates the SD50cm indice: number of days with snow depth >= 50 cm [days] :param arr: daily snowfall precipitation flux (e.g. "prsn") in mm/day :type arr: numpy.ndarray (3D) or numpy.ma.MaskedArray (3D) :param fill_val: fill value :type fill_val: float :rtype: numpy.ndarray (2D) (if "arr" is numpy.ndarray) or numpy.ma.MaskedArray (2D) (if "arr" is numpy.ma.MaskedArray) .. warning:: Units of "arr" must be ????. .. warning:: If "arr" is a masked array, the parameter "fill_val" is ignored, because it has no sense in this case. """ threshold = threshold * 10 # cm --> mm SD50cm = calc.get_nb_events(arr, logical_operation="get", thresh=threshold, fill_val=fill_val, out_unit=out_unit) return SD50cm
def ID_calculation(arr, fill_val=None, threshold=0, out_unit="days"): """ Calculates the ID indice: number of ice days (i.e. days with daily maximum temperature < 0 degrees Celsius) [days]. :param arr: daily max temperature (e.g. "tasmax") in Kelvin :type arr: numpy.ndarray (3D) or numpy.ma.MaskedArray (3D) :param fill_val: fill value :type fill_val: float :rtype: numpy.ndarray (2D) (if "arr" is numpy.ndarray) or numpy.ma.MaskedArray (2D) (if "arr" is numpy.ma.MaskedArray) .. warning:: Units of "arr" must be Kelvin. .. warning:: If "arr" is a masked array, the parameter "fill_val" is ignored, because it has no sense in this case. """ T = threshold + 273.15 ID = calc.get_nb_events(arr, logical_operation="lt", thresh=T, fill_val=fill_val, out_unit=out_unit) return ID