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

Add/set weather variables #9326

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3156c2f
Ignore output folder in prototypes
rcichota Sep 17, 2024
c463ff4
Update summary tags, fixe typos and clarified/standardised a few desc…
rcichota Sep 17, 2024
dbf5b71
organise the variables a bit so that similar types are together, Few …
rcichota Sep 17, 2024
3dc27e0
Changes variable DiffuseRadiationIndex to diffuseRadiationIndex (as i…
rcichota Sep 17, 2024
83c2c47
few more code changes to variable doco and extending tidying up to S…
rcichota Sep 18, 2024
a58b9e0
Merge branch 'master' of https://github.com/APSIMInitiative/ApsimX in…
rcichota Sep 18, 2024
d402a39
removing the 'this' qualification
rcichota Sep 18, 2024
e15317e
Making some variables settable, move a few calculations to functions
rcichota Sep 18, 2024
1fec9f2
Make latitude and longitude settable
rcichota Sep 18, 2024
b042562
Adding calculation for AirPressure (from soilTemperature)
rcichota Sep 18, 2024
aa6a77d
Increase pressicion of altitude (for airPressure) plus minor shuffle …
rcichota Sep 18, 2024
d4f9a4f
Standardised check for DiffuseFraction and CO2 (this partialy)
rcichota Sep 18, 2024
e283056
Enable airPressure to be read from met file, added defaults for Wind …
rcichota Sep 18, 2024
241d1af
Further standardisation of tests and behaviur for setting weather var…
rcichota Sep 18, 2024
c2eebc5
Revert "Further standardisation of tests and behaviur for setting wea…
rcichota Sep 18, 2024
c008084
redo-standardisation, in steps. only doco
rcichota Sep 18, 2024
3a0ff3c
second stage of standardising how weather variables are set
rcichota Sep 18, 2024
1d2fc62
thrid step of standardisation, consider day length
rcichota Sep 18, 2024
95be138
Make MeaT readble from met file as well as settable. Defaults to (Min…
rcichota Sep 18, 2024
a261c9d
reverting providing a value for daylength by default (models can only…
rcichota Sep 19, 2024
8e3b398
improving resilience to change in latitude
rcichota Sep 19, 2024
b8090d6
Ensure variables that could be filled in with 'default' calculation a…
rcichota Sep 19, 2024
9d95e32
Ensure sanity check on weather is done before derived outputs are com…
rcichota Sep 19, 2024
62d6f45
Fix test for NaN values
rcichota Sep 19, 2024
1df9195
rename file name variables in SimpleWeather to align with Weather
rcichota Sep 19, 2024
7842be9
Add variables to read in value for PET and evaporation (broadcasted, …
rcichota Sep 19, 2024
4158855
update few variable names
rcichota Sep 19, 2024
17bc66c
Test making altitude an input to Weather (used to compute AirPressure)
rcichota Sep 19, 2024
2bcfb56
Adding a test for the existence of 'zone' (to supply Altitude), not …
rcichota Sep 19, 2024
1f38bca
Make Link to 'zone' optional as not all simulation have one...
rcichota Sep 19, 2024
8d804af
Add constant to explicitly test AMP, Exposing evaporation variables
rcichota Sep 19, 2024
a23640d
Removing the added PET variables (need more thinking on this)
rcichota Sep 21, 2024
e07a6d2
Merge branch 'master' of https://github.com/APSIMInitiative/ApsimX in…
rcichota Sep 21, 2024
06ffd95
Minor update and code suffle to make ControlledEnvironment more compa…
rcichota Sep 21, 2024
76bc9c5
remove link to un-used Summary
rcichota Sep 21, 2024
392c9ca
Minor shuffle of code, cosmetic
rcichota Sep 21, 2024
6a8f51c
Updates to WeatherSample summary tags and some code shuffling to alig…
rcichota Sep 21, 2024
6301c9f
Merge branch 'master' of https://github.com/APSIMInitiative/ApsimX in…
rcichota Sep 30, 2024
a11fa18
Add variables for deafult values and FullFileName in WeatherSampler, …
rcichota Sep 30, 2024
fafeaa6
Merge branch 'master' of https://github.com/APSIMInitiative/ApsimX in…
rcichota Oct 6, 2024
aebb87b
Add all the basic output variables to WeatherSampler (align with Weat…
rcichota Oct 6, 2024
2843a4a
Fixed unit test
hol353 Oct 8, 2024
06eb6c9
Merge branch 'master' of https://github.com/APSIMInitiative/ApsimX in…
rcichota Oct 8, 2024
02fd45c
Add winter solstice day to WeatherSampler
rcichota Oct 8, 2024
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
Prev Previous commit
Next Next commit
Increase pressicion of altitude (for airPressure) plus minor shuffle …
…of code (keep an order to outputs)
rcichota committed Sep 18, 2024
commit aa6a77d28c3bd17b22457531f75549baf8f9ab8e
42 changes: 20 additions & 22 deletions Models/Climate/SimpleWeather.cs
Original file line number Diff line number Diff line change
@@ -386,8 +386,8 @@ public IEnumerable<string> Validate()
[EventSubscribe("Commencing")]
private void OnSimulationCommencing(object sender, EventArgs e)
{
maximumTemperatureIndex = 0;
minimumTemperatureIndex = 0;
maximumTemperatureIndex = 0;
radiationIndex = 0;
rainIndex = 0;
evaporationIndex = 0;
@@ -399,10 +399,7 @@ private void OnSimulationCommencing(object sender, EventArgs e)
dayLengthIndex = 0;
if (CO2 == 0)
CO2 = 350;
if (AirPressure == 0)
AirPressure = calculateAirPressure(27.09); // to default 1010;
if (DiffuseFraction == 0)
DiffuseFraction = -1;

if (reader != null)
{
reader.Close();
@@ -468,9 +465,9 @@ private void OnDoWeather(object sender, EventArgs e)
}

// assign values to output variables
Radn = TodaysMetData.Radn;
MaxT = TodaysMetData.MaxT;
MinT = TodaysMetData.MinT;
MaxT = TodaysMetData.MaxT;
Radn = TodaysMetData.Radn;
Rain = TodaysMetData.Rain;
PanEvap = TodaysMetData.PanEvap;
RainfallHours = TodaysMetData.RainfallHours;
@@ -480,6 +477,7 @@ private void OnDoWeather(object sender, EventArgs e)
DayLength = TodaysMetData.DayLength;
if (co2Index != -1)
CO2 = TodaysMetData.CO2;
AirPressure = calculateAirPressure(27.08889); // to default 1010;

// invoke event that allows other models to modify weather data
if (PreparingNewWeatherData != null)
@@ -524,20 +522,20 @@ public DailyMetDataFromFile GetMetData(DateTime date)
/// <returns>The weather data structure with values checked</returns>
private DailyMetDataFromFile CheckDailyMetData(DailyMetDataFromFile readMetData)
{
if (radiationIndex != -1)
readMetData.Radn = Convert.ToSingle(readMetData.Raw[radiationIndex], CultureInfo.InvariantCulture);
if (minimumTemperatureIndex != -1)
readMetData.MinT = Convert.ToSingle(readMetData.Raw[minimumTemperatureIndex], CultureInfo.InvariantCulture);
else
readMetData.Radn = reader.ConstantAsDouble("radn");
readMetData.MinT = reader.ConstantAsDouble("mint");

if (maximumTemperatureIndex != -1)
readMetData.MaxT = Convert.ToSingle(readMetData.Raw[maximumTemperatureIndex], CultureInfo.InvariantCulture);
else
readMetData.MaxT = reader.ConstantAsDouble("maxt");

if (minimumTemperatureIndex != -1)
readMetData.MinT = Convert.ToSingle(readMetData.Raw[minimumTemperatureIndex], CultureInfo.InvariantCulture);
if (radiationIndex != -1)
readMetData.Radn = Convert.ToSingle(readMetData.Raw[radiationIndex], CultureInfo.InvariantCulture);
else
readMetData.MinT = reader.ConstantAsDouble("mint");
readMetData.Radn = reader.ConstantAsDouble("radn");

if (rainIndex != -1)
readMetData.Rain = Convert.ToSingle(readMetData.Raw[rainIndex], CultureInfo.InvariantCulture);
@@ -617,8 +615,8 @@ public bool OpenDataFile()
throw new Exception(message);
}

maximumTemperatureIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Maxt");
minimumTemperatureIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Mint");
maximumTemperatureIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Maxt");
radiationIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Radn");
rainIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Rain");
evaporationIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Evap");
@@ -638,14 +636,14 @@ public bool OpenDataFile()
reader.AddConstant(constant.Name, constant.Value, constant.Units, constant.Comment);
}

if (maximumTemperatureIndex == -1)
if (reader == null || reader.Constant("maxt") == null)
throw new Exception("Cannot find MaxT in weather file: " + FileName);

if (minimumTemperatureIndex == -1)
if (reader == null || reader.Constant("mint") == null)
throw new Exception("Cannot find MinT in weather file: " + FileName);

if (maximumTemperatureIndex == -1)
if (reader == null || reader.Constant("maxt") == null)
throw new Exception("Cannot find MaxT in weather file: " + FileName);

if (radiationIndex == -1)
if (reader == null || reader.Constant("radn") == null)
throw new Exception("Cannot find Radn in weather file: " + FileName);
@@ -764,10 +762,6 @@ private void SensibilityCheck(Clock clock, SimpleWeather weatherToday)
{
throw new Exception("Error: Weather on " + clock.Today.ToString() + " has higher minimum temperature (" + weatherToday.MinT + ") than maximum (" + weatherToday.MaxT + ")");
}
if (weatherToday.VP <= 0)
{
throw new Exception("Error: Weather on " + clock.Today.ToString() + " has vapour pressure (" + weatherToday.VP + ") which is below 0");
}
if (weatherToday.Radn < 0)
{
throw new Exception("Error: Weather on " + clock.Today.ToString() + " has negative solar radiation (" + weatherToday.Radn + ")");
@@ -780,6 +774,10 @@ private void SensibilityCheck(Clock clock, SimpleWeather weatherToday)
{
throw new Exception("Error: Weather on " + clock.Today.ToString() + " has negative ranfaill (" + weatherToday.Radn + ")");
}
if (weatherToday.VP <= 0)
{
throw new Exception("Error: Weather on " + clock.Today.ToString() + " has vapour pressure (" + weatherToday.VP + ") which is below 0");
}
}
}
}
49 changes: 24 additions & 25 deletions Models/Climate/Weather.cs
Original file line number Diff line number Diff line change
@@ -520,8 +520,8 @@ public IEnumerable<string> Validate()
[EventSubscribe("Commencing")]
private void OnSimulationCommencing(object sender, EventArgs e)
{
maximumTemperatureIndex = 0;
minimumTemperatureIndex = 0;
maximumTemperatureIndex = 0;
radiationIndex = 0;
rainIndex = 0;
evaporationIndex = 0;
@@ -531,10 +531,7 @@ private void OnSimulationCommencing(object sender, EventArgs e)
co2Index = -1;
diffuseFractionIndex = 0;
dayLengthIndex = 0;
if (AirPressure == 0)
AirPressure = calculateAirPressure(27.09); // to default 1010;
if (DiffuseFraction == 0)
DiffuseFraction = -1;

if (reader != null)
{
reader.Close();
@@ -579,17 +576,18 @@ private void OnDoWeather(object sender, EventArgs e)
TodaysMetData = GetMetData(clock.Today);

// assign values to output variables
Radn = TodaysMetData.Radn;
MaxT = TodaysMetData.MaxT;
MinT = TodaysMetData.MinT;
MaxT = TodaysMetData.MaxT;
Radn = TodaysMetData.Radn;
DiffuseFraction = TodaysMetData.DiffuseFraction;
Rain = TodaysMetData.Rain;
PanEvap = TodaysMetData.PanEvap;
RainfallHours = TodaysMetData.RainfallHours;
VP = TodaysMetData.VP;
Wind = TodaysMetData.Wind;
DiffuseFraction = TodaysMetData.DiffuseFraction;
DayLength = TodaysMetData.DayLength;
CO2 = TodaysMetData.CO2;
AirPressure = calculateAirPressure(27.08889); // to default 1010;

// invoke event that allows other models to modify weather data
if (PreparingNewWeatherData != null)
@@ -618,8 +616,8 @@ public DataTable GetAllData()
metProps.Add("maxt");
metProps.Add("radn");
metProps.Add("rain");
metProps.Add("wind");
metProps.Add("diffr");
metProps.Add("wind");

return reader.ToTable(metProps);
}
@@ -682,20 +680,20 @@ public DailyMetDataFromFile GetMetData(DateTime date)
/// <returns>The weather data structure with values checked</returns>
private DailyMetDataFromFile CheckDailyMetData(DailyMetDataFromFile readMetData)
{
if (radiationIndex != -1)
readMetData.Radn = Convert.ToSingle(readMetData.Raw[radiationIndex], CultureInfo.InvariantCulture);
if (minimumTemperatureIndex != -1)
readMetData.MinT = Convert.ToSingle(readMetData.Raw[minimumTemperatureIndex], CultureInfo.InvariantCulture);
else
readMetData.Radn = reader.ConstantAsDouble("radn");
readMetData.MinT = reader.ConstantAsDouble("mint");

if (maximumTemperatureIndex != -1)
readMetData.MaxT = Convert.ToSingle(readMetData.Raw[maximumTemperatureIndex], CultureInfo.InvariantCulture);
else
readMetData.MaxT = reader.ConstantAsDouble("maxt");

if (minimumTemperatureIndex != -1)
readMetData.MinT = Convert.ToSingle(readMetData.Raw[minimumTemperatureIndex], CultureInfo.InvariantCulture);
if (radiationIndex != -1)
readMetData.Radn = Convert.ToSingle(readMetData.Raw[radiationIndex], CultureInfo.InvariantCulture);
else
readMetData.MinT = reader.ConstantAsDouble("mint");
readMetData.Radn = reader.ConstantAsDouble("radn");

if (rainIndex != -1)
readMetData.Rain = Convert.ToSingle(readMetData.Raw[rainIndex], CultureInfo.InvariantCulture);
@@ -819,15 +817,15 @@ public bool OpenDataFile()
throw new Exception(message);
}

maximumTemperatureIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Maxt");
minimumTemperatureIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Mint");
maximumTemperatureIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Maxt");
radiationIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Radn");
diffuseFractionIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "DifFr");
rainIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Rain");
evaporationIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Evap");
rainfallHoursIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "RainHours");
vapourPressureIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "VP");
windIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "Wind");
diffuseFractionIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "DifFr");
dayLengthIndex = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "DayLength");
co2Index = StringUtilities.IndexOfCaseInsensitive(reader.Headings, "CO2");

