lindsayplatt / salt-modeling-data

Reproducible code for downloading, processing, and modeling data related to river salinization dynamics
0 stars 0 forks source link

Add calculation of upstream salt #47

Closed lindsayplatt closed 8 months ago

lindsayplatt commented 8 months ago

Including all upstream salt as an additional attribute. Note that the download of catchments is still failing for one group of NHD COMIDs and I have chosen to just skip for now. I am working through the issues here: https://github.com/DOI-USGS/nhdplusTools/issues/376.

There is now an additional attribute in the p3_static_attributes target called attr_roadSaltCumulative which represents the aggregate salt for the current site's catchment and all of the catchments upstream from it.

Below are some snapshots of the new upstream data compared to the catchment-only salt. Note that for these plots, I first filtered any site where upstream was missing. There are 11 sites where cumulative is the same as catchment roadSalt, meaning they are the headwaters reach (ratio == 1 in the histogram). Most sites have less than half of the cumulative upstream salt applied in their individual catchment, which is expected.

image

image

lindsayplatt commented 8 months ago

Ope, meant to put the code for these

library(targets)
library(tidyverse)

tar_load(p2_attr_roadSalt)

p2_attr_roadSalt %>% 
  filter(!is.na(attr_roadSaltCumulative)) %>% 
  rename(`Catchment Salt` = attr_roadSalt,
         `Upstream Salt` = attr_roadSaltCumulative) %>% 
  pivot_longer(-site_no, names_to = 'salt_calc') %>% 
  ggplot() +
  geom_histogram(aes(value, fill = salt_calc)) +
  facet_grid(salt_calc ~ .) +
  theme_bw()

p2_attr_roadSalt %>% 
  filter(!is.na(attr_roadSaltCumulative)) %>% 
  mutate(ratio = attr_roadSalt / attr_roadSaltCumulative) %>% filter(ratio == 1)
  ggplot() +
  geom_histogram(aes(ratio)) + 
  xlab('Ratio of catchment salt to total cumulative upstream') +
  theme_bw()