ices-eg / ICES-VMS-and-Logbook-Data-Call

GNU General Public License v3.0
5 stars 5 forks source link

Integration of sediment data in the data call in a Block 2 and 3 Beta version #21

Open roimartins opened 9 months ago

roimartins commented 9 months ago

The integration of sediemnt data in teh block 2 and block 3 of the workflow.

The change on block 3 format will implies a change in the ICES Data Center API's , so will require more planning to incorporate in the data call request .

Suggested to create a Beta version and SFD member and dat submitors could volunteer to test the Beta version

jepol77 commented 8 months ago

Here is a possible way of adding habitat data (broad-scale seabed habitat from the new EUSeaMap 2023) to the tacsatEflalo file:

The first section is optional, since this has already been done by once, and the resulting

rds file can be downloaded directly from the dtu server.

Be sure that the download does not timeout before it is finished

options(timeout = max(5000, getOption("timeout")))

Download zip file to folder

url <- "https://files.emodnet-seabedhabitats.eu/data/EUSeaMap_2023.zip"

zipF <- paste0(outPath, "eusm.zip")

download.file(url, zipF)

sf_use_s2(F)

unzip and load into R Environment

unzip(zipF, exdir=outPath)

data(ICESareas)

ICESareas <- ICESareas |>

st_zm() |>

st_make_valid()

eusm <- st_read(paste0(outPath, "EUSeaMap_2023.gdb"), layer = "EUSeaMap_2023")

eusm <- eusm |>

st_zm() |>

select(all_of("MSFD_BBHT")) |>

st_crop(ICESareas)

st_geometry(eusm) <- "geometry"

eusm <- eusm |>

group_by(MSFD_BBHT) |>

summarize(geometry = st_union(geometry))

saveRDS(eusm, paste0(outPath, "eusm.rds"))

######## Download directly from dtu server - https://figshare.com/s/46ed591ca29f87c53311 ######## and save the eusm.rds file to your outPath

Load the file into R

eusm <- readRDS(paste0(outPath, "eusm.rds"))

Save as shapefile

st_write(eusm, paste0(outPath, "eusm.shp"))

year <- 2021 for(year in yearsToSubmit){ print(year) load(file = paste0(outPath,paste0("/tacsatEflalo",year,".RData")) ) sf_use_s2(F) #If not you probably get an error

Add habitat to the tacsateflalo file

tacsatEflalo <- tacsatEflalo |> sf::st_as_sf(coords = c("SI_LONG", "SI_LATI"), remove = F) |> sf::st_set_crs(4326) |> st_join(eusm, join = st_intersects) |> mutate(geometry = NULL) |> data.frame()