Earliest Dam Year
First load the network, and attributes
network load_file("data/ohio-river/ohio.network")
network gis.load_attrs("data/ohio-river/nid-uniq.gpkg", "nidId")
nodes.is_usgs = NAME match "^[0-9]+";
nodes.is_dam = !is_usgs;
network count(nodes.is_usgs)
network count(nodes.is_dam)
Results:
1806
4181
Counting the upstream dams again,
nodes<inp>.ndam = int(is_dam) + sum(inputs.ndam);
nodes.no_dam_us = ndam == 0;
network count(nodes {no_dam_us & is_usgs})
network count(nodes {no_dam_us & is_usgs}) / count(nodes.is_usgs)
Results:
605
0.33499446290143964
We can see 33% of the USGS gages do not have dams upstream.
And for those that do, let’s look at the construction year,
env.max_year = 9999; # todo test it with nan
nodes.dam_year = int(get_attr("yearCompleted", env.max_year));
nodes<inp>.dam_aff_yr = min_num(inputs.dam_aff_yr, dam_year);
nodes<inp>.dam_affected = dam_aff_yr < env.max_year;
network count(nodes.dam_affected & nodes.is_usgs)
network count(!nodes.no_dam_us & nodes.is_usgs)
network count(nodes.dam_affected & nodes.is_usgs) / count(!nodes.no_dam_us & nodes.is_usgs)
Results:
1152
1201
0.9592006661115737
This shows we have the construction year for 95% of the USGS gages that were constructed after at least one upstream dams.