This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(countrycode) | |
library(scico) | |
library(patchwork) | |
library(ggtext) | |
mapdata <- map_data("world") |> | |
mutate(iso3_code = countrycode(region, "country.name", "iso3c")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# %% | |
import xarray as xr | |
import pandas as pd | |
# %% | |
df = ( | |
xr.open_mfdataset("C:/Users/matte/data/CPC/preci*") | |
.resample(time = "MS").sum() | |
.load() | |
) | |
# %% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(lubridate) | |
library(tidyverse) | |
library(zoo) | |
read_station <- function(filename) { | |
read_csv(filename, | |
col_types = cols(DATE = col_datetime(format = "%Y%m%d")), | |
skip = 20 | |
) | |
} | |
station_files <- c( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
color_palette = c( | |
'Biomass' = '#7daf4bff', | |
'Coal' = '#af4b91b2', | |
'Gas' = '#d7642dff', | |
'Hydro-power' = '#00a0e1ff', | |
'Nuclear' = '#466eb4ff', | |
'Oil' = '#af4b91ff', | |
'Other' = '#b9c33799', | |
'Solar' = '#e6a532ff', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Before you start install all the referenced packages below | |
# including the development release of ecmwfr you will also | |
# need the rnaturalearthdata in addition to the normal package | |
# To run the code copy and paste segments as this is still | |
# rough around the edges and requires user interaction to | |
# set your CDS API key. | |
# load libraries | |
if(!require(devtools)){install.packages("devtools")} | |
devtools::install_github("khufkens/ecmwfr") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
df <- read_csv("ItalianCovidData/Daily Covis19 Italian Data Cumulative") %>% | |
select(1:5) %>% | |
gather(type, value, -Date, -Region) %>% | |
group_by(Date, Region) | |
total <- df %>% | |
dplyr::filter(Date == max(df$Date)) %>% | |
group_by( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(eurostat) | |
library(lubridate) | |
n_veih <- get_eurostat("tran_r_vehst") %>% # https://appsso.eurostat.ec.europa.eu/nui/show.do?dataset=tran_r_vehst&lang=en | |
dplyr::filter( | |
str_length(geo) == 2, | |
unit == "P_THAB", # NR: Number, P_THAB: Per thousand inhabitants | |
vehicle == "CAR" # Passenger cars | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import numpy as np | |
import pandas as pd | |
from pyproj import Proj, transform | |
import os.path | |
# Data for projections | |
# CHECK WITH https://epsg.io/transform#s_srs=4326&t_srs=3035&x=17.6830006&y=48.4970017 | |
inProj = Proj(init='epsg:4326') | |
outProj = Proj(init='epsg:3035') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ncdf4) | |
# files are 229x161x8760 | |
FILE_1 = nc_open('/emhires-data/data-warehouse/gridded/ERA5/era5-hourly-100m_v_component_of_wind-2018.europe.nc') | |
FILE_2 = nc_open('/emhires-data/data-warehouse/gridded/ERA5/era5-hourly-10m_v_component_of_wind-2018.europe.nc') | |
lat = ncvar_get(FILE_1, 'latitude') | |
lon = ncvar_get(FILE_1, 'longitude') | |
data_1 = ncvar_get(FILE_1, 'v100') # 2.5 GB in memory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cdsapi | |
import os | |
c = cdsapi.Client() | |
VARS = ['100m_u_component_of_wind','100m_v_component_of_wind','10m_u_component_of_wind', '10m_v_component_of_wind', '2m_temperature','surface_solar_radiation_downward_clear_sky','surface_solar_radiation_downwards', '2m_dewpoint_temperature','mean_sea_level_pressure'] | |
YEARS = [x for x in map(str, range(1979, 2019))] | |
for V in VARS: |
NewerOlder