-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting.py
More file actions
8196 lines (7404 loc) · 413 KB
/
plotting.py
File metadata and controls
8196 lines (7404 loc) · 413 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import platform
if platform.system() == 'Linux':
import matplotlib
matplotlib.use('TkAgg')
matplotlib.use('QT4Agg')
import os
import xarray as xr
import pandas as pd
import numpy as np
import datetime
import seaborn as sns
import math as math
import matplotlib.pyplot as plt
from sklearn import linear_model
from mpl_toolkits.basemap import Basemap
from matplotlib.colors import LogNorm
from pyldas.grids import EASE2
from pyldas.interface import LDAS_io
from bat_pyldas.functions import *
from scipy.stats import zscore
import scipy.interpolate
from statsmodels.nonparametric.smoothers_lowess import lowess as sm_lowess
from scipy.interpolate import interp2d
from validation_good_practice.ancillary import metrics
import sys
from scipy import stats
import pymannkendall as mk
import copy
from sympy import symbols, diff
import statsmodels.api as sm
# gdal, gdalconst, osr
def assign_units(var):
# Function to assign units to the variable 'var'.
if var == 'srfexc' or var == 'rzexc' or var == 'catdef':
unit = '[mm]'
elif var == 'ar1' or var == 'ar2':
unit = '[-]'
elif var == 'sfmc' or var == 'rzmc':
unit = '[m^3/m^3]'
elif var == 'tsurf' or var == 'tp1' or var == 'tpN':
unit = '[K]'
elif var == 'shflux' or var == 'lhflux':
unit = '[W/m^2]'
elif var == 'evap' or var == 'runoff':
unit = '[mm/day]'
elif var == 'zbar':
unit = '[m]'
else:
unit = ['not_known']
return (unit)
def plot_all_variables_temporal_moments(exp, domain, root, outpath, param='daily'):
# plot temporal mean and standard deviation of variables
outpath = os.path.join(outpath, exp, 'maps', 'stats')
if not os.path.exists(outpath):
os.makedirs(outpath, exist_ok=True)
io = LDAS_io(param, exp=exp, domain=domain, root=root)
[lons, lats, llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon] = setup_grid_grid_for_plot(io)
try:
m1 = xr.open_dataset(os.path.join(root, exp, 'output_postprocessed/', param + '_mean.nc'))
except:
m1 = io.timeseries.mean(axis=0)
try:
m2 = xr.open_dataset(os.path.join(root, exp, 'output_postprocessed/', param + '_std.nc'))
except:
m2 = io.timeseries.std(axis=0)
# mean
# m1 = io.timeseries.mean(axis=0)
for varname, da in m1.data_vars.items():
tmp_data = da
# cmin = 0
# cmax = 0.7
cmin = None
cmax = None
plot_title = varname
if varname == 'zbar':
cmin = -1.2
cmax = -0.05
if varname == 'runoff':
cmin = 0
cmax = 5
if varname == 'evap':
cmin = 0
cmax = 5
# if varname=='tp1':
# cmin=267
# cmax=295
# if varname=='fsw_change':
# tmp_data = tmp_data*365*6*24*60*60
plot_title = varname
# if varname=='fsw_change':
# plot_title='cumulative sum of fsw_change [mm]'
fname = varname + '_mean'
# plot_title='zbar [m]'
figure_single_default(data=tmp_data, lons=lons, lats=lats, cmin=cmin, cmax=cmax, llcrnrlat=llcrnrlat,
urcrnrlat=urcrnrlat,
llcrnrlon=llcrnrlon, urcrnrlon=urcrnrlon, outpath=outpath, exp=exp, fname=fname,
plot_title=plot_title)
# m2 = io.timeseries.std(axis=0)
for varname, da in m2.data_vars.items():
tmp_data = da
# cmin = 0
# cmax = 0.7
cmin = None
cmax = None
fname = varname + '_std'
# plot_title='zbar [m]'
plot_title = varname
figure_single_default(data=tmp_data, lons=lons, lats=lats, cmin=cmin, cmax=cmax, llcrnrlat=llcrnrlat,
urcrnrlat=urcrnrlat,
llcrnrlon=llcrnrlon, urcrnrlon=urcrnrlon, outpath=outpath, exp=exp, fname=fname,
plot_title=plot_title)
def plot_all_temporal_maps(exp, domain, root, outpath, param='daily'):
# plot temporal mean and standard deviation of the paper variables
def create_figure_maps(exp, domain, root, outpath):
outpath = os.path.join(outpath, 'maps')
if not os.path.exists(outpath):
os.makedirs(outpath, exist_ok=True)
io = LDAS_io(param, exp=exp, domain=domain, root=root)
[lons, lats, llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon] = setup_grid_grid_for_plot(io)
# m1 is the mean nc file
try:
m1 = xr.open_dataset(os.path.join(root, exp, 'output_postprocessed/', param + '_mean.nc'))
except:
m1 = io.timeseries.mean(axis=0)
# m2 is the std nc files
try:
m2 = xr.open_dataset(os.path.join(root, exp, 'output_postprocessed/', param + '_std.nc'))
except:
m2 = io.timeseries.std(axis=0)
# read in the catparam to use poros as a filter and creat masked data array of poros
params = LDAS_io(exp=exp, domain=domain, root=root).read_params('catparam')
# land fraction, if more than 0
frac_cell = io.grid.tilecoord.frac_cell.values
par = 'poros'
tc = io.grid.tilecoord
tg = io.grid.tilegrids
params[par].values[np.all(np.vstack((frac_cell < 0.95, params['poros'].values > 0.65)), axis=0)] = 1.0
params[par].values[params['poros'].values < 0.65] = np.nan
params[par].values[
np.all(np.vstack((params['poros'].values < 0.95, params['poros'].values > 0.65)), axis=0)] = 1.0
img = np.full(lons.shape, np.nan)
img[tc.j_indg.values, tc.i_indg.values] = params[par].values
data = np.ma.masked_invalid(img)
maskt = np.ma.getmask(data)
if exp[:2] == 'IN':
figsize = (30, 20)
else:
figsize = (25, 25)
runoff = m1.data_vars['runoff']
Rainf = m1.data_vars['Rainf']
lhflux = m1.data_vars['lhflux']
LWdown = m1.data_vars['LWdown']
SWdown = m1.data_vars['SWdown']
lwup = m1.data_vars['lwup']
swup = m1.data_vars['swup']
shflux = m1.data_vars['shflux']
Rnet = (LWdown + SWdown) - (swup + lwup)
RP_eff = runoff / Rainf
EReff = lhflux / Rnet
BR = shflux / lhflux
zbar = m1.data_vars['zbar']
sfmc = m1.data_vars['sfmc']
variables = ['zbar', 'sfmc', 'RP_eff', 'EReff', 'BR', 'runoff', 'Rainf', 'Rnet', 'lhflux']
# plots for zbar and
# variables = ['zbar', 'sfmc']
for i in variables:
da = eval(i)
varname = i
tmp_data = da
masked_var = np.ma.masked_array(da, mask=maskt)
mean = np.mean(masked_var)
mean = np.round(mean, 2)
sd = np.std(masked_var)
sd = np.round(sd, 2)
plt_img = np.ma.masked_invalid(masked_var)
fname = exp + '_' + varname + '_mean'
plot_title = varname + '_mean, m = ' + str(mean) + ', sd = ' + str(sd)
outpath_mean = outpath + '_mean'
if varname == 'zbar':
if ('TN' in exp) or ('TD' in exp):
cmin = -1.2
cmax = 0.0
else:
cmin = -5.0
cmax = 1.0
elif varname == 'sfmc':
if ('TN' in exp) or ('TD' in exp):
cmin = 0.4
cmax = 0.8
else:
cmin = 0.4
cmax = 0.8
elif varname == 'RP_eff':
cmin = 0.0
cmax = 0.7
elif varname == 'EReff':
cmin = 0.4
cmax = 1.0
elif varname == 'BR':
cmin = 0.0
cmax = 0.6
else:
cmin = None
cmax = None
if varname == 'BR':
figure_single_default(data=plt_img, lons=lons, lats=lats, cmin=cmin, cmax=cmax, llcrnrlat=llcrnrlat,
urcrnrlat=urcrnrlat, llcrnrlon=llcrnrlon, urcrnrlon=urcrnrlon,
outpath=outpath_mean, exp=exp, fname=fname, plot_title=plot_title,
cmap='coolwarm')
else:
figure_single_default(data=plt_img, lons=lons, lats=lats, cmin=cmin, cmax=cmax, llcrnrlat=llcrnrlat,
urcrnrlat=urcrnrlat, llcrnrlon=llcrnrlon, urcrnrlon=urcrnrlon,
outpath=outpath_mean, exp=exp, fname=fname, plot_title=plot_title)
runoff = m2.data_vars['runoff']
Rainf = m2.data_vars['Rainf']
evap = m2.data_vars['evap']
LWdown = m2.data_vars['LWdown']
SWdown = m2.data_vars['SWdown']
lwup = m2.data_vars['lwup']
swup = m2.data_vars['swup']
shflux = m2.data_vars['shflux']
Rnet = (LWdown + SWdown) - (swup + lwup)
RP_eff = runoff / Rainf
EReff = evap / Rnet
BR = shflux / evap
zbar = m2.data_vars['zbar']
sfmc = m2.data_vars['sfmc']
variables = ['zbar', 'sfmc']
# standard deviation plots only for sfmc and WTD
for i in variables:
da = eval(i)
varname = i
tmp_data = da
masked_var = np.ma.masked_array(da, mask=maskt)
mean = np.mean(masked_var)
mean = np.round(mean, 2)
sd = np.std(masked_var)
sd = np.round(sd, 2)
plt_img = np.ma.masked_invalid(masked_var)
fname = exp + '_' + varname + '_std'
plot_title = varname + '_std, m = ' + str(mean) + ', sd = ' + str(sd)
outpath_sd = outpath + '_sd'
if varname == 'zbar':
if ('TN' in exp) or ('TD' in exp):
cmin = 0.1
cmax = 0.6
else:
cmin = 0.5
cmax = 2.0
elif varname == 'sfmc':
if ('TN' in exp) or ('TD' in exp):
cmin = 0.00
cmax = 0.14
else:
cmin = 0.00
cmax = 0.14
figure_single_default(data=plt_img, lons=lons, lats=lats, cmin=cmin, cmax=cmax, llcrnrlat=llcrnrlat,
urcrnrlat=urcrnrlat, llcrnrlon=llcrnrlon, urcrnrlon=urcrnrlon, outpath=outpath_sd,
exp=exp, fname=fname, plot_title=plot_title, cmap='coolwarm')
# SA TN
root = '/staging/leuven/stg_00024/OUTPUT/sebastiana'
exp = 'SAMERICA_M09_PEATCLSMTN_v01'
create_figure_maps(exp, domain, root, outpath)
# SA CLSM
exp = 'SAMERICA_M09_CLSM_v01'
create_figure_maps(exp, domain, root, outpath)
# CO
exp = 'CONGO_M09_PEATCLSMTN_v01'
create_figure_maps(exp, domain, root, outpath)
# CO
exp = 'CONGO_M09_CLSM_v01'
create_figure_maps(exp, domain, root, outpath)
# IN TN
exp = 'INDONESIA_M09_PEATCLSMTN_v01'
create_figure_maps(exp, domain, root, outpath)
# IN TD
exp = 'INDONESIA_M09_PEATCLSMTD_v01'
create_figure_maps(exp, domain, root, outpath)
# IN CLSM
exp = 'INDONESIA_M09_CLSM_v01'
create_figure_maps(exp, domain, root, outpath)
def plot_catparams(exp, domain, root, outpath):
outpath = os.path.join(outpath, exp, 'maps', 'catparam')
if not os.path.exists(outpath):
os.makedirs(outpath, exist_ok=True)
io = LDAS_io('daily', exp=exp, domain=domain, root=root)
[lons, lats, llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon] = setup_grid_grid_for_plot(io)
tc = io.grid.tilecoord
tg = io.grid.tilegrids
params = LDAS_io(exp=exp, domain=domain, root=root).read_params('catparam')
for param in params:
img = np.full(lons.shape, np.nan)
img[tc.j_indg.values, tc.i_indg.values] = params[param].values
data = np.ma.masked_invalid(img)
fname = param
# cmin cmax, if not defined determined based on data
if ((param == "poros") | (param == "poros30")):
cmin = 0
cmax = 0.92
else:
cmin = None
cmax = None
figure_single_default(data=data, lons=lons, lats=lats, cmin=cmin, cmax=cmax, llcrnrlat=llcrnrlat,
urcrnrlat=urcrnrlat,
llcrnrlon=llcrnrlon, urcrnrlon=urcrnrlon, outpath=outpath, exp=exp, fname=fname,
plot_title=param)
def ToGeoTiff_catparams(exp, domain, root, outpath):
import pyproj
import gdal
from osgeo import osr
outpath = os.path.join(outpath, exp, 'maps', 'catparam')
if not os.path.exists(outpath):
os.makedirs(outpath, exist_ok=True)
io = LDAS_io('daily', exp=exp, domain=domain, root=root)
[lons, lats, llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon] = setup_grid_grid_for_plot(io)
tc = io.grid.tilecoord
tg = io.grid.tilegrids
params = LDAS_io(exp=exp, domain=domain, root=root).read_params('catparam')
ease = pyproj.Proj(("+proj=cea +lat_0=0 +lon_0=0 +lat_ts=30 "
"+x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m"))
x_min, y_max = ease(io.grid.tilegrids['ll_lon']['domain'], io.grid.tilegrids['ur_lat']['domain'])
x_min = x_min
y_max = y_max
for param in params:
if param == "poros":
img = np.full(lons.shape, np.nan)
img[tc.j_indg.values, tc.i_indg.values] = params[param].values
data = np.ma.masked_invalid(img)
drv = gdal.GetDriverByName("GTiff")
ds = drv.Create(outpath + "/" + param + ".tif", data.shape[1], data.shape[0], 1, gdal.GDT_Float32)
x_resolution = 9008.055210146
y_resolution = -9008.055210146
x_skew = 0
y_skew = 0
srs = osr.SpatialReference()
srs.ImportFromEPSG(6933)
ds.SetProjection(srs.ExportToWkt())
# The order of input arguments in this tuple is weired, but this is correct.
ds.SetGeoTransform((x_min, x_resolution, x_skew, y_max, y_skew, y_resolution))
ds.GetRasterBand(1).WriteArray(data)
# output_raster = outpath+"/"+param+"_WGS84.tif"
# srs2 = osr.SpatialReference()
# srs2.ImportFromEPSG(4326)
# gdal.Warp(output_raster,ds,dstSRS=srs2)
def plot_skillmetrics_comparison_et(et_obs, et_mod, ee_obs, ee_mod, br_obs, br_mod, rn_obs, rn_mod, sh_obs, sh_mod,
le_obs, le_mod, zbar_mod, eveg_mod, esoi_mod, eint_mod, wtd_obs, ghflux_mod,
Psurf_mod, Tair_mod, Tair_obs, AR1, AR2, AR4, sfmc, rzmc, srfexc, rzexc, catdef,
Qair, vpd_obs, Wind, exp, outpath):
INDEX = et_obs.columns
COL = ['bias (m)', 'ubRMSD (m)', 'Pearson_R (-)', 'RMSD (m)', 'abs_bias (m)']
df_metrics = pd.DataFrame(index=INDEX, columns=COL, dtype=float)
for c, site in enumerate(et_obs.columns):
df_tmp_et = pd.concat((et_obs[site], et_mod[site]), axis=1)
df_tmp_et.columns = ['data_obs', 'data_mod']
# this is done again to use in the skill metrics calculation, else transformations occur in original data
df_tmp2_et = pd.concat((et_obs[site], et_mod[site]), axis=1)
df_tmp2_et.columns = ['data_obs', 'data_mod']
df_tmp_ee = pd.concat((ee_obs[site], ee_mod[site]), axis=1)
df_tmp_ee.columns = ['data_obs', 'data_mod']
df_tmp_br = pd.concat((br_obs[site], br_mod[site]), axis=1)
df_tmp_br.columns = ['data_obs', 'data_mod']
df_tmp_rn = pd.concat((rn_obs[site], rn_mod[site]), axis=1)
df_tmp_rn.columns = ['data_obs', 'data_mod']
df_tmp2_rn = pd.concat((rn_obs[site], rn_mod[site]), axis=1)
df_tmp2_rn.columns = ['data_obs', 'data_mod']
df_tmp_sh = pd.concat((sh_obs[site], sh_mod[site]), axis=1)
df_tmp_sh.columns = ['data_obs', 'data_mod']
df_tmp_le = pd.concat((le_obs[site], le_mod[site]), axis=1)
df_tmp_le.columns = ['data_obs', 'data_mod']
"""metric calculation overall"""
# metric calculation with back-up df
bias_site = metrics.bias(df_tmp2_et) # Bias = bias_site[0]
ubRMSD_site = metrics.ubRMSD(df_tmp2_et) # ubRMSD = ubRMSD_site[0]
pearson_R_site = metrics.Pearson_R(df_tmp2_et) # Pearson_R = pearson_R_site[0]
RMSD_site = (ubRMSD_site[0] ** 2 + bias_site[0] ** 2) ** 0.5
abs_bias_site = bias_site.abs()
# abs_bias_site_value = abs(abs_bias_site)
# abs_bias_site = abs_bias_site('bias').update(abs_bias_site_value('bias'))
# Save metrics in df_metrics.
df_metrics.loc[site]['bias (mm/day)'] = bias_site[0]
df_metrics.loc[site]['ubRMSD (mm/day)'] = ubRMSD_site[0]
df_metrics.loc[site]['Pearson_R (-)'] = pearson_R_site[0]
df_metrics.loc[site]['RMSD (mm/day)'] = RMSD_site
df_metrics.loc[site]['abs_bias (mm/day)'] = abs_bias_site[0]
'''plotting et, zscore, ee, br and seperate plot for overall skillmetrics'''
# Create x-axis matching in situ data, for plotting time series
x_start_et = df_tmp2_et.index[0] # Start a-axis with the first day with an observed wtd value.
x_end_et = df_tmp2_et.index[-1] # End a-axis with the last day with an observed wtd value.
Xlim_wtd = [x_start_et, x_end_et]
Xlim_wtd_e = [x_start_et, df_tmp2_et.index[-191]]
# xlim to check only the first year of data
# Xlim_wtd = [df_tmp2_et.index[365+365], df_tmp2_et.index[365+365+364]]
# Calculate z-score for the time series.
df_zscore = df_tmp2_et.apply(zscore)
# define color based on where it is stored/which model run it uses
if '/Northern/' in outpath:
color = ['darkorange', '#1f77b4']
elif '/CLSM/' in outpath:
color = ['dimgray', '#1f77b4']
elif '/Drained' in outpath:
color = ['m', '#1f77b4']
elif '/Natural' in outpath:
color = ['g', '#1f77b4']
elif 'CLSMTN' in exp:
color = ['g', '#1f77b4']
elif 'CLSMTD' in exp:
color = ['m', '#1f77b4']
else:
color = ['#1f77b4', '#1f77b4']
# figures for the paper
fontsize = 24
df_tmp_et = df_tmp_et[['data_mod', 'data_obs']]
df_tmp_et.plot(figsize=(20, 5), fontsize=fontsize, style=['-', '.'], color=color, linewidth=2.5, markersize=6.5,
xlim=Xlim_wtd, legend=False)
plt.ylabel('ET (mm/day)', fontsize=fontsize)
plt.tick_params(axis='x', which='minor', bottom=False, top=False, labelbottom=False) # minor xticks
plt.tick_params(axis='x', which='major', bottom=True, top=False, labelbottom=True) # minor xticks
plt.ylim([0, 8])
plt.tight_layout()
fname = site + '_' + exp
if 'TD' in exp:
fname_long = os.path.join(
'/data/leuven/324/vsc32460/FIG/in_situ_comparison/paper/timeseries_ET/' + fname + '_TD' + '.png')
elif 'TN' in exp:
fname_long = os.path.join(
'/data/leuven/324/vsc32460/FIG/in_situ_comparison/paper/timeseries_ET/' + fname + '.png')
else:
fname_long = os.path.join(
'/data/leuven/324/vsc32460/FIG/in_situ_comparison/paper/timeseries_ET/' + fname + '_CLSM' + '.png')
plt.savefig(fname_long, dpi=350)
plt.close()
# fig1
fig1 = plt.figure(figsize=(16, 8.5))
fontsize = 12
ax1 = plt.subplot2grid((2, 1), (0, 0), rowspan=1, fig=None)
df_tmp_et = df_tmp_et[['data_mod', 'data_obs']]
df_tmp_et.plot(ax=ax1, fontsize=fontsize, style=['-', '.'], color=color, linewidth=0.9, markersize=3,
xlim=Xlim_wtd, ylim=[0, 7.5])
plt.ylabel('ET (mm/day)')
Title = site + '\n' + ' bias = ' + str(bias_site[0]) + ' (mm/day), ubRMSD = ' + str(
ubRMSD_site[0]) + '(mm/day), Pearson_R = ' + str(pearson_R_site[0]) + '(-), RMSD = ' + str(
RMSD_site) + '(mm/day), abs_bias = ' + str(abs_bias_site[0]) + ' (mm/day)'
plt.title(Title)
ax2 = plt.subplot2grid((2, 1), (1, 0), rowspan=1, fig=None)
df_zscore = df_zscore[['data_mod', 'data_obs']]
df_zscore.plot(ax=ax2, fontsize=fontsize, style=['-', '-'], color=color, linewidth=0.9, xlim=Xlim_wtd)
plt.ylabel('z-score')
plt.tight_layout()
fname = site
fname_long = os.path.join(outpath + '/et' + fname + '.png')
plt.savefig(fname_long, dpi=150)
plt.close()
# fig2
fig2 = plt.figure(figsize=(16, 8.5))
fontsize = 12
ax3 = plt.subplot2grid((3, 1), (0, 0), rowspan=1, fig=None)
df_tmp_ee = df_tmp_ee[['data_mod', 'data_obs']]
df_tmp_ee.plot(ax=ax3, fontsize=fontsize, style=['-', '.'], color=color, linewidth=0.9, markersize=3.8,
xlim=Xlim_wtd)
plt.ylabel('Evapotranspiration Efficiency (-)')
ax4 = plt.subplot2grid((3, 1), (1, 0), rowspan=1, fig=None)
df_tmp_le = df_tmp_le[['data_mod', 'data_obs']]
df_tmp_le.plot(ax=ax4, fontsize=fontsize, style=['-', '.'], color=color, linewidth=0.9, markersize=3.8,
xlim=Xlim_wtd)
plt.ylabel('Latent heat (W/m$^{2}$)')
ax5 = plt.subplot2grid((3, 1), (2, 0), rowspan=1, fig=None)
df_tmp_rn = df_tmp_rn[['data_mod', 'data_obs']]
df_tmp_rn.plot(ax=ax5, fontsize=fontsize, style=['-', '-'], color=color, linewidth=0.9, markersize=3.8,
xlim=Xlim_wtd)
plt.ylabel('Rn (W/m$^{2}$)')
plt.tight_layout()
fname = site
fname_long = os.path.join(outpath + '/ee' + fname + '.png')
plt.savefig(fname_long, dpi=150)
plt.close()
# fig3
fig3 = plt.figure(figsize=(16, 8.5))
fontsize = 12
ax6 = plt.subplot2grid((3, 1), (0, 0), rowspan=1, fig=None)
df_tmp_br = df_tmp_br[['data_mod', 'data_obs']]
df_tmp_br.plot(ax=ax6, fontsize=fontsize, style=['-', '.'], color=color, linewidth=0.9, markersize=3.8,
xlim=Xlim_wtd, ylim=[-0.2, 1.5])
plt.ylabel('Bowen Ratio (-)')
ax8 = plt.subplot2grid((3, 1), (2, 0), rowspan=1, fig=None)
df_tmp_le = df_tmp_le[['data_mod', 'data_obs']]
df_tmp_le.plot(ax=ax8, fontsize=fontsize, style=['-', '.'], color=color, linewidth=0.9, markersize=3.8,
xlim=Xlim_wtd)
plt.ylabel('Latent heat (W/m$^{2}$)')
ax7 = plt.subplot2grid((3, 1), (1, 0), rowspan=1, fig=None)
df_tmp_sh = df_tmp_sh[['data_mod', 'data_obs']]
df_tmp_sh.plot(ax=ax7, fontsize=fontsize, style=['-', '.'], color=color, linewidth=0.9, markersize=3.8,
xlim=Xlim_wtd)
plt.ylabel('Sensible heat (W/m$^{2}$)')
plt.tight_layout()
fname = site
fname_long = os.path.join(outpath + '/br' + fname + '.png')
plt.savefig(fname_long, dpi=150)
plt.close()
# fig4
fig4 = plt.figure(figsize=(20, 7.5))
fontsize = 12
# xlim to check only one specific year or period
# Xlim_wtd = [df_tmp2_et.index[365], df_tmp2_et.index[365+365+365]]
ax1 = plt.subplot2grid((2, 2), (0, 0), rowspan=1, colspan=1, fig=None)
df_tmp_ratios = df_tmp_ee.merge(df_tmp_br, left_index=True, right_index=True)
df_tmp_ratios.plot(ax=ax1, y=['data_mod_x', 'data_mod_y'], fontsize=fontsize, style=['-', '-'],
color=['darkorange', 'darkmagenta'], linewidth=0.9,
xlim=Xlim_wtd, label=['Evapotranspiration Efficiency ', 'Bowen Ratio'])
plt.ylabel('(-)')
ax2 = plt.subplot2grid((2, 2), (1, 0), rowspan=1, colspan=1, fig=None)
df_tmp_hf = df_tmp_le.merge(df_tmp_sh, left_index=True, right_index=True)
df_tmp_hf = df_tmp_hf.merge(df_tmp_rn, left_index=True, right_index=True)
df_tmp_hf.plot(ax=ax2, y=['data_mod', 'data_mod_x', 'data_mod_y'], fontsize=fontsize, style=['-', '-', '-'],
color=['gold', 'crimson', 'mediumblue'], linewidth=0.9,
xlim=Xlim_wtd, label=['Net Radiation', 'Latent Heat', 'Sensible Heat'])
plt.ylabel('(W/m$^{2}$)')
plt.legend()
ax3 = plt.subplot2grid((2, 2), (0, 1), rowspan=1, colspan=1, fig=None)
df_tmp_ratios.plot(ax=ax3, y=['data_obs_x', 'data_obs_y'], fontsize=fontsize, style=['-', '-'],
color=['darkorange', 'darkmagenta'], linewidth=0.9,
xlim=Xlim_wtd, label=['Evapotranspiration Efficiency ', 'Bowen Ratio'])
plt.ylabel('Evapotranspiration Efficiency (-)')
ax4 = plt.subplot2grid((2, 2), (1, 1), rowspan=1, colspan=1, fig=None)
df_tmp_hf = df_tmp_le.merge(df_tmp_sh, left_index=True, right_index=True)
df_tmp_hf = df_tmp_hf.merge(df_tmp_rn, left_index=True, right_index=True)
df_tmp_hf.plot(ax=ax4, y=['data_obs', 'data_obs_x', 'data_obs_y'], fontsize=fontsize, style=['-', '-', '-'],
color=['gold', 'crimson', 'mediumblue'], linewidth=0.9,
xlim=Xlim_wtd, label=['Net Radiation', 'Latent Heat', 'Sensible Heat'])
plt.ylabel('(W/m$^{2}$)')
plt.legend()
plt.tight_layout()
fname = site
fname_long = os.path.join(outpath + '/heat_fluxes' + fname + '.png')
plt.savefig(fname_long, dpi=150)
plt.close()
# fig5
fig5 = plt.figure(figsize=(26, 12))
fontsize = 12
df_dataframe = pd.concat(
(et_mod[site], eveg_mod[site], esoi_mod[site], eint_mod[site], zbar_mod[site], et_obs[site], wtd_obs[site]),
axis=1, join='inner')
df_dataframe.columns = ['evap', 'eveg', 'esoi', 'eint', 'zbar', 'et_obs', 'wtd_obs']
ax0 = plt.subplot2grid((2, 3), (0, 0), rowspan=1, colspan=1, fig=None)
df_dataframe.plot(ax=ax0, y='et_obs', x='wtd_obs', fontsize=fontsize, style=['.'], color=['#1f77b4'],
markersize=3.5)
plt.ylabel('In situ evapotranspiration (mm/day)', fontsize=22)
plt.xlabel('In situ water table depth (m)', fontsize=22)
plt.legend(fontsize=20)
plt.xlim((-2.3, 0.1))
plt.ylim(1, 8)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
ax10 = plt.subplot2grid((2, 3), (1, 0), rowspan=1, colspan=1, fig=None)
df_dataframe.plot(ax=ax10, y='et_obs', x='zbar', fontsize=fontsize, style=['.'], color=['r'], markersize=3.5)
plt.ylabel('In situ evapotranspiration (mm/day)', fontsize=22)
plt.xlabel('Water table depth (m)', fontsize=22)
plt.legend(fontsize=20)
plt.xlim((-2.3, 0.1))
plt.ylim(1, 8)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
ax1 = plt.subplot2grid((2, 3), (0, 1), rowspan=1, colspan=1, fig=None)
df_dataframe.plot(ax=ax1, y='evap', x='zbar', fontsize=fontsize, style=['.'], color=color, markersize=3.5)
plt.ylabel('Evapotranspiration (mm/day)', fontsize=22)
plt.xlabel('Water table depth (m)', fontsize=22)
plt.legend(fontsize=20)
plt.xlim((-2.3, 0.1))
plt.ylim(1, 8)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
ax2 = plt.subplot2grid((2, 3), (1, 1), rowspan=1, colspan=1, fig=None)
df_dataframe.plot(ax=ax2, y='eveg', x='zbar', fontsize=fontsize, style=['.'], color=color, markersize=3.5)
plt.ylabel('Plant Transpiration (mm/day)', fontsize=22)
plt.xlabel('Water table depth (m)', fontsize=22)
plt.legend(fontsize=20)
plt.xlim((-2.3, 0.1))
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
ax3 = plt.subplot2grid((2, 3), (0, 2), rowspan=1, colspan=1, fig=None)
df_dataframe.plot(ax=ax3, y='esoi', x='zbar', fontsize=fontsize, style=['.'], color=color, markersize=3.5)
plt.ylabel('Soil Evaporation (mm/day)', fontsize=22)
plt.xlabel('Water table depth (m)', fontsize=22)
plt.legend(fontsize=20)
plt.xlim((-2.3, 0.1))
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
ax4 = plt.subplot2grid((2, 3), (1, 2), rowspan=1, colspan=1, fig=None)
df_dataframe.plot(ax=ax4, y='eint', x='zbar', fontsize=fontsize, style=['.'], color=color, markersize=3.5)
plt.ylabel('Interception Evaporation (mm/day)', fontsize=22)
plt.xlabel('Water table depth (m)', fontsize=22)
plt.legend(fontsize=20)
plt.xlim((-2.3, 0.1))
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
plt.tight_layout()
fname = site
fname_long = os.path.join(outpath + '/ETcomponents_wtd' + fname + '.png')
plt.savefig(fname_long, dpi=150)
plt.close()
# calculation of ETpot and normalization plot
# calculation of ETpot according to Maes et al.2017
# Change Tair and rn from Tair_mod to Tair_obs and rn_mod to rn_obs
# Model ETpot!!!!
PM = 'False'
if 'True' in PM: # Penman Monteith based ETpot calculation
Tair_mod[site] = (Tair_mod[
site]) - 273.15 # to calculate everything as °C instead of K, how they do it in Allen et al. 1998 (=FAO)
gc_PM = 42.0 # mm/s
rc_PM = 1000 / gc_PM # s/m
raH = 208 / Wind[site] # s/m because windspeed is m/s
psi = 0.655 * (10e-6) * Psurf_mod[site]
rohcp = (psi * 0.622 * 2.4298) / (1.01 * (Tair_mod[site] + 273) * 0.287)
# VPD_mod calc
SVP = (610 * (10 ** ((7.5 * Tair_mod[site]) / (237.3 + Tair_mod[site]))))
RH = (Qair[site] * Psurf_mod[site]) / (0.622 * SVP) * 100
VPD_mod = ((100 - RH) / 100) * SVP
VPD_mod = pd.Series.to_frame(VPD_mod)
s_teller = (0.6108) * np.exp(((17.27 * Tair_mod[site]) / (Tair_mod[site] + 237.3)))
s_noemer = (Tair_mod[site] + 237.3) ** 2
s = 4098 * (s_teller / s_noemer)
ETpot_mod = (((s * (rn_mod[site] - ghflux_mod[site])) + (rohcp * VPD_mod[site]) / raH) / (
s + psi + (psi * rc_PM / raH))) / 7.3992
# In situ ETpot!!!
Tair_obs[site] = (
Tair_obs[
site]) # to calculate everything as °C instead of K, how they do it in Allen et al. 1998 (=FAO)
psi = 0.655 * (10e-6) * Psurf_mod[site]
rohcp = (psi * 0.622 * 2.4298) / (1.01 * (Tair_obs[site] + 273) * 0.287)
s_teller = (0.6108) * np.exp(((17.27 * Tair_obs[site]) / (Tair_obs[site] + 237.3)))
s_noemer = (Tair_obs[site] + 237.3) ** 2
s = 4098 * (s_teller / s_noemer)
ETpot_obs = (((s * (rn_obs[site] - ghflux_mod[site])) + (rohcp * vpd_obs[site]) / raH) / (
s + psi + (psi * rc_PM / raH))) / 7.3992
else: # Priestley and Taylor based ETpot calculation
# PT parameters
Tair_mod[site] = (Tair_mod[
site]) - 273.15 # to calculate everything as °C instead of K, how they do it in Allen et al. 1998 (=FAO)
alpha_PT = 1.09
psi = 0.655 * (10e-6) * Psurf_mod[site]
# model ETpot
s_teller = (0.6108) * np.exp(((17.27 * Tair_mod[site]) / (Tair_mod[site] + 237.3)))
s_noemer = (Tair_mod[site] + 237.3) ** 2
s = 4098 * (s_teller / s_noemer)
ETpot_mod = (alpha_PT * ((s * (rn_mod[site] - ghflux_mod[site])) / (s + psi))) / 7.3992
# In situ ETpot!
Tair_obs[site] = (
Tair_obs[
site]) # to calculate everything as °C instead of K, how they do it in Allen et al. 1998 (=FAO)
s_teller = (0.6108) * np.exp(((17.27 * Tair_obs[site]) / (Tair_obs[site] + 237.3)))
s_noemer = (Tair_obs[site] + 237.3) ** 2
s = 4098 * (s_teller / s_noemer)
ETpot_obs = (alpha_PT * ((s * (rn_obs[site] - ghflux_mod[site])) / (s + psi))) / 7.3992
# other df calculations
et_obs_used = et_obs[site]
et_mod_used = et_mod[site]
norm_et_mod = et_obs_used / ETpot_mod
norm_et_obs = et_obs_used / ETpot_obs
norm_et_mod_mod = et_mod_used / ETpot_mod
norm_et_mod = pd.Series.to_frame(norm_et_mod)
norm_et_obs = pd.Series.to_frame(norm_et_obs)
norm_et_mod_mod = pd.Series.to_frame(norm_et_mod_mod)
norm_et_wtd_mod = pd.concat([norm_et_mod, wtd_obs[site]], axis=1)
norm_et_wtd_mod.columns = ['et_norm_mod', 'wtd_obs']
norm_et_wtd_mod = norm_et_wtd_mod[
norm_et_wtd_mod['wtd_obs'].notna()] # removes all rows for each column with nan-values in column: wtd_obs
norm_et_wtd_obs = pd.concat([norm_et_obs, wtd_obs[site]], axis=1)
norm_et_wtd_obs.columns = ['et_norm_obs', 'wtd_obs']
norm_et_wtd_obs = norm_et_wtd_obs[
norm_et_wtd_obs['wtd_obs'].notna()] # removes all rows for each column with nan-values in column: wtd_obs
norm_et_wtd_mod_mod = pd.concat([norm_et_mod_mod, zbar_mod[site]], axis=1)
norm_et_wtd_mod_mod.columns = ['et_norm_mod_mod', 'wtd_mod']
norm_et_wtd_mod_mod = norm_et_wtd_mod_mod[
norm_et_wtd_mod_mod['wtd_mod'].notna()]
pot_et_wtd_mod = pd.concat([ETpot_mod, wtd_obs[site]], axis=1)
pot_et_wtd_mod.columns = ['pot_et_mod', 'wtd_obs']
pot_et_wtd_mod = pot_et_wtd_mod[
pot_et_wtd_mod['wtd_obs'].notna()] # removes all rows for each column with nan-values in column: wtd_obs
pot_et_wtd_obs = pd.concat([ETpot_obs, wtd_obs[site]], axis=1)
pot_et_wtd_obs.columns = ['pot_et_obs', 'wtd_obs']
pot_et_wtd_obs = pot_et_wtd_obs[
pot_et_wtd_obs['wtd_obs'].notna()] # removes all rows for each column with nan-values in column: wtd_obs
et_obs_used = pd.Series.to_frame(et_obs_used)
et_mod_used = pd.Series.to_frame(et_mod_used)
ETpot_mod = pd.Series.to_frame(ETpot_mod)
ETpot_obs = pd.Series.to_frame(ETpot_obs)
# if site is 'UndrainedPSF' or 'DrainedPSF':
# norm_et_wtd_obs.to_csv(
# r'/data/leuven/324/vsc32460/FIG/in_situ_comparison/IN/Natural/ET/ETpot_WTD_obs' + site + '.csv',
# index=True, header=True)
# norm_et_wtd_mod.to_csv(
# r'/data/leuven/324/vsc32460/FIG/in_situ_comparison/IN/Natural/ET/ETpot_WTD_mod' + site + '.csv',
# index=True, header=True)
# else:
# print('Not DrainedPSF or UndrainedPSF')
# fig6
fig6 = plt.figure(figsize=(20, 12))
fontsize = 12
# xlim to check only one specific year or period
# Xlim_wtd = [df_tmp2_et.index[365], df_tmp2_et.index[365+365+365]]
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan=1, colspan=1, fig=None)
ETpot_mod.plot(ax=ax1, fontsize=fontsize, style=['-'], color='darkorange', linewidth=0.9, xlim=Xlim_wtd)
plt.ylabel('Model potential ET (mm/day)', fontsize=16)
plt.legend()
plt.ylim([2, 8])
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan=1, colspan=1, fig=None)
et_obs_used.plot(ax=ax2, fontsize=fontsize, style=['-'], color='#1f77b4', linewidth=0.9, xlim=Xlim_wtd)
plt.ylabel('In situ ET \n (mm/day)', fontsize=16)
plt.legend()
ax3 = plt.subplot2grid((3, 1), (2, 0), rowspan=1, colspan=1, fig=None)
norm_et_mod.plot(ax=ax3, fontsize=fontsize, style=['-'], color='darkolivegreen', linewidth=0.9, xlim=Xlim_wtd)
plt.ylabel('Normalized ET with ETpot \n from model (mm/day)', fontsize=16)
plt.legend()
plt.ylim([0.25, 2])
plt.tight_layout()
fname = site
fname_long = os.path.join(outpath + '/ET_mod_timeseries' + fname + '.png')
plt.savefig(fname_long, dpi=150)
plt.close()
# fig7
fig7 = plt.figure(figsize=(20, 12))
fontsize = 12
ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan=1, colspan=1, fig=None)
ETpot_obs.plot(ax=ax1, fontsize=fontsize, style=['-'], color='sandybrown', linewidth=0.9, xlim=Xlim_wtd)
plt.ylabel('In situ potential ET (mm/day)', fontsize=16)
plt.legend()
plt.ylim([2, 8])
ax2 = plt.subplot2grid((3, 1), (1, 0), rowspan=1, colspan=1, fig=None)
et_obs_used.plot(ax=ax2, fontsize=fontsize, style=['-'], color='#1f77b4', linewidth=0.9, xlim=Xlim_wtd)
plt.ylabel('In situ ET \n (mm/day)', fontsize=16)
plt.legend()
ax3 = plt.subplot2grid((3, 1), (2, 0), rowspan=1, colspan=1, fig=None)
norm_et_obs.plot(ax=ax3, fontsize=fontsize, style=['-'], color='limegreen', linewidth=0.9, xlim=Xlim_wtd)
plt.ylabel('Normalized ET with ETpot \n from in situ (mm/day)', fontsize=16)
plt.legend()
plt.ylim([0.25, 2])
plt.tight_layout()
fname = site
fname_long = os.path.join(outpath + '/ET_obs_timeseries' + fname + '.png')
plt.savefig(fname_long, dpi=150)
plt.close()
# fig8
fig8 = plt.figure(figsize=(22, 13))
fontsize = 12
# remove haze and concat modeled to timeframe of observed
exclusion_dates = pd.date_range(start='2006/09/17', end='2006/12/17')
norm_et_wtd_obs = norm_et_wtd_obs.loc[~norm_et_wtd_obs.index.isin(exclusion_dates)]
overlap_check = pd.concat((norm_et_wtd_mod_mod, norm_et_wtd_obs["et_norm_obs"]), axis=1)
norm_et_wtd_mod_mod = overlap_check[overlap_check['et_norm_obs'].notna()]
norm_et_wtd_mod_mod = norm_et_wtd_mod_mod.drop(columns=["et_norm_obs"])
overlap_check = pd.concat((pot_et_wtd_mod, norm_et_wtd_obs["et_norm_obs"]), axis=1)
pot_et_wtd_mod = overlap_check[overlap_check['et_norm_obs'].notna()]
pot_et_wtd_mod = pot_et_wtd_mod.drop(columns=["et_norm_obs"])
overlap_check = pd.concat((pot_et_wtd_obs, norm_et_wtd_obs["et_norm_obs"]), axis=1)
pot_et_wtd_obs = overlap_check[overlap_check['et_norm_obs'].notna()]
pot_et_wtd_obs = pot_et_wtd_obs.drop(columns=["et_norm_obs"])
overlap_check = pd.concat((norm_et_wtd_mod, norm_et_wtd_obs["et_norm_obs"]), axis=1)
norm_et_wtd_mod = overlap_check[overlap_check['et_norm_obs'].notna()]
norm_et_wtd_mod = norm_et_wtd_mod.drop(columns=["et_norm_obs"])
ax1 = plt.subplot2grid((2, 3), (0, 0), rowspan=1, colspan=1, fig=None)
pot_et_wtd_mod.plot(ax=ax1, y='pot_et_mod', x='wtd_obs', fontsize=fontsize, style=['.'], color='darkorange',
markersize=4.5)
plt.ylabel('Model potential \n ET (mm/day)', fontsize=20)
plt.xlabel('In situ water table depth (m)', fontsize=20)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
ax2 = plt.subplot2grid((2, 3), (1, 0), rowspan=1, colspan=1, fig=None)
pot_et_wtd_obs.plot(ax=ax2, y='pot_et_obs', x='wtd_obs', fontsize=fontsize, style=['.'], color='sandybrown',
markersize=4.5)
plt.ylabel('In situ potential\n ET (mm/day)', fontsize=20)
plt.xlabel('In situ water table depth (m)', fontsize=20)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
ax3 = plt.subplot2grid((2, 3), (0, 1), rowspan=1, colspan=1, fig=None)
norm_et_wtd_mod.plot(ax=ax3, y='et_norm_mod', x='wtd_obs', fontsize=fontsize, style=['.'],
color='darkolivegreen', markersize=4.5)
plt.ylabel('In situ ET normalized with \n model ETpot (mm/day)', fontsize=20)
plt.xlabel('In situ water table depth (m)', fontsize=20)
plt.ylim([0.2, 2])
plt.xticks(fontsize=18)
# plt.xlim([-1.4, 0.2])
plt.yticks(fontsize=18)
ax4 = plt.subplot2grid((2, 3), (1, 1), rowspan=1, colspan=1, fig=None)
norm_et_wtd_obs.plot(ax=ax4, y='et_norm_obs', x='wtd_obs', fontsize=fontsize, style=['.'], color='limegreen',
markersize=4.3)
plt.ylabel('In situ ET normalized with \n in situ ETpot (mm/day)', fontsize=20)
plt.xlabel('In situ water table depth (m)', fontsize=20)
plt.ylim([0.2, 2])
# plt.xlim([-1.35, -0.2])
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
ax5 = plt.subplot2grid((2, 3), (1, 2), rowspan=1, colspan=1, fig=None)
norm_et_wtd_mod_mod.plot(ax=ax5, y='et_norm_mod_mod', x='wtd_mod', fontsize=fontsize - 4, style=['.'],
color='limegreen',
markersize=4.5)
plt.ylabel('Model ET normalized with \n model ETpot (mm/day)', fontsize=20)
plt.xlabel('Model water table depth (m)', fontsize=20)
plt.ylim([0.2, 2])
# plt.xlim([-1.4, 0.2])
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
plt.tight_layout()
fname = site
fname_long = os.path.join(outpath + '/potential_ET_WTD' + fname + '.png')
plt.savefig(fname_long, dpi=150)
plt.close()
# figextra
rn_wtd = pd.concat([rn_obs[site], wtd_obs[site]],
axis=1, join='inner')
RN_wtd = pd.concat([rn_mod[site], wtd_obs[site]],
axis=1, join='inner')
rn_wtd.columns = ['rn_obs', 'wtd_obs']
RN_wtd.columns = ['rn_mod', 'wtd_obs']
RN_wtd = RN_wtd[RN_wtd['wtd_obs'].notna()]
rn_wtd = rn_wtd[rn_wtd['wtd_obs'].notna()]
# remove haze period in rn data based on the period assigned above
overlap_check = pd.concat((rn_wtd, norm_et_wtd_obs["et_norm_obs"]), axis=1)
rn_wtd = overlap_check[overlap_check['et_norm_obs'].notna()]
rn_wtd = rn_wtd.drop(columns=["et_norm_obs"])
overlap_check = pd.concat((RN_wtd, norm_et_wtd_obs["et_norm_obs"]), axis=1)
RN_wtd = overlap_check[overlap_check['et_norm_obs'].notna()]
RN_wtd = RN_wtd.drop(columns=["et_norm_obs"])
figextra = plt.figure(figsize=(20, 20))
fontsize = 12
# calculate lowess fit and confidence interval 95%
def smooth(x, y, xgrid):
samples = np.random.choice(len(x), 1002, replace=True)
y_s = y[samples]
x_s = x[samples]
y_sm = sm_lowess(y_s, x_s, it=0, missing='drop', return_sorted=False)
# regularly sample it onto the grid
y_grid = scipy.interpolate.interp1d(x_s, y_sm, fill_value='extrapolate')(xgrid)
return y_grid
xgrid = np.linspace(pot_et_wtd_mod['wtd_obs'].min(), pot_et_wtd_mod['wtd_obs'].max())
K = 1000
ax1 = plt.subplot2grid((2, 2), (0, 0), fig=None)
pot_et_wtd_obs.plot(ax=ax1, y='pot_et_obs', x='wtd_obs', fontsize=fontsize + 4, style=['.'], color='#1f77b4',
markersize=4)
smooths = np.stack([smooth(pot_et_wtd_obs['wtd_obs'], pot_et_wtd_obs['pot_et_obs'], xgrid) for k in range(K)]).T
mean = np.nanmean(smooths, axis=1)
stderr = scipy.stats.sem(smooths, axis=1)
stderr = np.nanstd(smooths, axis=1, ddof=0)
plt.plot(xgrid, mean, color='k', linewidth=3.5)
plt.fill_between(xgrid, mean - 1.96 * stderr, mean + 1.96 * stderr, alpha=0.25)
plt.ylabel('In situ potential\n ET (mm/day)', fontsize=fontsize + 24)
plt.ylim([1, 8.6])
plt.xlabel('')
ax2 = plt.subplot2grid((2, 2), (0, 1), rowspan=1, colspan=1, fig=None)
pot_et_wtd_mod.plot(ax=ax2, y='pot_et_mod', x='wtd_obs', fontsize=fontsize + 4, style=['.'], color=color,
markersize=4)
smooths = np.stack([smooth(pot_et_wtd_mod['wtd_obs'], pot_et_wtd_mod['pot_et_mod'], xgrid) for k in range(K)]).T
mean = np.nanmean(smooths, axis=1)
stderr = scipy.stats.sem(smooths, axis=1)
stderr = np.nanstd(smooths, axis=1, ddof=0)
plt.plot(xgrid, mean, color='k', linewidth=3.5)
plt.fill_between(xgrid, mean - 1.96 * stderr, mean + 1.96 * stderr, alpha=0.25)
plt.ylabel('Model potential\n ET (mm/day)', fontsize=fontsize + 24)
plt.ylim([1, 8.6])
plt.xlabel('')
ax3 = plt.subplot2grid((2, 2), (1, 0), fig=None)
rn_wtd.plot(ax=ax3, y='rn_obs', x='wtd_obs', fontsize=fontsize + 4, style=['.'], color='#1f77b4', markersize=4)
smooths = np.stack([smooth(rn_wtd['wtd_obs'], rn_wtd['rn_obs'], xgrid) for k in range(K)]).T
mean = np.nanmean(smooths, axis=1)
stderr = scipy.stats.sem(smooths, axis=1)
stderr = np.nanstd(smooths, axis=1, ddof=0)
plt.plot(xgrid, mean, color='k', linewidth=3.5)
plt.fill_between(xgrid, mean - 1.96 * stderr, mean + 1.96 * stderr, alpha=0.25)
plt.ylabel('In situ net radiation (W/m²)', fontsize=fontsize + 24)
plt.xlabel('In situ WTD (m)', fontsize=fontsize + 24)