forked from MagdaChu/AgentSeal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAgentSeal1.0.nlogo
4393 lines (3798 loc) · 146 KB
/
AgentSeal1.0.nlogo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Author: Magda Chudzinska, Sophie Smout, Bernie McConnell, SMRU and Jacob Nabe-Nielsen Aarhus University
; Date: Created (started) 2018-02-02 in NetLogo 6.0.2
; Description:
; Patch size: 1000 x 1000 m
; time step: 900 s (15 min) but can be changed via slider
; The real world is 185 by 174 km 185 by 174 patches (St Andrews area)
; Model starts xxxxxx and finishes no later than xxxxx
;ask hauls [show (word xcor " " ycor)] ; to get coordinates
extensions
[
gis ; for importing gis layers as background
profiler ; for testing CPU use of various submodels
time ; to have ticks saved as real time
csv
nw ; netwerk extension to set shorstest path
matrix
array
table
]
globals
[
;;; LANDSCAPE RELATED GLOBALS
dist ; file showing distance from the shore
dist_HA1 ; distance form each patch haul-out with id 1
dist_HA2
dist_HA3
dist_HA4
dist_HA5
dist_HA6
dist_HA7
dist_HA8
dist_HA9
dist_HA10
dist_HA11
dist_HA12
dist_HA13
dist_HA14
dist_HA15
dist_HA16
dist_HA17
dist_HA18
dist_HA19
dist_HA20
dist_HA21
dist_HA22
dist_HA23
dist_HA24
dist_HA25
dist_HA26
dist_HA27
dist_HA28
dist_HA29
land ; raster (ascii) file with background land map (2 = land 0-1 = water (hsi))
areas5km ; model domain with 5x5 km resolution, used for memory procedure
areas25km
hsi25km
ho-list ; list of haul-out positions imported from text as agents, not background raster
xllcorner ; x of lower left corner of the environment, read from ascii file
yllcorner ; y of lower left corner of the environment, read from ascii file
patch_size ; reasambling 1 x 1 km
dayNumber ; consequite days (sunrise to sunrise) of the model
start-time ; the time at which the model starts
finish-time ; the time at the end of model
current-time ; the current simulation time
com_count ; for debugging, checking if each movement possibility has a procedure assigned
water-patches
land-patches
water-shore-patches
shore-patches
;;; GENERAL MOVEMENT GLOBALS
step_length ; this is 'normal' step length, defined by average speed, in absence of crw, some sort of 'normal, regular' seal move; used for seals to avoid land and during some travelling modes
;time_step ; duration of each time step [seconds]
;ref-mem-decay-rate ; memory decay rate, same rate applies to memorising haul-outs and good foraging spots, the unit is [decay/hour] so has to be adjusted to step length
expindex ; used in combination with BehaviorSpace to define paramet combination
;; LAND AVOIDANCE PROCEDURE GLOBALS
land-distance ; distance used to calculate how much land is ahead of seals in land avoidance procedure [number of patches]
;;; CRW WALK basic movement defined by correlated random walk (CRW) and hsi, based partly on kinesis
; movement as used in mackerel model and on my equations
; avg_Vsus ; average sustained swimming velocity, based on the observed value for speed for seals from East coast (data filtered from McClintock paper, see McClintock.R code) [m/s]
; std_Vsus ; standard deviation of the sustained swimming velocity calculated as above [m/s]
Vmin ; minimum swimming speed (bodylenghts/time step) calculated as above [m/s]
Vmax ; maximum swimming speed - set to 2m/s (Bernie, pers conv) [m/s]
avg_Vsus_corr ; corrected for time step and patch size [patch/time step]
std_Vsus_corr ; corrected for time step and patch size [patch/time step]
Vmin_corr ; corrected for time step and patch size [patch/time step]
Vmax_corr ; corrected for time step and patch size [patch/time step]
; sigK ; shape parameter for habitat suitability dependency ("functional responce") [unitless]
hsi_opt ; optimal habitat, most preferable by seals, if set to 1 (so max hsi, sigK does not matter and seals will always behave differently in habitat close to hab_opt [unitless]
; b ; parameter defining wiggliness of the movement, ranging from -1 to 1 with -1 resulting in zigzagging and 1 going in circles
; imp_dist ; importance of distance to target
; scale_alpha_k, lambda_rate ; two parameters defining gamma distribution of step length
;; DIVING, FORAGING, HOUL-OUT
;DiveDuration ; average dive duartion in seconds, set as slider but literature says it is about 3 minutes (Lesage 1999, Chudzinska master, Suryan 1998, Bjorge 1995) [s]
;search_rate ; search efficiency in m2/s so number of m2 a seal can 'scan' to search for fish during one second
; a_time ; a and b are coeeficients defining relartion between something (time since last haul-out, blubber or distance) and probabily of hauling-out (1 / (1 + a*exp(b*something))
; b_time
; a_blub
; b_blub
; a_dist
; b_dist
a_prob
; b_prob ; part of equation used for modelling probability of haulout with various stuff
; b_prob2 ; part of equation used for modelling probability of haulout with distance
;mean_durHO ; mean duration [h] of time hauling out, used in right skewed distribution
;multProbHaul ; multiplier used in the equation defining probability ofhaulout with distance to coast
; mean_g_per_fish ; weighted mean based on obsrved diet
; mean_kJ_per_fish ; weighted mean based on fish diet
;; MEMORY
; mem_level_passedBy_ho ; memory level of haul-out sites which were remembered by being passed by, parametereised value
; ref-mem-decay-rate ; decay rate of memorised patches, per time step, parameterised value
; haulOut_detection_distance ; distance at which seals are able to detect and remember passed by haul-out sites [km], parameterised value
; max_memory_day ; dusration [days] when memory drops close to 0 (see Figure 5 in Trade)
patches_km25_maxhsi ; list of max hsi in each 25km patch and their correpsonding ids
;; PRODUCING OUTPUT FILES
outputFileName_movement ; NetLogo overwrites files everytime a new model is run, to avoid it I want a new file to be produced with date and time in the file name
outputFileName_bodyCond ; NetLogo overwrites files everytime a new model is run, to avoid it I want a new file to be produced with date and time in the file name
outputFileName_crw ; NetLogo overwrites files everytime a new model is run, to avoid it I want a new file to be produced with date and time in the file name
outputFileName_spatial ; NetLogo overwrites files everytime a new model is run, to avoid it I want a new file to be produced with date and time in the file name
outputFileName_tripDurationExtend
outputFileName_ho_list
outputFileName_depletionStart
outputFileName_depletionEnd
outputFileName_hauloutCount
;; PARAMETERISATION
param-data ; matrix with all the parameters' combination used in parameterisation
]
patches-own
[
categ; ; land, water, shore (within 1 patch from land), haulout (patches directly underneet haul-outs)
hsi ; habitat suitability index, the higher the better the habitat [unitless, has value between 0 and 1]
hsi25km_max ; max value of hsi, calculated at the begining of the simulations, of patches in 25x25km2
distance2shore ; as the name says, distance of each patch to shore (land) [unit xy patches] - this is distance pre-calculated in R
distance2shoreNL ; this is the same distance as above but calculated within setup procedure, this slows down the setup A LOT but i keep it in the code to be used in case there is no distance file as input
Nseals ; cumulative number of seals which visited this patch
#Fish_m2 ; number of fish per m2 (!), used in energy intake procedure and in the future in habitat depletion
#FishTotal ; total number of fish per patch
;distance2HO_NL ; distance from a given patch to all haulout sites
distance_HO1 ; distance from a given patch to haulout sites with id 1, calculated in R, as an input file
distance_HO2
distance_HO3
distance_HO4
distance_HO5
distance_HO6
distance_HO7
distance_HO8
distance_HO9
distance_HO10
distance_HO11
distance_HO12
distance_HO13
distance_HO14
distance_HO15
distance_HO16
distance_HO17
distance_HO18
distance_HO19
distance_HO20
distance_HO21
distance_HO22
distance_HO23
distance_HO24
distance_HO25
distance_HO26
distance_HO27
distance_HO28
distance_HO29
km_5_id ; id of 5km resolution grid
km_25_id
]
breed [hauls haul] ; haul-out sites imported as text file, MUST be declared before seals as seals will be on top of haul-out sites
breed [seals seal]
breed [sps sp] ; agents used to create a linked shore line used in calculating shortest path from seal position to a haul-out site where seal is currently moving
sps-own
[
path ; list of sps on seal's way to the next haul-out
]
hauls-own
[
ho_id
;; based on annual surveys during moutling: Chris and Callan
;; for east coast data are from 1996-2015 and for Wash 1996-2016
mean96_16 ; mean number of counted seal 1996-2016
max96_16 ; max number of counted seal 1996-2016
min96_16 ; min number of counted seal 1996-2016
mean10_16 ; mean number of counted seal 2010-2016
max10_16 ; max number of counted seal 2010-2016
min10_16 ; min number of counted seal 2010-2016
PercAll ; percentage of all observed seals for each haul-out for entire survey time
Perc10_16 ; percentage of all observed seals for each haul-out for entire survey time for 2010-2015(6)
numberOfModelledSeals ; starting number of modelled seals hauling our on each haul-out based on PercAll or Perc10_16
closest_sp ; the shortest path point closest to haul-out
HONseals ; cumulative number of seals hauling out at each haul-out at a given tick
]
seals-own
[
;;;; BASIC BODY PARAMETERS
Blength ; body length [cm]
Tmass ; total body mass (not lean body mass)[g]
LBM ; lean body mass [g]
ResMass ; mass of reserves (mainly blubber) Tmass-LBM [g]
sex ; male or female
stomachCap ; stomach capacity calculated from relationship established for harp seals (Christiansen 2004); stomach weight (g) = 3.155*body weight (kg) + 132.930; 100g of stomach = 0.8l = 0.8 kg [g]
;;;; LAND AVOIDANCE procedure
is-land? ; used in land avoidance procedure
head-current ; finding suitable turning angle
count-left ; deciding the land avoidance direction
count-right ; deciding the land avoidance direction
#turning-angle
turning-counter ; used in avoid land procedure
avoidance-mode-right ; used when seals avoid land to the right
avoidance-mode-left ; used when seals avoid land to the left
avoid? ; true if seals are trying to avoid land, false if far from land, used for debugging
my_path ; list of sps along which seal goes to the next haul-out site of this seal ancounter land on its way to haul-out
my_path_outOfBay ; list of sps along which seal goes out of Firth of Forth if it has not been eating for sometime
;;; CRW AND BIASED-CRW MOVEMENT
prev_angle ; turning angle (not heading!) from the last step [degress from the last angle]
speed ; seals' speed (step length during crw) [patches/time step]
curr_turn_output ; turning angle in a given time step - for debugging and TRACE only
hsi_Im_on ; value of hsi of a patch seal is on - for debugging and TRACE only
target ; the target point (either haul-out or good patch) towards seal head with biased-crw
diff_heading ; local variable saved as seal-own for debugging only, see description of the variable in crw procedure
turn_hsi ; local variable saved as seal-own for debugging only, see description of the variable in crw procedure
dist2target ; local variable saved as seal-own for debugging only, see description of the variable in crw procedure
turn_bias ; local variable saved as seal-own for debugging only, see description of the variable in crw procedure
turn_crw
;;; ENERGETICS
activity ; foraging (F), short resting at sea (SRS) - to empty stomach, long resting at sea (LRS) to digest, haul-out (HO), land avoidance (LA), TR-HO - travelling from the moment seal decides to haul-out to actual houl-out site
BMR ; based on equation by Kleiber et al (1975): BMR = ((70 * Tmass^0.75)*0.004184*time_step/(24*60) ; some papers said it should be lean body mass but in Kleibers it is total body mass which make sense as we would expect super fat seals to have different bmr than skinny seals [MJ/time_step]
ee ; energy expenditure at a given time step [MJ/time_step]
cum_ee ; cumulative energy expenditure, zerod if sth happens XXXXXXXX [MJ]
daily_ee ; daily energy expenditure, zerod at the begininng of each day [MJ/day]
ei ; energy intake at a given time step (calculated from g fish) [MJ/time_step]
cum_ei ; cumulative energy intake, not sure if I will use for anything [MJ]
daily_ei ; daily energy intake, zerod at the begininng of each day [MJ/day]
DailyNetEnergy ; net energy intake CALCULATED AT THE BEGGINING OF EACH DAY !!!!!! it would be more logic to do it at the end of each day but coding so the model knows which is the last tick of the day is CPU consuming so lets still to first step of each day [MJ/day]
DaysWithNegativeDNE ; a counter showing number of consequitive days with daily net energy <= 0. It is set to zero everytime seals have DNE >=0
; FORAGING
#FishCaught ; number of fish caught during a dive bout (=one time step)
fishConsumed_g ; gram of consumed fish, restarted after each resting event [g]
TotalfishConsumed_g ; gram of consumed fish over the model duration [g]
fishConsumed_g_longResting ; gram of consumed fish, restarted after long-term resting , defines what happens after after seal consume > set body weight [g]
my_next_patch ; patch with larger attraction index towards which seal head after leaving a haul-out site
my_move_away_patch ; in 'move away' foraging scenarios this is the patch seals move away from
foraging_trip# ; foraging trip is defined as movement between two consequitive haul-out events (including haul-out which proceed the trip). This parameter is a counter and increases by 1 everytime a seal starts a new trip. Used to output trip duration and extend
; RESTING MODEL
; this is first, simple model trying to establish whyand when seals rest (incl resting at sea)
durationOfResting ; once seals are in a resting activity they spend x time resting and not moving [number of time step to rest]
; HAUL-OUT BEHAVIOUR
need2ho_TimeSinceLastHo ; set to true if seals have to haul-out for skin maintanance [true or false]
need2ho_BLUBBER_ALLOWS ; set to true if seals are fat enough to haul-out (false if they should not haul-out because they are too skinny) [true or false]
need2ho_DIGESTION_NEED ; set to true if seals have to haul-out to digest, if not they rest at sea [true or false]
my_next_ha ; seal's next haul-out site
durationSinceLastHa ; starts when seals leave a haul-out site and is reset when next haul-out starts. Needed in procedure mimicing a need a haul-out unrelated to digestion (skin?) [number of time steps]
typeOfHa ; for debugging, to establish frequency of various haul-out triggers (skin, CONDITION ot digest)
DurationOfDigestion ; there is a marked difference between energy expenditure during haul-out and during digestion. If seals decide to digest while hauling out, their energy expendture must equal to ee of digestion not haul-out so the part of haulout needed for digestion hass ee = digestion, rest of the same haul-out ee=ee of haul out (seals which digest while hauling out usually spend longer time than it is neccessary just for digestion [number of time steps]
distHaulOutDigestion ; distance to haul-out at the moment seals decide to haul-out for digestion - for debugging only
visited_ho_list ; list of haul-out sites (their whos) in the order of visit, used to calculate haulout matrices
previous_ho ; my last visited haulout
; MEMORY RELATED PARAMETERS
; haul-out memory
mem-haul-ids ; stores memorised haul-out who
memory-hauls-list ; list of memory level of visited/memorised haulouts
; patch related memory
patch-ids-5k ; stores locations of visited 5X5KM AREAS to whcih a visited patch belongs
patch-ei-5k ; list of lists showing all ei obtained on a given square, items from this list decay if stored for longer than what it takes memory to decay to almost zero
patch-area5id ; ids of 5x5km squares
;patch-ei-5k-days ; days when a given ei was memorised
patch-ei-5k-memory ; memory level of each entry of ei per square
patch-memory ; list of memory level of visited/memorised patches
;patch-ei-list ; list of visited patches and their corresponding energy intake (nested list of lists)
;patch-hsi-list ; list of visited patches and their corresponding hsi (nested list of lists)
patch-ei-table-array ; a table of visted square ids and corresponding ei
patch-mem-table-array ; a table of visted square ids and corresponding memory level
patch-pxcor-table-array ; a table of visted square ids and corresponding ei
patch-pycor-table-array ; a table of visted square ids and corresponding memory level
patch-ei-burnin-table-array ; a table of visted square ids and corresponding ei during burnin period
;patch-mem-burnin-table-array ; a table of visted square ids and corresponding memory level during burnin period - it is not needed because memory does to decay in burn in period
patch-pxcor-burnin-table-array ; a table of visted square ids and corresponding ei during burnin period
patch-pycor-burnin-table-array ; a table of visted square ids and corresponding memory level during burnin period
]
;;;;;;;;;;;;;;;;;;;;; SETTING ENVIRONMENT, BACKGROUND MAPS AND LANDSCAPE ;;;;;;;;;;;;;;;;;;
to set_landscape
; all gis data should be loaded in one procedure, otherwise the projection is different
; I have to be sure that all my ascci file start from the same xll and yllcorner
;(in gis while processing from feature to raster and than from ratser to ascci I have to specify
;in 'environment' 'processing extent' the same extent as study area.
;All my ascii data must have the same number of columns and rows (for St Andrews 174 (174km cause one cell = 1000m) columns and 185 rows)
;and cell size must be specified to 1000. however in model settings it must be max-pxcor
;173 and pycor 184 cause first row/column is 0, not 1 in case of St Andrews
clear-all
set patch_size 1000
set dist gis:load-dataset "Input/land_distance_EastCoast_noBay.asc"
set land gis:load-dataset "Input/GrecianEtAl2018.asc" ; hsi with values extrapolated to the little bays
set areas5km gis:load-dataset "Input/land_EastCoast_5km_NoBay.asc"
set areas25km gis:load-dataset "Input/land_EastCoast_25km_NoBay.asc"
set hsi25km gis:load-dataset "Input/Maxhsi_EastCoast_25km_NoBay.asc"
set dist_HA1 gis:load-dataset "Input/ho_distance_noBay_id_1.asc"
set dist_HA2 gis:load-dataset "Input/ho_distance_noBay_id_2.asc"
set dist_HA4 gis:load-dataset "Input/ho_distance_noBay_id_4.asc"
set dist_HA7 gis:load-dataset "Input/ho_distance_noBay_id_7.asc"
set dist_HA8 gis:load-dataset "Input/ho_distance_noBay_id_8.asc"
set dist_HA14 gis:load-dataset "Input/ho_distance_noBay_id_14.asc"
set dist_HA15 gis:load-dataset "Input/ho_distance_noBay_id_15.asc"
set dist_HA16 gis:load-dataset "Input/ho_distance_noBay_id_16.asc"
set dist_HA18 gis:load-dataset "Input/ho_distance_noBay_id_18.asc"
set dist_HA20 gis:load-dataset "Input/ho_distance_noBay_id_20.asc"
set dist_HA21 gis:load-dataset "Input/ho_distance_noBay_id_21.asc"
set dist_HA22 gis:load-dataset "Input/ho_distance_noBay_id_22.asc"
set dist_HA25 gis:load-dataset "Input/ho_distance_noBay_id_25.asc"
set dist_HA27 gis:load-dataset "Input/ho_distance_noBay_id_27.asc"
set dist_HA28 gis:load-dataset "Input/ho_distance_noBay_id_28.asc"
set dist_HA29 gis:load-dataset "Input/ho_distance_noBay_id_29.asc"
;gis:set-world-envelope gis:envelope-of land ;(gis:envelope-union-of (gis:envelope-of land) (gis:envelope-of haul-out)) ;I leave haulout code for now in case I decide to keep haulouts as raster
;resize-world 0 gis:width-of land 0 gis:height-of land
gis:apply-raster land hsi
gis:apply-raster areas5km km_5_id
gis:apply-raster areas25km km_25_id
gis:apply-raster hsi25km hsi25km_max
gis:apply-raster dist distance2shore
gis:apply-raster dist_HA1 distance_HO1
gis:apply-raster dist_HA2 distance_HO2
gis:apply-raster dist_HA4 distance_HO4
gis:apply-raster dist_HA7 distance_HO7
gis:apply-raster dist_HA8 distance_HO8
gis:apply-raster dist_HA14 distance_HO14
gis:apply-raster dist_HA15 distance_HO15
gis:apply-raster dist_HA16 distance_HO16
gis:apply-raster dist_HA18 distance_HO18
gis:apply-raster dist_HA20 distance_HO20
gis:apply-raster dist_HA21 distance_HO21
gis:apply-raster dist_HA22 distance_HO22
gis:apply-raster dist_HA25 distance_HO25
gis:apply-raster dist_HA27 distance_HO27
gis:apply-raster dist_HA28 distance_HO28
gis:apply-raster dist_HA29 distance_HO29
ask patch 98 39 [set hsi 0.01] ;this is Isle of May, I have to remove it for now
ask patches
[
;let value_l gis:raster-sample land patch pxcor pycor ; I should not use this function as it does something weird to the cells along the coastline
set distance2shore distance2shore / patch_size
set distance_HO1 distance_HO1 / patch_size
set distance_HO2 distance_HO2 / patch_size
set distance_HO4 distance_HO4 / patch_size
set distance_HO7 distance_HO7 / patch_size
set distance_HO8 distance_HO8 / patch_size
set distance_HO14 distance_HO14 / patch_size
set distance_HO15 distance_HO15 / patch_size
set distance_HO16 distance_HO16 / patch_size
set distance_HO18 distance_HO18 / patch_size
set distance_HO20 distance_HO20 / patch_size
set distance_HO21 distance_HO21 / patch_size
set distance_HO22 distance_HO22 / patch_size
set distance_HO25 distance_HO24 / patch_size
set distance_HO27 distance_HO27 / patch_size
set distance_HO28 distance_HO28 / patch_size
set distance_HO29 distance_HO29 / patch_size
if (Habitat = "GrecianEtAl2018")
[
if (hsi = 2)
[
set pcolor grey
set categ "land"
set hsi25km_max 0
]
if (hsi = 0 or hsi < 0.01 or hsi > 2)
[
set pcolor blue
set categ "water"
set hsi 0.01
]
if (hsi > 0 and hsi != 2)
[
set pcolor scale-color red hsi 1 0
set categ "water"
]
if (distance2shore <= 1 and categ = "water")
[
set categ "shore"
;set pcolor blue
]
]
if (distance2shore <= 1 and categ = "water")
[
set categ "shore"
;set pcolor blue
]
set #Fish_m2 hsi * #Fish_hsi_multiplier
set #FishTotal round (#Fish_m2 * patch_size ^ 2)
]
;calculate_distance2shore_NetLogo ; use it only if there is no input file with distance to shore
set water-patches patches with [categ = "water"]
set land-patches patches with [categ = "land"]
set water-shore-patches patches with [categ != "land"]
set shore-patches patches with [categ = "shore"]
;calculate_meanHSI_of25km_grids
set patches_km25_maxhsi table:make
if (Large_scale_foraging = "Omniscience" or Large_scale_foraging = "OmniSwitch")
[
if (Habitat = "GrecianEtAl2018") [makingGlobalList_of_best_patches]
]
reset-ticks
end
;to calculate_meanHSI_of25km_grids
;
; ; this takes long time and there is something wrong so I will calculate in r for now
; ; but in the future it must be calculated in here in cases we want to recalculate hsi more than once
; ask water-patches
; [
; let patchHere min-one-of water-patches [distance myself]
; let id_temp [km_25_id] of patchHere
; set hsi25 mean [hsi] of patches with [km_25_id = id_temp]
; ]
;
;end
to makingGlobalList_of_best_patches
let ids ([km_25_id] of water-shore-patches)
;show ids
foreach ids
[
x ->
let maxHSI [hsi25km_max] of one-of water-shore-patches with [km_25_id = x]
if maxHSI >= 2 [set maxHSI 0.05] ; due to my poor raster operation in r, some water patches have max hsi set to 2
table:put patches_km25_maxhsi x maxHSI
]
; making subset of this table with let's say best 15%
; I use the same code as for calculating 15% patches in Burn in scenario
let squareIDss table:keys patches_km25_maxhsi
let maxhsi table:values patches_km25_maxhsi
let temp_hsi_id []
(foreach maxhsi squareIDss
[
[x y] ->
set temp_hsi_id lput (list x y) temp_hsi_id
]
)
; then we sort these hsi from max to min
let temp_hsi_id-sorted sort-nested-lists-from-highest temp_hsi_id
;show temp_hsi_id-sorted
;show length temp_hsi_id-sorted
; then we take x% of the patches with highest hsi
; because East coast is small and I only have 27 25x25 km patches, I take 90% of patches
let list-length length temp_hsi_id-sorted
let x_perc round ((percOfsavedPatchesOmniscience * list-length) / 100)
if x_perc = 0 [set x_perc 1]
let x%_temp_hsi_id-sorted sublist temp_hsi_id-sorted 0 x_perc
;show (word "15% " fifteen%_temp_ei_id-sorted)
; now I have to swap ids and ei so id are first
let id_hsi_x% []
(foreach x%_temp_hsi_id-sorted
[
[x] ->
;show x
set id_hsi_x% lput (list (item 1 x) (item 0 x)) id_hsi_x%
]
)
;show (word "ids first "id_ei_15%)
set patches_km25_maxhsi table:from-list id_hsi_x%
show patches_km25_maxhsi
show length id_hsi_x%
end
; below os the option to calculate distance to shore if we dont have an input file
to calculate_distance2shore_NetLogo
;ask patches with [categ = "water"]
ask water-patches
[
;let closest_land_patch min-one-of patches with [categ = "land"] [distance myself]
let closest_land_patch min-one-of land-patches [distance myself]
set distance2shoreNL distance closest_land_patch
]
end
; below is the option to calculate distance to all haulouts if we dont have an input file
;to calculate_distance2haulouts_NetLogo
; ask patches with [categ = "water"]
;
; [
; set distance2HO_NL []
; set distance2HO_NL distance hauls in-radius 200
; ]
;end
to create-shortest-path-link
ask patches with [categ = "shore"] [ sprout-sps 1 ]
ask patches with [categ = "water" and distance2shore <= 10] [ sprout-sps 1 ]
ask sps
[
set shape "circle"
set color white
set size 0.05
let close_sp other sps in-radius 2
create-links-with close_sp
]
ask links [set color [255 255 255 25]] ; white color in rgb,last number defines transparency
;ask links [set color "grey"]
end
to load_haulouts
; values for East Coast
set xllcorner 428292.82952926 ; define the lower left corner (from ascii files), only used if we import agent positions from text
set yllcorner 6186935.0366855
; values for Wash
; set xllcorner 681440 ; define the lower left corner (from ascii files), only used if we import agent positions from text
; set yllcorner 5796687
file-open "Input/HaulOutPoints_EastCoast.txt"
while [ not file-at-end? ]
[
create-hauls 1
[
set ho_id file-read
let x-coord_temp (file-read - xllcorner) / patch_size
let y-coord_temp (file-read - yllcorner) / patch_size
setxy x-coord_temp y-coord_temp
set mean96_16 file-read
set min96_16 file-read
set max96_16 file-read
set mean10_16 file-read
set min10_16 file-read
set max10_16 file-read
set PercALl file-read
set Perc10_16 file-read
set size 3
set color green
set shape "square"
move-to min-one-of sps [distance myself]
set closest_sp min-one-of sps [distance myself]
;move-to min-one-of patches with [categ != "land"] [distance myself] ; haulout coordinates are based on 1*1 km grids and the coordinates are center of the grid. So to make sure that I dont have haul-out on land, I move them to water
let patch_under_haul_out min-one-of patches [distance myself]
ask patch_under_haul_out [set hsi 0 set categ "haulout" set #Fish_m2 0 set #FishTotal 0] ; patches on which haul-out sites are cannot have high hsi. Seals cannot forage on haul-out sites. It is maybe not super biologically correct but otherwise there are errors
]
]
file-close
end
;;;;;;;;;;;;;;;;;;;;; CREATING SEALS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to create_seals
;reset-timer
create-seals n_of_seals
[
ifelse Habitat = "Uniform" [set color black] [set color yellow]
setxy 0 0 ; starting point does not matter cause I tell seals to move to a another haulout immidietaly
;move-to one-of hauls
; the who of various agents depands on the order of agents being created.
; I want my seals to move to haul-out with min who
let HA_with_lowestWHO item 0 ([who] of hauls with [who = min [who] of hauls])
move-to haul HA_with_lowestWHO
set size 3
set is-land? []
set avoidance-mode-right false
set avoidance-mode-left false
set heading towards one-of other patches with [categ != "land"] ; because haul-out are in the middle of 5x5 km grid cell, they sometime end up on land and we want all houl-out site to be close to the shore, or at least not inland
set speed random-normal avg_Vsus_corr std_Vsus_corr
set prev_angle random-normal 0 std_dir
;if show_pd? [pd]
let ran random 2
ifelse ran = 0 [set sex "M"] [set sex "F"]
ifelse sex = "M" [set Blength random-normal 146 6.86 set Tmass (1.27 * Blength - 102.67) * 1000] ; length distribution of adult (>5 years) males seals - data from Aisla
[set Blength random-normal 138.6 5.7 set Tmass (0.86 * Blength - 49.67) * 1000] ; length distribution of adult (>5 years) females seals - data from Aisla
;set Tmass (1.13 * Blength - 84.5) * 1000 ; relationship between body length and total mass for adults (>5) in August - data from Aisla
;set Tmass (1.15 * Blength - 91.23) * 1000 ; relationship between body length and total mass for adults (>5) in sept october - data from Aisla + NL
let blubber% random (32 - 22) + 23 ; starting reserve mass is between 23-32% (Markussen 1992, Sparling 2006, Beltran 2017, Moray Firth data with blubber% calculated based on Ryg's equation (1990) for P. hispida)
set ResMass (Tmass * blubber%) / 100
set LBM (Tmass - ResMass)
set BMR ((70 * (Tmass / 1000) ^ 0.75) * 0.004184 * (time_step / 60)) / (24 * 60) ; Tmass must be in kg and time in mins
set stomachCap (3.155 * (Tmass / 1000) + 132.930) * 8 ; 0.8/100*1000; Christansen 2004, see description in seal-own attributes
set fishConsumed_g 0 ; seals start with empty stomach on a houl-out site at the beginning of day
set TotalfishConsumed_g 0
set fishConsumed_g_longResting 0
set activity "HO"
set ee 0
set daily_ee 0
set daily_ei 0
set cum_ee 0
set need2ho_DIGESTION_NEED false
set need2ho_TimeSinceLastHo false
set need2ho_BLUBBER_ALLOWS false
set my_path []
set my_path_outOfBay []
set foraging_trip# 1
]
distribute_seals_on_haulouts
;move-to haul 3124
; this has to be after seals are distributed over haul-out
ask seals
[
;let ha_im_on min-one-of hauls [distance myself]
let all_hauls [who] of hauls
set mem-haul-ids all_hauls;nearby_ha
; storing as list made from array to speed up, all haulout sites have low memory value, this value will be updated once a site is used or passed by
let lengthMem length mem-haul-ids
let temp_array array:from-list n-values lengthMem [0.20]
set memory-hauls-list array:to-list temp_array
; the site I am on should have the highest memory value (0.99)
let ha_im_on min-one-of hauls [distance myself]
let who_ha_im_on [who] of ha_im_on
if member? who_ha_im_on mem-haul-ids
[
let ha_im_on_pos position who_ha_im_on mem-haul-ids
;let temp_array2 array:from-list memory-hauls-list
;array:set temp_array2 ha_im_on_pos 0.99
set memory-hauls-list replace-item ha_im_on_pos memory-hauls-list 0.99
;set memory-hauls-list array:to-list temp_array2
]
;show memory-hauls-list
;show memory-hauls-array
;set memory-hauls-list fput 0.99 memory-hauls-list
;set patch-ids []
set patch-memory []
;set patch-hsi-list []
;set patch-ei-list []
set my_next_patch "none"
set my_move_away_patch "none"
set my_next_ha ha_im_on ; this has no influence on seal movement, it is used to output coordinates of the starting haul-out for calculating trip duration and extend
set visited_ho_list []
set visited_ho_list lput [who] of ha_im_on visited_ho_list
set previous_ho ha_im_on
set patch-ei-table-array table:make
set patch-mem-table-array table:make
set patch-pxcor-table-array table:make
set patch-pycor-table-array table:make
set patch-ei-burnin-table-array table:make
set patch-pxcor-burnin-table-array table:make
set patch-pycor-burnin-table-array table:make
;print table:length patch-mem-table-array
;set patch-ei-5k-days []
set patch-ids-5k []
set patch-ei-5k []
set patch-area5id []
set patch-ei-5k-memory []
]
;show timer
end
; seals should not be randomly distributed over the haul-out but according to proportion observed in reality. So most popular haulout sites should
; have most seals at the start
; procedure distributing seals at the start of the model over haul-outs in accordance to number of observed seals on various haul-outs
to distribute_seals_on_haulouts
;let list_ha n-values count hauls [i -> i]
ask seals
[
carefully
[
loop
[
let countSeals count seals-here
let whoOf_ho_im_on [who] of hauls-here ;ho-Im-on
ifelse countSeals > [numberOfModelledSeals] of hauls-here
[move-to one-of hauls with [who = (whoOf_ho_im_on + 1)]]
[stop]
]
]
[
move-to one-of hauls
]
]
ask hauls
[
set HONseals count seals-here
]
end
;;;;;;;;;;;;;;;;;;;;; LAND AVOIDANCE, COPIED FROM SAIMAA SEAL MODEL ;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; Liukonnen et al, 2018, Ecological Modelling 368 (2018) 321–335
to see-if-land-ahead
; the list can be extended if measuring land at step length is not enough but shorter/longer distancees are needed
; but the more to calculate the slower the model so I need to find a compromise
; in Saimaa model short distances where added, in our case these have to be dostances > step_length/patch_size
let check-land-distances
(list
;(step_length / patch_size)
(step_length * 2) ;/ patch_size
(step_length * 3) ;/ patch_size
(step_length * 4) ;/ patch_size
)
set is-land? []
foreach check-land-distances
[
x ->
carefully
[
if ([categ = "land"] of patch-ahead x)
[
set is-land? fput true is-land?
;set pcolor green
;print word [who] of seals "land ahead"
]
]
[
set is-land? fput true is-land? ; originally should be true, if I change it to false nothing happens anyway
;print word [who] of seals "debug land nobody"
]
]
end
;----------------------------------------------------
to avoid-land-decision
;; AVOIDANCE MODE DECISION
;; Count how much is land in each side of the individual and avoid land where less
set head-current heading
;; right side
set count-right 0
set heading (head-current + 45)
set count-right count patches in-cone land-distance 90 with [categ = "land"]
;; left side
set count-left 0
set heading (head-current - 45)
set count-left count patches in-cone land-distance 90 with [categ = "land"]
;; if equal amount of land patches, random selection
if count-left = count-right
[
ifelse random-float 1 > 0.5
[
set count-right count-right + 1
stop
]
[
set count-left count-left + 1
]
]
ifelse count-left < count-right
[
; choose left direction
set heading head-current
set avoidance-mode-right false
set avoidance-mode-left true
avoid-land-left
stop
;print(word [who] of seals with [avoidance-mode-left = true] "avoiding left")
]
[
; choose right direction
set heading head-current
set avoidance-mode-right true
set avoidance-mode-left false
avoid-land-right
;print(word [who] of seals with [avoidance-mode-right = true] "avoiding left")
]
end
;
;;;------------------------------
;
to avoid-land-left
;; After making a decision to left OR in left land avoidance mode
;; Adjusts the turning angle for avoiding the land from left side
set heading head-current
see-if-land-ahead
set turning-counter 0
ifelse empty? is-land?
;; If no land ahead and the seal wants to avoid the land from the left side,
;; it needs to turn "right" from current heading (clockwise). (makes the seal to follow the shoreline of an island)
[
let head-prev head-current
loop
[
turn-clockwise
;print (word [who] of seals "turning clockwise")
see-if-land-ahead
if not empty? is-land?
[
;; When land encountered while turning, the seal knows that no more turning is needed
;; and it can choose the turning angle as the previous one
set heading head-prev
fd step_length; / patch_size
stop
]
if turning-counter = 36
[
;; The step lenght is sometimes too small to encounter land.
;; If this happens, the seal can simply take a step towards target
;; as it went around 360 degrees already
;;let patch_Notland min-one-of patches with [categ != "land"] [distance myself]
let patch_Notland min-one-of water-shore-patches [distance myself]
set heading towards patch_Notland
;print (word [who] of seals with [turning-counter = 36] "1turning counter = 36")
move-to patch_Notland ; sometimes seals move on land during crw procedure and get stuck there, this is to 'force' them to move back to water
;fd step_length; / patch_size
stop
]
set head-prev head-current
]
]
;; If there is land ahead and the seal wants to avoid the land from the left side,
;; it needs to turn left from current heading.
[
loop
[
turn-anticlockwise
;print (word [who] of seals "turning anticlockwise")
see-if-land-ahead
if empty? is-land?
[
;; When land is not encountered while turning, the seal knows that no more turning is needed
fd step_length; / patch_size
stop
]
if turning-counter = 36
[
;; The step lenght is sometimes too large and encounters always land.
;; If this happens, the seal can decrease the step lenght and start trying again
;print (word [who] of seals with [turning-counter = 36] "2turning counter = 36")
set turning-counter 0
;fd step_length * 0.5
;set step_length step_length * 0.5
;move-to min-one-of patches with [categ != "land"] [distance myself] ; sometimes seals move on land during crw procedure and get stuck there, this is to 'force' them to move back to water
move-to min-one-of water-shore-patches [distance myself] ; sometimes seals move on land during crw procedure and get stuck there, this is to 'force' them to move back to water
]
]
]
end
;
;;------------------------------
;
to avoid-land-right
;; After making a decision to right OR in right land avoidance mode (possible in movement modes 1 and 3, targeted moving)
;; Adjusts the turning angle for avoiding the land from the right side
set heading head-current
see-if-land-ahead
set turning-counter 0
ifelse empty? is-land?
;; If no land ahead and the seal wants to avoid the land from the right side,
;; it needs to turn "left" from current heading. (makes the seal to follow the shoreline of an island)
[
let head-prev head-current
loop
[
turn-anticlockwise
;print (word [who] of seals "turning anticlockwise")
see-if-land-ahead
if not empty? is-land?
[
;; When land encountered while turning, the seal knows that no more turning is needed
;; and it can choose the turning angle as the previous one
set heading head-prev
fd step_length; / patch_size
stop
]
if turning-counter = 36 ; 360 degrees
[
;; The step lenght is sometimes too small to encounter land.
;; If this happens, the seal can simply take a step towards target
;; as it went around 360 degrees already
;;let patch_land min-one-of patches with [categ != "land"] [distance myself]
let patch_land min-one-of water-shore-patches [distance myself]
set heading towards patch_land
;set heading towards target
;print (word [who] of seals with [turning-counter = 36] "3turning counter = 36")
move-to patch_land ; sometimes seals move on land during crw procedure and get stuck there, this is to 'force' them to move back to water
;fd step_length; / patch_size
stop
]
set head-prev head-current
]
]
;; If there is land ahead and the seal wants to avoid the land from the right side,
;; it needs to turn right from current heading.
[
loop
[
turn-clockwise
;print (word [who] of seals "turning clockwise")
see-if-land-ahead
if empty? is-land?
[
;; When land is not encountered while turning, the seal knows that no more turning is needed
fd step_length; / patch_size
stop
]
if turning-counter = 36
[
;; The step lenght is sometimes too large and encounters always land.
;; If this happens, the seal can decrease the step lenght and start trying again
;print (word [who] of seals with [turning-counter = 36] "4turning counter = 36")
set turning-counter 0
;;move-to min-one-of patches with [categ != "land"] [distance myself] ; sometimes seals move on land during crw procedure and get stuck there, this is to 'force' them to move back to water
move-to min-one-of water-shore-patches [distance myself] ; sometimes seals move on land during crw procedure and get stuck there, this is to 'force' them to move back to water
;fd step_length * 0.5
;set step_length step_length * 0.5
]
]
]