;NetLogo v6.1.1 code ;The purpose of this model is to simulate bear detections on East Bay Island as a function of our remote camera array ;We explicitly replicate the camera number and placement direction, with manufacturer specified detection range and angle ;Each run, a bear does a correlated random walk through the island ;Then we ask the question, did cameras detect that bear? ;Barnas- April 04/20 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; extensions [ gis ;Used to load in the drone imagery for Mitivik Island csv ;Used to read the .csv file containing the camera coordinates and directions ] globals [ drone-path ;Holds the file path for the drone imagery files (needed to load the island landscape) output-file-path ;Holds the path for the output files (needs to be different from the drone island landscape) units ;The size that each patch is meant to represent (in meteres) -> used for math on how fast bears are walking. landscape ;Stores the gis data file (the layer you are importing) detected ;Was the bear detected at all? coordinates ;Stores the .csv file of camera coordinates i ;Placeholder variable used to loop through coordinates ] patches-own [cover-type] ;Patch variable that holds whether it is a water or land patch. breed [cameras camera] ;Ya gotta have cameras! breed [bears bear] ;And ya gotta have bears! cameras-own [ saw-bear? ;Camera variable that tells whether a bear was detected by that camera xcam ;Stores the real X coordinate for the camera ycam ;Stores the real Y coordinate for the camera ] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;LANDSCAPE SETUP PROCEDURES ;Here we are using drone imagery to explicitly depict Mitivik Island as land and water cells to setup-landscape clear-all reset-ticks set units 10 ;each patch is worth 10m. So if you wanted to calculate how many patches ;50m is, You would go 50/units = 5 patches. ;Or how many patches is 79.3 meters? 79.3 / 10 = 7.93 (get it?) ;E.g. if you want bears to move forward 14 meters: ask bears [forward 14 / units ] -> moves them forward 1.4 patches. ;To make this work on a different computer, you need to change this path to the folder that you keep the ;drone imagery files in. Shouldn't have to change anything else (besides making sure you have the files!) carefully[set drone-path "C:/Users/16043/Desktop/People/Erica Geldart/Bear Detection Simulation/drone imagery files/"] ; [user-message "Did you properly set the path for the drone imagery files??"] ;This error message will print if the path is not specified correctly resize-world -42 42 -25 25 ;First we load the coordinate system associated with your imagery files (this is the prj) carefully [gis:load-coordinate-system (word drone-path "test_island.prj")] [user-message "Error with the .prj file. Did you forget to change the path to the drone files? Or does the .prj file exist?"] ;Next, we load the actual imagery data. Each polygon is associated with a type (1 or 2). If a patch overlaps with multiple types, carefully [set landscape gis:load-dataset (word drone-path "test_island.shp")] [user-message "Error with the .shp file. Did you forget to change the path to the drone files? Or does the .shp file exist? You also need: .cpg, .dbf, .sbn, .sbx, .shp (xml), .shx "] ;This wraps the boundaries of your landscape to the boundaries of your GIS layers (may look wonky) gis:set-world-envelope (gis:envelope-of landscape) ;This is more of a checking thing. Ask all the patches that overlap with your GIS layers to turn blue ;They should ALL overlap because we wrapped the envelopes. ask patches gis:intersecting landscape [set pcolor blue] ;Takes the property of the GIS layer (type) and applies it to the given patch variable (cover-type) ;1.Note this only works for polygons. ;2.For some reason, this only works if the GIS layer property is in all capitals...so in Arc it is "type", but here it is "TYPE" (weird eh?) gis:apply-coverage landscape "TYPE" cover-type ;FOR SOME REASON, THIS NEEDS TO BE IN CAPITALS!!! ;FINALLY... ;Ask the patches to set their color based on the value of TYPE ask patches [ ifelse cover-type = 1 [set pcolor green] [set pcolor blue]] ;Because today we don't care about code efficiency ;and sometimes you need to be cute. Print "Welcome to East Bay Island!" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Reading in coordinates and creating cameras ;First read in the camera gps coordinates file. set coordinates csv:from-file "camera_locations.csv" set detected 0 ;Bear not detected = 0, detected = 1 (0's and 1's are easier to work with vs TRUE/FALSE) set i 0 ;Just so that we start off at the "zeroth" row. create-cameras 35[ set shape "square" set size 1 set color black set saw-bear? FALSE let temp_coordinates item i coordinates ;Subset the first row of the coordinates file set xcam item 1 temp_coordinates ;The x coordinate is item #1 set ycam item 2 temp_coordinates ;The y coordinate is item #2 set heading item 3 temp_coordinates ;The camera heading is item #4 setxy nl-x(xcam) nl-y(ycam) ;These are the reporters that will rescale those coordinates set i i + 1] ;Increase i by 1 so that we move on by 1 row for the next camera. ;Visualize the detection distance of cameras according to manufacturer specifications ;BTC-5HDPX detection distance = 90 meters, Detection angle = 41.9 degrees ;According to https://www.trailcampro.com/collections/trail-camera-reviews/products/browning-strike-force-hd-pro-x ask cameras [ask patches in-cone (90 / units) 41.9 [set pcolor red]] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Procedure to make a bear at the edge of the world make-a-bear end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Procedure to introduce a bear to the system to make-a-bear ;Make a bear at the edge of the world and have them face the nearest green patch. ;This just makes it so that they don't just immediately leave right away. create-bears 1 [set size 3 set color white ifelse random-float 1 <= 0.5 [ifelse random-float 1 <= 0.5 [setxy min-pxcor random-ycor] ;These blocks just make it so the bear shows up at the edge of the world [setxy max-pxcor random-ycor]] ; [ifelse random-float 1 <= 0.5 ; [setxy random-pxcor min-pycor] ; [setxy random-pxcor max-pycor]]; pen-down face min-one-of patches with [pcolor = green][distance myself] ;Face the nearest green patch move-to min-one-of patches with [pcolor = green][distance myself]] ;Actually...just move there right away, so we guarantee the bear hits the island end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Go procedures ;Bears will do a correlated random walk through the island ;As they walk through, cameras will record if they saw the bear or not, based on if bear passes through their detection cone ;Simulation ends when the bear reaches the edge of the world and leaves the system. to go ;Stop condition: stop the simulation when the bear has left ;At the end of the simulation, we ask if any cameras saw a bear. ;If any camera did, we set the global deteced? to 1 (indicating that the bear was observed) if count bears < 1 [ if any? cameras with [saw-bear? = TRUE][set detected 1] show detected stop] ;First we make the bears move ask bears [ if not can-move? 1 [die] right (random-float bear-turning-angle) - (bear-turning-angle / 2) ;From P.Jagielski's MS: PB walk speed = 3.4 km /hr ;-> 3400m / 3600 seconds ;-> 0.94 meters per second forward 0.94 / units ;Move forward 0.094 patches each timestep. ] ;Then we have the cameras ask if they see the bear ask cameras [if any? bears in-cone (90 / units) 41.9 [set saw-bear? TRUE ask patches in-cone (90 / units) 41.9 [set pcolor yellow]]] tick end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;REPORTERS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;The only reporters I have are used to scale the real world coordinates to the netlogo scale. ;And the only resource I could find on how to do this was from: ;https://stackoverflow.com/questions/63057644/netlogo-doesent-recognize-the-gis-coordinates-in-the-defined-envelope-of-the-wo ;Scale the X coordinate to-report nl-x [#x] let world gis:envelope-of landscape let minx item 0 world let maxx item 1 world report ((#x - minx) / (maxx - minx)) * (max-pxcor - min-pxcor) + min-pxcor end ;Scale the Y coordinate to-report nl-y [#y] let world gis:envelope-of landscape let miny item 2 world let maxy item 3 world report ((#y - miny) / (maxy - miny)) * (max-pycor - min-pycor) + min-pycor end ;Fin.