Commit 570bebef authored by Lars Bärring's avatar Lars Bärring Committed by Klaus Zimmermann
Browse files

Add index function diurnal_temperature_range (closes #153)

parent d5e6246e
......@@ -1477,7 +1477,7 @@ indices:
low_data: tasmin
high_data: tasmax
index_function:
name: dtr
name: diurnal_temperature_range
parameters:
ET:
short_name: "dtr"
......
......@@ -33,6 +33,12 @@ index_functions:
condition:
kind: operator
diurnal_temperature_range:
description: |
This index function takes two inputs, low_data and high_data, i.e.
daily minimum and maximum temperature.
From this it calculated the average diurnal temperature range.
first_occurrence:
description: |
Calculates the first time some condition is met.
......
......@@ -3,6 +3,7 @@
from .index_functions import ( # noqa: F401
CountLevelCrossings,
CountOccurrences,
DiurnalTemperatureRange,
FirstOccurrence,
LastOccurrence,
SpellLength,
......
......@@ -56,6 +56,25 @@ class CountOccurrences(ThresholdMixin, IndexFunction):
return res.astype('float32')
class DiurnalTemperatureRange(IndexFunction):
def __init__(self):
super().__init__(units=Unit('degree_Celsius'))
def prepare(self, input_cubes):
props = {(cube.dtype, cube.units, cube.standard_name)
for cube in input_cubes.values()}
assert len(props) == 1
dtype, units, standard_name = props.pop()
assert units in [Unit('Kelvin'), Unit('degree_Celsius')]
super().prepare(input_cubes)
def call_func(self, data, axis, **kwargs):
res = (data['high_data'] - data['low_data']).mean(axis=axis)
return res.astype('float32')
lazy_func = call_func
class FirstOccurrence(ThresholdMixin, IndexFunction):
def __init__(self, threshold, condition):
super().__init__(threshold, condition, units=Unit('days'))
......
......@@ -60,6 +60,7 @@ setuptools.setup(
'statistics=climix.index_functions:Statistics',
'thresholded_statistics=climix.index_functions:ThresholdedStatistics',
'temperature_sum=climix.index_functions:TemperatureSum',
'diurnal_temperature_range=climix.index_functions:DiurnalTemperatureRange',
],
},
project_urls={
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment