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

Read more daily input #228

Merged
merged 34 commits into from
Jun 5, 2023
Merged

Read more daily input #228

merged 34 commits into from
Jun 5, 2023

Conversation

N1ckP3rsl3y
Copy link
Contributor

@N1ckP3rsl3y N1ckP3rsl3y commented Jan 18, 2023

Nicholas Persley added 9 commits January 10, 2023 15:06
- Added a new constant, "MAX_INPUT_COLUMNS", from SOILWAT2 which holds the maximum possible input columns (14) to be read-in excluding the "DOY" input column
- "p_Year" now takes in new daily cloud cover, wind speed, relative humidity, shortwave radiation, and actual vapor pressure
- rSOILWAT2 now transfers listed values above to SOILWAT2 through "allHist"
- Updated "cYear" to hold more column head names
- Instead of four column, `rSW2_setAllWeather()` now expects 15
- Class "swWeather" handles new flags from SOILWAT2 side:
	* Monthly value usage
	* Temperature (components), precipitation, cloud cover, wind speed, relative humidity, specific humidity, dewpoint temperature, actual vapor pressure, and shortwave radiation
	* Other component flags for wind speed and specific humidity
- Added actual vapor pressure and shortwave radiation to "swMonthlyScalingParams" and within "onGet_SW_WTH_setup()"

- Translate SOILWAT2 flags to rSOILWAT2 within `onGet_SW_WTH_setup()`
- Translate rSOILWAT2 flags to SOILWAT2 within `onSet_SW_WTH_setup()`
- Translate scaling factors of actual vapor pressure and shortwave radiation to and from SOILWAT2 and rSOILWAT2 in `onGet_SW_WTH_setup()` and `onSet_SW_WTH_setup()`

Note: The program is currently not able to update test input due to the second example generation from `prepare_testInput_objects.R` resulting in a crash due to bad weather input
- `rSW2_setAllWeather()` uses monthly sky input values from the class "swCloud" to get user input monthly values to be interpolated
- Mirrored possible calculations from `_read_weather_hist()/readAllWeather()` (SOILWAT2) to add functionality on the R side without other possible difficulties
* Clarification: Interpolation and call to `actualVaporPressure1()` which are in `readAllWeather()` on the SOILWAT2 side, have been combined with other calculations within `rSW2_setAllWeather()`
- `onGet_SW_WTH_setup()`, `onSet_SW_WTH_setup()`, and class "swWeather" now hold six new flags which break temp2, hurs2, and windComp into their respective parts
- `rSW2_setAllWeather()` translates some flags once they are gathered from the class "swWeather" instead of translating every time the flag is needed
- `rSW2_setAllWeather()` tests for a range of input columns from 4 through MAX_INPUT_COLUMNS + 1 (15)
Copy link
Member

@dschlaep dschlaep left a comment

Choose a reason for hiding this comment

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

Nice progress!

I added some comments for specific lines. And here some general comments

  • We will need methods/functions that handle weather data in the previous format, e.g., by upgrading them to the new format on the fly; see sw_upgrade()

  • Some values in the weather data objects are currently not making much sense. For instance, for Ex1_weather (contains nonsensical values for several of the new variables; and for some that are turned off by default)

> head(Ex1_weather[[1]]@data)
     DOY Tmax_C Tmin_C PPT_cm cloudCov windSpeed windSpeed_east windSpeed_north
[1,]   1  -0.52 -15.67   0.22 66.48387       1.3             61             999
[2,]   2  -2.06  -7.86   0.72 66.80645       1.3             61             999
[3,]   3  -4.04 -14.47   0.22 67.12903       1.3             61             999
[4,]   4  -1.26  -9.20   0.55 67.45161       1.3             61             999
[5,]   5   0.65 -10.85   0.02 67.77419       1.3             61             999
[6,]   6   0.35 -18.72   0.00 68.09677       1.3             61             999
         rel_H rel_H_max rel_H_min spec_H dewpointTemp_C actVP shortWR
