1
1
/*
2
- * © 2021 . TU Dortmund University,
2
+ * © 2020 . TU Dortmund University,
3
3
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
4
4
* Research group Distribution grid planning and operation
5
5
*/
6
6
package edu .ie3 .datamodel .io .factory .timeseries ;
7
7
8
+ import edu .ie3 .datamodel .exceptions .FactoryException ;
8
9
import edu .ie3 .datamodel .models .StandardUnits ;
9
10
import edu .ie3 .datamodel .models .timeseries .individual .TimeBasedValue ;
10
- import edu .ie3 .datamodel .models .value .SolarIrradianceValue ;
11
11
import edu .ie3 .datamodel .models .value .TemperatureValue ;
12
12
import edu .ie3 .datamodel .models .value .WeatherValue ;
13
- import edu .ie3 .datamodel .models .value .WindValue ;
14
13
import edu .ie3 .util .TimeUtil ;
15
14
import edu .ie3 .util .quantities .PowerSystemUnits ;
16
15
import edu .ie3 .util .quantities .interfaces .Irradiance ;
17
16
import java .time .ZonedDateTime ;
18
- import java .time .format .DateTimeFormatter ;
19
17
import java .util .*;
20
18
import javax .measure .quantity .Angle ;
21
19
import javax .measure .quantity .Length ;
24
22
import org .locationtech .jts .geom .Point ;
25
23
import tech .units .indriya .ComparableQuantity ;
26
24
import tech .units .indriya .quantity .Quantities ;
25
+ import tech .units .indriya .unit .Units ;
27
26
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
- */
32
27
public class CosmoTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFactory {
28
+ private static final String TIME = "time" ;
29
+ private static final String COORDINATE_ID = "coordinateId" ;
33
30
private static final String DIFFUSE_IRRADIANCE = "diffuseIrradiance" ;
34
31
private static final String DIRECT_IRRADIANCE = "directIrradiance" ;
35
32
private static final String TEMPERATURE = "temperature" ;
36
33
private static final String WIND_DIRECTION = "windDirection" ;
37
34
private static final String WIND_VELOCITY = "windVelocity" ;
38
-
39
35
private static final String GROUND_TEMPERATURE_SURFACE = "groundTemperatureSurface" ;
40
36
private static final String GROUND_TEMPERATURE_1M = "groundTemperature1m" ;
41
37
42
38
public CosmoTimeBasedWeatherValueFactory (TimeUtil timeUtil ) {
43
39
super (timeUtil );
44
40
}
45
41
46
- public CosmoTimeBasedWeatherValueFactory (DateTimeFormatter dateTimeFormatter ) {
47
- super (dateTimeFormatter );
48
- }
49
-
50
- public CosmoTimeBasedWeatherValueFactory () {
51
- super ();
52
- }
53
-
54
42
@ Override
55
43
protected List <Set <String >> getFields (Class <?> entityClass ) {
56
44
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 ));
64
54
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 );
70
60
}
71
61
72
62
@ Override
73
63
protected TimeBasedValue <WeatherValue > buildModel (TimeBasedWeatherValueData data ) {
74
64
Point coordinate = data .getCoordinate ();
75
65
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
- );
87
66
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 );
89
77
78
+ Map <ComparableQuantity <Length >, TemperatureValue > groundTemperatures = new HashMap <>();
90
79
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
+ }
98
87
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
+ }
106
94
107
95
WeatherValue weatherValue =
108
96
new WeatherValue (
@@ -112,7 +100,8 @@ protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data
112
100
temperature ,
113
101
windDirection ,
114
102
windVelocity ,
115
- groundTemperatures );
103
+ groundTemperatures );
104
+
116
105
return new TimeBasedValue <>(time , weatherValue );
117
106
}
118
107
}
0 commit comments