|
| 1 | +/* |
| 2 | + * © 2020. TU Dortmund University, |
| 3 | + * Institute of Energy Systems, Energy Efficiency and Energy Economics, |
| 4 | + * Research group Distribution grid planning and operation |
| 5 | +*/ |
| 6 | +package edu.ie3.datamodel.io.factory.timeseries; |
| 7 | + |
| 8 | +import edu.ie3.datamodel.models.StandardUnits; |
| 9 | +import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue; |
| 10 | +import edu.ie3.datamodel.models.value.WeatherValue; |
| 11 | +import edu.ie3.util.TimeUtil; |
| 12 | +import edu.ie3.util.quantities.PowerSystemUnits; |
| 13 | +import edu.ie3.util.quantities.interfaces.Irradiation; |
| 14 | +import java.time.ZoneId; |
| 15 | +import java.time.ZonedDateTime; |
| 16 | +import java.util.*; |
| 17 | +import javax.measure.quantity.Angle; |
| 18 | +import javax.measure.quantity.Speed; |
| 19 | +import javax.measure.quantity.Temperature; |
| 20 | +import org.locationtech.jts.geom.Point; |
| 21 | +import tech.units.indriya.ComparableQuantity; |
| 22 | +import tech.units.indriya.quantity.Quantities; |
| 23 | +import tech.units.indriya.unit.Units; |
| 24 | + |
| 25 | +/** |
| 26 | + * Factory implementation of {@link TimeBasedWeatherValueFactory}, that is able to handle field to |
| 27 | + * value mapping in the column scheme, ie<sup>3</sup> uses to store it's data from German Federal |
| 28 | + * Weather Service's ICON-EU model |
| 29 | + */ |
| 30 | +public class IconTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFactory { |
| 31 | + /* Redefine the column names to meet the icon specifications */ |
| 32 | + private static final String COORDINATE = "coordinateId"; |
| 33 | + private static final String TIME = "datum"; |
| 34 | + private static final String DIFFUSE_IRRADIATION = "aswdifdS"; |
| 35 | + private static final String DIRECT_IRRADIATION = "aswdirS"; |
| 36 | + private static final String TEMPERATURE = "t2m"; |
| 37 | + private static final String WIND_VELOCITY_U = "u131m"; |
| 38 | + private static final String WIND_VELOCITY_V = "v131m"; |
| 39 | + |
| 40 | + public IconTimeBasedWeatherValueFactory(TimeUtil timeUtil) { |
| 41 | + super(timeUtil); |
| 42 | + } |
| 43 | + |
| 44 | + public IconTimeBasedWeatherValueFactory(String timePattern) { |
| 45 | + super(timePattern); |
| 46 | + } |
| 47 | + |
| 48 | + public IconTimeBasedWeatherValueFactory() { |
| 49 | + super(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd HH:mm:ss")); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public String getCoordinateIdFieldString() { |
| 54 | + return COORDINATE; |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public String getTimeFieldString() { |
| 59 | + return TIME; |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + protected List<Set<String>> getFields(TimeBasedWeatherValueData data) { |
| 64 | + Set<String> minConstructorParams = |
| 65 | + newSet( |
| 66 | + TIME, |
| 67 | + DIFFUSE_IRRADIATION, |
| 68 | + DIRECT_IRRADIATION, |
| 69 | + TEMPERATURE, |
| 70 | + WIND_VELOCITY_U, |
| 71 | + WIND_VELOCITY_V); |
| 72 | + Set<String> allParameters = new HashSet<>(minConstructorParams); |
| 73 | + allParameters.addAll( |
| 74 | + newSet( |
| 75 | + "albRad", |
| 76 | + "asobS", |
| 77 | + DIFFUSE_IRRADIATION, |
| 78 | + "aswdifuS", |
| 79 | + DIRECT_IRRADIATION, |
| 80 | + TEMPERATURE, |
| 81 | + "tG", |
| 82 | + "u10m", |
| 83 | + WIND_VELOCITY_U, |
| 84 | + "u20m", |
| 85 | + "u216m", |
| 86 | + "u65m", |
| 87 | + "v10m", |
| 88 | + WIND_VELOCITY_V, |
| 89 | + "v20m", |
| 90 | + "v216m", |
| 91 | + "v65m", |
| 92 | + "w131m", |
| 93 | + "w20m", |
| 94 | + "w216m", |
| 95 | + "w65m", |
| 96 | + "z0", |
| 97 | + "p131m", |
| 98 | + "p20m", |
| 99 | + "p65m", |
| 100 | + "sobsRad", |
| 101 | + "t131m")); |
| 102 | + Set<String> allParametersWithUuid = new HashSet<>(allParameters); |
| 103 | + allParametersWithUuid.add("uuid"); |
| 104 | + |
| 105 | + return Arrays.asList(minConstructorParams, allParameters, allParametersWithUuid); |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data) { |
| 110 | + Point coordinate = data.getCoordinate(); |
| 111 | + java.util.UUID uuid = data.containsKey(UUID) ? data.getUUID(UUID) : java.util.UUID.randomUUID(); |
| 112 | + ZonedDateTime time = timeUtil.toZonedDateTime(data.getField(TIME)); |
| 113 | + ComparableQuantity<Irradiation> directIrradiation = |
| 114 | + data.getQuantity(DIRECT_IRRADIATION, PowerSystemUnits.WATT_PER_SQUAREMETRE) |
| 115 | + .to(StandardUnits.IRRADIATION); |
| 116 | + ComparableQuantity<Irradiation> diffuseIrradiation = |
| 117 | + data.getQuantity(DIFFUSE_IRRADIATION, PowerSystemUnits.WATT_PER_SQUAREMETRE) |
| 118 | + .to(StandardUnits.IRRADIATION); |
| 119 | + ComparableQuantity<Temperature> temperature = |
| 120 | + data.getQuantity(TEMPERATURE, Units.KELVIN).to(StandardUnits.TEMPERATURE); |
| 121 | + ComparableQuantity<Angle> windDirection = getWindDirection(data); |
| 122 | + ComparableQuantity<Speed> windVelocity = getWindVelocity(data); |
| 123 | + WeatherValue weatherValue = |
| 124 | + new WeatherValue( |
| 125 | + coordinate, |
| 126 | + directIrradiation, |
| 127 | + diffuseIrradiation, |
| 128 | + temperature, |
| 129 | + windDirection, |
| 130 | + windVelocity); |
| 131 | + return new TimeBasedValue<>(uuid, time, weatherValue); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Determines the wind direction. In ICON the wind velocity is given in three dimensional |
| 136 | + * Cartesian coordinates. Here, the upward component is neglected. 0° or 0 rad are defined to |
| 137 | + * point northwards. The angle increases clockwise. Please note, that the wind direction is the |
| 138 | + * direction, the wind <b>comes</b> from and not goes to. We choose to use the wind velocity |
| 139 | + * calculations at 131 m above ground, as this is a height that pretty good matches the common hub |
| 140 | + * height of today's onshore wind generators, that are commonly connected to the voltage levels of |
| 141 | + * interest. |
| 142 | + * |
| 143 | + * @param data Collective information to convert |
| 144 | + * @return A {@link ComparableQuantity} of type {@link Speed}, that is converted to {@link |
| 145 | + * StandardUnits#WIND_VELOCITY} |
| 146 | + */ |
| 147 | + private static ComparableQuantity<Angle> getWindDirection(TimeBasedWeatherValueData data) { |
| 148 | + /* Get the three dimensional parts of the wind velocity vector in cartesian coordinates */ |
| 149 | + double u = |
| 150 | + data.getDouble(WIND_VELOCITY_U); // Wind component from west to east (parallel to latitudes) |
| 151 | + double v = |
| 152 | + data.getDouble( |
| 153 | + WIND_VELOCITY_V); // Wind component from south to north (parallel to longitudes) |
| 154 | + |
| 155 | + double angle = Math.toDegrees(Math.atan2(-u, -v)); |
| 156 | + return Quantities.getQuantity(angle < 0 ? angle + 360d : angle, PowerSystemUnits.DEGREE_GEOM) |
| 157 | + .to(StandardUnits.WIND_DIRECTION); |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * Determines the wind velocity. In ICON the wind velocity is given in three dimensional Cartesian |
| 162 | + * coordinates. Here, the upward component is neglected. We choose to use the wind velocity |
| 163 | + * calculations at 131 m above ground, as this is a height that pretty good matches the common hub |
| 164 | + * height of today's onshore wind generators, that are commonly connected to the voltage levels of |
| 165 | + * interest. |
| 166 | + * |
| 167 | + * @param data Collective information to convert |
| 168 | + * @return A {@link ComparableQuantity} of type {@link Speed}, that is converted to {@link |
| 169 | + * StandardUnits#WIND_VELOCITY} |
| 170 | + */ |
| 171 | + private static ComparableQuantity<Speed> getWindVelocity(TimeBasedWeatherValueData data) { |
| 172 | + /* Get the three dimensional parts of the wind velocity vector in cartesian coordinates */ |
| 173 | + double u = data.getDouble(WIND_VELOCITY_U); |
| 174 | + double v = data.getDouble(WIND_VELOCITY_V); |
| 175 | + |
| 176 | + double velocity = Math.sqrt(Math.pow(u, 2) + Math.pow(v, 2)); |
| 177 | + return Quantities.getQuantity(velocity, Units.METRE_PER_SECOND).to(StandardUnits.WIND_VELOCITY); |
| 178 | + } |
| 179 | +} |
0 commit comments