mcglinnlab / shark-ray-div

Global patterns of shark and ray diversity
0 stars 1 forks source link

bathymetry in the server #18

Closed EmmalineSheahan closed 2 years ago

EmmalineSheahan commented 6 years ago

So I've tried running this from the terminal twice:

library(readr)
bathy <- read_tsv('./topo_all.xyz', col_names = T)

and it runs and finishes after a few minutes and nothing shows up in the environment

dmcglinn commented 6 years ago

I'm trying to look into this but I don't see topo_all.xyz in your home or project directories. What is that file's path?

dmcglinn commented 6 years ago

No worries on file path, I have this file in my own directory. I'll let you know what I learn

dmcglinn commented 6 years ago

This worked for me:

topo = read_tsv('../gis/topo/topo_all.xyz', col_names=F)
dim(topo)
[1] 373248000         3

So I guess it is possible that by setting col_names=T it got messed up, but it really should have worked. Maybe keep the terminal open next time.

dmcglinn commented 6 years ago

Here are the relevant lines of code to add to the script "./scripts/raster_polygons.R" to read and process this file:

library(ncdf4)
topo = raster('../gis/etopo/ETOPO1_Ice_c_gmt4.grd')
proj4string(topo) = CRS("+proj=longlat +datum=WGS84")

topo_ras = projectRaster(topo, oceans_raster)

factor_val <- c(1, 2, 4, 8, 16, 32)
topo_list <- lapply(factor_val, function (x)
  aggregate(topo_ras, fac = x, fun = mean))
save(topo_list, file = './data/raster/topo_list.Rdata')

Note above the object factor_val includes the value 1. I know you said this caused you trouble but it works fine with raster version 2.6-7. This also simplifies the code and makes it clearer how the data will be aggregated so please make this change for how the other rasters are treated unless the problem you previously experienced is still persisting.

Here is a link to the created topo_list.Rdata file:

https://www.dropbox.com/s/j3045gc0hsu7owc/topo_list.Rdata?dl=0