rescale_stack() not working with mollweide
Closed this issue · 3 comments
Want to rescale the seamount raster stack so each raster is [0-1]
prjres <- "_mol50km"
s_seamounts <- get_d_prjres("s_phys_seamounts",prjres)%>%
rescale_stack(from_all=F)
Results in warning:
Warning message:
In .local(x, ...) :
This function is only useful for Raster* objects with a longitude/latitude coordinates
And produces rasters with funky rescaling not [0-1]
Hi @mvisalli,
I fixed the code in bbnj::rescale_stack()
/ bbnj::rescale_raster()
that throws the warning to work with argument multiply_area
so now raster::area()
only gets applied to geographic coordinate system (gcs) projection raster or stack and base::prod(raster::res(r))
is otherwise applied to cell area values assuming projection in meters and multiplier in km^2.
The rescaling seems to work for me. See the range 0-3, 0-6, 0-2 be transformed into 0-0.5, 0-1, 0-0.3 using the default from_all=TRUE
argument:
> (s_seamounts <- get_d_prjres("s_phys_seamounts",prjres))
class : RasterStack
dimensions : 360, 720, 259200, 3 (nrow, ncol, ncell, nlayers)
resolution : 50104.02, 50111.38 (x, y)
extent : -18037447, 18037447, -9020048, 9020048 (xmin, xmax, ymin, ymax)
crs : +proj=moll +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +towgs84=0,0,0
names : gt200lteq800m, gt800m, lteq200m
min values : 0, 0, 0
max values : 3, 6, 2
>
> (s_seamounts_r <- rescale_stack(s_seamounts, from_all = T))
class : RasterStack
dimensions : 360, 720, 259200, 3 (nrow, ncol, ncell, nlayers)
resolution : 50104.02, 50111.38 (x, y)
extent : -18037447, 18037447, -9020048, 9020048 (xmin, xmax, ymin, ymax)
crs : +proj=moll +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +towgs84=0,0,0
names : gt200lteq800m, gt800m, lteq200m
min values : 0, 0, 0
max values : 0.5000000, 1.0000000, 0.3333333
Rescaling by each also seems to work, ie from_all = FALSE
:
(s_seamounts_r <- rescale_stack(s_seamounts, from_all = F))
class : RasterStack
dimensions : 360, 720, 259200, 3 (nrow, ncol, ncell, nlayers)
resolution : 50104.02, 50111.38 (x, y)
extent : -18037447, 18037447, -9020048, 9020048 (xmin, xmax, ymin, ymax)
crs : +proj=moll +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +towgs84=0,0,0
names : gt200lteq800m, gt800m, lteq200m
min values : 0, 0, 0
max values : 1, 1, 1
Works for me, thank you!!