wpeterman / ResistanceGA

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

SS_opitm error for continuous surface: Error in if (abs(MIN - MAX) < threshold) { : missing value where TRUE/FALSE needed #19

Closed EveTC closed 1 year ago

EveTC commented 3 years ago

Hello,

I am trying to run SS_opitm() on a elevation, a continuous landscape. I have managed to get SS_optim working previously for a categorical surface but I receive the error below for my elevation surface.

Error in if (abs(MIN - MAX) < threshold) { :
  missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In max(R@data@values, na.rm = TRUE) :
  no non-missing arguments to max; returning -Inf
2: In min(R@data@values, na.rm = TRUE) :
  no non-missing arguments to min; returning Inf

The code I am running is as below:

library("ResistanceGA")

# Set directories
write.dir <- "/pub28/eve/Pararge_aegeria/FINAL/Analyses/MNP_vcfprim/Route_of_col/ResistanceGA/Scot_exp/run1_sep_180621/dem/"
raster_dir <- "/pub28/eve/Pararge_aegeria/FINAL/Analyses/MNP_vcfprim/Route_of_col/ResistanceGA/Scot_exp/Input/raster_sep/dem/"

# Run resistanceGA
GA.inputs <- GA.prep(method="AIC", ASCII.dir=raster_dir, Results.dir = write.dir, select.trans="A", seed=231)
gdist.inputs <- gdist.prep(length(Scot.sp), samples=Scot.sp, response= lower(Scot_fst), method='costDistance')
demOnly_run1_180621 <- SS_optim(gdist.inputs = gdist.inputs, GA.inputs = GA.inputs, diagnostic_plots=FALSE)

I checked that all the point do have values on the raster

dem_raster <- raster("/pub28/eve/Pararge_aegeria/FINAL/Analyses/MNP_vcfprim/Route_of_col/ResistanceGA/Scot_exp/Input/raster_sep/dem/Elevation.asc")
checkDEM <- extract(dem_raster,Scot.sp)
checkDEM
# No NAs present - all points have data

Any ideas what is causing this problem?

I am carrying out my PhD. So my appologies if this is a simple fix, as I am new to this package. I really would like to make this method work as it is perfect for what I am hoping to achieve in my next paper.

EveTC commented 3 years ago

Information on the raster:

>dem
class      : RasterLayer
dimensions : 325, 300, 97500  (nrow, ncol, ncell)
resolution : 1000, 1000  (x, y)
extent     : 120000, 420000, 6e+05, 925000  (xmin, xmax, ymin, ymax)
crs        : +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs
source     : Elevation.asc
names      : Elevation

I also recieve the same error when I use another continuous surface:

>hedge
class      : RasterLayer
dimensions : 325, 300, 97500  (nrow, ncol, ncell)
resolution : 1000, 1000  (x, y)
extent     : 120000, 420000, 6e+05, 925000  (xmin, xmax, ymin, ymax)
crs        : +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs
source     : Hedgerow.asc
names      : Hedgerow

However resistanceGA works fine on a categorical surface which has the same resolution, extent and dimensions.

wpeterman commented 3 years ago

Can you share the DEM you're working with?

On Fri, Jun 18, 2021 at 8:58 AM EveTC @.***> wrote:

Hello,

I am trying to run SS_opitm() on a elevation, a continuous landscape. I have managed to get SS_optim working previously for a categorical surface but I receive the error below for my elevation surface.

Error in if (abs(MIN - MAX) < threshold) { : missing value where TRUE/FALSE needed In addition: Warning messages: 1: In @.@values, na.rm = TRUE) : no non-missing arguments to max; returning -Inf 2: In @.@values, na.rm = TRUE) : no non-missing arguments to min; returning Inf

The code I am running is as below:

library("ResistanceGA")

Set directories

write.dir <- "/pub28/eve/Pararge_aegeria/FINAL/Analyses/MNP_vcfprim/Route_of_col/ResistanceGA/Scot_exp/run1_sep_180621/dem/" raster_dir <- "/pub28/eve/Pararge_aegeria/FINAL/Analyses/MNP_vcfprim/Route_of_col/ResistanceGA/Scot_exp/Input/raster_sep/dem/"

Run resistanceGA

GA.inputs <- GA.prep(method="AIC", ASCII.dir=raster_dir, Results.dir = write.dir, select.trans="A", seed=231) gdist.inputs <- gdist.prep(length(Scot.sp), samples=Scot.sp, response= lower(Scot_fst), method='costDistance') demOnly_run1_180621 <- SS_optim(gdist.inputs = gdist.inputs, GA.inputs = GA.inputs, diagnostic_plots=FALSE)

I checked that all the point do have values on the raster

dem_raster <- raster("/pub28/eve/Pararge_aegeria/FINAL/Analyses/MNP_vcfprim/Route_of_col/ResistanceGA/Scot_exp/Input/raster_sep/dem/Elevation.asc") checkDEM <- extract(dem_raster,Scot.sp) checkDEM

No NAs present - all points have data

Any ideas what is causing this problem?

I am carrying out my PhD. So my appologies if this is a simple fix, as I am new to this package. I really would like to make this method work as it is perfect for what I am hoping to achieve in my next paper.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/wpeterman/ResistanceGA/issues/19, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLQUNEM65VDMRKQ74EDODTTM7JBANCNFSM465UGXEA .

--

-Bill-

EveTC commented 3 years ago

Hi, thank you for your quick response. I can do as the dataset is open access. However, GitHub wont let me upload a .asc file - can I email you directly instead? If so what is email is best?

Thank you, Eve

wpeterman commented 3 years ago

Yes, you can email me the file or send a link to download.

On Fri, Jun 18, 2021 at 10:13 AM EveTC @.***> wrote:

Hi, thank you for your wuick response. I can do - GitHub wont let me upload a .asc file - can I email you directly instead? Thank you, Eve

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/wpeterman/ResistanceGA/issues/19#issuecomment-864069267, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDLQUMV6LBGNDRDDCDSP4TTTNH77ANCNFSM465UGXEA .

--

-Bill-

EveTC commented 3 years ago

Hi I have sent you an email with the DEM raster. Thank you for your help

EveTC commented 3 years ago

Just wondering if you received the DEM raster via email? I am not sure if I sent it to the correct place? If not I can try again, Thank you

willright28 commented 2 years ago

Hi @EveTC Have you solved this problem? I met the same one. Hope to get some good news.

Thanks in advanced!

EveTC commented 2 years ago

Hi @willright28,

@wpeterman was fantastic help and he worked out that it was something to do with gdistance. He couldn't fix the direct problem but found that my rasters worked for him using circuitscape (Julia implementation). So perhaps try that?

I did recieve a further error with circuitscape and Julia which was to do with the set up of my system. I was working on a computer cluster, so parallel didnt seem to work. I instead had to run it locally which worked without issue.

I hope this helps somewhat :) and thank you again @wpeterman for your help solving my issue

willright28 commented 2 years ago

Thanka for your reply. I used ResistanceFA in my PC. As you mentioned, my raster file worked fine with the circuitscape in julia, so I think it's something to do within the ResiatanceGA. And what I used was ji.prep, I called the julia in R and encountered this problem, but there wasn't error message when I used GA.prep just time-consuming. Any clues or suggestions is appreciated.

---Original--- From: @.> Date: Thu, Jan 13, 2022 20:26 PM To: @.>; Cc: @.**@.>; Subject: Re: [wpeterman/ResistanceGA] SS_opitm error for continuous surface: Error in if (abs(MIN - MAX) < threshold) { : missing value where TRUE/FALSE needed (#19)

Hi @willright28,

@wpeterman was fantastic help and he worked out that it was something to do with gdistance. He couldn't fix the direct problem but found that my rasters worked for him using circuitscape (Julia implementation). So perhaps try that?

I did recieve a further error with circuitscape and Julia which was to do with the set up of my system. I was working on a computer cluster, so parallel didnt seem to work. I instead had to run it locally which worked without issue.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Message ID: @.***>