Skip to content

Commit 920be80

Browse files
Address review feedback and align test suite
1 parent 0342ae2 commit 920be80

20 files changed

+498
-675
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased/Snapshot]
88

9+
### Added
10+
- Add ground temperature (1m) as option to weather data. [#1343](https://github.com/ie3-institute/PowerSystemDataModel/issues/1343)
11+
912
### Fixed
1013
- Fixed handling of `CongestionResult.InputModelType` in `EntityProcessor` [#1325](https://github.com/ie3-institute/PowerSystemDataModel/issues/1325)
1114
- -Fixed em fields in input models [#1331](https://github.com/ie3-institute/PowerSystemDataModel/issues/1331)
Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
/*
2-
* © 2021. TU Dortmund University,
2+
* © 2020. TU Dortmund University,
33
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
44
* Research group Distribution grid planning and operation
55
*/
66
package edu.ie3.datamodel.io.factory.timeseries;
77

8+
import edu.ie3.datamodel.exceptions.FactoryException;
89
import edu.ie3.datamodel.models.StandardUnits;
910
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
10-
import edu.ie3.datamodel.models.value.SolarIrradianceValue;
1111
import edu.ie3.datamodel.models.value.TemperatureValue;
1212
import edu.ie3.datamodel.models.value.WeatherValue;
13-
import edu.ie3.datamodel.models.value.WindValue;
1413
import edu.ie3.util.TimeUtil;
1514
import edu.ie3.util.quantities.PowerSystemUnits;
1615
import edu.ie3.util.quantities.interfaces.Irradiance;
1716
import java.time.ZonedDateTime;
18-
import java.time.format.DateTimeFormatter;
1917
import java.util.*;
2018
import javax.measure.quantity.Angle;
2119
import javax.measure.quantity.Length;
@@ -24,85 +22,75 @@
2422
import org.locationtech.jts.geom.Point;
2523
import tech.units.indriya.ComparableQuantity;
2624
import tech.units.indriya.quantity.Quantities;
25+
import tech.units.indriya.unit.Units;
2726

28-
/**
29-
* Factory implementation of {@link TimeBasedWeatherValueFactory}, that is able to handle field to
30-
* value mapping in the typical PowerSystemDataModel (PSDM) column scheme
31-
*/
3227
public class CosmoTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFactory {
28+
private static final String TIME = "time";
29+
private static final String COORDINATE_ID = "coordinateId";
3330
private static final String DIFFUSE_IRRADIANCE = "diffuseIrradiance";
3431
private static final String DIRECT_IRRADIANCE = "directIrradiance";
3532
private static final String TEMPERATURE = "temperature";
3633
private static final String WIND_DIRECTION = "windDirection";
3734
private static final String WIND_VELOCITY = "windVelocity";
38-
3935
private static final String GROUND_TEMPERATURE_SURFACE = "groundTemperatureSurface";
4036
private static final String GROUND_TEMPERATURE_1M = "groundTemperature1m";
4137

4238
public CosmoTimeBasedWeatherValueFactory(TimeUtil timeUtil) {
4339
super(timeUtil);
4440
}
4541

46-
public CosmoTimeBasedWeatherValueFactory(DateTimeFormatter dateTimeFormatter) {
47-
super(dateTimeFormatter);
48-
}
49-
50-
public CosmoTimeBasedWeatherValueFactory() {
51-
super();
52-
}
53-
5442
@Override
5543
protected List<Set<String>> getFields(Class<?> entityClass) {
5644
Set<String> minConstructorParams =
57-
newSet(
58-
COORDINATE_ID,
59-
DIFFUSE_IRRADIANCE,
60-
DIRECT_IRRADIANCE,
61-
TEMPERATURE,
62-
WIND_DIRECTION,
63-
WIND_VELOCITY);
45+
new HashSet<>(
46+
Set.of(
47+
COORDINATE_ID,
48+
TIME,
49+
DIFFUSE_IRRADIANCE,
50+
DIRECT_IRRADIANCE,
51+
TEMPERATURE,
52+
WIND_DIRECTION,
53+
WIND_VELOCITY));
6454

65-
Set<String> allParameters =
66-
expandSet(minConstructorParams, GROUND_TEMPERATURE_SURFACE, GROUND_TEMPERATURE_1M);
67-
minConstructorParams.remove(COORDINATE_ID);
68-
allParameters.remove(COORDINATE_ID);
69-
return Collections.singletonList(minConstructorParams);
55+
Set<String> withGroundTemps = new HashSet<>(minConstructorParams);
56+
withGroundTemps.add(GROUND_TEMPERATURE_SURFACE);
57+
withGroundTemps.add(GROUND_TEMPERATURE_1M);
58+
59+
return List.of(minConstructorParams, withGroundTemps);
7060
}
7161

7262
@Override
7363
protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data) {
7464
Point coordinate = data.getCoordinate();
7565
ZonedDateTime time = timeUtil.toZonedDateTime(data.getField(TIME));
76-
SolarIrradianceValue solarIrradiance = new SolarIrradianceValue(
77-
data.getQuantity(DIRECT_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE),
78-
data.getQuantity(DIFFUSE_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE)
79-
);
80-
TemperatureValue temperature = new TemperatureValue(
81-
data.getQuantity(TEMPERATURE, StandardUnits.TEMPERATURE)
82-
);
83-
WindValue wind = new WindValue(
84-
data.getQuantity(WIND_DIRECTION, StandardUnits.WIND_DIRECTION),
85-
data.getQuantity(WIND_VELOCITY, StandardUnits.WIND_VELOCITY)
86-
);
8766

88-
Map<ComparableQuantity<Length>, TemperatureValue> groundTemperatures = new HashMap<>();
67+
ComparableQuantity<Irradiance> directIrradiance =
68+
data.getQuantity(DIRECT_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE);
69+
ComparableQuantity<Irradiance> diffuseIrradiance =
70+
data.getQuantity(DIFFUSE_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE);
71+
ComparableQuantity<Temperature> temperature =
72+
data.getQuantity(TEMPERATURE, StandardUnits.TEMPERATURE);
73+
ComparableQuantity<Angle> windDirection =
74+
data.getQuantity(WIND_DIRECTION, StandardUnits.WIND_DIRECTION);
75+
ComparableQuantity<Speed> windVelocity =
76+
data.getQuantity(WIND_VELOCITY, StandardUnits.WIND_VELOCITY);
8977

78+
Map<ComparableQuantity<Length>, TemperatureValue> groundTemperatures = new HashMap<>();
9079

91-
data.getField(GROUND_TEMPERATURE_SURFACE).ifPresent(value -> {
92-
ComparableQuantity<Length> depth = Quantities.getQuantity(0, StandardUnits.DEPTH);
93-
TemperatureValue tempValue = new TemperatureValue(
94-
data.getQuantity(GROUND_TEMPERATURE_SURFACE, StandardUnits.TEMPERATURE)
95-
);
96-
groundTemperatures.put(depth, tempValue);
97-
});
80+
try {
81+
TemperatureValue tempValue =
82+
new TemperatureValue(
83+
data.getQuantity(GROUND_TEMPERATURE_SURFACE, StandardUnits.TEMPERATURE));
84+
groundTemperatures.put(Quantities.getQuantity(0, Units.METRE), tempValue);
85+
} catch (FactoryException ignored) {
86+
}
9887

99-
data.getField(GROUND_TEMPERATURE_1M).ifPresent(value -> {
100-
ComparableQuantity<Length> depth = Quantities.getQuantity(1, StandardUnits.DEPTH);
101-
TemperatureValue tempValue = new TemperatureValue(
102-
data.getQuantity(GROUND_TEMPERATURE_1M, StandardUnits.TEMPERATURE)
103-
);
104-
groundTemperatures.put(depth, tempValue);
105-
});
88+
try {
89+
TemperatureValue tempValue =
90+
new TemperatureValue(data.getQuantity(GROUND_TEMPERATURE_1M, StandardUnits.TEMPERATURE));
91+
groundTemperatures.put(Quantities.getQuantity(1, Units.METRE), tempValue);
92+
} catch (FactoryException ignored) {
93+
}
10694

10795
WeatherValue weatherValue =
10896
new WeatherValue(
@@ -112,7 +100,8 @@ protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data
112100
temperature,
113101
windDirection,
114102
windVelocity,
115-
groundTemperatures);
103+
groundTemperatures);
104+
116105
return new TimeBasedValue<>(time, weatherValue);
117106
}
118107
}

src/main/java/edu/ie3/datamodel/io/factory/timeseries/IconTimeBasedWeatherValueFactory.java

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,32 @@
55
*/
66
package edu.ie3.datamodel.io.factory.timeseries;
77

8+
import edu.ie3.datamodel.exceptions.FactoryException;
89
import edu.ie3.datamodel.models.StandardUnits;
910
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
11+
import edu.ie3.datamodel.models.value.TemperatureValue;
1012
import edu.ie3.datamodel.models.value.WeatherValue;
1113
import edu.ie3.util.quantities.PowerSystemUnits;
1214
import edu.ie3.util.quantities.interfaces.Irradiance;
1315
import java.time.ZonedDateTime;
1416
import java.time.format.DateTimeFormatter;
1517
import java.util.*;
1618
import javax.measure.quantity.Angle;
19+
import javax.measure.quantity.Length;
1720
import javax.measure.quantity.Speed;
1821
import javax.measure.quantity.Temperature;
1922
import org.locationtech.jts.geom.Point;
2023
import tech.units.indriya.ComparableQuantity;
2124
import tech.units.indriya.quantity.Quantities;
2225
import tech.units.indriya.unit.Units;
2326

24-
/**
25-
* Factory implementation of {@link TimeBasedWeatherValueFactory}, that is able to handle field to
26-
* value mapping in the column scheme, ie<sup>3</sup> uses to store its data from German Federal
27-
* Weather Service's ICON-EU model
28-
*/
2927
public class IconTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFactory {
30-
/* Redefine the column names to meet the icon specifications */
3128
private static final String DIFFUSE_IRRADIANCE = "aswdifdS";
3229
private static final String DIRECT_IRRADIANCE = "aswdirS";
3330
private static final String TEMPERATURE = "t2m";
3431
private static final String WIND_VELOCITY_U = "u131m";
3532
private static final String WIND_VELOCITY_V = "v131m";
36-
37-
/** Ground-/Skin-Temperature at surface (0m) */
3833
private static final String GROUND_TEMP_SURFACE = "tG";
39-
/** Soil-Temperature at 100cm depth (example parameter name) */
4034
private static final String SOIL_TEMP_100CM = "tso100cm";
4135

4236
public IconTimeBasedWeatherValueFactory() {
@@ -52,13 +46,19 @@ protected List<Set<String>> getFields(Class<?> entityClass) {
5246
Set<String> minParameters =
5347
newSet(
5448
DIFFUSE_IRRADIANCE, DIRECT_IRRADIANCE, TEMPERATURE, WIND_VELOCITY_U, WIND_VELOCITY_V);
49+
50+
Set<String> minParametersWithGroundTemp = new HashSet<>(minParameters);
51+
minParametersWithGroundTemp.add(GROUND_TEMP_SURFACE);
52+
minParametersWithGroundTemp.add(SOIL_TEMP_100CM);
53+
5554
Set<String> allParameters =
5655
expandSet(
5756
minParameters,
5857
"albrad",
5958
"asobs",
6059
"aswdifuS",
61-
"tG",
60+
GROUND_TEMP_SURFACE,
61+
SOIL_TEMP_100CM,
6262
"u10m",
6363
"u20m",
6464
"u216m",
@@ -78,7 +78,7 @@ protected List<Set<String>> getFields(Class<?> entityClass) {
7878
"sobsrad",
7979
"t131m");
8080

81-
return Arrays.asList(minParameters, allParameters);
81+
return Arrays.asList(minParameters, minParametersWithGroundTemp, allParameters);
8282
}
8383

8484
@Override
@@ -93,56 +93,48 @@ protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data
9393
data.getQuantity(TEMPERATURE, Units.KELVIN).to(StandardUnits.TEMPERATURE);
9494
ComparableQuantity<Angle> windDirection = getWindDirection(data);
9595
ComparableQuantity<Speed> windVelocity = getWindVelocity(data);
96+
97+
Map<ComparableQuantity<Length>, TemperatureValue> groundTemperatures = new HashMap<>();
98+
99+
try {
100+
TemperatureValue tempValue =
101+
new TemperatureValue(
102+
data.getQuantity(GROUND_TEMP_SURFACE, Units.KELVIN).to(StandardUnits.TEMPERATURE));
103+
groundTemperatures.put(Quantities.getQuantity(0, Units.METRE), tempValue);
104+
} catch (FactoryException ignored) {
105+
}
106+
107+
try {
108+
TemperatureValue tempValue =
109+
new TemperatureValue(
110+
data.getQuantity(SOIL_TEMP_100CM, Units.KELVIN).to(StandardUnits.TEMPERATURE));
111+
groundTemperatures.put(Quantities.getQuantity(1, Units.METRE), tempValue);
112+
} catch (FactoryException ignored) {
113+
}
114+
96115
WeatherValue weatherValue =
97116
new WeatherValue(
98117
coordinate,
99118
directIrradiance,
100119
diffuseIrradiance,
101120
temperature,
102121
windDirection,
103-
windVelocity);
122+
windVelocity,
123+
groundTemperatures);
124+
104125
return new TimeBasedValue<>(time, weatherValue);
105126
}
106127

107-
/**
108-
* Determines the wind direction. In ICON the wind velocity is given in three dimensional
109-
* Cartesian coordinates. Here, the upward component is neglected. 0° or 0 rad are defined to
110-
* point northwards. The angle increases clockwise. Please note, that the wind direction is the
111-
* direction, the wind <b>comes</b> from and not goes to. We choose to use the wind velocity
112-
* calculations at 131 m above ground, as this is a height that pretty good matches the common hub
113-
* height of today's onshore wind generators, that are commonly connected to the voltage levels of
114-
* interest.
115-
*
116-
* @param data Collective information to convert
117-
* @return A {@link ComparableQuantity} of type {@link Speed}, that is converted to {@link
118-
* StandardUnits#WIND_VELOCITY}
119-
*/
120128
private static ComparableQuantity<Angle> getWindDirection(TimeBasedWeatherValueData data) {
121-
/* Get the three dimensional parts of the wind velocity vector in cartesian coordinates */
122-
double u =
123-
data.getDouble(WIND_VELOCITY_U); // Wind component from west to east (parallel to latitudes)
124-
double v =
125-
data.getDouble(
126-
WIND_VELOCITY_V); // Wind component from south to north (parallel to longitudes)
129+
double u = data.getDouble(WIND_VELOCITY_U);
130+
double v = data.getDouble(WIND_VELOCITY_V);
127131

128132
double angle = Math.toDegrees(Math.atan2(-u, -v));
129133
return Quantities.getQuantity(angle < 0 ? angle + 360d : angle, PowerSystemUnits.DEGREE_GEOM)
130134
.to(StandardUnits.WIND_DIRECTION);
131135
}
132136

133-
/**
134-
* Determines the wind velocity. In ICON the wind velocity is given in three dimensional Cartesian
135-
* coordinates. Here, the upward component is neglected. We choose to use the wind velocity
136-
* calculations at 131 m above ground, as this is a height that pretty good matches the common hub
137-
* height of today's onshore wind generators, that are commonly connected to the voltage levels of
138-
* interest.
139-
*
140-
* @param data Collective information to convert
141-
* @return A {@link ComparableQuantity} of type {@link Speed}, that is converted to {@link
142-
* StandardUnits#WIND_VELOCITY}
143-
*/
144137
private static ComparableQuantity<Speed> getWindVelocity(TimeBasedWeatherValueData data) {
145-
/* Get the three dimensional parts of the wind velocity vector in cartesian coordinates */
146138
double u = data.getDouble(WIND_VELOCITY_U);
147139
double v = data.getDouble(WIND_VELOCITY_V);
148140

0 commit comments

Comments
 (0)