Sys.setenv(LANG = "en")
Sys.setlocale("LC_TIME","en_GB")
library(startR)
library(s2dverification)
library(abind)
library(CSTools)
library(zeallot)
library(s2dv)
library(easyVerification)
library(ClimProjDiags)
library(ggplot2)



Lat <- data0$hcst$coords$latitude
Lon <- data0$hcst$coords$longitude

PlotEquiMap(aug03,Lon,Lat,coast_width=1.5, filled.continents = FALSE, brks = 21, bar_limits = c(-10,10), toptitle = ("blablabla"),width=10, height= 10,units = "Pa", country.borders=TRUE, bar_extra_margi\
n = c(1, 0, 1, 0), fileout = "tas_cat_130803.png",triangle_ends = c(TRUE,TRUE),intylat=10,intxlon=10)


#ggsave("subseasonal_BCN_heatwave_tasmax_bss90.png", plot, width = 7, height = 5)

path <- "/esarchive/scratch/ptrascas/R/sunset/tas_clim/era5land_monthlymean.nc"
path <- paste0(path)
lons.min <- -50
lons.max <- 5
lats.min <- 35
lats.max <- 45
clim <- Start(dat = path, 
     		  var='tas', 
		  lat = values(list(lats.min, lats.max)),
                  lat_reorder = Sort(decreasing = TRUE),
                  lon = values(list(lons.min, lons.max)),
                  lon_reorder = CircularSort(-180, 180),
                  synonims = list(lat=c('lat','latitude'),
                  lon=c('lon','longitude')),
                  return_vars = list(lat = 'dat',
                  lon = 'dat'),
                  split_multiselected_dims = TRUE,
                  retrieve = TRUE)

clim <- as.s2dv_cube(clim)
clim$data <- clim$data[1,1,,] - 273.15

path <- "/esarchive/recon/ecmwf/era5land/daily_mean/tas_f1h/tas_202308.nc"
path <- paste0(path)
day <- Start(dat = path,
                  var='tas',
		  time = 'all',
                  lat = values(list(lats.min, lats.max)),
                  lat_reorder = Sort(decreasing = TRUE),
                  lon = values(list(lons.min, lons.max)),
                  lon_reorder = CircularSort(-180, 180),
                  synonims = list(lat=c('lat','latitude'),
                  lon=c('lon','longitude')),
                  return_vars = list(lat = 'dat',
                  lon = 'dat'),
                  split_multiselected_dims = TRUE,
                  retrieve = TRUE)

day <- as.s2dv_cube(day)

day$data <- day$data[1,1,23,,]-273.15

Lat <- clim$coords$lat
Lon <- clim$coords$lon

anomaly <- day$data-clim$data

PlotEquiMap(anomaly,Lon,Lat,coast_width=1.5, filled.continents = FALSE, brks = 21, bar_limits = c(-10,10),
			toptitle = ("Anomalia de temperatura 23/08/23"),width=10, height= 10,units = "C", 
			country.borders=TRUE, bar_extra_margin = c(1, 0, 1, 0), 
			fileout = "tas_iberia_230823.png",
			triangle_ends = c(TRUE,TRUE),intylat=10,intxlon=10)