[1,] 0.2024587         0         0      0              0     0       0
[2,] 0.2576992         0         0      0              0     0       0
[3,] 0.1848576         0         0      0              0     0       0
[4,] 0.2524647         0         0      0              0     0       0
[5,] 0.2549731         0         0      0              0     0       0
[6,] 0.1858799         0         0      0              0     0       0

R/D_swWeatherData.R Outdated Show resolved Hide resolved
R/D_swWeatherData.R Outdated Show resolved Hide resolved
R/D_swWeather.R Outdated Show resolved Hide resolved
src/rSW_Weather.c Outdated Show resolved Hide resolved
src/rSW_Weather.c Outdated Show resolved Hide resolved
src/rSW_Weather.c Outdated Show resolved Hide resolved
src/rSW_Weather.c Outdated Show resolved Hide resolved
src/rSW_Weather.c Outdated Show resolved Hide resolved
.gitmodules Show resolved Hide resolved
R/D_swWeatherData.R Outdated Show resolved Hide resolved
Nicholas Persley and others added 5 commits February 12, 2023 21:35
- Create a new function `strip_weather_data_NA_columns()` to eliminate unused columns of the newest version of "swWeatherData" (15 columns)
	* If an object of this type were to contain only four useful columns of data, nine would be unused and then takes up more space than needed

dbW_dataframe_to_weatherData():
- Removed check for input column names to be of length four to account for variability
- Function sets column names based on ones sent in and are no longer hardcoded

sw_upgrade():
- Now strips unnecessary columns of the input object through the use of `strip_weather_data_NA_columns()`

swWeatherData():
- No longer directly copies column names from the created object
	* Common columns are now detected and set so no error is caused due to unequal amount of columns to be set
- Removed `strip_weather_data_NA_columns()`
- Reverted `dbW_dataframe_to_weatherData()` to the previous version to only deal with four columns
- Reverted `swWeatherData()` to directly get slots from the local instance of "swWeatherData"
- `sw_upgrade()` no longer calls `strip_weather_data_NA_columns()`
- SOILWAT2 contains a struct of the name "allHist" which contains:
	* max/min/avg temperature and precipitation
	* cloud cover, wind speed, relative humidity, actual vapor pressure, and shortwave radiation
