-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics_app_V2.7.py
1663 lines (1456 loc) · 81.7 KB
/
metrics_app_V2.7.py
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 xarray as xr
import time
import numpy as np
from netCDF4 import Dataset
import glob
import seaborn
import sys
from dico_ds_to_sc import *
from dico_ds_to_map import *
from dash import Dash, html, dcc, Input, Output, Patch, State
import scipy.optimize as op
import scipy.stats as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from kapteyn import kmpfit
dset=xr.open_dataset("Metrics.nc")
dset_ts=xr.open_dataset("TimeSeries.nc")
params=xr.open_dataset("Params_TUN.nc")
dset_sc=xr.open_dataset("Seasonal.nc")
dset_map={"OCE_Grid_T_LR":xr.open_dataset("Climatos_OCE_Grid_T_LR.nc"),
"OCE_Grid_T_DepthLv_LR":xr.open_dataset("Climatos_OCE_Grid_T_DepthLv_LR.nc"),
"OCE_Diaptr_W_LR":xr.open_dataset("Climatos_OCE_Diaptr_W_LR.nc"),
"ICE_LR":xr.open_dataset("Climatos_ICE_LR.nc"),
"ATM_LR":xr.open_dataset("Climatos_ATM_LR.nc"),
"OCE_Grid_T_VLR":xr.open_dataset("Climatos_OCE_Grid_T_VLR.nc"),
"OCE_Grid_T_DepthLv_VLR":xr.open_dataset("Climatos_OCE_Grid_T_DepthLv_VLR.nc"),
"OCE_Diaptr_W_VLR":xr.open_dataset("Climatos_OCE_Diaptr_W_VLR.nc"),
"ICE_VLR":xr.open_dataset("Climatos_ICE_VLR.nc"),
"ATM_VLR":xr.open_dataset("Climatos_ATM_VLR.nc")}
external_stylesheets = ["./assets/custom.css",'https://codepen.io/chriddyp/pen/bWLwgP.css']
app = Dash(__name__,external_stylesheets=external_stylesheets,prevent_initial_callbacks="initial_duplicate")
df = xr.combine_by_coords([dset,params])
df2 = dset_ts
def expon(xdata,A,B,C):
return A*np.exp(B*xdata)+C
def regression(xdata,ydata,regtype):
if regtype=="Linear":
reg=st.linregress(xdata,ydata)
coefs=[reg.intercept,reg.slope],reg.rvalue**2,reg.pvalue,[reg.intercept_stderr,reg.stderr]
if regtype=="LinLog":
reg=st.linregress(xdata,np.log(ydata-ydata.min))
coefs=[reg.intercept,reg.slope,ydata.min],reg.rvalue**2,reg.pvalue,[reg.intercept_stderr,reg.stderr,np.nan]
if regtype=="LogLin":
reg=st.linregress(np.log(xdata-xdata.min),ydata)
coefs=[reg.intercept,reg.slope],reg.rvalue**2,reg.pvalue,[reg.intercept_stderr,reg.stderr]
if regtype=="LogLog":
reg=st.linregress(np.log(xdata-xdata.min),np.log(ydata-ydata.min))
coefs=[reg.intercept,reg.slope,ydata.min],reg.rvalue**2,reg.pvalue,[reg.intercept_stderr,reg.stderr,np.nan]
if regtype=="Y=A*exp(B*X)+C":
reg=op.curve_fit(expon,xdata,ydata,nan_policy="omit")
coefs=reg.popt,np.nan,np.nan,np.sqrt(np.diag(reg.pcov))
return coefs
#def reconstruction(xdata,coefs,regtype):
# if regtype=="Linear":
# y_fit=xdata*coefs[0][1]+coefs[0][0]
# if regtype=="LinLog":
# y_fit=coefs[0][2]+np.exp(coefs[0][1]*xdata+coefs[0][0])
# if regtype=="LogLin":
# y_fit=coefs[0][0]+coefs[0][1]*np.log(xdata-xdata.min)
# if regtype=="LogLog":
# y_fit=coefs[0][2]+np.exp(np.log(xdata-xdata.min)*coefs[0][1]+coefs[0][0])
# if regtype=="Y=A*exp(B*X)+C":
# y_fit=coefs[0][2]+coefs[0][0]*np.exp(coefs[0][1]*xdata)
# return y_fit
#def lower_bnd(xdata,coefs,regtype):
# if regtype=="Linear":
# y_fit=xdata*(coefs[0][1]-coefs[3][1])+coefs[0][0]-coefs[3][0]
# if regtype=="LinLog":
# y_fit=coefs[0][2]+np.exp((coefs[0][1]-coefs[3][1])*xdata+coefs[0][0]-coefs[3][0])
# if regtype=="LogLin":
# y_fit=coefs[0][0]-coefs[3][0]+(coefs[0][1]-coefs[3][1])*np.log(xdata-xdata.min)
# if regtype=="LogLog":
# y_fit=coefs[0][2]+np.exp(np.log(xdata-xdata.min)*(coefs[0][1]-coefs[3][1])+coefs[0][0]-coefs[3][0])
# if regtype=="Y=A*exp(B*X)+C":
# y_fit=coefs[0][2]+coefs[0][0]*np.exp(coefs[0][1]*xdata)
# return y_fit
#
#def upper_bnd(xdata,coefs,regtype):
# if regtype=="Linear":
# y_fit=xdata*(coefs[0][1]-coefs[3][1])+coefs[0][0]-coefs[3][0]
# if regtype=="LinLog":
# y_fit=coefs[0][2]+np.exp((coefs[0][1]-coefs[3][1])*xdata+coefs[0][0]-coefs[3][0])
# if regtype=="LogLin":
# y_fit=coefs[0][0]-coefs[3][0]+(coefs[0][1]-coefs[3][1])*np.log(xdata-xdata.min)
# if regtype=="LogLog":
# y_fit=coefs[0][2]+np.exp(np.log(xdata-xdata.min)*(coefs[0][1]-coefs[3][1])+coefs[0][0]-coefs[3][0])
# if regtype=="Y=A*exp(B*X)+C":
# y_fit=coefs[0][2]+coefs[0][0]*np.exp(coefs[0][1]*xdata)
# return y_fit
def model_expo(p, x):
a, b, c = p
return a*np.exp(b*x) +c
def model_lin(p,x):
a,b = p
return a*x +b
def model_poly2(p,x):
a,b,c=p
return a*x**2 +b*x +c
def model_poly3(p,x):
a,b,c,d=p
return a*x**3 +b*x**2 +c*x +d
def model_log(p,x):
a,b,c=p
return a*np.log(np.abs(x +b)) + c
def model_pow(p,x):
a,b,c,d=p
return a*np.abs(x +b)**c +d
def dfdp_fun(p,x,modelname):
if modelname=="Linear":
a,b=p
return [x,1]
if modelname=="Logarithmic":
a,b,c=p
return [np.log(np.abs(x+b)),a/np.abs(x+b),1]
if modelname=="Exponential":
a,b,c=p
return [np.exp(b*x),a*x*np.exp(b*x),1]
if modelname=="Power-like":
a,b,c,d=p
return [np.abs(x+c)**b,a*np.abs(x+c)**b*np.log(np.abs(x+c)),np.sign(x+c)*a*b*np.abs(x+c)**(b-1),1]
if modelname=="Polynomial 2":
a,b,c=p
return[x**2,x,1]
if modelname=="Polynomial 3":
a,b,c,d=p
return [x**3,x**2,x,1]
models={"Exponential":model_expo,
"Linear":model_lin,
"Logarithmic":model_log,
"Power-like":model_pow,
"Polynomial 2":model_poly2,
"Polynomial 3":model_poly3}
start_params={"Exponential":[.1,.1,.1],
"Linear":[.1,.1],
"Logarithmic":[.1,.1,.1],
"Power-like":[.1,.1,.1,.1],
"Polynomial 2":[.1,.1,.1],
"Polynomial 3":[.1,.1,.1,.1]}
equations={"Exponential":"Y=A*exp(B*X)+C",
"Linear":"Y=A*X+B",
"Logarithmic":"Y=A*log|X + B|+C",
"Power-like":"Y=A*|X+B|**C + D",
"Polynomial 2":"Y=A*X**2+B*X +C",
"Polynomial 3":"Y=A*X**3 + B*X**2 + C*X + D"}
def model_fit(modelname,x,y):
f = kmpfit.simplefit(models[modelname], start_params[modelname], x, y)
X=np.linspace(x.min(),x.max(),num=500)
dfdp = dfdp_fun(f.params,X,modelname)
return f.confidence_band(X, dfdp, 0.95, models[modelname]),f.params,f.stderr
coord_dict={"LR0":(0,"LR"),
"LR1":(1,"LR"),
"VLR0":(0,"VLR"),
"VLR1":(1,"VLR"),
"Hyb0":(0,"Hyb"),
"Hyb1":(1,"Hyb"),
"ICO":(0,"ICO")}
simcheck_index_Met={"LR0":0,"LR1":2,"VLR0":4,"VLR1":6,"ICO":8}
simcheck_index_TS={"LR0":1,"LR1":3,"VLR0":5,"VLR1":7,"ICO":9}
simcheck_index_Met2D_PPM={"LR0":0,"LR1":1,"VLR0":2,"VLR1":3,"ICO":4}
simcheck_index_TS_PPM={"LR0":1,"LR1":3,"VLR0":5,"VLR1":7,"ICO":9}
simcheck_index_Met3D_PPM={"LR0":0,"LR1":2,"VLR0":4,"VLR1":6,"ICO":8}
marker_dict1={"LR0":{"color":"royalblue","symbol":"circle"},
"LR1":{"color":"royalblue","symbol":"circle-open"},
"VLR0":{"color":"orangered","symbol":"square"},
"VLR1":{"color":"orangered","symbol":"square-open"},
"Hyb0":{"color":"seagreen","symbol":"diamond"},
"Hyb1":{"color":"seagreen","symbol":"diamond-open"},
"ICO":{"color":"darkorchid","symbol":"diamond"}}
marker_dict2={"LR0":{"size":4,"color":"black","symbol":"circle"},
"LR1":{"size":4,"color":"black","symbol":"circle-open"},
"VLR0":{"size":4,"color":"black","symbol":"square"},
"VLR1":{"size":4,"color":"black","symbol":"square-open"},
"Hyb0":{"size":4,"color":"black","symbol":"diamond"},
"Hyb1":{"size":4,"color":"black","symbol":"diamond-open"},
"ICO":{"size":4,"color":"black","symbol":"diamond"}}
marker_dict3={"LR0":{"size":4,"symbol":"cross-thin","line_color":"black","line_width":0.5},
"LR1":{"size":4,"symbol":"cross-thin","line_color":"black","line_width":0.5},
"VLR0":{"size":4,"symbol":"cross-thin","line_color":"black","line_width":0.5},
"VLR1":{"size":4,"symbol":"cross-thin","line_color":"black","line_width":0.5},
"Hyb0":{"size":4,"symbol":"cross-thin","line_color":"black","line_width":0.5},
"Hyb1":{"size":4,"symbol":"cross-thin","line_color":"black","line_width":0.5},
"ICO":{"size":4,"symbol":"cross-thin","line_color":"black","line_width":0.5}}
marker_dict4={"LR0":{"color":"royalblue","symbol":"circle"},
"LR1":{"line_color":"royalblue","symbol":"circle-open"},
"VLR0":{"color":"orangered","symbol":"square"},
"VLR1":{"line_color":"orangered","symbol":"square-open"},
"Hyb0":{"color":"seagreen","symbol":"diamond"},
"Hyb1":{"line_color":"seagreen","symbol":"diamond-open"},
"ICO":{"color":"darkorchid","symbol":"diamond"}}
line_colors={"LR0":{"color":"royalblue"},
"LR1":{"color":"royalblue",'dash':'dot'},
"VLR0":{"color":"orangered"},
"VLR1":{"color":"orangered",'dash':'dot'},
"Hyb0":{"color":"seagreen"},
"Hyb1":{"color":"seagreen",'dash':'dot'},
"ICO":{"color":"darkorchid"}}
figscatter=go.Figure()
figTSx=go.Figure()
figTSy=go.Figure()
figSC=go.Figure()
figMapX=go.Figure()
figMapY=go.Figure()
figMapZ=go.Figure()
figscatterPPM2D=go.Figure()
figscatterPPM3D=go.Figure()
figTSPPM=go.Figure()
figSCPPM=go.Figure()
for simcheck in ["LR0","LR1","VLR0","VLR1","ICO"]:
etau,simutype=coord_dict[simcheck]
figscatter.add_trace( go.Scatter(x=[],
y=[],
hovertext=[],
opacity=1,
marker=marker_dict1[simcheck],
mode="markers",
customdata=np.array([]),
name="Metrics "+simcheck
))
figscatter.add_traces(go.Scatter(x=[],
y=[],
hoverinfo='skip',
opacity=0.2,
marker=marker_dict2[simcheck],
mode="markers",
showlegend=True,
name="TS "+simcheck))
figscatter.add_trace(go.Scatter(x=[],y=[],name="Selected TS",hoverinfo='skip',opacity=1,marker={"size":4,"symbol":"cross-thin","line_color":"black","line_width":0.5},showlegend=False,line_width=0.6,line_color="black",line_dash="dot",mode="lines+markers"))
figscatter.add_trace(go.Scatter(x=[],y=[],name="Regression on Selected Data",hoverinfo='skip',opacity=1,line_width=1.5,line_color="black",mode="lines"))
figscatter.add_trace(go.Scatter(
name='Upper Bound',
x=[],
y=[],
hoverinfo='skip',
mode='lines',
marker=dict(color="#444"),
line=dict(width=0),
showlegend=False))
figscatter.add_trace(go.Scatter(
name='Lower Bound',
x=[],
y=[],
hoverinfo='skip',
marker=dict(color="#444"),
line=dict(width=0),
mode='lines',
fillcolor='rgba(68, 68, 68, 0.3)',
fill='tonexty',
showlegend=False))
figscatter.add_annotation(x=0, y=0.95, xanchor='left', yanchor='top',
xref='paper', yref='paper', showarrow=False, align='left',
text="",font_size=14)
figscatter.update_xaxes(title="", type='linear')
figscatter.update_yaxes(title="", type='linear')
figscatter.update_layout(font_family="Didot",height=800,margin={'l': 40, 'b': 40, 't': 10, 'r': 0}, hovermode='closest',legend_xref="paper",legend_bgcolor='rgba(0,0,0,0)',legend_xanchor="right",legend_x=0.99)
from PIL import Image
img = Image.open('assets/Mevisto.png')
figscatter.add_layout_image(
dict(
source=img,
xref="x",
yref="y",
x=-1,
y=3.5,
sizex=7,
sizey=7,
# sizing="stretch",
opacity=0.7,
layer="above")
)
figTSx.add_annotation(x=0, y=0.9, xanchor='left', yanchor='bottom',
xref='paper', yref='paper', showarrow=False, align='left',
text="",font_size=20)
figTSx.update_xaxes(showgrid=False)
figTSx.update_layout(legend_xref="paper",legend_x=0.99,legend_bgcolor='rgba(0,0,0,0)',legend_xanchor="right", font_family="Didot", xaxis_title="Years",yaxis_title="",margin={'l': 0, 'b': 30, 'r': 0, 't': 10})
figTSy.add_annotation(x=0, y=0.9, xanchor='left', yanchor='bottom',
xref='paper', yref='paper', showarrow=False, align='left',
text="",font_size=20)
figTSy.update_xaxes(showgrid=False)
figTSy.update_layout(legend_xref="paper",legend_x=0.99,legend_bgcolor='rgba(0,0,0,0)',legend_xanchor="right",font_family="Didot", xaxis_title="Years",yaxis_title="",margin={'l': 0, 'b': 30, 'r': 0, 't': 10})
figMapX.update_layout(margin={'l': 0, 'b': 0, 'r': 0, 't': 0},font_family='Didot')
figMapY.update_layout(margin={'l': 0, 'b': 0, 'r': 0, 't': 0},font_family='Didot')
figMapX.add_annotation(x=0.3, y=0.5, xanchor='auto', yanchor='auto',
xref='paper', yref='paper', showarrow=False, align='center',
text="NO CLIMATOLOGY MAP",font_size=20)
figMapY.add_annotation(x=0.3, y=0.5, xanchor='auto', yanchor='auto',
xref='paper', yref='paper', showarrow=False, align='center',
text="NO CLIMATOLOGY MAP",font_size=20)
figMapZ.update_layout(margin={'l': 0, 'b': 0, 'r': 0, 't': 0},font_family='Didot')
figMapZ.add_annotation(x=0.3, y=0.5, xanchor='auto', yanchor='auto',
xref='paper', yref='paper', showarrow=False, align='center',
text="NO CLIMATOLOGY MAP",font_size=20)
figSC.update_xaxes(title="", type='linear')
figSC.update_yaxes(title="", type='linear')
figSC.update_layout(font_family="Didot",height=800,margin={'l': 40, 'b': 40, 't': 10, 'r': 0}, legend_xref="paper",legend_bgcolor='rgba(0,0,0,0)',legend_xanchor="right",legend_x=0.99)
figSC.add_annotation(x=0, y=0.9, xanchor='left', yanchor='bottom',
xref='paper', yref='paper', showarrow=False, align='left',
text="",font_size=20)
figTSPPM.add_annotation(x=0, y=0.9, xanchor='left', yanchor='bottom',
xref='paper', yref='paper', showarrow=False, align='left',
text="",font_size=20)
figTSPPM.update_xaxes(showgrid=False)
figTSPPM.update_layout(legend_xref="paper",legend_x=0.99,legend_bgcolor='rgba(0,0,0,0)',legend_xanchor="right", font_family="Didot", xaxis_title="Years",yaxis_title="",margin={'l': 0, 'b': 30, 'r': 0, 't': 10})
figSCPPM.update_xaxes(title="", type='linear')
figSCPPM.update_layout(font_family="Didot",height=800,margin={'l': 40, 'b': 40, 't': 10, 'r': 0}, legend_xref="paper",legend_bgcolor='rgba(0,0,0,0)',legend_xanchor="right",legend_x=0.99)
figSCPPM.add_annotation(x=0, y=0.9, xanchor='left', yanchor='bottom',
xref='paper', yref='paper', showarrow=False, align='left',
text="",font_size=20)
for simcheck in ["LR0","LR1","VLR0","VLR1","ICO"]:
etau,simutype=coord_dict[simcheck]
figscatterPPM3D.add_trace( go.Scatter3d(x=[],
y=[],
z=[],
hovertext=[],
opacity=1,
marker=marker_dict1[simcheck],
mode="markers",
customdata=np.array([]),
name="Metrics3D "+simcheck,
marker_colorscale="Bluered"
))
figscatterPPM3D.add_traces(go.Scatter3d(x=[],
y=[],
z=[],
hoverinfo='skip',
opacity=0.2,
marker=marker_dict2[simcheck],
mode="markers",
showlegend=True,
name="TS "+simcheck))
figscatterPPM3D.add_trace(go.Scatter3d(x=[],y=[],z=[],name="Selected TS",visible=False,hoverinfo='skip',opacity=1,marker={"size":4,"symbol":"x","line_color":"black","line_width":0.5},showlegend=False,line_width=0.6,line_color="black",line_dash="dot",mode="lines+markers"))
figscatterPPM3D.update_scenes(yaxis_title_text="",xaxis_title_text="",zaxis_title_text="")
figscatterPPM3D.update_xaxes(title="", type='linear')
figscatterPPM3D.update_yaxes(title="", type='linear')
figscatterPPM3D.update_layout(font_family="Didot",height=800,margin={'l': 40, 'b': 40, 't': 10, 'r': 0}, hovermode='closest',legend_xref="paper",legend_bgcolor='rgba(0,0,0,0)',legend_xanchor="right",legend_x=0.99)
#print(figscatterPPM3D)
for simcheck in ["LR0","LR1","VLR0","VLR1","ICO"]:
etau,simutype=coord_dict[simcheck]
figscatterPPM2D.add_trace( go.Scatter(x=[],
y=[],
hovertext=[],
opacity=1,
marker=marker_dict1[simcheck],
marker_size=8,
mode="markers",
customdata=np.array([]),
marker_colorscale="Bluered",
name="Metrics "+simcheck
))
figscatterPPM2D.update_xaxes(title="", type='linear')
figscatterPPM2D.update_yaxes(title="", type='linear')
figscatterPPM2D.update_layout(font_family="Didot",height=800, margin={'l': 40, 'b': 40, 't': 10, 'r': 0}, hovermode='closest',legend_xref="paper",legend_bgcolor='rgba(0,0,0,0)',legend_xanchor="right",legend_x=0.99)
#,scattermode="group", scattergap=0.00000001
app.layout = html.Div([html.Div([html.H6('Welcome to',style={'color': "black",'display':'inline-block','marginLeft':'160px'}),
html.H1('MeVisTo',style={'color': "darkred",'display':'inline-block','margin':'0px 30px'}),
html.H6('a MEtric VISualisation TOol',style={'color': "black",'display':'inline-block'})],
style={'textAlign': 'center','verticalAlign': 'top','fontFamily':"Didot",'color': "darkred"}),
html.Button(children="Show How to",id="tuto-button",style={'position':'absolute','right': 0,'top': 0, 'marginTop': '22px','marginRight': '22px','height':'36px','fontSize':20, 'width':'15%','padding':'0 0','paddingBottom':'36px','backgroundColor':'#FFFFFF',}),
html.Div([dcc.Markdown('''
## How to Use MeVisTo
MeVisTo is a Tool created for the development of the **IPSL Climate Model**.
Its core objective is to **help the scientists working on tuning the model parameters in making sense of and acting on the output data of a large ensemble of simulations**, that is to help in :
* Finding and understanding the relationships between the tuning parameters and the behaviour of the climate model (its sensitivity).
* Exploring the quantification of these relationships through the creation and benchmark of a set of metrics computed from output variables.
* Defining proper methods for the selection and use of these metrics in the tuning process.
* Applying these methods in the construction of an automatic tuning process.
The main theme of this tool is **Dimension Reduction**. The object we’re working on is a 4+N dimensional hyperspace (4 space-time dimensions, N parameter dimensions) on which are defined a great number of variables.
MeVisTo uses typical dimension reduction techniques to help visualize and make sense of this object : spatial average and temporal average (for now, maybe PCA and such will be added later).
You can thus find 4 different types of data in this tool : **Scalar metrics**, **Time Series**, **Seasonal Cycles* and **Climatology Maps**. The first is the core of the tool, with the 3 latter used for benchmarking and diagnostics.
In MeVisTo, you can visualize the scalar metrics in two ways :
* You can relate 2 metrics with each other, or 1 metric and 1 parameter, or 2 parameters with each other : that’s the **ANY-ANY Comparison Tab**.
* You can look at the concurrent effect of 2 parameters on 1 metric : that’s the **PARAM-PARAM-Metric Comparison Tab**.
For each, you’ll be presented with a scatter plot on the left and the diagnostic graphs on the right. You **select the variables** you need in the dropdowns at the top and **check the simulation type(s)** you want in the bottom left.
The diagnostic graphs are actualised when you **hover a data point** on the scatter plot with your cursor.
Other tweaks and tools are available, such as :
* For ANY-ANY Comparison : A basic **regression** tool above the scatter plot. You can select a regression type in the dropdown, then toggle the regression button.
The regression on the simulation set of checked simtypes will be computed, as well as the 95% confidence band on the curve.
* For PARAM-PARAM-Metric Comparison : **2D View with Color** as a 3rd dimension, or **3D View with Color** available for contrast, that you can activate on the top right.
* For the **Climatology Maps** : You can choose to have the "raw" (time averaged) variable shown, or its anomaly to the local mean, or the anomaly normalized by the local standard deviation. It’s on the top left of the map.
Mean and STD are calculated along the ensemble dimension for each Simulation Type (e.g. LR0 only, VLR0 only, etc...). By pushing 1 or 2 times the button on the top right of the map, you can show the ensemble mean and the STD of that variable.
By default the Colormap range is automatically computed by Simulation Type, but you can set manually the range if you need to ; just untoggle the AutoScale button and enter the values you want. It’s located on the bottom of the map.
''')],style={'display': 'none'},id="how-to"),
html.Div(style={'width':'100%'},children=[dcc.Tabs(id='maintab',value='tab-2D',
style={'width':'90vh','height':'3vw','transformOrigin':'left','transform':'translate(1vw,90vh) rotate(270deg)'},
children=[dcc.Tab(label='Param-Param-Metric Comparison',style={'padding':'2px 25px'},selected_style={'padding':'2px 25px','color':'darkred','borderTop':'darkred'},value='tab-3D',children=[html.Div([html.Div([
html.Div([
dcc.Dropdown(
list(params),
id='crossparam-xaxis-column',placeholder="Select for xaxis an AMIP_metric, a PARAMETER, or metric_REGION_Time"
, maxHeight=400
),
dcc.RadioItems(
['Linear', 'Log'],
'Linear',
id='crossparam-xaxis-type',
labelStyle={'display': 'inline-block', 'marginTop': '5px'},
style={'display': 'inline-block'})
],
style={'width': '47%', 'display': 'inline-block'}),
html.Button("\u21CC",id="switch-axes-PPM",n_clicks=0,style={'height':'36px','fontSize':20,'textAlign': 'center','verticalAlign': 'top', 'width':'6%','padding':'0 0'}),
html.Div([
dcc.Dropdown(
list(params),
id='crossparam-yaxis-column',placeholder="Select a yaxis PARAMETER"
, maxHeight=400
),
dcc.RadioItems(
['Linear', 'Log'],
'Linear',
id='crossparam-yaxis-type',
labelStyle={'display': 'inline-block', 'marginTop': '5px'}
)
], style={'width': '47%', 'display': 'inline-block','verticalAlign':'top'})]
, style={'padding': '10px 5px',"width":"49%",'display':'inline-block'}),
html.Div([
dcc.Dropdown(list(df),
id='crossparam-metric-column',placeholder="Select a yaxis PARAMETER"
, maxHeight=400,),
dcc.Checklist(['Metric as Color','3D'],['Metric as Color'],id='crossparam-type',inline=True)
] ,style={'width':'49%','display':'inline-block','verticalAlign':'top','padding':'10px 5px'}),
html.Div([html.Div([
dcc.Graph(figure=figscatterPPM2D,
id='crossparam-indicator-scatter2D',
hoverData={'points': [{'customdata':np.array([])}]},
style={'width': '100%', "verticalAlign": "top",'display': 'block', 'padding': '0 20','height':'49vw'}),
dcc.Graph(figure=figscatterPPM3D,
id='crossparam-indicator-scatter3D',
hoverData={'points': [{'customdata':np.array([])}]},
style={'width': '100%', "verticalAlign": "top",'display': 'none', 'padding': '0 20','height':'49vw'}),
html.Div([dcc.Checklist(['LR0','Hyb0','VLR0'],[],id='crossparam-nnetau_0-check',inline=True),
dcc.Checklist(['LR1','Hyb1','VLR1','ICO'],[],id='crossparam-nnetau_1-check',inline=True)],
style={'width': '49%','padding': '0px 20px 20px 20px'})],
style={'verticalAlign':'top','width': '49%', 'display': 'inline-block'}),
html.Div([dcc.Graph(figure=figTSPPM,id='TS-PPM',style={"height": '30vh','display':'inline-block', 'width': '49%'}),
dcc.Graph(figure=figSCPPM,id='seasonal-PPM',style={"height":'30vh','width':'49%','display':'inline-block'}),
html.Div([dcc.RadioItems(['Raw', 'Anomaly','Standardised Anomaly'],'Raw',id='maps-PPM-flavor',style={'display': 'inline-block', 'width':'60%','marginTop': '5px'},labelStyle={'display': 'inline-block', 'marginTop': '5px'}),
html.Button(children="Show Mean or STD Map",id="EnsMapsPPM",n_clicks=0,style={'backgroundColor':'#FFFFFF', 'width':'40%', 'height':'36px', 'padding':'0 1vw','textAlign':'center', 'display': 'inline-block', "verticalAlign": "top"}),
dcc.Graph(figure=figMapZ,id='maps-PPM',style={"width":"100%","height":'45vh',"verticalAlign": "top",'display': 'inline-block', 'padding': '0 0'}),
html.Div(id='text-zPPM',children="ColorScale",style={"width":"10%","display":"inline-block"}),
html.Button(children="AutoScale ON",id="ScalePPM",n_clicks=0,style={'backgroundColor':'#CCCCCC', 'width':'20%', 'height':'36px', 'padding':'0 1vw','textAlign':'center', 'display': 'inline-block', "verticalAlign": "top"}) ,
dcc.Input(id="input_minPPM",type="number",debounce=True,disabled=True,placeholder="Minimum Value",style={'width':'35%'}),dcc.Input(id="input_maxPPM",type="number",disabled=True,placeholder="Maximum Value",style={'width':'35%'}),
] ,style={'verticalAlign':'top', 'display': 'inline-block'})]
,style={'verticalAlign':'top','width': '49%', 'display': 'inline-block'})
], style={'width': '100%', "verticalAlign": "top",'display': 'inline-block', 'padding': '0 20'}
)
#, html.Div(dcc.Dropdown([],[],multi=True)
],style={'paddingRight':'3vw','transform':'translate(3vw,-2vw)','height':'90vh'})]),
dcc.Tab(label='ANY-ANY Comparison',selected_style={'padding':'2px 25px','color':'darkred','borderTop':'darkred'},style={'padding':'2px 25px'},value='tab-2D',children=[html.Div([html.Div([
html.Div([
dcc.Dropdown(
list(df),
id='crossfilter-xaxis-column',placeholder="Select for xaxis an AMIP_metric, a PARAMETER, or metric_REGION_Time"
, maxHeight=400
),
dcc.RadioItems(
['Linear', 'Log'],
'Linear',
id='crossfilter-xaxis-type',
labelStyle={'display': 'inline-block', 'marginTop': '5px'},
style={'width': '30%', 'display': 'inline-block'}),
html.Div(children=[
html.Button("Regression",id="regonoff",n_clicks=0,style={'backgroundColor':'#FFFFFF', 'width':'40%', 'height':'36px', 'padding':'0 1vw','textAlign':'center', 'display': 'inline-block', "verticalAlign": "top"}),
html.Div([dcc.Dropdown(["Linear","Exponential","Logarithmic","Power-like","Polynomial 2","Polynomial 3"],value="Linear",id='regtype',placeholder="Select your regression")],style={'width': '60%', 'display': 'inline-block', "verticalAlign": "top"})],
style={'width':'70%','display': 'inline-block',"verticalAlign": "top"})
],
style={'width': '47%', 'display': 'inline-block'}),
html.Button("\u21CC",id="switch-axes",n_clicks=0,style={'height':'36px','fontSize':20,'textAlign': 'center','verticalAlign': 'top', 'width':'6%','padding':'0 0'}),
html.Div([
dcc.Dropdown(
list(df),
id='crossfilter-yaxis-column',placeholder="Select for yaxis an AMIP_metric, a PARAMETER, or Metric_REGION_Time"
, maxHeight=400
),
dcc.RadioItems(
['Linear', 'Log'],
'Linear',
id='crossfilter-yaxis-type',
labelStyle={'display': 'inline-block', 'marginTop': '5px'}
)
], style={'width': '47%', 'display': 'inline-block','verticalAlign':'top'})
], style={'padding': '10px 5px'}),
html.Div([
html.Div([dcc.Graph(figure=figscatter,
id='crossfilter-indicator-scatter',
hoverData={'points': [{'customdata':np.array([])}]},style={"width":"100%","verticalAlign": "top",'display': 'inline-block', 'padding': '0 20','height':'49vw'}),
html.Div([dcc.Checklist(['LR0','Hyb0','VLR0'],[],id='crossfilter-nnetau_0-check',inline=True),
dcc.Checklist(['LR1','Hyb1','VLR1','ICO'],[],id='crossfilter-nnetau_1-check',inline=True)],
style={'width': '60%','padding': '0px 20px 20px 20px'})],style={'width': '49%', "verticalAlign": "top",'display': 'inline-block'}),
# ,style={'width': '49%', "verticalAlign": "top",'display': 'inline-block', 'padding': '0 20','height':'49vw'} ),
html.Div([dcc.Tabs(id="tabs-2D",
value='tab-1',
style={"height":30},
children=[
dcc.Tab(label='Time Series',
value='tab-1',
style={"padding":"3px 25px"},
selected_style={"padding":"3px 20px",'color':'darkred','borderTopColor':'darkred'},
children=[html.Div([
dcc.Graph(figure=figTSx,id='x-time-series',style={"height": '24vw'}),
dcc.Graph(figure=figTSy,id='y-time-series',style={"height": '24vw'}),
], style={'display':'inline-block', 'width': '100%'})]
),
dcc.Tab(label='Mean Seasonal Cycle',
value='tab-2',
style={"padding":"3px 25px"},
selected_style={"padding":"3px 20px",'color':'darkred','borderTopColor':'darkred'},
children=[dcc.Graph(figure=figSC,id='seasonal',style={"height":'48vw'})]
),
dcc.Tab(label='Climatological Maps',
value='tab-3',
style={"padding":"3px 25px"},
selected_style={"padding":"3px 20px",'color':'darkred','borderTopColor':'darkred'},
children=[dcc.RadioItems(['Raw', 'Anomaly','Standardised Anomaly'],'Raw',id='maps-flavor',style={'display': 'inline-block', 'width':'60%','marginTop': '5px'},labelStyle={'display': 'inline-block', 'marginTop': '5px'}),
html.Button(children="Show Mean or STD Map",id="EnsMaps",n_clicks=0,style={'backgroundColor':'#FFFFFF', 'width':'40%', 'height':'36px', 'padding':'0 1vw','textAlign':'center', 'display': 'inline-block', "verticalAlign": "top"}),
dcc.Graph(figure=figMapX,id='maps-x',style={"width":"100%","height":'21.9vw',"verticalAlign": "top",'display': 'inline-block', 'padding': '0 0'}),
dcc.Graph(figure=figMapY,id='maps-y',style={"width":"100%","height":'21.9vw',"verticalAlign": "top",'display': 'inline-block', 'padding': '0 0'}),
html.Div(id='text-x',children="X ColorScale",style={"width":"15%","display":"inline-block"}),
html.Button(children="AutoScale ON",id="ScaleX",n_clicks=0,style={'backgroundColor':'#CCCCCC', 'width':'20%', 'height':'36px', 'padding':'0 1vw','textAlign':'center', 'display': 'inline-block', "verticalAlign": "top"}) ,
dcc.Input(id="input_minx",type="number",debounce=True,disabled=True,placeholder="Minimum Value",style={'width':'32.5%'}),dcc.Input(id="input_maxx",type="number",disabled=True,placeholder="Maximum Value",style={'width':'32.5%'}),
html.Div(id='text-y',children="Y ColorScale",style={'width':'15%',"display":"inline-block"}),
html.Button(children="AutoScale ON",id="ScaleY",n_clicks=0,style={'backgroundColor':'#CCCCCC', 'width':'20%', 'height':'36px', 'padding':'0 1vw','textAlign':'center', 'display': 'inline-block', "verticalAlign": "top"}) ,
dcc.Input(id="input_miny",type="number",debounce=True,disabled=True,placeholder="Minimum Value",style={'width':'32.5%'}),dcc.Input(id="input_maxy",type="number",disabled=True,placeholder="Maximum Value",style={'width':'32.5%'}),
]
)
], )],style={'width': '49%', 'display': 'inline-block'})
], style={'width': '100%', "verticalAlign": "top",'display': 'inline-block', 'padding': '0 20'}
),
],style={'paddingRight':'3vw','transform':'translate(3vw,-2vw)','height':'90vh'})])])])])
### How TO
@app.callback(
Output('how-to', 'style'),
Output('tuto-button','children'),
Output('tuto-button','style'),
State('how-to', 'style'),
Input('tuto-button','n_clicks'),
State('tuto-button','style'))
def show_tuto(style,click,button_style):
if click%2==0:
style["display"]="none"
label="Show How To"
button_style['backgroundColor']='#FFFFFF'
else:
style["display"]="inline"
label="Hide How To"
button_style['backgroundColor']='#CCCCCC'
return style,label,button_style
### 3D Scatter Plot
@app.callback(
Output('crossparam-xaxis-column', 'value'),
Output('crossparam-yaxis-column', 'value'),
State('crossparam-xaxis-column', 'value'),
State('crossparam-yaxis-column', 'value'),
Input('switch-axes-PPM','n_clicks'))
def switch_axes_PPM(xaxis,yaxis,click):
return yaxis,xaxis
@app.callback(
Output('crossparam-indicator-scatter2D', 'figure',allow_duplicate=True),
Output('crossparam-indicator-scatter3D', 'figure', allow_duplicate=True),
Output('crossparam-indicator-scatter2D', 'style', allow_duplicate=True),
Output('crossparam-indicator-scatter3D', 'style',allow_duplicate=True),
Input('crossparam-xaxis-column', 'value'),
Input('crossparam-yaxis-column', 'value'),
Input('crossparam-metric-column', 'value'),
Input('crossparam-nnetau_0-check', 'value'),
Input('crossparam-nnetau_1-check','value'),
Input('crossparam-type','value'))
def update_BG_PPM(xaxis_column_name, yaxis_column_name,metric_column_name,
nnetau0,nnetau1,crossparam_type,selpoints=[]):
styleon=style={'width': '100%', "verticalAlign": "top",'display': 'block', 'padding': '0 20','height':'49vw'}
styleoff=style={'width': '100%', "verticalAlign": "top",'display': 'none', 'padding': '0 20','height':'49vw'}
style2D=styleon
style3D=styleoff
dff = df
fig2D = Patch()
fig3D=Patch()
if xaxis_column_name!=None and yaxis_column_name!=None and metric_column_name!=None and nnetau0+nnetau1!=[]:
fig3D.layout.images=[]
for simcheck in ["LR0","LR1","VLR0","VLR1","ICO"]:
if simcheck in (nnetau0+nnetau1):
etau,simutype=coord_dict[simcheck]
dset=dff.sel(nnetau=etau,SimuType=simutype).dropna(dim="NSimu",how="any",thresh=50)
print(dset["NSimu"].data)
dset2=df2.sel(nnetau=etau,SimuType=simutype).dropna(dim="NSimu",how="any",thresh=50)
custom=np.stack([np.array([simutype]*len(dset['NSimu'])),np.array([etau]*len(dset['NSimu'])),dset['NSimu'].data],axis=-1)
print("Custom :",custom)
print("Selected Vars : X =",xaxis_column_name,", Y=",yaxis_column_name)
if xaxis_column_name==None or yaxis_column_name==None or metric_column_name==None:
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["x"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["y"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["z"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["hovertext"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["customdata"]=np.array([])
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["x"]=[]
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["y"]=[]
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["hovertext"]=[]
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["customdata"]=np.array([])
elif "3D" in crossparam_type:
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["x"]=dset[xaxis_column_name].data
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["y"]=dset[yaxis_column_name].data
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["z"]=dset[metric_column_name].data
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["hovertext"]=dset['Simu_Name'].data
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["customdata"]=custom
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["x"]=[]
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["y"]=[]
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["hovertext"]=[]
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["customdata"]=np.array([])
style2D=styleoff
style3D=styleon
else:
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["x"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["y"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["z"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["hovertext"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["customdata"]=np.array([])
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["x"]=dset[xaxis_column_name].data
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["y"]=dset[yaxis_column_name].data
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["hovertext"]=dset['Simu_Name'].data
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["customdata"]=custom
style2D=styleon
style3D=styleoff
if "Metric as Color" in crossparam_type:
print("Coloring")
if "3D" in crossparam_type:
fig3D.data[simcheck_index_Met3D_PPM[simcheck]].marker.color=dset[metric_column_name].data
else:
fig2D.data[simcheck_index_Met2D_PPM[simcheck]].marker.color=dset[metric_column_name].data
else:
fig3D.data[simcheck_index_Met3D_PPM[simcheck]].marker.color=marker_dict1[simcheck]["color"]
fig2D.data[simcheck_index_Met2D_PPM[simcheck]].maker.color=marker_dict1[simcheck]["color"]
if xaxis_column_name==None or yaxis_column_name==None or metric_column_name==None or not "3D" in crossparam_type:
fig3D["data"][simcheck_index_TS_PPM[simcheck]]["x"]=[]
fig3D["data"][simcheck_index_TS_PPM[simcheck]]["y"]=[]
fig3D["data"][simcheck_index_TS_PPM[simcheck]]["z"]=[]
else:
fig3D["data"][simcheck_index_TS_PPM[simcheck]]["x"]=np.tile(dset[xaxis_column_name].data.T,(dset2.year.size,1)).T.ravel()
fig3D["data"][simcheck_index_TS_PPM[simcheck]]["z"]=dset2[metric_column_name].data.ravel()
fig3D["data"][simcheck_index_TS_PPM[simcheck]]["y"]=np.tile(dset[yaxis_column_name].data.T,(dset2.year.size,1)).T.ravel()
else:
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["x"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["y"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["z"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["hovertext"]=[]
fig3D["data"][simcheck_index_Met3D_PPM[simcheck]]["customdata"]=np.array([])
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["x"]=[]
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["y"]=[]
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["hovertext"]=[]
fig2D["data"][simcheck_index_Met2D_PPM[simcheck]]["customdata"]=np.array([])
fig3D.data[simcheck_index_Met3D_PPM[simcheck]].marker.color=marker_dict1[simcheck]["color"]
fig2D.data[simcheck_index_Met2D_PPM[simcheck]].marker.color=marker_dict1[simcheck]["color"]
fig3D["data"][simcheck_index_TS_PPM[simcheck]]["x"]=[]
fig3D["data"][simcheck_index_TS_PPM[simcheck]]["y"]=[]
return fig2D,fig3D,style2D,style3D
@app.callback(
Output('crossparam-indicator-scatter3D', 'figure',allow_duplicate=True),
Input('crossparam-xaxis-column', 'value'),
Input('crossparam-yaxis-column', 'value'),
Input('crossparam-metric-column', 'value'),
Input('crossparam-type','value'),
Input('crossparam-indicator-scatter3D', 'hoverData'))
def update_selected(xaxis_column_name, yaxis_column_name,metric_column_name,crossparam_type,hoverData,selpoints=[]):
dff = df
simu_coord = hoverData['points'][0]['customdata']
fig = Patch()
# if simu_coord==np.array([]):
# return fig
fig.data[10].line=line_colors[simu_coord[0]+simu_coord[1]]
if xaxis_column_name==None or yaxis_column_name==None or metric_column_name==None or not "3D" in crossparam_type:
fig["data"][10]["x"]=[]
fig["data"][10]["y"]=[]
fig["data"][10]["z"]=[]
else:
fig["data"][10]["x"]=np.tile(df[xaxis_column_name].sel(NSimu=int(simu_coord[2])).data,df2.year.size)
fig["data"][10]["y"]=np.tile(df[yaxis_column_name].sel(NSimu=int(simu_coord[2])).data,df2.year.size)
fig["data"][10]["z"]=df2[metric_column_name].sel(NSimu=int(simu_coord[2]),SimuType=simu_coord[0],nnetau=int(simu_coord[1])).data
return fig
@app.callback(
Output('crossparam-indicator-scatter2D', 'figure',allow_duplicate=True),
Output('crossparam-indicator-scatter3D', 'figure',allow_duplicate=True),
Input('crossparam-xaxis-column', 'value'),
Input('crossparam-yaxis-column', 'value'),
Input('crossparam-metric-column', 'value'),
Input('crossparam-xaxis-type', 'value'),
Input('crossparam-yaxis-type', 'value'))
def update_layout(xaxis_column_name, yaxis_column_name,metric_column_name,
xaxis_type, yaxis_type):
fig2D = Patch()
fig3D = Patch()
fig2D["layout"]["xaxis"]["title"]=xaxis_column_name
fig2D["layout"]["xaxis"]["type"]='linear' if xaxis_type == 'Linear' else 'log'
fig2D["layout"]["yaxis"]["title"]=yaxis_column_name
fig2D["layout"]["yaxis"]["type"]='linear' if yaxis_type == 'Linear' else 'log'
fig3D["layout"]["xaxis"]["title"]=xaxis_column_name
fig3D["layout"]["xaxis"]["type"]='linear' if xaxis_type == 'Linear' else 'log'
fig3D["layout"]["yaxis"]["title"]=yaxis_column_name
fig3D["layout"]["yaxis"]["type"]='linear' if yaxis_type == 'Linear' else 'log'
fig3D.layout.scene.xaxis.title.text=xaxis_column_name
fig3D.layout.scene.yaxis.title.text=yaxis_column_name
fig3D.layout.scene.zaxis.title.text=metric_column_name
return fig2D,fig3D
### 3D Time Series
@app.callback(
Output('TS-PPM', 'figure',allow_duplicate=True),
Input('crossparam-metric-column', 'value'),
# State('crossparam-metric-type', 'value'),
Input('crossparam-nnetau_0-check', 'value'),
Input('crossparam-nnetau_1-check','value'))
def update_all_metric_timeseries(metric_column_name,nnetau0,nnetau1 ,axis_type='Linear'):
if metric_column_name!=None and metric_column_name in df2:
title = '<b>{}</b>'.format("No Sim Selected")
return create_time_series(axis_type, title, metric_column_name,nnetau0+nnetau1)
return empty_time_series()
@app.callback(
Output('TS-PPM', 'figure',allow_duplicate=True),
Input('crossparam-indicator-scatter2D', 'hoverData'),
Input('crossparam-indicator-scatter3D', 'hoverData'),
Input('crossparam-type', 'value'),
Input('crossparam-metric-column', 'value'))
def update_selected_metric_timeseries(hoverData2D,hoverData3D,crossparam_type, metric_column_name):
if "3D" in crossparam_type:
hoverData=hoverData3D
else:
hoverData=hoverData2D
simu_custom=hoverData['points'][0]['customdata']
# if simu_custom==np.array([]):
# return Patch()
simu_chk=simu_custom[0]+simu_custom[1]
dff = df2.sel(NSimu=int(simu_custom[2]),SimuType=simu_custom[0],nnetau=int(simu_custom[1]))
if metric_column_name!=None and metric_column_name in df2:
dff2 = dff[metric_column_name]
title = '<b>{}</b>'.format(dff.Simu_Name.data)
return selected_time_series(dff2,title,simu_chk)
return Patch()
### 3D Seasonal Cycles
def create_seasonal_PPM(title, metric_column_name,simucateg):
fig = Patch()
data=[]
for simcheck in simucateg:
etau,simutype=coord_dict[simcheck]
dset2=dset_sc.sel(nnetau=etau,SimuType=simutype).dropna(dim="NSimu",how="any",thresh=50)
for ind in range(len(dset2[metric_column_name])):
data.append(go.Scatterpolar(mode='lines+markers',name="",connectgaps=True,r=recollement(dset2[metric_column_name][ind].data-np.nanmean(dset2[metric_column_name][ind].data)),theta=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan"],showlegend=False,opacity=0.1,hoverinfo='skip',marker={"size":3,"symbol":0,"color":"black"},line_color="black"))
data.append(go.Scatterpolar(mode='lines+markers',name="Sim",r=[], theta=[],text=[],textposition=f'top right',textfont={'size':30,'color':['white','black','white','black','white','black','white','black','white','black','white','black','white']},marker=marker_dict4["LR0"],line=line_colors["LR0"]))
# fig.layout.yaxis.type='linear' if yaxis_type == 'Linear' else 'log'
# fig.layout.xaxis.type='linear' if xaxis_type == 'Linear' else 'log'
fig["layout"]["annotations"][0].x=0
fig["layout"]["annotations"][0].y=0.85
fig["layout"]["annotations"][0].xanchor='left'
fig["layout"]["annotations"][0].yanchor='bottom'
fig["layout"]["annotations"][0].align='left'
fig["layout"]["annotations"][0].text=title
fig["layout"]["annotations"][0].font_size=16
fig.data=data
return fig
def selected_seasonal_PPM(dff1,title,simu_chk):
fig = Patch()
fig["data"][-1]['r']=recollement(dff1.data-np.nanmean(dff1.data))
fig["data"][-1]['theta']=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan"]
fig["data"][-1]["marker"]=marker_dict4[simu_chk]
fig["data"][-1]["line"]=line_colors[simu_chk]
fig["data"][-1]["name"]=title
fig["layout"]["annotations"][0]["text"]=title
return fig
@app.callback(
Output('seasonal-PPM', 'figure',allow_duplicate=True),
Input('crossparam-metric-column', 'value'),
Input('crossparam-nnetau_0-check', 'value'),
Input('crossparam-nnetau_1-check','value'))
def update_all_seasonal_PPM(metric_column_name, nnetau0,nnetau1):
if metric_column_name!=None and Met_to_SC[metric_column_name] in dset_sc :
title = '<b>{}</b>'.format("No Sim Selected")
return create_seasonal_PPM(title, Met_to_SC[metric_column_name],nnetau0+nnetau1)
return empty_seasonal()
@app.callback(
Output('seasonal-PPM', 'figure',allow_duplicate=True),
Input('crossparam-indicator-scatter2D', 'hoverData'),
Input('crossparam-indicator-scatter3D', 'hoverData'),
Input('crossparam-type', 'value'),
Input('crossparam-metric-column', 'value'))
def update_selected_seasonal_PPM(hoverData2D,hoverData3D,crossparam_type, metric_column_name):
if "3D" in crossparam_type:
hoverData=hoverData3D
else:
hoverData=hoverData2D
simu_custom=hoverData['points'][0]['customdata']
# if simu_custom==np.array([]):
# return Patch()
simu_chk=simu_custom[0]+simu_custom[1]
dff = dset_sc.sel(NSimu=int(simu_custom[2]),SimuType=simu_custom[0],nnetau=int(simu_custom[1]))
if metric_column_name!=None and Met_to_SC[metric_column_name] in dset_sc:
dff1 = dff[Met_to_SC[metric_column_name]]
title = '<b>{}</b>'.format(dff.Simu_Name.data)
return selected_seasonal_PPM(dff1,title,simu_chk)
return Patch()
### 2D Scatter Plot
@app.callback(
Output('crossfilter-xaxis-column', 'value'),
Output('crossfilter-yaxis-column', 'value'),
State('crossfilter-xaxis-column', 'value'),
State('crossfilter-yaxis-column', 'value'),
Input('switch-axes','n_clicks'))
def switch_axes(xaxis,yaxis,click):
return yaxis,xaxis
@app.callback(
Output('crossfilter-indicator-scatter', 'figure',allow_duplicate=True),
Input('crossfilter-xaxis-column', 'value'),
Input('crossfilter-yaxis-column', 'value'),
Input('crossfilter-nnetau_0-check', 'value'),
Input('crossfilter-nnetau_1-check','value'))
def update_BG(xaxis_column_name, yaxis_column_name,
nnetau0,nnetau1,selpoints=[]):
dff = df
fig = Patch()
if xaxis_column_name!=None and yaxis_column_name!=None and nnetau0+nnetau1!=[]:
fig.layout.images=[]
for simcheck in ["LR0","LR1","VLR0","VLR1","ICO"]:
if simcheck in (nnetau0+nnetau1):
etau,simutype=coord_dict[simcheck]
dset=dff.sel(nnetau=etau,SimuType=simutype).dropna(dim="NSimu",how="any",thresh=50)
print(dset["NSimu"].data)
dset2=df2.sel(nnetau=etau,SimuType=simutype).dropna(dim="NSimu",how="any",thresh=50)
custom=np.stack([np.array([simutype]*len(dset['NSimu'])),np.array([etau]*len(dset['NSimu'])),dset['NSimu'].data],axis=-1)
print("Custom :",custom)
print("Selected Vars : X =",xaxis_column_name,", Y=",yaxis_column_name)
if xaxis_column_name==None or yaxis_column_name==None:
fig["data"][simcheck_index_Met[simcheck]]["x"]=[]
fig["data"][simcheck_index_Met[simcheck]]["y"]=[]
fig["data"][simcheck_index_Met[simcheck]]["hovertext"]=[]
fig["data"][simcheck_index_Met[simcheck]]["customdata"]=np.array([])
else:
fig["data"][simcheck_index_Met[simcheck]]["x"]=dset[xaxis_column_name].data
fig["data"][simcheck_index_Met[simcheck]]["y"]=dset[yaxis_column_name].data
fig["data"][simcheck_index_Met[simcheck]]["hovertext"]=dset['Simu_Name'].data
fig["data"][simcheck_index_Met[simcheck]]["customdata"]=custom
if xaxis_column_name==None or yaxis_column_name==None or ((not xaxis_column_name in dset2) and (not yaxis_column_name in dset2)):
fig["data"][simcheck_index_TS[simcheck]]["x"]=[]
fig["data"][simcheck_index_TS[simcheck]]["y"]=[]
elif not xaxis_column_name in dset2:
fig["data"][simcheck_index_TS[simcheck]]["x"]=np.tile(dset[xaxis_column_name].data.T,(dset2.year.size,1)).T.ravel()
fig["data"][simcheck_index_TS[simcheck]]["y"]=dset2[yaxis_column_name].data.ravel()
elif not yaxis_column_name in dset2:
fig["data"][simcheck_index_TS[simcheck]]["x"]=dset2[xaxis_column_name].data.ravel()
fig["data"][simcheck_index_TS[simcheck]]["y"]=np.tile(dset[yaxis_column_name].data.T,(dset2.year.size,1)).T.ravel()
else:
fig["data"][simcheck_index_TS[simcheck]]["x"]=dset2[xaxis_column_name].data.ravel()
fig["data"][simcheck_index_TS[simcheck]]["y"]=dset2[yaxis_column_name].data.ravel()
else:
fig["data"][simcheck_index_Met[simcheck]]["x"]=[]
fig["data"][simcheck_index_Met[simcheck]]["y"]=[]
fig["data"][simcheck_index_Met[simcheck]]["hovertext"]=[]
fig["data"][simcheck_index_Met[simcheck]]["customdata"]=np.array([])
fig["data"][simcheck_index_TS[simcheck]]["x"]=[]
fig["data"][simcheck_index_TS[simcheck]]["y"]=[]
return fig
@app.callback(
Output('crossfilter-indicator-scatter', 'figure',allow_duplicate=True),
Input('crossfilter-xaxis-column', 'value'),
Input('crossfilter-yaxis-column', 'value'),
Input('crossfilter-indicator-scatter', 'hoverData'))
def update_selected(xaxis_column_name, yaxis_column_name,hoverData,selpoints=[]):
dff = df
simu_coord = hoverData['points'][0]['customdata']
fig = Patch()
# if simu_coord==np.array([]):
# return fig
fig.data[10].line=line_colors[simu_coord[0]+simu_coord[1]]
if xaxis_column_name==None or yaxis_column_name==None or ((not xaxis_column_name in df2) and (not yaxis_column_name in df2)):
fig["data"][10]["x"]=[]