Code Monkey home page Code Monkey logo

smnorris / bcfishpass Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 14.0 30.78 MB

Model and monitor aquatic habitat connectivity in BC. Tools to plan and prioritize the assessment and remediation of barriers.

Home Page: https://smnorris.github.io/bcfishpass

License: Apache License 2.0

Shell 18.23% Python 27.32% HTML 4.63% PLpgSQL 34.78% Makefile 14.21% Dockerfile 0.82%
fish-passage fish-observation british-columbia fwa stream-network gradient-barriers pscis roads dra digital-road-atlas

bcfishpass's People

Contributors

alexlcwf avatar laurab-cwf avatar mateo9569 avatar matthewcooper11 avatar newgraphenvironment avatar nickw-cwf avatar njohanley avatar sami-kurani avatar smnorris avatar tomasmillakoch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bcfishpass's Issues

add support for misc definite barriers

To support:

  • defining areas outside of model consideration
  • misc barriers that aren't covered by existing types

Perhaps an additional misc table is required - add 01_prep/04_other/data/misc.csv and a corresponding misc.sql.

Hopefully it is safe to presume that there won't be very many of these, no automated matching of points to streams is necessary - misc points can simply be coded with an id and notes, plus blue_line_key (or linear_feature_id) and downstream_route_measure for location.

pscis_modelledcrossings_streams_xref QA

PSCIS assessed crossings are not getting matched to nearby modelled crossings because of empty modelled_crossing_id values in the xref.

Fix may require some manual QA but a query on nearby modelled crossings (instream within 100m or so) should identify most and be fairly easy to fix.

Alternatively changing the logic in the matching is possible... but I think this xref should explicitly match pscis crossings to modelled crossings where possible, not just streams. When modelled_crossing_id is null in the xref it should be fairly safe to conclude that there is no mapped road at this location.

habitat model - spawning and rearing habitat refinements

  1. Rearing habitat downstream of spawning habitat does not need to actually be connected to the spawning habitat
  2. Consider a maximum distance upstream from spawning habitat for connected rearing habitat to be valid
  3. double line rivers meeting slope criteria should be coded as spawning habitat (due to general under-estimation of channel width by the channel width model on larger streams)
  4. Investigate measuring channel width across river polygons if time allows
  5. Include ALL potential rearing habitat DOWNSTREAM of spawning habitats (for that spp)
  6. Include potential rearing habitat UPSTREAM of spawning habitat that is NOT connected IF slope between the rearing/spawning does not exceed 5% (with caveat that there may be an instream distance threshold applied in future)
  7. Sockeye are different - model rearing habitat first and then add potential spawning habitat DOWNSTREAM of rearing lake where slope of segments between spawn and rear is <2% (again subject to a distance threshold TBD)

check area outputs in report.sql

When adding sums, each area needs to be wrapped in a COALESCE():

COALESCE(ROUND(((SUM(uwb.area_lake) + SUM(uwb.area_manmade)) / 10000)::numeric, 2), 0) AS total_lakereservoir_ha,

becomes

ROUND(((SUM(COALESCE(uwb.area_lake, 0)) + SUM(COALESCE(uwb.area_manmade, 0))) / 10000)::numeric, 2) AS total_lakereservoir_ha,

web map - add crossings

First, add provided key barriers for January 2021 workshops discussion.
After workshops, add all crossings.

file organization

All the subfolders in /sql are a bit scattered, this could still use some tidying

bcfishpass.crossings crossing type values

Existing values are ad-hoc, some improvement could be made so user can quickly understand more about the crossing:

select distinct crossing_source, crossing_type from bcfishpass.crossings;
   crossing_source    | crossing_type
----------------------+---------------
 ASSESSED             | BRIDGE
 ASSESSED             | PIPEARCH
 MODELLED_CROSSINGS   | CBS
 ASSESSED             | OVAL
 ASSESSED             | WOODBOX
 HABITAT CONFIRMATION | ROUND
 HABITAT CONFIRMATION | OVAL
 ASSESSED             | FORD
 ASSESSED             | ROUND
 REMEDIATED           | BRIDGE
 HABITAT CONFIRMATION | FORD
 MODELLED_CROSSINGS   | OBS
 ASSESSED             | CRTBOX
 BCDAMS               | DAM

For crossings linked to modelled crossings we can note what road/rail source the modelled crossing came from.
For crossings that are PSCIS only I'm less sure what we can pull through.

Include MORR, ADMS, LNTH watershed groups

