pacificclimate / data-prep-actions

Data Preparation actions - record of ephemera used to prepare data for PCIC data portals and other tools
0 stars 0 forks source link

Script to add species and region information to watershed map #57

Closed corviday closed 1 year ago

corviday commented 2 years ago

This command line script should take two inputs - a shapefile (map file) containing a number of named regions, and a CSV file (spreadsheet) that, for each watershed, lists whether a particular group of salmon (conservation unit) is present in that region. We'd like the information about which species of salmon is present to be added to the map file so it can be displayed on the BC-SRIF portal.

CSV FORMAT The CSV has a row for each watershed, identified by watershed code (WTRSHDGRPC), and a column for each individual salmon population; it looks like this:

WTRSHDGRPC cc_ck_509 cc_ck_510
PORI 0 1
UPET 0 0
LCHL 0 0
GUIC 0 0

This tells us that the salmon population cc_ck_509 is not present in the PORI watershed, but cc_ck_510 is present in this watershed. The first part of the salmon population code is the region:

Abbreviation Region
cc Central Coast
fr Fraser
hg Haida Gwaii
na Nass
sk Skeet
vimi Vancouver Island and Mainland Inlets

The second part of the salmon population code is the species:

Abbreviation Species
ck Chinook
cm Chum
co Coho
pke Pink Even
pko Pink Odd
sel Sockeye Lake
ser Sockeye River

For each watershed, we'd like to be able to display on the website which region it was in and which salmon species are present. In the shapefile, we'd like to add a region property and an attribute for each of the species of salmon, which we can figure out from the codes of the salmon populations present in each watershed. So add properties named "region", "chinook", "chum", etc. I think spaces might cause trouble in property names, so use an underscore for the two-word species names.

So if, for example, the salmon group cc_ck_509 is present in watershed PORI, this is a population of Chinook salmon on the Central Coast, and we know that PORI is in the Central Coast region and is home to some Chinook salmon. cc_pke_304 might also be marked as present in PORI, which would mean Pink Even salmon were present in this watershed as well.

Set the region property to the name of the region (all salmon populations in a watershed should have the same regio, a watershed can only be in one region) and set the species property to 1 if one or more of the salmon populations present are that species, and 0 otherwise.

Useful notes:

corviday commented 1 year ago

We have changed how we handle salmon populations; they are now stored in a postGIS database, instead of shapefiles. This script is no longer needed (though we need a script to add population data to the postGIS database instead).