rspatial / dismo

R dismo package
GNU General Public License v3.0
22 stars 11 forks source link

Weird errors when running maxent() #16

Closed RussellGrayxd closed 3 years ago

RussellGrayxd commented 3 years ago

Hey dev team, I have been using dismo for quite a long time and I have never run into errors like this before. I have been troubleshooting for days now and haven't been able to resolve the issue.

So basically, if I run maxent() with other data, using identical script, it works just fine... But I have a new dataset that I'm using, which I have double and triple checked the data for (occurences, raster variables, matching projections, no NA values) and it does not run with maxent(). When I try to run the following code:

mod <- dismo::maxent(x=pder, #env conditions p=pa, #1=presence; 0=absence path=paste0(getwd(),"/output/maxent_outputs"), args=prepPara(userfeatures="L", betamultiplier = 2, replicates=10, ## 10 replicates replicatetype="bootstrap")) # parameter specifications

I get this error: Warning: Setting randomseed to true so that replicates are not identical Error: Error reading files Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 't': cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'C:/Users/Russe/Desktop/SVW/CivetPaper/Output/output/maxent_outputs/maxentResults.csv': No such file or directory

There is nothing wrong with the file directory, no issues with spaces in the names, or anything. I have tried dozens of other directories at this point and all of them run the same error. However, when I run my other data (in which maxent runs fine), I can save the output to this same directory without issue.

My data occurences are a species in Vietnam, all predictor variables are cropped and masked to Vietnam. "pa" is a presence absence vector, "pder" is a dataframe of extracted environmental values from the raster stack. Again, there are no NA values in my dataset.

Please help, I have no idea what else I could possibly do and the others who have run into this issue online still have no resolution posted.

RussellGrayxd commented 3 years ago

Ok so I managed to solve the issue by re-masking all of my stacked rasters to my shapefile. I guess Maxent was reading the NA values of the outer extents of the rasters and getting confused. I thought I had done this before stacking, but I guess I was wrong.

The error message is quite misleading because the issue has nothing to do with directories, but rather an issue with the data itself.