BenioffOceanInitiative / bbnj

R package for assessing marine biodiversity beyond national jurisdiction (BBNJ)
https://BenioffOceanInitiative.github.io/bbnj
4 stars 0 forks source link

seascape indices change when reprojected #11

Closed mvisalli closed 5 years ago

mvisalli commented 5 years ago

Just flagging that seascape indices change when projected into mol_50km. e.g. calling seascape 5 returns seascape 3.

molscape<-get_d_prjres("s_phys_scapes",prjres = "_mol50km")
molscape[[5]]
class      : RasterLayer 
dimensions : 360, 720, 259200  (nrow, ncol, ncell)
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 
source     : /Users/morgan/github/bbnj/inst/data/phys_scapes_mol50km/class_3.tif 
names      : class_3
values     : 0, 1  (min, max)

So subset by name i.e.

get_d_prjres("s_phys_scapes",prjres) %>%
      raster::subset(c("class_1","class_2","class_5","class_8","class_9"))
mvisalli commented 5 years ago

Also @bbest did seascape values change from continuous to binary in reprojected versions?

mvisalli commented 5 years ago

When seascape indices change when reprojected, it messes up seascape numbering in scenario report. To address this I added this line: https://github.com/ecoquants/bbnj/blob/6758a09b91285644aa7e910e9857be25028fc7d8/inst/app/www/scenarios/s00c.bio.30pct.gl.mol50km.Rmd#L80

And changed the way seascapes are named in report. https://github.com/ecoquants/bbnj/blob/6758a09b91285644aa7e910e9857be25028fc7d8/inst/app/www/scenarios/s00c.bio.30pct.gl.mol50km.Rmd#L89

Probably a better/more elegant way to fix this but it seems to be working for an interim fix

bbest commented 5 years ago

Hi @mvisalli,

Good eye and fix on the class names getting jumbled!

Yes, I previously reported the amount of each class per half-degree cell since the original scapes raster is 0.1 º and I could aggregate to 0.5º:

https://github.com/ecoquants/bbnj/blob/9fbca3b32db925d21c69c6754d3459b1177f70fa/data-raw/create_data.R#L393

But then with new projection-resolutions (pr), there isn't a clean strategy for doing this, and instead:

  1. identify seascape class based on nearest neighbor: https://github.com/ecoquants/bbnj/blob/6758a09b91285644aa7e910e9857be25028fc7d8/data-raw/create_data.R#L560-L562
  2. use prioritizr::binary_stack() to split single raster of seascape class values to stack of rasters per class with binary 1 or 0 values https://github.com/ecoquants/bbnj/blob/6758a09b91285644aa7e910e9857be25028fc7d8/data-raw/create_data.R#L564
mvisalli commented 5 years ago

Got it, thanks!