MORR - for New Graph Bulkley reporting
ADMS/LNTH - for Braumandl 2020 confirmation mapping

Of course, this is already covered by #36 - Processs all salmon watersheds - but adding just these three is a good short term step towards that.

channel width - exclude additional measured widths

Based on review by Nick M, exclude these points from channel width measures:

stream_sample_site_id IN 
(44813,44815,10997,8518,37509,37510,53526,15603,98,8644,117,8627,142,8486,8609,15609,10356)
stream_crossing_id IN  (57592,123894,57408,124137)

Gradient barriers - not generated for cross border streams?

See blue_line_key=356518984 at Frozen Lake in Flathead watershed.

Segment linear_feature_id=706880333 is almost 40% over 528m - a gradient barrier should be created at the beginning of this line. Problem likely because this stream segment is not connected with the rest of the stream, it dips down into Montana.

reporting - additional summary metrics

For WCRP:

a) the total habitat blocked by each barrier type (Barrier Extent)
b) the % of each barrier type that are barriers/potential barriers (out of those that have been assessed) (Barrier Severity)

channel width - enable support for modelling any watershed

Channel width predictor model is provided by Nick Mazany-Wright at CWF based on an R analysis that is run per watershed group.

data file organization

Many QA updates to various features are required.
Currently several data files are included, mostly in separate folders:

  • 01_prep/01_modelled_stream_crossings/data/modelled_stream_crossings_fixes.csv
  • 01_prep/02_pscis/data/pscis_barrier_result_fixes.csv
  • 01_prep/02_pscis/data/pscis_modelledcrossings_streams_xref.csv
  • 01_prep/05_other/data/falls.geojson

There may be other lookups required as well, and usage needs to be documented.
It might be easier to consolidate these data files into a single folder so the user applying QA can see them all / and the documentation in the same spot.

accessibility QA - MORR

review

  • PSCIS - stream - modelled crossing matches
  • modelled crossings with most upstream stream
  • dams with most upstream stream (Owen Lake outlet in particular)

barrier report

for bcfishpass.barriers_anthropogenic, create view/report Including the usual passable/potentially accessible:

  • area upstream
  • length upstream total
  • length upstream, by slope class

etc- for prioritization.

Also include key PSCIS and road attributes where available.

reporting - add summary report per watershed group

Summarize the status per watershed (but perhaps make the reporting area flexible):

  • number of crossings/type etc
  • length, pct stream accessible / potentially accessible
  • length, pct habitat accessible / potentially accessible
    etc

accessibility QA - ADMS

review

  • PSCIS - stream - modelled crossing matches
  • modelled crossings with most upstream stream
  • dams with most upstream stream

Is it possible to avoid creating yet another crossings id column?

Crossings come from 3 sources:

  1. modelled crossings
  2. PSCIS
  3. dams

Because each source has its own set of ids, we create a new aggregated_crossings_id column for the crossings table. This is generally fine because the source modelled_crossing_id, pscis crossing_id and dam_id are kept. But for the dnstr_crossings and dnstr_barriers_anthropogenic columns it would be much nicer to use the source ids for clarity. Plus yet another crossing id column gets even more confusing.

There shouldn't be much/any overlap in the id values - perhaps there is a way to combine them into the aggregated_crossings_id without changing them?

Or simply create a primary key based on all three columns? This might work in the db but will not work for QGIS or other tools which need a single unique id

modelled_crossing_type_source - check repeated codes, consider adding to crossings table, consider adding a manual review code

Not sure why ali.crossings modelled_crossing_id 4606812 is listed as PASSABLE . Was this reviewed by hand or are there bridge details from a railway layer? If so, should there be a flag to indicate this?

I had a look at https://github.com/smnorris/bcfishpass/blob/main/01_prep/01_modelled_stream_crossings/sql/08_identify_open_bottom_structures.sql for clues but couldn't figure things out.

reporting - add road tenure report

Add table that attempts to summarize road tenure info associated with each crossing.
Keep this as a separate table from the main reports, let the user join them together.

accessibility model - output codes

https://github.com/smnorris/bcfishpass/blob/main/02_model/sql/model.sql burns output values to the streams table in the accessiblility_model_<species> columns.

CURRENT CODES

ACCESSIBLE - downstream of definite barriers and any modelled or assessed anthropogenic barriers
POTENTIALLY ACCESSIBLE - downstream of definite barriers, upstream of modelled anthropogenic barrier(s)
POTENTIALLY ACCESSIBLE - PSCIS BARRIER DOWNSTREAM - downstream of definite barriers, upstream of assessed PSCIS barrier / potential barrier

PROPOSED ADDITIONS

POTEENTIALLY ACCESSIBLE - PSCIS POTENTIAL DOWNSTREAM - upstream of crossing assessed as POTENTIAL
ACCESSIBLE - REMEDIATED - upstream of a remediated crossing, downstream of any other barriers

Remediated class would require extracting remediations into a separate temp table and running bcfishpass.py add-downstram-ids ...

channel width - no data for some streams

Some streams do not get assigned a channel width, eg linear_feature_id = 17055882.

This is because they don't get a precipitation value... because when we relate the precip data provided based on watershed_feature_id of the fundamental watersheds to streams based on watershed codes... there is actually no fundamental watershed with watershed codes matching this stream.

This seems to generally be an issue for segments in rivers.

Fix is likely to do a spatial join for streams with watershed code / local code combination that is not present in fwa_watersheds_poly.

Document installation process on windows

psql2csv is listed as a requirement and is available on Homebrew .

I am currently on a windows machine.

Homebrew 2.0.0 documentation indicates that homebrew officially supports Linux and Windows 10 with Windows Subsystem for Linux (WSL).

Do you think this is the way to go and if so do you think that the other requirements - bcfishobs, bcdata and pgdata should be loaded into a conda env that is loaded inside of a WSL as per https://gist.github.com/kauffmanes/5e74916617f9993bc3479f401dfec7da ?

remove dnstr_crossings when crossing type = OBS and barrier_status = PASSABLE

When modelled crossings meet modelled habitat-based criteria that flags them as potentially important and dnstr_crossings is NULL it allows the reviewer to have a look at only the most downstream crossing within the watershed of interest. If that crossing looks like a good crossing to follow up on in the field it can be assumed that the rest of the crossings upstream will be looked at in turn if/when it makes sense.

Currently, all modelled_crossings that meet my habitat-based query in the Upper Elk River have dnstr_crossings . A review of a subset of these indicates that often these crossings are actually on the Elk River and have a barrier_status of PASSABLE (ex aggregated_crossings_id = 22095 and aggregated_crossings_id = 9510) .

Is there a way to pull the aggregated_crossings_id with the barrier_status = PASSABLE out of the dnstr_crossings column of the crossings layer or add another queriable column for review purposes?

provide conda environment

Create a conda environment that includes all dependencies - this should take some of the pain out of cross-platform installation (but windows users would still have to edit the shell scripts or use bash via windows subsystem linux or similar)

habitat model - include wetlands

We want to multiply CO rearing habitat by 1.5x in wetlands to better account for it, but currently wetlands are not included at all in the spawning/rearing models - only rivers and edge_type IN (1000,1100,2000,2300) (single line bluelines, primary and secondary flow).

Are wetlands potential rearing habitat for all species, or just Coho?

pscis_barrier_result_fixes.csv - tidy structure

This is a lookup simply for remapping barrier_result_code based on manual review.
There is no need to retain PSCIS info other than the stream_crossing_id - remove columns:

  • crossing_subtype_code
  • barrier_result_code
  • assessment_comment

Add reviewer, notes columns, a structure similar to the other lookup/xref tables.

report on m not km

For various upstream summary indicators in point_report.sql, report in m rather than km.

Add spawning/rearing habitat model(s)

For goal setting and prioritization, identify potential spawning (and perhaps rearing) habitat along streams.

One simple habitat potential model based on attributes already in the streams table:

Species Gradient (spawning) Stream Order (spawning)
Chinook 0-3% (<1% optimal) 3-5 (4-5 optimal)
Coho 0-3% 3-5 (4-5 optimal)
Steelhead 0-12% (<5% optimal) 2-5 (3-5 optimal)
Sockeye 0-2% 3-5 (4-5 optimal)

This just requires adding 4-5 new columns (one for a combination of the four species) and applying an UPDATE based on the gradient and stream order.

A better/more refined option is to model potential spawning habitat based on gradient, channel width and potentially channel confinement. Channel width would be modelled based on: upstream watershed area, mean annual precip, stream magnitude, area wetlands upstream etc. Channel confinement modelling TBD.

Potentially even better is to model potential habitat based on gradient and modelled annual discharge for the stream.

gradient barrier points present in waterbodies

Some gradient barrier points are in waterbodies because the valley slopes up quickly from river/lake edge.
When running the slope calculation, remove streams of waterbody edge types.

model README

Document how to tweak the barriers/observations/streams sql files

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.