Skip to content

pp/#1343 Add ground temperature (1m) as option to weather data. #1348

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

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@

import edu.ie3.datamodel.models.StandardUnits;
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue;
import edu.ie3.datamodel.models.value.SolarIrradianceValue;
import edu.ie3.datamodel.models.value.TemperatureValue;
import edu.ie3.datamodel.models.value.WeatherValue;
import edu.ie3.datamodel.models.value.WindValue;
import edu.ie3.util.TimeUtil;
import edu.ie3.util.quantities.PowerSystemUnits;
import edu.ie3.util.quantities.interfaces.Irradiance;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.*;
import javax.measure.quantity.Angle;
import javax.measure.quantity.Length;
import javax.measure.quantity.Speed;
import javax.measure.quantity.Temperature;
import org.locationtech.jts.geom.Point;
import tech.units.indriya.ComparableQuantity;
import tech.units.indriya.quantity.Quantities;

/**
* Factory implementation of {@link TimeBasedWeatherValueFactory}, that is able to handle field to
Expand All @@ -33,6 +36,9 @@ public class CosmoTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFact
private static final String WIND_DIRECTION = "windDirection";
private static final String WIND_VELOCITY = "windVelocity";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this empty line

private static final String GROUND_TEMPERATURE_SURFACE = "groundTemperatureSurface";
private static final String GROUND_TEMPERATURE_1M = "groundTemperature1m";

public CosmoTimeBasedWeatherValueFactory(TimeUtil timeUtil) {
super(timeUtil);
}
Expand All @@ -55,31 +61,58 @@ protected List<Set<String>> getFields(Class<?> entityClass) {
TEMPERATURE,
WIND_DIRECTION,
WIND_VELOCITY);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it possible to simply add the additonal values here when creating the set? so the removal of the coordinate_id would be obsolete, right?

Set<String> allParameters =
expandSet(minConstructorParams, GROUND_TEMPERATURE_SURFACE, GROUND_TEMPERATURE_1M);
minConstructorParams.remove(COORDINATE_ID);
allParameters.remove(COORDINATE_ID);
return Collections.singletonList(minConstructorParams);
}

@Override
protected TimeBasedValue<WeatherValue> buildModel(TimeBasedWeatherValueData data) {
Point coordinate = data.getCoordinate();
ZonedDateTime time = timeUtil.toZonedDateTime(data.getField(TIME));
ComparableQuantity<Irradiance> directIrradiance =
data.getQuantity(DIRECT_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE);
ComparableQuantity<Irradiance> diffuseIrradiance =
data.getQuantity(DIFFUSE_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE);
ComparableQuantity<Temperature> temperature =
data.getQuantity(TEMPERATURE, StandardUnits.TEMPERATURE);
ComparableQuantity<Angle> windDirection =
data.getQuantity(WIND_DIRECTION, StandardUnits.WIND_DIRECTION);
ComparableQuantity<Speed> windVelocity =
data.getQuantity(WIND_VELOCITY, StandardUnits.WIND_VELOCITY);
SolarIrradianceValue solarIrradiance = new SolarIrradianceValue(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rollback this. Within Simona we expect these values to be ComparableQuantity and not SolarIrradianceValue (at least this is my understanding). Second, I would like to keep the changes in this PR limited to adding the new values and not refactoring existing code.

data.getQuantity(DIRECT_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE),
data.getQuantity(DIFFUSE_IRRADIANCE, PowerSystemUnits.WATT_PER_SQUAREMETRE)
);
TemperatureValue temperature = new TemperatureValue(
data.getQuantity(TEMPERATURE, StandardUnits.TEMPERATURE)
);
WindValue wind = new WindValue(
data.getQuantity(WIND_DIRECTION, StandardUnits.WIND_DIRECTION),
data.getQuantity(WIND_VELOCITY, StandardUnits.WIND_VELOCITY)
);

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


data.getField(GROUND_TEMPERATURE_SURFACE).ifPresent(value -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens in the case NotPresent?

ComparableQuantity<Length> depth = Quantities.getQuantity(0, StandardUnits.DEPTH);
TemperatureValue tempValue = new TemperatureValue(
data.getQuantity(GROUND_TEMPERATURE_SURFACE, StandardUnits.TEMPERATURE)
);
groundTemperatures.put(depth, tempValue);
});

data.getField(GROUND_TEMPERATURE_1M).ifPresent(value -> {
ComparableQuantity<Length> depth = Quantities.getQuantity(1, StandardUnits.DEPTH);
TemperatureValue tempValue = new TemperatureValue(
data.getQuantity(GROUND_TEMPERATURE_1M, StandardUnits.TEMPERATURE)
);
groundTemperatures.put(depth, tempValue);
});

WeatherValue weatherValue =
new WeatherValue(
coordinate,
directIrradiance,
diffuseIrradiance,
temperature,
windDirection,
windVelocity);
windVelocity,
groundTemperatures);
return new TimeBasedValue<>(time, weatherValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public class IconTimeBasedWeatherValueFactory extends TimeBasedWeatherValueFacto
private static final String WIND_VELOCITY_U = "u131m";
private static final String WIND_VELOCITY_V = "v131m";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also remove the line here. Please add also a getter for the new data and add them to the existing ones (where it is expected to apply). Also the buildModel seem to have it, right?

/** Ground-/Skin-Temperature at surface (0m) */
private static final String GROUND_TEMP_SURFACE = "tG";
/** Soil-Temperature at 100cm depth (example parameter name) */
private static final String SOIL_TEMP_100CM = "tso100cm";

