Skip to content

Repository files navigation

Human_Wildlife_Encounter_Detection

This repository contains the code and scripts necessary to reproduce the analyses and figures presented in 'A Method for Spatializing Disturbance by Detecting Human-Wildlife Encounters from GNSS Trajectories' submitted to Agile.

The first step is to download and extract the files included in this github project.

Restore Database

This section provides a step by step process to restore the database using PGadmin4. You can install PGadmin4 or use your prefered SQL method though the step by step guide is done using PGadmin4. When opening Pgadmin4, you may receive a password prompt for a password set during the installation.

The first step is to create a new database by right clicking database tab, hover over 'create' and select 'database'.

DB_1_create_db_blocks

The following prompt will appear where you must give the database a name. Here I use ‘ResRoute’ which is used in the accompanying code as the default database name. Then click save.

DB_2_create_db_2

Download ‘0_Create_and_Populate_Database.sql’ file from this github project if not already done and update the file paths in ‘0_Create_and_Populate_Database.sql’ to the location you extracted the data. This can be easily done in a text editor with find and replace.

Find : ‘ADD PATH TO DATA FILES => ’

Replace: The path to your folder containing the data This should update all file paths automatically. Alternatively manually update the 15 locations.

update_file_paths drawio

After updating the file paths, run ‘0_Create_and_Populate_Database.sql’ in the ‘PSQL Tool’. To do this, right click the database name and select ‘PSQL Tool’. Check that the path is correct. The database name should appear at the end of the command window followed by ‘=#’. Run the following line of code update with the path to where you saved the updated ‘0_Create_and_Populate_Database.sql’.

\i PATH/TO/FILE/0_Create_and_Populate_Database.sql

DB_3_open_scratchpad_2 DB____55

The expected runtime is about 4.7 min

The final output will look like this.

Create a python environment

Here I will use Visual Studio Code and Jupyter Notebook.

The first step is to create a virtual environment.

In Visual Studio Code, open the folder containing the project.

Use 'ctrl + shift + p' then select 'Interpreter' and select your python installation. See images below.

hide_identity_nom drawio image

Then use 'ctrl + shift + p' to select 'Python: Create Environment...' followed by 'Venu' followed by 'Python #.#.#'

image image image

Followed by this, you must install the required libraries. Open the terminal using 'ctrl + shift + ù' and pip install all the libraries in the 'requirements' file.

the_requirments install_requirments

Tracklib is not able to be installed using pip, so you must download and extract Tracklib from the following link https://github.com/umrlastig/tracklib.

Finally the file 'my_utils.py' must be updated. the variable folder_path = r"ADD PATH TO TRACKLIB FOLDER e.x. => \tracklib" must be updated to the path where Tracklib has been extracted.

Create Encounter Events

Next, to create the encounter events tables in the database, you must edit a couple of lines in the '1_main_Create_Encounter_Events.py' file. The tracklib_folder_path variable must be replaced with the path where you extracted tracklib. If your database does not use the preset values listed here you must update the variables to match your database.

  • 'db' is the name of the database
  • 'db_user' is the name of the user of the database
  • 'db_password' must be the password to the database

Then if you click 'Run Below', it will create the Encounter Events tables for each set of variables used in the paper.

encounter_events_111

The total expected run time is 150 min (2.5 hours)

  • Default: Create Encounter Events --- 50 min
  • HDA = 500: Create Encounter Events --- 66 min
  • d_gap_a = 999999999: Create Encounter Events --- 17 min
  • d_gap_h = 999999999: Create Encounter Events --- 15 min
image

Run Intervisibility

The file '2_Intervisibility.py' must be run in a QGIS environment. To do this, open QGIS and select the 'python console' using the icon in the image below or by using 'ctrl + alt + p'.

QGIS_1

Open the '2_Intervisibility.py' file using the 'open script...' icon shown below

QGIS_2 QGIS_3

After opening the file, the path to the dem must be updated and then, to run the file, set run all to true or uncomment one of the predefined sets of variables. QGIS is not stable while running such a large calculation and may freeze during the run. I have found that uncommenting and running the intervisibility check one at a time is more stable.

After selecting a method, click on the green arrow to run the code.

QGIS_4

Expected run times (Total run time: 25 min)

  • For default: 3.4 min
  • For HDA_radius = 500: 11 min
  • For d_gap_h = None: 57 seconds
  • For d_gap_a = None: 68 seconds
  • For Chamois height 0.8 m: 3.6 min
  • For Chamois height = 1.2 m: 4 min
  • For Chamois height 1.2 m: 4.2 min

Create Encounters

