RangeShifter / RangeShiftR-pkg

RangeShiftR-package with new structure using subtree for RS core files
GNU General Public License v3.0
2 stars 0 forks source link

Issue when definining SpDistFile in a patch-based model #44

Open Daviser95 opened 3 months ago

Daviser95 commented 3 months ago

Hi! I am encountering an issue when defining the species distribution file in a patch-based mode. I have loaded the sites as in Figure 1, but when computing colonization time, it seems that in some regions only a small portion of the defined species distribution patches were considered occupied. I have tried several times to change the parameters to create the SPDistFile, but so far I haven't solved this issue.

This is the code to load the required files:

My_discrete_landscape_allpopuni_ranges <- ImportedLandscape(LandscapeFile =  "landscape.asc", 
                                        Resolution = 250,
                                        HabPercent = F,
                                        Nhabitats = 10,
                                        K_or_DensDep = carrycap,
                                        CostsFile = "cost.asc",
                                        PatchFile = "allpatches_final.asc",
                                        SpDistFile = "sites_allpopuni_final.asc",
                                        SpDistResolution = 250)

Each patch (defined in the PatchFile) has a unique ID, while in the SpDistFile, all the patches have a unique value (1). The patches didn't touch themselves, but I am not sure if this could cause this issue.

Screenshots These are the patches defined to be occupied (the SPDistFile) at the start of the simulation. bug1

This is the output from the Colonisation Stats, specifically the Colonization Time, in which only two patches in the southern part seemed to be occupied when the simulation started. bug2

I would very much appreciate any suggestions about how to fix this issue.

JetteReeg commented 3 months ago

Hi, it would be great if you could provide me with a minimal working example including input maps and a RangeShifter parameter master. Only then I can have a closer look at the issue.

Daviser95 commented 3 months ago

Hi Jette, thank you for your response! You can find the inputs and the code from this link: https://www.swisstransfer.com/d/8d853a9d-936f-4fa1-860a-1cff9593b244. The simulation needs about 5 minutes to end.

There are the parameters:

s1_balkpoppop_uni_ranges #riepilogo dei parametri
 Batch # 1 

 Simulation # 1 
 -----------------
   Replicates =  100 
   Years      =  100 
   Absorbing  =  FALSE 
 File Outputs:
   Range,       every 1 years
   Occupancy,   every 1 years
   Populations, every 1 years, starting year 0
   Individuals, every 1 years, starting year 0 
   SMS paths,  every 1 years, starting year 0 
   SMS heat map

 Landscape imported from file:
   landscape.asc
   with 10 unique integer habitat code(s)
   K or 1/b        :  0 0 0 0 0 1e-04 2e-04 3e-04 4e-04 0.00047 [inds per ha].
   Patches imported from file 
allpatches_final.asc 
   SMS costs imported from file 
cost.asc 
   Resolution      : 250 
 Initial Species Distribution imported from file:
   sites_balkpopuni_final.asc 
   Resolution      : 250 

 Demography:
  Stage-structured population:
   Stages           : 3 
   Transition matrix:
     [,1] [,2] [,3]