public IconTimeBasedWeatherValueFactory() {
super();
}
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/edu/ie3/datamodel/models/value/WeatherValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
package edu.ie3.datamodel.models.value;

import edu.ie3.util.quantities.interfaces.Irradiance;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import javax.measure.quantity.Angle;
import javax.measure.quantity.Length;
import javax.measure.quantity.Speed;
import javax.measure.quantity.Temperature;
import org.locationtech.jts.geom.Point;
Expand All @@ -25,11 +29,14 @@ public class WeatherValue implements Value {
/** Wind values for this coordinate */
private final WindValue wind;

/** Optional: A map of ground temperatures at different depths. The key represents the depth. */
private Map<ComparableQuantity<Length>, TemperatureValue> groundTemperatures = Map.of();
/**
* @param coordinate of this weather value set
* @param solarIrradiance values for this coordinate
* @param temperature values for this coordinate
* @param wind values for this coordinate
* @param groundTemperatures A map of ground temperatures at different depths
*/
public WeatherValue(
Point coordinate,
Expand All @@ -40,6 +47,7 @@ public WeatherValue(
this.solarIrradiance = solarIrradiance;
this.temperature = temperature;
this.wind = wind;
this.groundTemperatures = Collections.unmodifiableMap(new HashMap<>(groundTemperatures));
}

/**
Expand Down Expand Up @@ -81,6 +89,16 @@ public WindValue getWind() {
return wind;
}

/**
* Returns a map of ground temperatures, with the depth as key. The map is unmodifiable. Returns
* an empty map if no values are available.
*
* @return A map of ground temperatures.
*/
public Map<ComparableQuantity<Length>, TemperatureValue> getGroundTemperatures() {
return groundTemperatures;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -89,12 +107,13 @@ public boolean equals(Object o) {
return coordinate.equals(that.coordinate)
&& solarIrradiance.equals(that.solarIrradiance)
&& temperature.equals(that.temperature)
&& wind.equals(that.wind);
&& wind.equals(that.wind)
&& groundTemperatures.equals(that.groundTemperatures);
}

@Override
public int hashCode() {
return Objects.hash(coordinate, solarIrradiance, temperature, wind);
return Objects.hash(coordinate, solarIrradiance, temperature, wind, groundTemperatures);
}

@Override
Expand All @@ -108,6 +127,8 @@ public String toString() {
+ temperature
+ ", wind="
+ wind
+ groundTemperatures
+ ", groundTemperatures="
+ '}';
}
}
Loading