Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request #403 default time referenced to forecast time #421

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CCDFDataModel/CTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,10 @@ time_t CTime::getEpochTimeFromDateString(CT::string dateString) {

CTime::Date CTime::subtractPeriodFromDate(CTime::Date date, CT::string period) {
CTime::Date datePeriod = periodToDate(period);
return this->subtractPeriodFromDate(date, datePeriod);
}

CTime::Date CTime::subtractPeriodFromDate(CTime::Date date, CTime::Date datePeriod) {
Date newDate;
newDate.year = date.year - datePeriod.year;
newDate.month = date.month - datePeriod.month;
Expand All @@ -1063,7 +1067,23 @@ CTime::Date CTime::subtractPeriodFromDate(CTime::Date date, CT::string period) {
newDate.minute = date.minute - datePeriod.minute;
newDate.second = date.second - datePeriod.second;
double offset = this->dateToOffset(newDate);
return this->offsetToDate(offset);
}

CTime::Date CTime::addPeriodToDate(CTime::Date date, CT::string period) {
CTime::Date datePeriod = periodToDate(period);
return this->addPeriodToDate(date, datePeriod);
}

CTime::Date CTime::addPeriodToDate(CTime::Date date, CTime::Date datePeriod) {
Date newDate;
newDate.year = date.year + datePeriod.year;
newDate.month = date.month + datePeriod.month;
newDate.day = date.day + datePeriod.day;
newDate.hour = date.hour + datePeriod.hour;
newDate.minute = date.minute + datePeriod.minute;
newDate.second = date.second + datePeriod.second;
double offset = this->dateToOffset(newDate);
return this->offsetToDate(offset);
}

Expand Down
11 changes: 11 additions & 0 deletions CCDFDataModel/CTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ class CTime {
* @return Date
*/
Date subtractPeriodFromDate(CTime::Date date, CT::string period);
Date subtractPeriodFromDate(CTime::Date date, Date period);

/**
* @brief Can be used to add an iso8601 period string to a date. The function ensures that allowed ranges for the individual time componets are preserved.
*
* @param date
* @param period
* @return Date
*/
Date addPeriodToDate(CTime::Date date, CT::string period);
Date addPeriodToDate(CTime::Date date, Date period);

/**
* @brief Converts a iso8601 period string to a date
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ USER root
LABEL maintainer="[email protected]"

# Version should be same as in Definitions.h
LABEL version="2.29.0"
LABEL version="2.29.1"

# Try to update image packages
RUN apt-get -q -y update \
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**Version 2.29.1 2024-12-23**
- Default value for time dimension can now be based on default value of reference_time dimension (Issue #403)

**Version 2.29.0 2024-11-11**
- Adds support for grids where the data cells are defined by lat_bnds and lon_bnds parameters describing the cell bounds.

Expand Down
2 changes: 1 addition & 1 deletion adagucserverEC/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#ifndef Definitions_H
#define Definitions_H

#define ADAGUCSERVER_VERSION "2.29.0" // Please also update in the Dockerfile to the same version
#define ADAGUCSERVER_VERSION "2.29.1" // Please also update in the Dockerfile to the same version

// CConfigReaderLayerType
#define CConfigReaderLayerTypeUnknown 0
Expand Down
304 changes: 161 additions & 143 deletions adagucserverEC/utils/XMLGenUtils.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>


<Layer type="database">
<Name>time_default_min</Name>
<Title>time_default_min</Title>
<Variable>air-temperature-pl</Variable>
<FilePath
filter="^uwcw_ha43_dini_5p5km_air-temperature-pl_geoweb_nc_20240711T0.*_TEST_10x8\.nc$">
{ADAGUC_PATH}data/datasets/ha43_dini/</FilePath>
<Styles>temperature_wow</Styles>
<Dimension name="forecast_reference_time" units="ISO8601" default="max">reference_time</Dimension>
<Dimension name="temp_at_pl" units="hPa" default="max" hidden="false">pressure_level_in_hpa</Dimension>
<Dimension name="time" units="ISO8601" interval="PT1H" default="min">time</Dimension>

</Layer>
<Layer type="database">
<Name>time_default_max</Name>
<Title>time_default_max</Title>
<Variable>air-temperature-pl</Variable>
<FilePath
filter="^uwcw_ha43_dini_5p5km_air-temperature-pl_geoweb_nc_20240711T0.*_TEST_10x8\.nc$">
{ADAGUC_PATH}data/datasets/ha43_dini/</FilePath>
<Styles>temperature_wow</Styles>
<Dimension name="forecast_reference_time" units="ISO8601" default="max">reference_time</Dimension>
<Dimension name="temp_at_pl" units="hPa" default="max" hidden="false">pressure_level_in_hpa</Dimension>
<Dimension name="time" units="ISO8601" interval="PT1H" default="max">time</Dimension>

</Layer>

<Layer type="database">
<Name>time_default_forecast_reference_time</Name>
<Title>time_default_forecast_reference_time</Title>
<Variable>air-temperature-pl</Variable>
<FilePath
filter="^uwcw_ha43_dini_5p5km_air-temperature-pl_geoweb_nc_20240711T0.*_TEST_10x8\.nc$">
{ADAGUC_PATH}data/datasets/ha43_dini/</FilePath>
<Styles>temperature_wow</Styles>
<Dimension name="forecast_reference_time" units="ISO8601" default="max">reference_time</Dimension>
<Dimension name="temp_at_pl" units="hPa" default="max" hidden="false">pressure_level_in_hpa</Dimension>
<Dimension name="time" units="ISO8601" interval="PT1H" default="forecast_reference_time">
time</Dimension>

</Layer>


<Layer type="database">
<Name>time_default_forecast_reference_time_and_duration</Name>
<Title>time_default_forecast_reference_time_and_duration</Title>
<Variable>air-temperature-pl</Variable>
<FilePath
filter="^uwcw_ha43_dini_5p5km_air-temperature-pl_geoweb_nc_20240711T0.*_TEST_10x8\.nc$">
{ADAGUC_PATH}data/datasets/ha43_dini/</FilePath>
<Styles>temperature_wow</Styles>
<Dimension name="forecast_reference_time" units="ISO8601" default="max">reference_time</Dimension>
<Dimension name="temp_at_pl" units="hPa" default="max" hidden="false">pressure_level_in_hpa</Dimension>
<Dimension name="time" units="ISO8601" interval="PT1H"
default="forecast_reference_time+PT1H">time</Dimension>

</Layer>


</Configuration>
15 changes: 10 additions & 5 deletions doc/configuration/Dimension.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ Back to [Configuration](./Configuration.md)
- name - The name of the dimension in the netcdf file
- interval - Optional, the time resolution of the dataset in
[ISO8601](ISO8601.md) format.
- default - The default value of the dimension in [ISO8601](ISO8601.md)
format, can also be "min" or "max" to select the first or latest
date as default. Defaults to "max".
- default - Defaults to "max". See details below
- units - Override the units of the dimension
- quantizeperiod - Optional, see below
- quantizemethod - Optional, see below
Expand All @@ -25,8 +23,15 @@ Back to [Configuration](./Configuration.md)

- See [ISO8601](../info/ISO8601.md) for the time resolution specification

Time quantization
-----------------
## default value

- The default value of the dimension can be specified as datestring in [ISO8601](ISO8601.md) format
- Can be "min" or "max" to select the first or latest
- Can be set to "forecast_reference_time" to reference the default value of the forecast_reference_time dimension.
- Can be set to "forecast_reference_time+PT1H" to reference the default value of the forecast_reference_time dimension, and it will add a ISO8601 Period to the derived value. See test [data/config/datasets/adaguc.tests.403_default_time_referenced_to_forecast_time.xml](../../data/config/datasets/adaguc.tests.403_default_time_referenced_to_forecast_time.xml) for details.


## Time quantization

Time values received in the URL as input can be rounded to more discrete
time periods. For example when noon, 12:03:53, is received as input, it
Expand Down
34 changes: 34 additions & 0 deletions tests/AdagucTests/TestWMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -2598,3 +2598,37 @@ def test_WMSGetLegendGraphic_SolarTerminator(self):
data.getvalue(),
AdagucTestTools().readfromfile(self.expectedoutputsspath +
filename))



def test_WMSGetCapabilities_403_default_time_referenced_to_forecast_time(self):
"""
See https://github.com/KNMI/adaguc-server/issues/403
"""
AdagucTestTools().cleanTempDir()

config = (
ADAGUC_PATH
+ "/data/config/adaguc.tests.dataset.xml,"
+ ADAGUC_PATH
+ "/data/config/datasets/adaguc.tests.403_default_time_referenced_to_forecast_time.xml"
)
# pylint: disable=unused-variable
status, data, headers = AdagucTestTools().runADAGUCServer(
args=["--updatedb", "--config", config], env=self.env, isCGI=False
)
self.assertEqual(status, 0)

filename = "test_WMSGetCapabilities_403_default_time_referenced_to_forecast_time.xml"
# pylint: disable=unused-variable
status, data, headers = AdagucTestTools().runADAGUCServer(
"dataset=adaguc.tests.403_default_time_referenced_to_forecast_time&service=WMS&request=GetCapabilities",
{"ADAGUC_CONFIG": ADAGUC_PATH + "/data/config/adaguc.tests.dataset.xml"},
)
AdagucTestTools().writetofile(self.testresultspath + filename, data.getvalue())
self.assertEqual(status, 0)
self.assertTrue(
AdagucTestTools().compareGetCapabilitiesXML(
self.testresultspath + filename, self.expectedoutputsspath + filename
)
)
Loading
Loading