OCHA-DAP / pa-flood-pilot-validation

0 stars 0 forks source link

Gff data wireframing init framework #9

Open zackarno opened 1 year ago

zackarno commented 1 year ago

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:

https://github.com/OCHA-DAP/pa-flood-pilot-validation/blob/e6946462805318eb6fd02b18fea78b78fb089e7b/_targets.R#L40-L126

Extract relevant forecast/historical Data

Spatial Wrangling

Spatialize gauge locations -> join to basins (levels 4 & 4)

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:

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:

  1. finding all distinct times (by basin, date, gauge) the threshold (2 year RP) was breached.
  2. 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.
  3. For +/- n days in that basin it counts the number of gauges that had thresholds crossed.

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.