wpeterman / ResistanceGA

Optimize resistance surfaces using Genetic Algorithms
36 stars 15 forks source link

Error in { : task 1 failed - "duplicate "by" values not allowed" in MS_optim #30

Closed RiverAdelle closed 1 year ago

RiverAdelle commented 1 year ago

I received this error when running MS_optim. I checked all .asc files and all parameters and they are all correct. The code I'm using is here:

CS.inputs <- CS.prep(n.Pops = length(sample.locales), CS_Point.File = paste0(write.dir2,"samples.txt"), CS.program = CS.program, response = wcpw)

Run this for each layer to write .asc files to directory

CS.response7 <- Run_CS(CS.inputs = CS.inputs, r=Culv, CurrentMap = TRUE, EXPORT.dir = "C:/Users/rwatson17/Desktop/Watson_Opt/MS/")

now you should have multiple .asc files in your directory

GA.inputs <- GA.prep(ASCII.dir = write.dir2, Results.dir = write.dir2, method = "LL", max.cat = 100, max.cont = 100, parallel = 6)

gdist.inputs <- gdist.prep(length(sample.locales), samples = sample.locales, method = 'commuteDistance') # Optimize using commute distance

PARM must be in the order of the rasters, check order: Culv, Cond, Elev, NLCD, Slope, SS

GA.inputs$layer.names

Fill in parm using the outputs from SS_optim (?Combine_Surfaces) for categorical put all the feature #s in order

PARM <- c(1.7,1,43.4,88.5,100,3,11.5,21.9,1,13.7,5.1,1,14.5,41.6,1,7.3,100,1,9.3,100)

Combine resistance surfaces

Resist <- Combine_Surfaces(PARM = PARM, gdist.inputs = gdist.inputs, GA.inputs = GA.inputs, out = NULL, rescale = TRUE)

View combined surface

plot(Resist, main = "scaled composite resistance")

Create the true resistance/response surface

gdist.response <- Run_gdistance(gdist.inputs = gdist.inputs, r = Resist) gdist.inputs <- gdist.prep(n.Pops = length(sample.locales), samples = sample.locales, response = as.vector(gdist.response), method = 'commuteDistance')

Multi.Surface_optim <- MS_optim(gdist.inputs = gdist.inputs, GA.inputs = GA.inputs)

Error in { : task 3 failed - "duplicate "by" values not allowed"

wpeterman commented 1 year ago

It's not clear what you're attempting to do. It looks like you're creating resistance surfaces with known parameters, then using these with MS optim. There really isn't a need to specify resistance values a priori as this is done during optimization.

I am not certain what the error is that you received. However, support for gdistanceis largely discontinued in favor of using Circuitscape with Julia. See the vignettes in latest GitHub release of ResistanceGA for downloading, installing, and examples. If you continue to have issues, I'm happy to troubleshoot if you can share input files used in the analysis.