Closed EmilyMarkowitz-NOAA closed 10 months ago
Hi Em,
I'm not entirely clear on what you're asking for in terms of development. In the first set of plots, the shapes "bleed" between regions because of the properties of the data. There are no zeros in the region without data and the closest value to the region along the boundary had catch > 0.
The inverse distance weighting functions aren't supposed to 'decide' which data to use for interpolation. It's expected that the user will make the decisions about which data to include in the interpolation. For example, the built-in 2017 YFS data set only includes the SEBS but you could use the data to predict densities in the NBS if you wanted to (certainly not advisable).
If the issue is that the areas don't align between regions after generating predictions for individual regions, you can interpolate the between the EBS and NBS instead then mask to the region of interest. If that's the issue, I'd recommend setting set.crs = "EPSG:3338" to use Alaska AEA for both regions.
Either way, I would strongly advise using simple features outputs instead of stars for generating plots. Code examples below using the built-in YFS data set.
library(akgfmaps)
ebs_layers <- akgfmaps::get_base_layers(select.region = "ebs",
set.crs = "EPSG:3338")
sample_locations <- sf::st_as_sf(akgfmaps::YFS2017,
coords = c("LONGITUDE", "LATITUDE"),
crs = "WGS84") |>
sf::st_transform(crs = "EPSG:3338")
idw <- make_idw_stack(x = dplyr::bind_rows(akgfmaps::YFS2017,
dplyr::mutate(akgfmaps::YFS2017, YEAR = 999)),
grouping.vars = "YEAR",
out.crs = "EPSG:3338",
region = "ebs",
extrapolation.grid.type = "sf")
ggplot() +
geom_sf(data = idw$extrapolation.stack,
mapping = aes(fill = var1.pred),
color = NA) +
geom_sf(data = sample_locations) +
scale_fill_viridis_d() +
facet_wrap(~YEAR)
# Note here that the output already includes the survey region. You could filter this to exclude a region without data and it wouldn't affect estimation, etc because IDW is deterministic.
ggplot() +
geom_sf(data = idw$extrapolation.stack,
mapping = aes(fill = var1.pred)) +
facet_wrap(~SURVEY)
Thanks for this explanation. Will work on implementing your suggestion above and let you know if I have any further questions.
Issue
Thanks so much for making the
akgfmaps::make_idw_stack() function()
! I think this issue can be considered a follow up to https://github.com/afsc-gap-products/akgfmaps/issues/28. Currently, when the function is run, it assumes that survey region is the same for all unique_groups (in this case,years
) of data. While this is typically true and there a species will typically inhabit one survey region over time, there are cases when we need to plot over the EBS and NBS regions and the fish may only sometimes be in one of the two regions in a given year. In those cases (e.g., organism A is in the EBS and the NBS in year 1 and only in the EBS in year 2), the function will inapproraitely plot across the two regions in year 2 when the organism wasn't there (first figure). Below I've constructed a reproducible example of my work around for combining these plots when an organism inconsistently exists across the two regions (second figure).The Ask: Is there a savvy way to incorporate stacking plots in different regions (something like below) into your
akgfmaps::make_idw_stack() function()
? If not, I have my work around, but if so, great!General code to pull and prep data for both examples
Test 1: Create IDW stack where the IDW interpolates across all regions for all years
The problem: the shapes bleed into areas they aren't supposed to.
Test 2: Create IDW stack using proper regions for all data
Here I have to
This is messy and not ideal, but works! I bet you've got a clever solution for this. If youv've told me in the past how to work this (a bit but not quite in https://github.com/afsc-gap-products/akgfmaps/issues/28), please remind me and sorry in advance!
Properly plots species distributions limited to the survey areas they were found in.