Closed ALEJANDRA-TOMASINI closed 4 years ago
It looks as though the ai_reproject layer has had the crs force-changed rather than reprojected. The units of the extent and resolution suggest that these were originally degrees lat and longs. Check the crs of the data after you first import it - then use projectRaster
this is the data after I first imported it:
ai class : RasterLayer dimensions : 4566, 6929, 31637814 (nrow, ncol, ncell) resolution : 0.016667, 0.016667 (x, y) extent : -168.1242, -52.63859, 7.006816, 83.10834 (xmin, xmax, ymin, ymax) crs : NA source : /home/shomeb/m/mariagui/Mexican-mammal-phylogenetic-diversity/canlup_f/w001001.adf names : w001001 values : 0, 1 (min, max)
I cannot use project raster since the cry is NA:
ai1<-projectRaster(ai,crs=crs(mexicomammalstack)) Error in projectRaster(ai, crs = crs(mexicomammalstack)) : input projection is NA
Check through the metadata associated with the raster layers - but looking at the extent values, and given that this is Canis lupus, it seems reasonable that these are geographic coordinates. You can set the crs to be '+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0', then use projectRaster to reproject to the projection of the other species data.
I already did that and it worked for the projection. I still cannot manage to stack the two of them because the extent is different. I tried "extent" to try set the extent of the mexicomammalstack, to the new distribution ranges, did not worked.
I searched in Jesus' scrip and it seemed he had kind of the same problem. I tried that part of his code but still did not work so I'm still stocked in adding the new distribution ranges.... is only 2 species anyways... i figured that the rest of the maps are not available anyways:
filelist2<-list.files('differentextent',full.names = T) filelist2
mexicomammalstack2<-stack(filelist2)
names(mexicomammalstack2)<-substring(names(mexicomammalstack2),1) names(mexicomammalstack2)
plot(mexicomammalstack2[[1]])
mexicomammalstack2<-projectRaster(mexicomammalstack2,crs= "+proj=aea +lat_1=14.5 +lat_2=32.5 +lat_0=24 +lon_0=-105 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs") mexicomammalstack2
mexicomammalstackbn<-stack(mexicomammalstack,crop(mexicomammalstack2,mexicomammalstack))
Stack the two
mexicomammalstackbn<-stack(mexicomammalstack,crop(mexicomammalstack2,mexicomammalstack)) Error in compareRaster(x) : different extent
extent(mexicomammalstack2,mexicomammalstack) Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘yFromRow’ for signature ‘"RasterBrick", "RasterStack"’
moving on... now I want to know how many species do I have inside and how many outside PA, I guess it would be informative to know which as well. Also, I want to know how many times a sp./branch tip is protected in the total set of PA.
I have no clear idea of how to do this. I was thinking separating the polygons of the PA:
SRiPA<-mask(SR_lcc,ALLPA_ToUse) cellStats(SRiPA, stat='mean', na.rm=TRUE, asSample=TRUE) cellStats(SRiPA, stat='max', na.rm=TRUE, asSample=TRUE) cellStats(SRiPA, stat='min', na.rm=TRUE, asSample=TRUE)
but I think that with that I only get the largest number of sp. contained in one cell inside the PA, not really the total number of species conserved by the total area of PA.
For the B diversity you suggested to make a new dataset where all of Mexico’s protected areas are merged into a single community. But could I do this for counting #of species as well? Also do I do this with:
communitydata2 <- getValues(mexicomammalstack_10km) #????
What I dont understand is which data to use for creating the new community, with for SR and PD
First - the extent: If you are certain that they have the same CRS and the CRS is correctly defined, you can then crop the larger one (C.lupus) to the smaller extent (Mexico). If you still cannot stack them it is then because the grids do not exactly overlap. Then you can use resample, setting the method='ngb' argument.
To identify which species are present or missing from protected areas, you can extract the species stack and the protected areas raster. Use indexing to identify which species are not present in any of the protected areas.
To combine all protected areas into one community (to look at turnover between all protected areas against individual unprotected cells) you can use the community dataset that you read into picante. Add a protected area column to that dataset, then sum the species presences across all protected cells in that dataset (i.e. how many protected area cells each species is found within). This is interesting from a conservation perspective. Before you do the B diversity turnover analysis, convert it back to presence-absence.
I'll try here, may be is better. I manage to get the same projection on both the new distribution maps and the mammal stack that I've been using. The problem is that the extent, the resolution and the dimensions of the file are different so I cannot add the new distribution maps to the mammal stack. I can save in the same file, but when I ask to stack all the files, I get an error:
mexicomammalstack<-stack(filelist) Error in compareRaster(rasters) : different extent
So is there a way to convert the new distribution maps with not only the same projection as the mammals tack but also the rest of the info?
*ai_reproject= distribution map of Canis lupus