-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostpro_icon_plot_irr_area_VARS_mnmx.py
More file actions
92 lines (72 loc) · 3.6 KB
/
postpro_icon_plot_irr_area_VARS_mnmx.py
File metadata and controls
92 lines (72 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import numpy as np
from netCDF4 import Dataset
import xarray as xr
import pandas as pd
from glob import glob
import os
import os.path
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from matplotlib import colors
# Plots all variables only for irrigated areas daymax and min (only T_2M) CHANGE timec
# Output directory
save_to_path =os.path.abspath('/hpc/uwork/extjroqu/bacy_plots/p01_postprocessing/plots/daily_weight')
# It opens files, grid and extpar
timec = "daymax" # daymin daymax
country = "ALL" # ALL IP
fontlab = 16
dr_data = "/hpc/uwork/extjroqu/bacy_plots/icon-nwp0_results/mean_data_cdo/"
dr_extra = "/hpc/uhome/extjroqu/bacy_data/"
gridfile = Dataset(dr_extra+"griddir/icon_grid_9999_R13B07_L.nc") #3km eu domain
clon, clat = np.rad2deg( gridfile.variables["clon"]) , np.rad2deg( gridfile.variables["clat"]) #[::-1] )
####################### i_var has lon lat with irrigation grids #######################
var_list = ["T_2M"]
for v in var_list:
# It opens files, grid and extpar
varname = v
dset2 = xr.open_dataset(dr_data+"diff_fc06_"+varname+"_"+timec+"_irri.nc")
dset1 = xr.open_dataset(dr_data+"diff_sat03_"+varname+"_"+timec+"_irri.nc")
dset3 = xr.open_dataset(dr_data+"diff_24h_11_"+varname+"_"+timec+"_irri.nc")
dset4 = xr.open_dataset(dr_data+"diff_24h_05_"+varname+"_"+timec+"_irri.nc")
dset5 = xr.open_dataset(dr_data+"diff_24h_02_"+varname+"_"+timec+"_irri.nc")
exp_size = 5
exp_coords = np.linspace(1, exp_size, exp_size)
time_x = dset1.step.size #if time is 14 weeks
time_coords = dset1.step.values #if time is 14 weeks
concat_mean = xr.zeros_like(xr.DataArray(np.empty([exp_size,time_x]), coords=([('exp', exp_coords),('time',time_coords)])))
concat_mean['time'] = dset1.coords['step'].values
ds_list = [dset1, dset2, dset3, dset4, dset5]
for d in range(exp_size):
if timec == 'daymax':
concat_mean[d,:] = ds_list[d]["mx2t"]
concat_mean.attrs['units'] = dset1["mx2t"].units
elif timec == 'daymin':
concat_mean[d,:] = ds_list[d]["mn2t"]
concat_mean.attrs['units'] = dset1["mn2t"].units
else:
print("No varname")
df_w = pd.DataFrame(concat_mean, index=['SAT','FC','MIT','MSP','MFR'], columns=concat_mean.time.values)
# Plot the data for other variables
df_w_transposed = df_w.T
# Specify custom colors, second option colorblind friendly
#custom_colors = ['red', 'blue','purple', 'green', 'orange']
custom_colors = ["#D55E00", "#0072B2","#984ea3" ,"#009E73", "#E69F00"]
# Plot no STD
fig, ax = plt.subplots(figsize=(10, 4))
for column, color in zip(df_w_transposed.columns, custom_colors):
plt.plot(df_w_transposed.index, df_w_transposed[column], label=column, color=color)
plt.legend(loc='lower left',bbox_to_anchor =(0, 0),fontsize=14)
plt.grid()
plt.xticks(rotation=45, ha='right', fontsize=fontlab)
plt.ylabel("\u0394 "+str(varname)+" ("+str(concat_mean.units)+")", fontsize=fontlab)
plt.tight_layout() #Remove excess of white space
plt.savefig(os.path.join(save_to_path,"diff_merged_"+str(varname)+"_"+str(timec)+"_irri_n.png"),dpi=300)
plt.close()
print("Variable MAX for "+str(varname)+": ",concat_mean.max(dim='time').values)
print("Variable MIN for "+str(varname)+": ",concat_mean.min(dim='time').values)
print("Variable MEAN for "+str(varname)+": ",concat_mean.mean(dim='time').values)
print("DONE plot irr mean for all exp "+str(timec)+" "+str(varname))
print("DONE with all variables!")