Código
library(tidyverse)
library(sf)
library(stars)
# library(raster)
# library(RStoolbox)
library(lubridate)
library(broom)
library(s2)
sf_use_s2(FALSE)library(tidyverse)
library(sf)
library(stars)
# library(raster)
# library(RStoolbox)
library(lubridate)
library(broom)
library(s2)
sf_use_s2(FALSE)La capa de las comunidades autónomas de España se puede descargar desde la pagina de ArcGIS
spain <-
read_sf('data/CCAA/Comunidades_Autonomas_ETRS89_30N.shp') %>%
st_transform (4326) %>%
st_combine() %>%
st_sf()
ggplot() +
geom_sf(data = spain) +
geom_sf() +
theme_minimal()Extraer el shape file de la Comunidad Valenciana y la Región de Murcia. Los datos se filtraron para excluir las Islas Columbretes.
costa_blanca <-
read_sf('data/CCAA/Comunidades_Autonomas_ETRS89_30N.shp') %>%
filter(Texto_Alt == "Murcia" | Texto_Alt == "Comunitat Valenciana") %>%
st_transform (4326) %>%
st_crop(
xmin = -3,
xmax = 0.6,
ymin = 41,
ymax = 37
) %>%
st_combine() %>%
st_sf()
ggplot() +
geom_sf(data = costa_blanca) +
geom_sf() +
theme_minimal()La Figura 3 muestra la capa que se calculó como un buffer de 50 km desde la linea de costa basado en la distancia geodésica.
buffer_costa <-
s2_buffer_cells(
s2_geog_from_wkb(st_as_binary(st_geometry(costa_blanca)), check = FALSE),
distance = 5e4,
max_cells = 1e4
) %>%
st_as_sf() %>%
st_difference(spain)
ggplot() +
geom_sf(data = buffer_costa, fill = "lightblue", col = "gray80") +
geom_sf(data = costa_blanca) +
geom_sf() +
coord_sf() +
theme_minimal()Se pueden bajar desde GEBCO y luego recortarlos en base al poligono de la costa Valenciana y Murciana
bathy_df <-
read_stars('data/gebco_2022_n42.4292_s34.4751_w-6.6577_e3.0981.tif', crs = st_crs(4326)) %>%
st_crop(buffer_costa) %>%
as_tibble() %>%
mutate(depth = as.numeric(`gebco_2022_n42.4292_s34.4751_w-6.6577_e3.0981.tif`), .keep = 'unused') %>%
drop_na()Luego se puede visualizar con el Figura 4 utilizando una transformación de raíz cuadrada para las profundidades.
ggplot() +
geom_raster(data = bathy_df, aes(x, y, fill = abs(depth))) +
scale_fill_viridis_c(option = 'D', name = "Depth") +
geom_contour(data = bathy_df, aes(x, y, z = depth)) +
geom_sf(data = costa_blanca) +
geom_contour(data = bathy_df, aes(x, y, z = depth), color = 'gray50') +
coord_sf() +
labs(x = NULL, y = NULL) +
theme_void()Primero me bajo datos de SST usando motuclient para Python.
import motuclient
!python -m motuclient --motu https://nrt.cmems-du.eu/motu-web/Motu --service-id MEDSEA_ANALYSISFORECAST_PHY_006_013-TDS --product-id med-cmcc-tem-an-fc-h --longitude-min -2 --longitude-max 1.2 --latitude-min 36.9 --latitude-max 41 --date-min "2022-09-17 23:30:00" --date-max "2022-09-17 23:30:00" --depth-min 1.0182 --depth-max 1.0183 --variable thetao --out-dir data --out-name temp_20_sept.nc --user jatalah --pwd *******El fichero nc primero se convierte en un tibble, luego en un objeto sf, para luego poder recortarlo basado el polígono de la costa Valenciana y de la Región de Murcia. Los puntos negros en la Figura 5 son las instalaciones de acuicultura obtenidas de la capa del portal Acuivisor.
sst_sept_17 <-
read_ncdf('data/temp_20_sept.nc', make_units = F, var = 'thetao') %>%
as_tibble() %>%
drop_na() %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326) %>%
st_intersection(buffer_costa)
recintos <-
read_sf('data/acuivisor_data/Recintos.shp') %>%
st_crop(st_bbox(buffer_costa))
ggplot() +
geom_sf(data = sst_sept_17, aes(color = thetao)) +
scale_color_viridis_c(option = 'H', name = "°C") +
geom_sf(
fill = grey(0.9),
color = grey(0.6),
lwd = 0.2,
data = spain,
) +
geom_sf(
data = recintos,
size = 30,
pch = 18,
color = 'black'
) +
coord_sf(xlim = c(-2, 2),
ylim = c(36, 41),
expand = TRUE) +
labs(y = "Latitude", x = 'Longitude') +
theme_minimal()Descargo los datos de SST desde Copernicus entre 1981 and 2021 utilizando la capa cmems_SST_MED_SST_L4_REP_OBSERVATIONS_010_021 basada en un modelo L4 para el Mediterráneo.
import motuclient
!python -m motuclient --motu https://my.cmems-du.eu/motu-web/Motu --service-id SST_MED_SST_L4_REP_OBSERVATIONS_010_021-TDS --product-id cmems_SST_MED_SST_L4_REP_OBSERVATIONS_010_021 --longitude-min -2 --longitude-max 1.2 --latitude-min 36.9 --latitude-max 41 --date-min "1981-08-25 00:00:00" --date-max "2022-03-03 00:00:00" --variable analysed_sst --out-dir data --out-name sst_all.nc --user jatalah --pwd *******Los datos se convierten en un dataframe usando el paquete tidync. Luego se ajusta el tiempo desde segundos a formato fecha y se convierte la temperatura de grados Kelvin a Celcius.
august_sst <-
read_ncdf('data/sst_all.nc', var = 'analysed_sst', make_units = F) %>%
as_tibble() %>%
drop_na() %>%
mutate(year = year(time),
month = month(time),
sst = analysed_sst - 273,
15) %>%
group_by(lon, lat, year, month) %>%
summarise(sst = mean(sst)) %>% # calcular medias mensuales
filter(month ==8) %>%
ungroup()Para el análisis de las tendencias en SST se utilizaron las temperaturas del mes de Agosto como indicador del mes mas cálido. Luego se ajustaron regresiones lineares con temperatura como variable respuesta y año como variable independiente para cada pixel.
La Figura 6 muestra las pendientes (aumento en grados por cada año) como indicador de tendencia de cambios de SST a través del tiempo en la zona de estudio.
lms <-
august_sst %>%
group_by(lat,lon) %>%
nest() %>%
mutate(lm = map(data, ~lm(sst~year, .x)),
lm_sum = map(lm , tidy)) %>%
dplyr::select(lm_sum) %>%
unnest(cols = c('lm_sum')) %>%
ungroup() %>%
dplyr::filter(term == "year")
lms %>%
# filter(p.value<0.05) %>%
st_as_sf(coords = c("lon", "lat"), crs = 4326, agr = "constant") %>%
st_crop(extent(buffer_costa)) %>%
st_intersection(buffer_costa) %>%
ggplot() +
geom_sf(aes(color = estimate)) +
scale_color_viridis_c(option = 'H', name = "Trend") +
geom_sf(
fill = grey(0.9),
color = grey(0.6),
lwd = 0.2,
data = spain
) +
coord_sf(xlim = c(-2, 2),
ylim = c(36, 41),
expand = TRUE) +
labs(y = "Latitude", x = 'Longitude') +
theme_minimal() Finalmente la Figura 7 muestra los cambios del promedio de SST para toda el area de estudio a través de los años.
august_sst %>%
group_by(year) %>%
summarise(sst = mean(sst)) %>%
ggplot(aes(year, sst)) +
geom_line() +
geom_smooth() +
theme_minimal()