Okay - I created a bit of git mess merging various branches in the wrong order and then fixing, but now it's cleaned up and all changes are integrated into this branch which can be merged into main after review. I think you have reviewed most everything aside from the main targets workflow so I will break that down here for your convenience
Targets workflow
Loading data
lines 40 - 134 (shown in snippet/permalink below)
Here we create targets that are created from files located on gdrive. You should be familiar with most as you used them in your code, I just transferred them to targets.
The new one here are:
nga_adm : just a list of all sf data.frames containing all nga admin files (for convenince)
basins_clipped : Hydrobasin levels 4 & 5 clipped to nga admin 0
gauge_google_sp - location of all gauges in sf/spatial format from metadata tab of workbook
gauges_basin_google I join the gauge locations
Classify historical Discharge
Next we go through the historical discharge data and classify whether or not each day is above the breaches, exceeds, or is below 2,5,20 year RP values.
The code for the function that creates google_historical_class object is here:
The wrangling for ghistorical_rp2_breach_pct_basin_gauges target basically works by:
finding all distinct times (by basin, date, gauge) the threshold (2 year RP) was breached.
iterating through this distinct list by filtering the entire historical record to the each events basing and +/- n days (here we do +/-5) in that basin.
For +/- n days in that basin it counts the number of gauges that had thresholds crossed.
Could make this last target wrangling into some sort of function if we think useful for later.
Email Mockup
I don't think it is really worth reviewing the code for the email mockup/draft yet as it was more just created quickly as a proof of concept and to show people what we mean by email alert. I think there is still too much to discuss regarding the email contents for it to be worth your time to review yet.
Okay - I created a bit of git mess merging various branches in the wrong order and then fixing, but now it's cleaned up and all changes are integrated into this branch which can be merged into main after review. I think you have reviewed most everything aside from the main targets workflow so I will break that down here for your convenience
Targets workflow
Loading data
lines 40 - 134 (shown in snippet/permalink below) Here we create targets that are created from files located on gdrive. You should be familiar with most as you used them in your code, I just transferred them to targets.
The new one here are:
nga_adm
: just a list of all sf data.frames containing all nga admin files (for convenince)basins_clipped
: Hydrobasin levels 4 & 5 clipped to nga admin 0https://github.com/OCHA-DAP/pa-flood-pilot-validation/blob/e6946462805318eb6fd02b18fea78b78fb089e7b/_targets.R#L40-L126
Extract relevant forecast/historical Data
gauge_google_wb
takes the full workbook (list of data.frames) and removes any potential duplicate forecastsg_realtime_gauge
- extracts just data.frames containing individual gauges data aand binds them togethergoogle_historical
- reads in nowcast data -- i think this code is mainly from one of your scripts so you should be familiarSpatial Wrangling
Spatialize gauge locations -> join to basins (levels 4 & 4)
gauge_google_sp
- location of all gauges in sf/spatial format frommetadata
tab of workbookgauges_basin_google
I join the gauge locationsClassify historical Discharge
Next we go through the historical discharge data and classify whether or not each day is above the breaches, exceeds, or is below 2,5,20 year RP values.
The code for the function that creates
google_historical_class
object is here:https://github.com/OCHA-DAP/pa-flood-pilot-validation/blob/e6946462805318eb6fd02b18fea78b78fb089e7b/R/tar_utils.R#L17-L58
we then just join the basin ID on.
Aggregate threshold crossings to basin
The wrangling for
ghistorical_rp2_breach_pct_basin_gauges
target basically works by:https://github.com/OCHA-DAP/pa-flood-pilot-validation/blob/e6946462805318eb6fd02b18fea78b78fb089e7b/_targets.R#L228-L295
Could make this last target wrangling into some sort of function if we think useful for later.
Email Mockup
I don't think it is really worth reviewing the code for the email mockup/draft yet as it was more just created quickly as a proof of concept and to show people what we mean by email alert. I think there is still too much to discuss regarding the email contents for it to be worth your time to review yet.