After Intervisibility has been added for all encounter events tables encounters can be calculated by using the '3_main_Create_Encounters.py' file. '3_main_Create_Encounters.py' has the same 4 lines as '1_main_Create_Encounter_Events.py'.

  • tracklib_folder_path must be set to the path to where tracklib is loaded
  • 'db' is the name of the database
  • 'db_user' is the name of the user of the database
  • 'db_password' must be the password to the database
enounters___

After updating the required lines the click 'run below' at the top cell this will execute all cells creating encounter events of all settings used in the paper.

Expected total run time is 133 min (2.2 hours)

  • default settings: 7 min
  • HDA = 500: 30 min
  • d_gap_h = None: 6 min
  • d_gap_a = None: 7 min
  • t_gap = 2 min: 5 min
  • t_gap = 4 min: 5.5 min
  • t_gap = 16 min: 5.5 min
  • t_gap = 2 hours: 5 min
  • t_gap = 4 hours: 5.5 min
  • t_gap = 24 hours: 5.5 min
  • height_chamois = 0.8 m: 2.5 min
  • height_chamois = 1.2 m: 2.6 min
  • height_human = 2 m: 2.6 min
  • Ignoring intervisibility: 8.5 min
  • Ignoring intervisibility hda = 500: 35 min

Run Figures

After creating the encounter tables to recreate the results from the paper figures can be created by running the various figure python folders. Only figures that include results or data are included here. Diagram figures that do not use data are not included.

Figure_8_data_map.py 75 seconds

This file only requires that the database path is accurate i.e. the following are accurate

  • db = 'ResRoute'
  • db_connection_url = "postgresql://postgres:postgres@localhost:5432/ResRoute"

Figure_9_Depiction_of_ECA.py 36 seconds

This file only requires that the database path is accurate i.e. the following are accurate

  • db = 'ResRoute'
  • db_connection_url = "postgresql://postgres:postgres@localhost:5432/ResRoute"

Figure_10_histogram_by_distance.py 20 seconds

This file only requires that the database path is accurate i.e. the following are accurate

  • db = 'ResRoute'
  • db_connection_url = "postgresql://postgres:postgres@localhost:5432/ResRoute"

Figure_11_histogram_by_time_of_day.py 9 seconds

This file requires that the following are updated

  • file path to tracklib
  • db = 'ResRoute'
  • db_connection_url = "postgresql://postgres:postgres@localhost:5432/ResRoute"

Figure_12_kernel_density_estimate.py 20 seconds

This file requires that the following are updated if they do not match the defaults

  • db = 'ResRoute'
  • db_user = 'postgres'

Figure_13_seasons_heatmap.py 2 minutes

Note that this figure in the original submission, had a error in the code which has been updated to create the correct figure. The corrected figure will be used in the final. The heat map had an overflow error that if the value passed 255 would lead to the value resetting. As such 256 => 1; 510=>255; 511=>1 ext.

The original figure was this below

heat_map

While the updated figure that will be used in the in the final submission is as below and the current code should produce the second figure.

heatmap

This file requires the following to be update

  • folder_path = r"ADD PATH TO TRACKLIB FOLDER"
  • db_connection_url = "postgresql://postgres:postgres@localhost:5432/ResRoute"
  • elevation_path = 'ADD PATH TO ELEVATION FILE => /bouge_elev.tif'

Run Tables

Table_2_chamois_data.py 3 seconds

This file requires the following to be update

  • db = 'ResRoute'
  • db_user = 'postgres'
  • db_password = 'postgres'

Table_3_human_data.py 2 seconds

This file requires the following to be update

  • db = 'ResRoute'
  • db_user = 'postgres'
  • db_password = 'postgres'

Table_5_HDA_radius_and_Intervisibility.py 9 seconds

This file requires the following to be update

  • db = 'ResRoute'
  • db_user = 'postgres'
  • db_password = 'postgres'

Table_6_parameters.py 45 seconds

This file requires the following to be update

  • db = 'ResRoute'
  • db_user = 'postgres'
  • db_password = 'postgres'

Table_7_ORTEGA.py 5-6 hours

This file runs many instances of the Ortega library for comparison but forces Ortega to run one pair of trajectories at a time severely affecting it's optimization. To save time in recreating the table after the first run checkpoints are saved as text files. It also has a significant run time in on the scale of 5-6 hours.

If the csv of the Ortega results is already created to only rerun the table only run the first and last cells.

This file requires the following to be update

  • db = 'ResRoute'
  • db_user = 'postgres'

Table_8_trajectories_seasons.py 3 seconds

  • db = 'ResRoute'
  • db_user = 'postgres'
  • db_password = 'postgres'

About

This repository contains the code, and scripts necessary to reproduce the analyses and figures presented in 'A New Spatio-Temporal Method for Detecting Human-Wildlife Encounters from GNSS Trajectories' submitted to Agile.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages