diff --git a/README.rst b/README.rst index e8670e79..b2b4fcfb 100644 --- a/README.rst +++ b/README.rst @@ -43,6 +43,7 @@ Atlite can process the following weather data fields and can convert them into f .. * Surface roughness .. * Height maps .. * Soil temperature +.. * Dewpoint temperature .. * Wind power generation for a given turbine type diff --git a/atlite/convert.py b/atlite/convert.py index 3c41e75e..d275843d 100644 --- a/atlite/convert.py +++ b/atlite/convert.py @@ -241,6 +241,21 @@ def soil_temperature(cutout, **params): return cutout.convert_and_aggregate(convert_func=convert_soil_temperature, **params) +# dewpoint temperature +def convert_dewpoint_temperature(ds): + """ + Return dewpoint temperature. + """ + # Temperature is in Kelvin + return ds["dewpoint temperature"] - 273.15 + + +def dewpoint_temperature(cutout, **params): + return cutout.convert_and_aggregate( + convert_func=convert_dewpoint_temperature, **params + ) + + def convert_coefficient_of_performance(ds, source, sink_T, c0, c1, c2): assert source in ["air", "soil"], NotImplementedError( "'source' must be one of ['air', 'soil']" diff --git a/atlite/cutout.py b/atlite/cutout.py index 7c2aeeef..5a636e6f 100644 --- a/atlite/cutout.py +++ b/atlite/cutout.py @@ -35,6 +35,7 @@ coefficient_of_performance, convert_and_aggregate, csp, + dewpoint_temperature, heat_demand, hydro, irradiation, @@ -681,6 +682,8 @@ def layout_from_capacity_list(self, data, col="Capacity"): soil_temperature = soil_temperature + dewpoint_temperature = dewpoint_temperature + coefficient_of_performance = coefficient_of_performance solar_thermal = solar_thermal diff --git a/atlite/datasets/era5.py b/atlite/datasets/era5.py index f234ba71..58a62dda 100644 --- a/atlite/datasets/era5.py +++ b/atlite/datasets/era5.py @@ -53,7 +53,7 @@ def nullcontext(): "solar_altitude", "solar_azimuth", ], - "temperature": ["temperature", "soil temperature"], + "temperature": ["temperature", "soil temperature", "dewpoint temperature"], "runoff": ["runoff"], } @@ -199,11 +199,22 @@ def get_data_temperature(retrieval_params): Get wind temperature for given retrieval parameters. """ ds = retrieve_data( - variable=["2m_temperature", "soil_temperature_level_4"], **retrieval_params + variable=[ + "2m_temperature", + "soil_temperature_level_4", + "2m_dewpoint_temperature", + ], + **retrieval_params, ) ds = _rename_and_clean_coords(ds) - ds = ds.rename({"t2m": "temperature", "stl4": "soil temperature"}) + ds = ds.rename( + { + "t2m": "temperature", + "stl4": "soil temperature", + "d2m": "dewpoint temperature", + } + ) return ds diff --git a/test/test_preparation_and_conversion.py b/test/test_preparation_and_conversion.py index c8a5ecdb..b1f4ec09 100644 --- a/test/test_preparation_and_conversion.py +++ b/test/test_preparation_and_conversion.py @@ -273,6 +273,16 @@ def soil_temperature_test(cutout): assert demand.sum() > 0 +def dewpoint_temperature_test(cutout): + """ + Test the atlite.Cutout.dewpoint_temperature function with different + settings. + """ + demand = cutout.dewpoint_temperature() + assert demand.notnull().all() + assert demand.sum() > 0 + + def wind_test(cutout): """ Test the atlite.Cutout.wind function with two different layouts. @@ -684,6 +694,10 @@ def test_heat_demand_era5(cutout_era5): def test_soil_temperature_era5(cutout_era5): return soil_temperature_test(cutout_era5) + @staticmethod + def test_dewpoint_temperature_era5(cutout_era5): + return dewpoint_temperature_test(cutout_era5) + @staticmethod def test_line_rating_era5(cutout_era5): return line_rating_test(cutout_era5)