Open technoautotroph opened 8 years ago
I have learned a little from reading the rSPACE help file that talks about map
and Optional argument filter.map
. However, I still don't know how to import my custom made rectangular raster image (.jpg or .png) to have it treated as a raster map for analysis in rSPACE.
Thanks!
I will try this tomorrow - this should convert my raster image into a map:
library(raster)
# Give it lat/lon coords for 36-37°E, 3-2°S
extent(Raster.test) <- c(36,37,-3,-2)
# ... and assign a projection
projection(Raster.test) <- CRS("+proj=longlat +datum=WGS84")
plot(Raster.test)
#Use writeRaster() e.g.
writeRaster(Raster.test, "~/myraster.tif", format = "GTiff")
However, I still need to get the raster into rSPACE.
Sorry for putting so many comments. I ended up using QGIS and followed the guidance on the following site: http://www.qgistutorials.com/en/docs/georeferencing_basics.html - to create a GTIFF file. This worked great.
Also learned that the coding provided for loading the raster image does not work.
WolverineHabitat<-raster::raster(system.file('external/WolvHabitat_Bitterroot.tif', package='rSPACE'))
Can be simplified:
WolverineHabitat <- raster('Q:/2015/FWCP/15295-069 Peace Wetlands&Amphibians/Analysis and Database/rSPACE/WolvHabitat_Bitterroot.tif', package='rSPACE')
The simulation worked great for WolverineHabitat. I'm now trying to learn how to use my custom map for Ambystoma macrodactylum (AMMA). I get an error output:
Building landscape...
Error in tabulate(gridLayer[habitatOK], nbins = max(IDs)) :
invalid value of 'nbins'
In addition: Warning messages:
1: In max(IDs) : no non-missing arguments to max; returning -Inf
2: In tabulate(gridLayer[habitatOK], nbins = max(IDs)) :
NAs introduced by coercion to integer range
I probably have to account for the difference in size of my map. Here is a comparison of the two maps:
> WolverineHabitat
class : RasterLayer
dimensions : 277, 297, 82269 (nrow, ncol, ncell)
resolution : 0.004434074, 0.004434074 (x, y)
extent : -115.4532, -114.1363, 45.51177, 46.74001 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : Q:\2015\FWCP\15295-069 Peace Wetlands&Amphibians\Analysis and Database\rSPACE\WolvHabitat_Bitterroot.tif
names : WolvHabitat_Bitterroot
values : 0.2, 1 (min, max)
> AMMAHabitat
class : RasterLayer
band : 1 (of 3 bands)
dimensions : 3456, 1884, 6511104 (nrow, ncol, ncell)
resolution : 0.4953675, 0.4953675 (x, y)
extent : 394893.3, 395826.5, 6274671, 6276383 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=10 +ellps=GRS80 +units=m +no_defs
data source : Q:\2015\FWCP\15295-069 Peace Wetlands&Amphibians\Analysis and Database\rSPACE\Factor Ross Overview 2015_AMMA_modified.tif
names : Factor_Ross_Overview_2015_AMMA_modified
values : 0, 255 (min, max)
What will I need to change to run the simulation? I'm looking into grid_size
Thanks
Hi, sorry for the delay in getting back to your question. Can you copy over the parameters that you are using to run your simulations?
It looks like the values in your habitat layer run from 0-255. Have you tried a map with values 0-1? This is just a wild guess from the info you've provided.
I would like to thank Martha for her assistance. Progress has been made, but my maps still do not load into r-space. Here is what we've learned:
## 2.) Load packages and libraries
if (!require("RStoolbox")) install.packages("RStoolbox")
if (!require("tiff")) install.packages("tiff")
if (!require("rSPACE")) install.packages("rSPACE")
if (!require("raster")) install.packages("raster")
library(RStoolbox)
library(tiff)
library(rSPACE)
library(raster)
## 3.) Load habitat layer - convert to 0 to 1 scale
AMMAHabitat <- raster('Factor Ross Overview 2016_AMMA km.tif', package='rSPACE')
AMMAHabitatN <- rescaleImage(AMMAHabitat, ymin = 0, ymax = 1)
A.small <- AMMAHabitatN[sample(nrow(AMMAHabitatN), 3), ] # List a smaller version
A.small
This is as far as I can get. Using the default BaseParameters – I get the following output:
Building landscape...
Error: cannot allocate vector of size 769.5 Mb
In addition: Warning messages:
1: In makeGrid(map, gridsize = pList$grid_size) :
Reached total allocation of 3907Mb: see help(memory.size)
2: In makeGrid(map, gridsize = pList$grid_size) :
Reached total allocation of 3907Mb: see help(memory.size)
3: In makeGrid(map, gridsize = pList$grid_size) :
Reached total allocation of 3907Mb: see help(memory.size)
4: In makeGrid(map, gridsize = pList$grid_size) :
Reached total allocation of 3907Mb: see help(memory.size)
Any assistance would be greatly appreciated. Thanks!
Hi Mark - Even with an exanded habitat layer, you still shouldn't be apply the baseline values for Wolverine in your Amphibian study. The grid for the Wolverine landscape has a cell size of 100km^2. That isn't going to work on a landscape that is 6 x 12 km. You need to think about what kind of values will be appropriate for your landscape, and adjust the baseline parameters.
Increasing the map while presumably keeping the small resolution for your habitat is likely to produce memory allocation errors, depending on the computer set-up that you're using. I think a better solution here is to use your original map, but spend more time in determining appropriate parameter values in your specific application. This is definitely not the kind of program where you can plug and chug the same values on any landscape!
HI Martha - thanks for the feedback. I will try my best to think about the settings, but I admit that I don't have a full understanding of the program. I have played with the numbers and will keep thinking this through. I realize that this is still in development, but would it be possible to obtain a draft manual some time in the near future?
I am not convinced that I am experiencing a problem with the input parameters. I have tried many different kinds of parameters that are logical according to the map and species.
I think that this is a problem with the maps and their size. The Wolverine map example works great. It is a much smaller image in terms of resolution and file size - even though it scales across 170 km. If anything, I hope that my inexperience here and bold attempt to solve my issues will serve as a means to assist with an "rSPACE for Dummies" training manual.
I'm going to spend some time converting my raster maps into the same kind of format as the Wolverine raster image. I will project it into a lat / long system and will see how I can reduce the resolution. I'm assuming that this is accomplished with the raster package? Here are the some of the features I see for comparison:
WolvHabitat_Bitterroot.tif = 52 KB AMapS.tif = 19,104 KB
> res(AMapS)
[1] 1 1
> res(Wolverine)
[1] 0.004434074 0.004434074
> area(Wolverine)
class : RasterLayer
dimensions : 277, 297, 82269 (nrow, ncol, ncell)
resolution : 0.004434074, 0.004434074 (x, y)
extent : -115.4532, -114.1363, 45.51177, 46.74001 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : layer
values : 0.1661531, 0.1698737 (min, max)
> area(AMapS)
class : RasterLayer
dimensions : 10613, 8291, 87992383 (nrow, ncol, ncell)
resolution : 1, 1 (x, y)
extent : 390632, 398923, 6270159, 6280772 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=10 +ellps=GRS80 +units=m +no_defs
data source : C:\Users\mthompson\AppData\Local\Temp\RtmpINgkaS\raster\r_tmp_2016-04-14_123701_7772_10891.grd
names : layer
values : 1, 1 (min, max)
Warning messages:
1: In .local(x, ...) :
This function is only useful for Raster* objects with a longitude/latitude coordinates
2: In .rasterFromRasterFile(grdfile, band = band, objecttype, ...) :
size of values file does not match the number of cells (given the data type)
I will keep you posted.
Can you post the code and parameter list that you are using?
The code and maps have been uploaded (uploading) into the Dropbox folder that I shared with you.
The details are all shown here - code with parameter list:
## 2.) Load packages and libraries
if (!require("RStoolbox")) install.packages("RStoolbox")
if (!require("tiff")) install.packages("tiff")
if (!require("rSPACE")) install.packages("rSPACE")
if (!require("raster")) install.packages("raster")
library(RStoolbox)
library(tiff)
library(rSPACE)
library(raster)
## 3.) Load habitat layer - convert to 0 to 1 scale
AMapL <- raster('Q:/2016/FWCP/15295-069 Peace Wetlands and Amphibians/Analysis and Database/rSPACE/AMapL.tif', package='rSPACE')
AMapS <- raster('Q:/2016/FWCP/15295-069 Peace Wetlands and Amphibians/Analysis and Database/rSPACE/AMapS.tif', package='rSPACE')
Wolverine <- raster('Q:/2016/FWCP/15295-069 Peace Wetlands and Amphibians/Analysis and Database/rSPACE/WolvHabitat_Bitterroot.tif', package='rSPACE')
area(AMapL)
area(AMapS)
area(Wolverine)
AMapL <- rescaleImage(AMapL, ymin = 0, ymax = 1)
AMapS <- rescaleImage(AMapL, ymin = 0, ymax = 1)
l.list <- AMapL[sample(nrow(AMapL), 3), ] # List out a smaller version of the raster
l.list
s.list <- AMapS[sample(nrow(AMapS), 3), ] # List out a smaller version of the raster
s.list
###I have two maps - AMapS = 933.2 m x 1712 m, AMapL = 8291 m x 10613 m
### = 0.9332 km x 0.1712 km = 8.291 km x 10.613 km
#####################################
## Input parameter list for AMapL ###
#####################################
BParL <- enter.parameters()
###Population simulation - This should not change my mapping problems
#Initial population size = 50 ##This is a small number to start with, but okay
##Population growth rate = 0.933 ##"following a standard exponential growth equation" - Sure
##Number of years = 2 ##Reduced to 2 years to simplify
##Number of individual types = 2 ##Male/Female
##Proportion of population by type = 0.6 0.4 ##This should not change my mapping problems - Assume Female:Male, there are more females
###Movement paramaters - This will relate to my mapping parameters
##AMapL parameters
##Buffer distance between activity centers (km)? = 0.12 0.17
##"..often treated as the average distance between home range centres) and the minimum habitat suitability value at which activity centres can occur."
##"Distance between activity centres (km) for each type of individual"
##Long-toed salamanders maximum/average range sizes (km2): 1.00/0.28 (juveniles), 0.36/.17 (males), 0.41/0.12 (females)
##Movement radius = 0.90 1.00
##I expect most individuals will stay confined to an area that is 2 km in size, giving females smaller movement radius
##Proportion of movements within radius = 0.7 0.9 ##I did the inverse of Wolverine, because males tend to move more in salamanders
##Max proportion of movements to allow (1 = include all) = 0.95 0.95 ##Sure - seems fine for first trial of data
##Sampling Design
##Cell size (in km2)? = 0.002 ##My plots are 0.2 hectares in size, so I will use this value for the cell size.
##Minimum habitat value for activity centers = 1.0 ##Habitat scored 1.0 is best habitat, so this is where the habitat centers should begin.
##Proportion of cell in habitat = 0.5 ##Sure - this shouldn't impact the mapping
##Maximum visits per year = 3 ##We visit only 3 times per season
LAreaExample <- encounter.history(map=AMapL, Parameters=BParL, showSteps=T)
##Output:
##Building landscape...
##Error: cannot allocate vector of size 671.3 Mb
##In addition: There were 12 warnings (use warnings() to see them)
#####################################
## Input parameter list for AMapS ###
#####################################
BParS <- enter.parameters()
###Population simulation - This should not change my mapping problems
#Initial population size = 50 ##This is a small number to start with, but okay
##Population growth rate = 0.933 ##"following a standard exponential growth equation" - Sure
##Number of years = 2 ##Reduced to 2 years to simplify
##Number of individual types = 2 ##Male/Female
##Proportion of population by type = 0.6 0.4 ##This should not change my mapping problems - Assume Female:Male, there are more females
###Movement paramaters - This will relate to my mapping parameters
##AMapS parameters - they are smaller in this map, since the area is so small we want to keep the animals in the boundary of the map
##Buffer distance between activity centers (km)? = 0.05 0.05
##"..often treated as the average distance between home range centres) and the minimum habitat suitability value at which activity centres can occur."
##"Distance between activity centres (km) for each type of individual"
##Long-toed salamanders maximum/average range sizes (km2): 1.00/0.28 (juveniles), 0.36/.17 (males), 0.41/0.12 (females)
##Movement radius = 0.05 0.05
##In this smaller map I am keeping the radius very small to keep animals in the boundary of the map
##Proportion of movements within radius = 0.7 0.9 ##I did the inverse of Wolverine, because males tend to move more in salamanders
##Max proportion of movements to allow (1 = include all) = 0.95 0.95 ##Sure - seems fine for first trial of data
##Sampling Design
##Cell size (in km2)? = 0.002 ##My plots are 0.2 hectares in size, so I will use this value for the cell size.
##Minimum habitat value for activity centers = 1.0 ##Habitat scored 1.0 is best habitat, so this is where the habitat centers should begin.
##Proportion of cell in habitat = 0.5 ##Sure - this shouldn't impact the mapping
##Maximum visits per year = 3 ##We visit only 3 times per season
SAreaExample <- encounter.history(map=AMapS, Parameters=BParS, showSteps=T)
##Output:
##Building landscape...
##Error: cannot allocate vector of size 671.3 Mb
##In addition: Warning messages:
##1: In makeGrid(map, gridsize = pList$grid_size) :
## Reached total allocation of 3907Mb: see help(memory.size)
##2: In makeGrid(map, gridsize = pList$grid_size) :
## Reached total allocation of 3907Mb: see help(memory.size)
##3: In makeGrid(map, gridsize = pList$grid_size) :
## Reached total allocation of 3907Mb: see help(memory.size)
##4: In makeGrid(map, gridsize = pList$grid_size) :
## Reached total allocation of 3907Mb: see help(memory.size)
##5: In makeGrid(map, gridsize = pList$grid_size) :
## Reached total allocation of 3907Mb: see help(memory.size)
##6: In makeGrid(map, gridsize = pList$grid_size) :
## Reached total allocation of 3907Mb: see help(memory.size)
I have succeeded in getting an output using my maps and the parameters above!! Yay - I'm very excited!! The problem was related to the resolution. It was fixed using the following:
##From the Raster package - to create a new RasterLayer or RasterBrick with a lower resolution (larger cells)
aggregate(AMapS, fact=2)
I am looking forward to learning more about the software, input parameters, and simulations that can be run. Keep up the great work Martha!
There is little instruction on the raster map other than the example:
WolverineHabitat<-raster::raster(system.file('external/WolvHabitat_Bitterroot.tif', package='rSPACE'))\n")
I’ve tried to take a look at the WolvHabitat_Bitterroot.tif file and my computer says that the file is corrupt. It seems like there is more to this than I currently understand. R suggested that I load rgdal, which I did. I pasted the code above (using my local base directory) and get the following:
The raster map was not described in your paper and I don’t see an explanation in the online examples.
Next I tried:
library(png)
Map.test <- readPNG('C:.../external/RasterTest.png')
Raster.test <- as.raster(Map.test)
This works, but then I don't know how to get this into rSPACE.
My hope is to use an orthophoto that we have from our project site. My plan is:
Any assistance on this would be appreciated!
Thanks in advance,
Mark Thompson, MSc, MEd, RPBio