- "swWeatherData" now contains all but average temperature (since it's calculated when data is transferred to SOILWAT2)
- "swWeatherData" keeps "DOY"
@codecov
Copy link

codecov bot commented May 2, 2023

Codecov Report

Merging #228 (050d3fa) into release/devel_v6.0.0 (693e992) will increase coverage by 0.91%.
The diff coverage is 76.47%.

❗ Current head 050d3fa differs from pull request most recent head 2f427a3. Consider uploading reports for the commit 2f427a3 to get more accurate results

@@                   Coverage Diff                    @@
##           release/devel_v6.0.0     #228      +/-   ##
========================================================
+ Coverage                 57.58%   58.49%   +0.91%     
========================================================
  Files                        42       42              
  Lines                      7719     8038     +319     
========================================================
+ Hits                       4445     4702     +257     
- Misses                     3274     3336      +62     
Impacted Files Coverage Δ
R/rSOILWAT2_deprecated.R 0.00% <0.00%> (ø)
src/SW_R_init.c 100.00% <ø> (ø)
R/D_swWeather.R 46.66% <44.73%> (+5.96%) ⬆️
R/Rsw.R 68.85% <50.00%> (-0.98%) ⬇️
R/sw_dbW_WeatherDatabase.R 78.62% <84.29%> (+4.67%) ⬆️
R/D_swWeatherData.R 71.01% <85.36%> (-28.99%) ⬇️
src/rSW_Weather.c 94.23% <89.83%> (-3.59%) ⬇️
R/A_swGenericMethods.R 39.54% <100.00%> (+0.69%) ⬆️
R/K_swContainer.R 35.57% <100.00%> (+1.14%) ⬆️
R/swWeatherGenerator.R 36.40% <100.00%> (+0.01%) ⬆️
... and 1 more

including
- `solar_radiation()` now handles observed radiation values and missing cloud cover
- use consistent column names
- column 7 is for actual vapor pressure and column 8 for shortwave radiation
- class "swWeather" gains `desc_rsds` (description of radiation inputs) and `dailyInputFlags` (logical vector describing which daily weather input variables are active in the associated weather data object)
- class "swWeatherData" holds now up to 14 daily weather input variables: "Tmax_C", "Tmin_C", "PPT_cm", "cloudCov_pct", "windSpeed_mPERs", "windSpeed_east_mPERs", "windSpeed_north_mPERs",  "rHavg_pct", "rHmax_pct", "rHmin_pct", "specHavg_pct", "Tdewpoint_C", "actVP_kPa", "shortWR"

- update C functions that copy values between R and C functionality
- `getWeatherData_folders()` can read new daily weather inputs either via R code (that leaves values and variables as is) or via C code (connecting to SOILWAT2 which processes variables as needed for a simulation run)
- new C level `rSW2_readAllWeatherFromDisk()` to use SOIILWAT2 to read (and process) daily weather inputs from disk
- weather data are a list of elements of the class "swWeatherData" -- we cannot use S4 method `sw_upgrade()` --> `upgrade_weatherHistory()`
- monthly scaling parameters of class "swMonthlyScalingParams" are contained within "swWeather" -- we cannot use its S4 method `sw_upgrade()` --> `sw_upgrade_MonthlyScalingParams()`

- `dbW_check_weatherData()` now checks for valid "swWeatherData" objects carefully and via new argument `check_all` checks carefully for slot "year" in case it is missing
new:
- `calc_dailyInputFlags()` estimates which weather variables are active (here, those that are not only missing)
- `is_missing_weather()` produces a logical matrix checking for all possible values that could indicate missing weather values
- `weatherGenerator_dataColumns()` lists weather variables that the Markov weather generator implements
- `weather_dataAggFun()` lists functions that are used to temporally summarize each weather variable (e.g., `mean()` for temperature, `sum()` for precipitation amount)

updated:
- `dbW_convert_to_GregorianYears()`: argument `name_data` is now by default the result of `weather_dataColumns()`
- `dbW_dataframe_to_weatherData()`: argument `weatherDF_dataColumns` is now by default the result of `weather_dataColumns()` (plus "DOY")
- `dbW_weatherData_to_monthly()` and `dbW_dataframe_aggregate()`: new argument `funs` with default the result of `weather_dataAggFun()`plus "DOY")
- `dbW_weather_to_SOILWATfiles()`: argument `weatherDF_dataColumns` is now by default the result of `weather_dataColumns()` (plus "DOY")
- `dbW_weatherData_round()`: argument `weatherDF_dataColumns` is now by default the result of `weather_dataColumns()`
- `dbW_check_weatherData()`: now also checks if each "swWeatherData" object is valid and gains argument `check_all` to carefully check for year slot and correct number of days
- `dbW_generateWeather()`: now handles correctly new daily weather variables (but only those in `weatherGenerator_dataColumns()` are implemented by the weather generator)
- update scripts that prepare package and test data: they now make sure that weather history objects pass checks
- comparisons of weather data now makes mostly sense for those variables that don't have the potential to be calculated/processed by SOILWAT2
- check that previous versions can be successfully upgraded so that they validity and other checks
@dschlaep dschlaep self-requested a review June 2, 2023 16:25
included changes:
- Fix `mvnorm()`: avoid NaN as tmin output
- set seed for reproducible output
@dschlaep dschlaep merged commit e62e4a2 into release/devel_v6.0.0 Jun 5, 2023
7 checks passed
@dschlaep dschlaep deleted the read_more_daily_input branch July 27, 2023 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants