README.md
# Combining HMMs and SSFs code
Repository containing code for paper <i>Combining habitat selection, behavioural states, and individual variation to predict fish spatial usage near a barrier</i>
<h> Rough breakdown of code
<b>Code to filter raw data</b> contains code to go from raw positions to the approach tracks used in the paper (https://doi.org/10.5281/zenodo.14313343). This is python code and includes some purpose written functions. The hydraulic data (rasters for flow velocity, water depth, spatial velocity gradient, flow velocity angle and spatial velocity angle) are located at https://doi.org/10.5281/zenodo.14318807
<b>scripts</b> contains R code for various purposes - applying crawl to interpolate the tracks, adding standardised columns for modelling, filtering to keep good quality tracks (x 2 scripts), a code to perform model selection (as in-built R functions didn't work with the fit_issf function used), creating SSF dataframes. Scripts that have to run in a specific order are numbered.
It is important to note that for the SSF only and the HMM-SSFs that the same code is used to process the data. As I did the SSF only analyses first (in Mawer et al. (2023)). The dataframes made in Mawer et al. then had HMMs applied, states assigned and the analyses repeated per state. The code here is therefore altered as needed for which dataset (SSF only or HMM-SSF).
<b>Cross validating codes</b> contain the codes to simulate tracks to cross validate the SSFs. This involves code written in C++ by James Campbell (code by James Campbell in folder cpp).
<b>Prediction code</b> contains the code used to predict spatial usage of the two species from the SSF outputs, and to plot the results.
<b>Results code</b> - The file "hmm_+_ssf_explore.Rmd" does the data exploration for all model results (i.e. both the combined states SSFs and the HMM-SSFs).