[1,]    0  0.0  3.0
[2,]    1  0.4  0.0
[3,]    0  0.6  0.9
   Maximum age      : 17 
   Minimum age      : 0 0 2 
   Reprod. seasons  : 1 
   Prob. Reprod.    : 1 
   Reprod. Intervals: 0 
   SurvScheduling   : 1 
   Density-dependence in:
    - Fecundity
   PostDestructn    : FALSE (all die)

  Reproduction Type : 1 (sexual model)
   PropMales : 0.5 

 Dispersal: 
  Emigration:
   DensDep = TRUE 
   StageDep = TRUE 
   SexDep = TRUE 
   Emigration probabilities:
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0  0.0    0    0
[2,]    0    1  0.0    0    0
[3,]    1    0  0.4   10    1
[4,]    1    1  0.9   10    1
[5,]    2    0  0.0    0    0
[6,]    2    1  0.0    0    0

  Transfer:
   Stochastic Movement Simulator
   PR = 10 , MemSize = 10 
   Method: Harmonic mean 
   DP       = 5 
   GoalType: Dispersal bias:
   GoalBias = 1.5 
   AlphaDB = 0.2 , BetaDB = 10 
   StraightenPath = TRUE 
   Costs  read from file 
   StepMort = 0.05 0.01 0.002 0.001 5e-04 1e-04 1e-05 0 0 0 

  Settlement:
   DensDep = TRUE 
   StageDep = TRUE 
   SexDep = TRUE 
   Settlement conditions:
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    1  -10    1
[2,]    0    1    1  -10    1
[3,]    1    0    1  -10    1
[4,]    1    1    1  -10    1
[5,]    2    0    1  -10    1
[6,]    2    1    1  -10    1
   FindMate = FALSE FALSE FALSE TRUE FALSE TRUE 
   MinSteps = 50 
   MaxSteps = 2500 
   MaxStepsYear = 300 

 Initialisation: 
   InitType = 1 : Initialisation from loaded species distribution map
                  all presence cells/patches.
   InitDens = 1 : At half K_or_DensDep 
   PropStages = 0 0 1 
   InitAge = 0  : Minimum age 

Let me know if you need further information, thank you!

JetteReeg commented 3 months ago

Hi,

Thanks for providing the files and the script.

Input files

I have checked your input files

library(terra)
# read in files
land <- rast(paste0(dirpath, "Inputs/","landscape.asc"))
patches <- rast(paste0(dirpath, "Inputs/","allpatches_final.asc"))
costs <- rast(paste0(dirpath, "Inputs/","cost.asc"))
distinit <- rast(paste0(dirpath, "Inputs/","sites_balkpopuni_final.asc"))
# remove all non-patch cells
values(distinit)[values(distinit)<1] <- NA
values(patches)[values(patches)<1] <- NA

# plot patches
plot(patches, axes=F, col="green4", legend=F)
# add patch IDs
text(as.polygons(patches, dissolve=T) ,labels=values(patches_pol)[,1])
# mark initial patches
plot(as.polygons(distinit, dissolve=T), col=NA, border='red',lwd=2, add=T)

image

It seems that some of your patches are split into two seperate patches even though they are connected? Not sure if this is intended.

In addition, the current RangeShiftR version 1.1.1 also checks whether all habitat cells have a cost value of at least 1. This seem not to be the case in your files. This should not have an effect on the initialisation, but might nevertheless influence your simulations.

Initial population size

Next, I checked the population output file to check how many individuals are initialised (year 0) in which patches.

pop <- readPop(s, dirpath) # s is your RS parameter master
pop[pop$PatchID %in% c(12:22) & pop$Year==0,]

image

It seems that the carrying capacity of many of your initial patches (individuals per hectar) is too low to carry 2 individuals. That means if you initialise at half capacity, no individuals will be initialised in these patches.

Even I initialised on all patches at full carrying capacity, several of the patches you selected for initial distribution not hold any individual in year 0 and only 2 patches can hold 2 individuals:

image

So overall you should have a closer look at these points:

Best, Jette

Daviser95 commented 3 months ago

Hi Jette, Thank you very much for all this information! I will for sure give a better look at the carrying capacity. For what concerns the Patches, actually they are not connected, but only very close to each other. They don't represent the best suitable patches, but they are a buffered minimum convex polygon, so they reflect the home range of the target species. Checking the habitat layer is basically a reclassified (to be discrete) habitat suitability layer, and currently, some of these patches cover areas with medium values of suitability. I am not sure if this could be the reason that is causing the issue of the SpDistFile. Because the non-habitat cells are the same for all layers, so maybe the low suitability values in some of the initial patches, together with the low carrying capacity, and the low amount of area of the patches, are causing the issue reported. Does this make sense?

Maybe an alternative would be to connect all the suitable patches (for example, after a least-cost path analysis), to obtain only one final bigger patch.

Again, thank you very much! Best, Davide