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

Bugfix435: calculated relative humidity #436

Merged
merged 12 commits into from
Nov 26, 2024

Conversation

dschlaep
Copy link
Member

@dschlaep dschlaep commented Nov 20, 2024

Fix the calculation of relative humidity (close #435). Previously, relative humidity was incorrectly calculated if based on vapor pressure or specific humidity.

Fix the count of days on which a missing weather value was replaced by a non-missing value from the preceding day for the method "LOCF" (last observation carried forward; close #437). Previously, any day with a missing weather value was counted.

- check that relative humidity is calculated from vp, tmax, and tmin

-> test is now correctly failing (i.e., indicating the presence of bug #345):
```
[ RUN      ] WeatherFixtureTest.WeatherInputDayMet
tests/gtests/test_SW_Weather.cc:1033: Failure
The difference between SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[0] and expectedResult is 72.577207808923504, which exceeds tol6, where
SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[0] evaluates to 0.73310310918104549,
expectedResult evaluates to 73.310310918104548, and
tol6 evaluates to 9.9999999999999995e-07.

tests/gtests/test_SW_Weather.cc:1042: Failure
The difference between SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay] and expectedResult is 73.035512241813024, which exceeds tol6, where
SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay] evaluates to 0.73773244688700024,
expectedResult evaluates to 73.773244688700018, and
tol6 evaluates to 9.9999999999999995e-07.

[  FAILED  ] WeatherFixtureTest.WeatherInputDayMet (1 ms)
```
- check that relative humidity is calculated from specific humidity, tmax, and tmin

-> test is correctly failing (i.e., indicating the presence of bug #345):
```
[ RUN      ] WeatherFixtureTest.WeatherInputMACAtype2
tests/gtests/test_SW_Weather.cc:1322: Failure
The difference between SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[0] and 100. * e / es is 20.125763304504432, which exceeds tol6, where
SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[0] evaluates to 100,
100. * e / es evaluates to 79.874236695495568, and
tol6 evaluates to 9.9999999999999995e-07.

tests/gtests/test_SW_Weather.cc:1333: Failure
The difference between SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay] and 100. * e / es is 21.22859263656683, which exceeds tol6, where
SW_Run.Weather.allHist[yearIndex]->r_humidity_daily[midJanDay] evaluates to 100,
100. * e / es evaluates to 78.77140736343317, and
tol6 evaluates to 9.9999999999999995e-07.

[  FAILED  ] WeatherFixtureTest.WeatherInputMACAtype2 (8 ms)
```
- each attribute of structs SW_WEATHER_NOW, SW_WEATHER_HIST, and SW_SKY are now documented with units
- clarify internal units of specific humidity (mass of water vapor in unit mass of moist air) [g kg-1]
- add comment that specify the correct units in read_weather_hist()
- checkAllWeather() now warns if relative humidity is within 0-1
- fix #435
* read_weather_hist() now uses relativeHumidity1() to calculate relative humidity from vapor pressure -- fixing first part of bug #435
* read_weather_hist() now uses relativeHumidity2() to calculate relative humidity from specific humidity inputs -- fixing second part of bug #435
** the conversion from specific to relative humidity is not exact, the code snaps estimated values within 100-150% to 100% relative humidity (with a warning)

--> the new tests introduced in recent commits (b04a09e05bd7f74487e179b86b0de42310970af9, 6457893f749e9bf775a18521d80cfdc7153e9d07) are now passing

- new functions
* relativeHumidity1() calculates relative humidity from vapor pressure and temperature by estimating saturated vapor pressure
* relativeHumidity2() calculates relative humidity from specific humidity and temperature with a pressure correction from elevation
* actualVaporPressure4()calculates vapor pressure from specific humidity with a pressure correction from elevation

- other changes
* readAllWeather() and read_weather_hist() gain argument "elevation" which is used for the pressure correction when calculating relative humidity from specific humidity inputs
* update unit tests to reflect changes
- test now checks for all weather variables: tests "WeatherDefaultValues" and "WeatherSomeMissingValuesDays"

- renamed tests for consistency
* test "WeatherInputGridMET" was previously "WeatherInputDailyGridMet"
* test "WaterBalanceWithGridMET" was previously "WaterBalanceWithGRIDMET"
* test "WeatherInputDaymet" was previously "WeatherInputDayMet"
* test "WeatherInputMACAtype1" was previously "WeatherInputMACA"
* test "WaterBalanceWithMACAtype1" was previously" WaterBalanceWithMACA"

- renamed "maca" example input data to "maca-type1" for consistency

- tests with weather data types ("WeatherInput*" and "WaterBalanceWith*" with * in {"GridMET", "MACAtype1", "MACAtype2" and "Daymet"}) now
* set every value of dailyInputIndices and dailyInputFlags to clarify which inputs are available and which are not available
* new checks that no weather value is missing (except for Daymet which does not provide inputs for wind speed)
* updated checks for relative humidity

- new test "WaterBalanceWithMACAtype2"
@dschlaep dschlaep self-assigned this Nov 20, 2024
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 81.03448% with 11 lines in your changes missing coverage. Please review.

Project coverage is 73.22%. Comparing base (3e5657a) to head (2138228).
Report is 13 commits behind head on master.

Files with missing lines Patch % Lines
src/SW_Weather.c 76.59% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #436      +/-   ##
==========================================
+ Coverage   73.00%   73.22%   +0.22%     
==========================================
  Files          20       20              
  Lines        6005     6025      +20     
==========================================
+ Hits         4384     4412      +28     
+ Misses       1621     1613       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dschlaep dschlaep linked an issue Nov 25, 2024 that may be closed by this pull request
- close #437 "Incorrect count of LOCF in generateMissingWeather()"

- the number of days on which LOCF was applied is now correctly counting only the days when there was a missing value that was replaced by a non-missing value
- previously, any day with a missing value was counted -- even if it was not replaced by a non-missing value

- for instance, inputs without solar radiation or without vapor pressure previously caused that every day was counted towards the maximum permissible number of LOCFs

- note: initial values for LOCF changed from 0 to "missing" -- this matters only for days at the beginning of the time period that have missing values before a later day with a first non-missing value
@dschlaep dschlaep requested a review from N1ckP3rsl3y November 25, 2024 22:50
@dschlaep dschlaep merged commit ccce564 into master Nov 26, 2024
11 checks passed
@dschlaep dschlaep deleted the bugfix435ForV800_calculatedRelativeHumidity branch November 26, 2024 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants