Mean Sea Surface Temperature 1958 - 2022
Sea Surface Mean Temperature
Data donwloaded from here:
https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-oras5?tab=form
First, create an account, then sign in and get it
upload r packages
library(ncdf4)
library(raster)
open your netcdf files from your directory and make it writable
nc <- nc_open("Inputs_and_Data/sst_1958_2022.nc", write = T)
Explore the dataset
nc$var$sosstsst
tail(nc$var$nav_lat)
nc$dim$time_counter
tail(nc$dim$lon$vals) # -179.98 to 179
tail(nc$dim$lat$vals) # -89.98 to -89.98
nc$dim$time$vals
nc2$dim$time
nc2$var$time
Get some variables
lon <- ncvar_get(nc, 'lon')
lat <- ncvar_get(nc, 'lat')
temp <- ncvar_get(nc, 'sosstsst')
time <- ncvar_get(nc, 'time_counter')
head(time)
Transform date variable
library(chron)
month.day.year(time, c(month = 1, day = 1, year = 2011))
time2 <- month.day.year(time/86400, c(month = 1, day = 1, year = 1981))
month <- time2$month
day <- time2$day
year <- time2$year
dates_df <- cbind(year, month, day)
dates_df <- as.data.frame(dates_df)
vec_time <- paste(dates_df$year, dates_df$month, dates_df$day, sep = '-')
vec_time
rasters from netcdf files
library(oceanmap)
sst <- nc2raster(nc, varname = 'sosstsst')
Calculate the mean of all layers of sea surface temperature
mean_nc2 <- calc(sst, fun = mean)
Map mean sea surface temperature
extent(mean_nc2) <- extent(-180, 180, -77, 90)
v(mean_nc2, replace.na= F, v_contour = T, fill = T,
cb.title = "(\u00B0C)", cbpos='r', )#cb= colorbar|RasterStack object