@@ -840,14 +838,14 @@ public bool OpenDataFile()
reader.AddConstant(constant.Name, constant.Value, constant.Units, constant.Comment);
}

if (maximumTemperatureIndex == -1)
if (reader == null || reader.Constant("maxt") == null)
throw new Exception("Cannot find MaxT in weather file: " + FullFileName);

if (minimumTemperatureIndex == -1)
if (reader == null || reader.Constant("mint") == null)
throw new Exception("Cannot find MinT in weather file: " + FullFileName);

if (maximumTemperatureIndex == -1)
if (reader == null || reader.Constant("maxt") == null)
throw new Exception("Cannot find MaxT in weather file: " + FullFileName);

if (radiationIndex == -1)
if (reader == null || reader.Constant("radn") == null)
throw new Exception("Cannot find Radn in weather file: " + FullFileName);
@@ -1107,10 +1105,6 @@ private void SensibilityCheck(Clock clock, Weather weatherToday)
{
summary.WriteMessage(weatherToday, "Error: Weather on " + clock.Today.ToString() + " has higher minimum temperature (" + weatherToday.MinT + ") than maximum (" + weatherToday.MaxT + ")", MessageType.Warning);
}
if (weatherToday.VP <= 0)
{
summary.WriteMessage(weatherToday, "Error: Weather on " + clock.Today.ToString() + " has vapour pressure (" + weatherToday.VP + ") which is below 0", MessageType.Warning);
}
if (weatherToday.Radn < 0)
{
summary.WriteMessage(weatherToday, "Error: Weather on " + clock.Today.ToString() + " has negative solar radiation (" + weatherToday.Radn + ")", MessageType.Warning);
@@ -1123,6 +1117,11 @@ private void SensibilityCheck(Clock clock, Weather weatherToday)
{
summary.WriteMessage(weatherToday, "Error: Weather on " + clock.Today.ToString() + " has negative rainfall (" + weatherToday.Radn + ")", MessageType.Warning);
}
if (weatherToday.VP <= 0)
{
summary.WriteMessage(weatherToday, "Error: Weather on " + clock.Today.ToString() + " has vapour pressure (" + weatherToday.VP + ") which is below 0", MessageType.Warning);
}

return;
}