forked from daspy/daspy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DAS_Assim.py
3024 lines (2529 loc) · 280 KB
/
DAS_Assim.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
# -*- coding: utf-8 -*-
'''
Copyright of DasPy:
Author - Xujun Han (Forschungszentrum Jülich, Germany)
DasPy was funded by:
1. Forschungszentrum Jülich, Agrosphere (IBG 3), Jülich, Germany
2. Cold and Arid Regions Environmental and Engineering Research Institute, Chinese Academy of Sciences, Lanzhou, PR China
3. Centre for High-Performance Scientific Computing in Terrestrial Systems: HPSC TerrSys, Geoverbund ABC/J, Jülich, Germany
Please include the following references related to DasPy:
1. Han, X., Li, X., He, G., Kumbhar, P., Montzka, C., Kollet, S., Miyoshi, T., Rosolem, R., Zhang, Y., Vereecken, H., and Franssen, H. J. H.:
DasPy 1.0 : the Open Source Multivariate Land Data Assimilation Framework in combination with the Community Land Model 4.5, Geosci. Model Dev. Discuss., 8, 7395-7444, 2015.
2. Han, X., Franssen, H. J. H., Rosolem, R., Jin, R., Li, X., and Vereecken, H.:
Correction of systematic model forcing bias of CLM using assimilation of cosmic-ray Neutrons and land surface temperature: a study in the Heihe Catchment, China, Hydrology and Earth System Sciences, 19, 615-629, 2015a.
3. Han, X., Franssen, H. J. H., Montzka, C., and Vereecken, H.:
Soil moisture and soil properties estimation in the Community Land Model with synthetic brightness temperature observations, Water Resour Res, 50, 6081-6105, 2014a.
4. Han, X., Franssen, H. J. H., Li, X., Zhang, Y. L., Montzka, C., and Vereecken, H.:
Joint Assimilation of Surface Temperature and L-Band Microwave Brightness Temperature in Land Data Assimilation, Vadose Zone J, 12, 0, 2013.
'''
import os, sys, time, datetime, random, math, gc, subprocess, glob, signal, string, shutil, warnings, multiprocessing, socket, getpass, ctypes, platform, functools, copy
import numpy, scipy, scipy.stats, scipy.signal, netCDF4, scipy.ndimage
import pp,imp
sys.path.append('SysModel/CLM')
sys.path.append('Utilities')
sys.path.append('Utilities/Soil')
sys.path.append('Algorithm')
sys.path.append('Algorithm/GSIF')
sys.path.append('Algorithm/ReBEL')
sys.path.append('Algorithm/Noise')
sys.path.append('Algorithm/MultiScale')
sys.path.append('Algorithm/Geostatistics/CorrelationModel')
sys.path.append('Algorithm/Geostatistics/Scripts')
sys.path.append('ForcingData')
from Call_CLM_CESM import *
from ParFor import *
from Read_Soil_Texture import *
from DAS_Assim_Common import *
from DAS_Driver_Common import *
def CLM_Assim_Common(Block_Index, Model_Driver, Def_PP, Def_First_Run, Def_Print, Def_Multiresolution, Def_ReBEL, Def_Localization, Num_Local_Obs, eps, msw_infl, parm_infl, Post_Inflation_Alpha, Def_ParFor, Row_Numbers, Col_Numbers, Ensemble_Number, Ensemble_Number_Predict, Call_Gstat_Flag, Assim_Algorithm_Name, Model_State, E0_SysModel, E0_ObsModel, \
Stop_Month, Stop_Day, Stop_Hour, UTC_Zone, MODEL_X_Left, MODEL_X_Right, MODEL_Y_Lower, MODEL_Y_Upper, Proj_String, Z_Resolution, Sub_Block_Ratio_Row, Sub_Block_Ratio_Col, Observation_X_Left, Observation_X_Right, Observation_Y_Lower, Observation_Y_Upper, Variable_List,
Grid_Resolution_CEA, Prop_Grid_Array_Sys, Prop_Grid_Array_H_Trans, Model_Variance, Write_DA_File_Flag, Mask, Mask_Index, Land_Mask_Data, Observation_Variance, SensorQuantity, SensorQuantity_Index,
Observation_NLats, Observation_NLons, Observation_Longitude, Observation_Latitude, Observation_Matrix, DAS_Depends_Path, DasPy_Path, CLM_NA, NAvalue, Soil_Layer_Index_DA, Soil_Layer_Num, ParFlow_Layer_Num, omp_get_num_procs_ParFor, Normal_Score_Trans, PDAF_Assim_Framework, PDAF_Filter_Type, NSLOTS, DAS_Output_Path, Region_Name,
Variable_Assimilation_Flag, Teta_Residual, Teta_Saturated, Teta_Field_Capacity, Teta_Wilting_Point, SensorType, SensorVariable, SensorResolution, Datetime_Start, Datetime_Stop, Datetime_Stop_Init, Datetime_Initial,
Observation_Corelation_Par, Bias_Estimation_Option_Model, Bias_Estimation_Option_Obs, Low_Ratio_Par, High_Ratio_Par,
Model_State_Inflation_Range, Model_State_Inflation_Range_STD, Model_Bias_Range, Observation_Bias_Range, Model_Bias_Range_STD, Observation_Bias_Range_STD, Model_Bias_STD, Observation_Bias_STD,
CLM_Ground_Temperature_Ensemble_Mat,CLM_Vegetation_Temperature_Ensemble_Mat,CLM_Soil_Moisture_Ensemble_Mat,CLM_Soil_Temperature_Ensemble_Mat, PF_PRESSURE_Ensemble_Mat, PF_SATURATION_Ensemble_Mat,
Prop_Grid_Array_Sys_parm_infl, CLM_Latent_Heat_parm_infl, CLM_Surface_Temperature_parm_infl, CLM_Ground_Temperature_parm_infl,CLM_Vegetation_Temperature_parm_infl, CLM_Soil_Moisture_parm_infl,CLM_Soil_Temperature_parm_infl, PF_SATURATION_parm_infl,
CLM_Ground_Temperature_Ensemble_Mat_Bias,CLM_Vegetation_Temperature_Ensemble_Mat_Bias,CLM_Soil_Moisture_Ensemble_Mat_Bias,CLM_Soil_Temperature_Ensemble_Mat_Bias,
CLM_Surface_Temperature_parm_infl_Bias, CLM_Ground_Temperature_parm_infl_Bias,CLM_Vegetation_Temperature_parm_infl_Bias, CLM_Soil_Moisture_parm_infl_Bias,CLM_Soil_Temperature_parm_infl_Bias,
Prop_Grid_Array_Bias, Observation_Bias, Prop_Grid_Array_Sys_parm_infl_Bias, Observation_parm_infl_Bias, Def_CDF_Matching, Plot_Analysis, Parameter_Optimization_Flag,
Start_Month, maxpft, Feedback_Assim, Dim_Soil_Par, Soil_Par_Sens, Dim_Veg_Par, Veg_Par_Sens, Dim_PFT_Par, PFT_Par_Sens, Dim_Hard_Par, Hard_Par_Sens, Soil_Par_Sens_Dim, Veg_Par_Sens_Dim, PFT_Par_Sens_Dim, Hard_Par_Sens_Dim, \
Parameter_Soil_Space_Ensemble, Parameter_Soil_Space_parm_infl, Parameter_Veg_Space_Ensemble, Parameter_Veg_Space_parm_infl, Parameter_PFT_Space_Ensemble, Parameter_PFT_Space_parm_infl, Parameter_Hard_Space_Ensemble, Parameter_Hard_Space_parm_infl, Parameter_Min_Max, \
Soil_Layer_Thickness_Ratio, Soil_Texture_Layer_Opt_Num, Soil_Sand_Clay_Sum, Parameter_Range_Soil, Parameter_Range_Veg, Parameter_Range_PFT, Parameter_Range_Hard, Parameter_Regularization, Par_Soil_Uniform_STD, Par_Veg_Uniform_STD, Par_PFT_Uniform_STD, Par_Hard_Uniform_STD,
Saturation_SSat, Saturation_SRes, Saturation_N, Saturation_Alpha, DateString_Plot, *vartuple):
pyper = imp.load_source("pyper",DasPy_Path+"Utilities/pyper.py")
Call_ReBEL_Octave = imp.load_source("Call_ReBEL_Octave",DasPy_Path+"Algorithm/ReBEL/Call_ReBEL_Octave.py")
gssm_das_octave = []
letkf = imp.load_source("letk",DasPy_Path+"Algorithm/DAS/letkf.py")
letkf_common = imp.load_dynamic("letkf_common",DasPy_Path+"Algorithm/DAS/letkf_common.so")
octave = vartuple[0]
Analysis_Grid = numpy.zeros((Row_Numbers, Col_Numbers),dtype=numpy.float32)
Localization_Map_Mask = numpy.zeros((Row_Numbers, Col_Numbers),dtype=numpy.float32)
Analysis_Grid_Array = numpy.zeros((Ensemble_Number, Row_Numbers, Col_Numbers),dtype=numpy.float32)
Innovation_State = numpy.zeros_like(Analysis_Grid_Array,dtype=numpy.float32)
Increments_State = numpy.zeros_like(Analysis_Grid_Array,dtype=numpy.float32)
#--------------Find Available Observations
Observation_Matrix_Temp = numpy.copy(Observation_Matrix)
Obs_Index = numpy.where(Observation_Matrix_Temp.flatten() != NAvalue)
Obs_Index_Dim = numpy.size(Obs_Index)
if Def_Print:
print "Obs_Index_Dim", Obs_Index_Dim
del Observation_Matrix_Temp
#--------------- Save the Observation Grid for DA -----------------
Obs_Grid = numpy.zeros((Obs_Index_Dim, 3),dtype=numpy.float32)
Obs_Grid[:, 0] = Observation_Longitude.flatten()[Obs_Index]
Obs_Grid[:, 1] = Observation_Latitude.flatten()[Obs_Index]
Obs_Grid[:, 2] = Observation_Matrix.flatten()[Obs_Index]
if Write_DA_File_Flag:
numpy.savetxt(DasPy_Path+'Analysis/DAS_Temp/X_Diff.txt', Mask[:, 0] - Observation_Longitude.flatten())
numpy.savetxt(DasPy_Path+'Analysis/DAS_Temp/Y_Diff.txt', Mask[:, 1] - Observation_Latitude.flatten())
numpy.savetxt(DasPy_Path+'Analysis/DAS_Temp/Obs_Grid.txt', Obs_Grid)
#------------------------- Prepare DA --------------------
State_DIM_Single_Layer = numpy.size(numpy.where(Mask_Index == False))
# Expand the dimension to include the deep layers
Mask_Copy = numpy.copy(Mask)
Mask_Index_Single_Layer = numpy.copy(Mask_Index)
Def_ReBEL_Temp = Def_ReBEL
Def_Localization_Temp = Def_Localization
if Def_ReBEL_Temp == 1:
if (not Parameter_Optimization_Flag) and (not ((numpy.size(numpy.where(Bias_Estimation_Option_Model == 1)) >= 1) or (numpy.size(numpy.where(Bias_Estimation_Option_Obs == 1)) >= 1))):
# For State Estimation
if Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Soil_Moisture":
if SensorType == "InSitu":
for i in range(Soil_Layer_Num - 5 -1):
Mask_Index = numpy.append(Mask_Index,Mask_Index_Single_Layer)
Mask = numpy.vstack((Mask,Mask_Copy))
if Feedback_Assim: # and (string.atoi(Stop_Month) >= 4) and (string.atoi(Stop_Month) <= 10):
for i in range(Soil_Layer_Num + 2):
Mask_Index = numpy.append(Mask_Index,Mask_Index_Single_Layer)
Mask = numpy.vstack((Mask,Mask_Copy))
else:
for i in range(Soil_Layer_Num - 5):
Mask_Index = numpy.append(Mask_Index,Mask_Index_Single_Layer)
Mask = numpy.vstack((Mask,Mask_Copy))
if Feedback_Assim: # and (string.atoi(Stop_Month) >= 4) and (string.atoi(Stop_Month) <= 10):
for i in range(Soil_Layer_Num + 2):
Mask_Index = numpy.append(Mask_Index,Mask_Index_Single_Layer)
Mask = numpy.vstack((Mask,Mask_Copy))
elif (Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Surface_Temperature"):
for i in range(Soil_Layer_Num + 2):
Mask_Index = numpy.append(Mask_Index,Mask_Index_Single_Layer)
Mask = numpy.vstack((Mask,Mask_Copy))
if Feedback_Assim: # and (string.atoi(Stop_Month) >= 4) and (string.atoi(Stop_Month) <= 10):
for i in range(Soil_Layer_Num - 5):
Mask_Index = numpy.append(Mask_Index,Mask_Index_Single_Layer)
Mask = numpy.vstack((Mask,Mask_Copy))
else:
# For Parameter Estimation
if Soil_Par_Sens_Dim >= 1:
for Par_Index in range(Dim_Soil_Par):
if Soil_Par_Sens[Par_Index]:
Mask_Index = numpy.append(Mask_Index,Mask_Index_Single_Layer)
Mask = numpy.vstack((Mask,Mask_Copy))
if PFT_Par_Sens_Dim >= 1:
for Par_Index in range(Dim_PFT_Par):
if PFT_Par_Sens[Par_Index]:
Mask_Index = numpy.append(Mask_Index,Mask_Index_Single_Layer)
Mask = numpy.vstack((Mask,Mask_Copy))
if Def_Print:
print "numpy.shape(Mask_Index),numpy.shape(Mask)",numpy.shape(Mask_Index),numpy.shape(Mask)
nx = numpy.size(numpy.where(Mask_Index == False)) # Number of Model Grids
ny = Obs_Index_Dim # Number of the Observations
if Def_Print:
if (not Parameter_Optimization_Flag) and (not ((numpy.size(numpy.where(Bias_Estimation_Option_Model == 1)) >= 1) or (numpy.size(numpy.where(Bias_Estimation_Option_Obs == 1)) >= 1))):
# For State Estimatio
if Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Soil_Moisture":
if SensorType == "InSitu":
if Feedback_Assim: # and (string.atoi(Stop_Month) >= 4) and (string.atoi(Stop_Month) <= 10):
print "The Number of Model Grid is:", nx / (Soil_Layer_Num-5+17)
else:
print "The Number of Model Grid is:", nx / (Soil_Layer_Num-5)
else:
if Feedback_Assim: # and (string.atoi(Stop_Month) >= 4) and (string.atoi(Stop_Month) <= 10):
print "The Number of Model Grid is:", nx / (Soil_Layer_Num-5+1+17)
else:
print "The Number of Model Grid is:", nx / (Soil_Layer_Num-5+1)
elif (Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Surface_Temperature"):
if Feedback_Assim: # and (string.atoi(Stop_Month) >= 4) and (string.atoi(Stop_Month) <= 10):
print "The Number of Model Grid is:", nx / (Soil_Layer_Num+3+10)
else:
print "The Number of Model Grid is:", nx / (Soil_Layer_Num+3)
else:
print "The Number of Model Grid is:", nx / (1)
else:
# For Parameter Estimation
if Soil_Par_Sens_Dim >= 1:
print "The Number of Model Grid is:", nx / (Soil_Par_Sens_Dim+1)
if PFT_Par_Sens_Dim >= 1:
print "The Number of Model Grid is:", nx / (PFT_Par_Sens_Dim+1)
print "The Number of Observation Grid is:", ny
if (not Parameter_Optimization_Flag) and (not ((numpy.size(numpy.where(Bias_Estimation_Option_Model == 1)) >= 1) or (numpy.size(numpy.where(Bias_Estimation_Option_Obs == 1)) >= 1))):
# For State Estimation
if Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Soil_Moisture":
if Feedback_Assim: # and (string.atoi(Stop_Month) >= 4) and (string.atoi(Stop_Month) <= 10):
if SensorType == "InSitu":
if (nx / (Soil_Layer_Num-5+17)) < ny:
print "******************nx / (Soil_Layer_Num-5+17) < ny************************",nx / (Soil_Layer_Num-5+17),ny
os.abort()
else:
if (nx / (Soil_Layer_Num-5+1+17)) < ny:
print "******************nx / (Soil_Layer_Num-5+1+17) < ny************************",nx / (Soil_Layer_Num-5+1+17),ny
os.abort()
else:
if SensorType == "InSitu":
if (nx / (Soil_Layer_Num-5)) < ny:
print "******************nx / (Soil_Layer_Num-5) < ny************************",nx / (Soil_Layer_Num-5),ny
os.abort()
else:
if (nx / (Soil_Layer_Num-5+1)) < ny:
print "******************nx / (Soil_Layer_Num-5+1) < ny************************",nx / (Soil_Layer_Num-5+1),ny
os.abort()
elif (Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Surface_Temperature"):
if Feedback_Assim: # and (string.atoi(Stop_Month) >= 4) and (string.atoi(Stop_Month) <= 10):
if (nx / (Soil_Layer_Num+3+10)) < ny:
print "******************nx / (Soil_Layer_Num+3+10) < ny************************",nx / (Soil_Layer_Num+3+10),ny
os.abort()
else:
if (nx / (Soil_Layer_Num+3)) < ny:
print "******************nx / (Soil_Layer_Num+3) < ny************************",nx / (Soil_Layer_Num+3),ny
os.abort()
else:
if (nx / (1)) < ny:
print "******************nx / (1) < ny************************",nx / (1),ny
os.abort()
else:
# For Parameter Estimation
if Soil_Par_Sens_Dim >= 1:
if (nx / (Soil_Par_Sens_Dim + 1)) < ny:
print "******************nx / (numpy.size(numpy.where(Soil_Par_Sens == True)) + 1)************************",nx / (Soil_Par_Sens_Dim + 1),ny
os.abort()
if PFT_Par_Sens_Dim >= 1:
if (nx / (PFT_Par_Sens_Dim + 1)) < ny:
print "******************nx / (numpy.size(numpy.where(PFT_Par_Sens == True)) + 1)************************",nx / (PFT_Par_Sens_Dim + 1),ny
os.abort()
#H Operator where the Value of H is 1.0 at the Location of the Observed Grid
Mask_False = numpy.where(Mask_Index == False)
Mask_False_Single_Layer = numpy.where(Mask_Index_Single_Layer == False)
if Def_Print:
print "Mask_False",Mask_False[0]
print "Mask_False_Single_Layer",Mask_False_Single_Layer
h = numpy.zeros((ny, nx),dtype=numpy.integer)
#h[~Mask_Index,~Mask_Index] = 1.0
if Def_Print >= 3:
print "Obs_Index",Obs_Index[0]
if Def_ParFor:
#print "State_DIM_Single_Layer",State_DIM_Single_Layer,numpy.shape(h[:,0:State_DIM_Single_Layer])
#----------------------------------******* Using ParFor to Accelerate H_Operator"
ParFor_H_Operator(h[:,0:State_DIM_Single_Layer],ny,Mask_False_Single_Layer[0],Obs_Index[0],Variable_Assimilation_Flag[Variable_List.index("Soil_Moisture")],\
SensorVariable,SensorType,Soil_Layer_Index_DA,State_DIM_Single_Layer,\
Parameter_Optimization_Flag,Bias_Estimation_Option_Model[Variable_List.index(SensorVariable)], Bias_Estimation_Option_Obs[Variable_List.index(SensorVariable)],DAS_Depends_Path,omp_get_num_procs_ParFor)
else:
for ny_index in range(ny):
if numpy.size(numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])) > 0:
#print numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])
if (not Parameter_Optimization_Flag) and (not ((numpy.size(numpy.where(Bias_Estimation_Option_Model == 1)) >= 1) or (numpy.size(numpy.where(Bias_Estimation_Option_Obs == 1)) >= 1))):
# For State Estimation
if Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Soil_Moisture":
if SensorType == "InSitu":
#print Mask_False_Single_Layer[0],Obs_Index[0][ny_index],numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])
H_Col_Index = numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])[0][0] + Soil_Layer_Index_DA*State_DIM_Single_Layer
else:
#print Mask_False_Single_Layer[0],Obs_Index[0][ny_index],numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])
H_Col_Index = numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])[0][0]
else:
H_Col_Index = numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])[0][0]
elif (not Parameter_Optimization_Flag) and ((numpy.size(numpy.where(Bias_Estimation_Option_Model == 1)) >= 1) or (numpy.size(numpy.where(Bias_Estimation_Option_Obs == 1)) >= 1)):
# For Bias Estimation
if Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Soil_Moisture":
H_Col_Index = numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])[0][0]
else:
H_Col_Index = numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])[0][0]
else:
# For Bias Estimation
H_Col_Index = numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])[0][0]
#print "numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])[0][0]",numpy.where(Mask_False_Single_Layer[0] == Obs_Index[0][ny_index])[0][0]
h[ny_index,H_Col_Index] = 1
#
#-------------------------------------=========== Do Data Assimilation ========================================================'
if (not Parameter_Optimization_Flag) and (not ((numpy.size(numpy.where(Bias_Estimation_Option_Model == 1)) >= 1) or (numpy.size(numpy.where(Bias_Estimation_Option_Obs == 1)) >= 1))):
# For State Estimation
if Write_DA_File_Flag:
#numpy.savetxt(DasPy_Path+"Analysis/DAS_Temp/h.txt", h) # h is too large to save
numpy.savetxt(DasPy_Path+"Analysis/DAS_Temp/E0_SysModel_State.txt", E0_SysModel)
numpy.savetxt(DasPy_Path+"Analysis/DAS_Temp/E0_ObsModel_State.txt", E0_ObsModel)
else:
if Write_DA_File_Flag:
#numpy.savetxt(DasPy_Path+"Analysis/DAS_Temp/h.txt", h) # h is too large to save
numpy.savetxt(DasPy_Path+"Analysis/DAS_Temp/E0_SysModel_Parameter.txt", E0_SysModel)
numpy.savetxt(DasPy_Path+"Analysis/DAS_Temp/E0_ObsModel_Parameter.txt", E0_ObsModel)
# 4D-LETKF
nwindow = 1 # time window for 4D-LETKF
R = numpy.diagflat(Observation_Variance.flatten()[Obs_Index])
GridSize_Sys = abs((MODEL_X_Right - MODEL_X_Left) / Col_Numbers)
GridSize_Obs = abs((MODEL_X_Right - MODEL_X_Left) / Col_Numbers)
#------------------------- Call Assimilation Algorithm --------------------"
ftype = Assim_Algorithm_Name
bf = []
alpha_bias = 0.5 # LETKF Bias Correction Turning Parameter
B = []
gssm_name = 'CLM'
Gssm_model_tag = 'GSSM_CLM'
U1 = [0]
U2 = [0]
#print numpy.shape(Mask[~Mask_Index,:])
#print numpy.shape(E0_SysModel[:,:]),numpy.shape(E0_ObsModel[:,:])
#print nx,ny,numpy.shape(Mask[~Mask_Index,:])
print 'There are ', nx, ' Grids need to be processed! ','nthreads',omp_get_num_procs_ParFor,' Num_Local_Obs ',Num_Local_Obs,"for Block",Block_Index
if Def_Print:
print "numpy.shape(parm_infl)",numpy.shape(parm_infl)
#numpy.savetxt("E0_SysModel.txt",E0_SysModel[:,0:Ensemble_Number])
#numpy.savetxt("E0_ObsModel.txt",E0_ObsModel)
if (not Parameter_Optimization_Flag) and (not ((numpy.size(numpy.where(Bias_Estimation_Option_Model == 1)) >= 1) or (numpy.size(numpy.where(Bias_Estimation_Option_Obs == 1)) >= 1))):
# For State Estimation
if Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Soil_Moisture":
State_Layer_Num_Single_Column = 11 + ParFlow_Layer_Num
if Feedback_Assim:
State_Layer_Num_Single_Column = 11 + 15
elif (Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Surface_Temperature"):
State_Layer_Num_Single_Column = 18
if Feedback_Assim:
State_Layer_Num_Single_Column = 18 + 10
else:
State_Layer_Num_Single_Column = 1
elif Parameter_Optimization_Flag:
if Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Soil_Moisture":
State_Layer_Num_Single_Column = 1
if Feedback_Assim:
State_Layer_Num_Single_Column = 1
elif (Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Surface_Temperature"):
State_Layer_Num_Single_Column = 1
if Feedback_Assim:
State_Layer_Num_Single_Column = 1
else:
State_Layer_Num_Single_Column = 1
if PFT_Par_Sens_Dim >= 1:
Par_Uniform_STD = numpy.asarray(Par_PFT_Uniform_STD,numpy.float32)
Par_Sens_Dim = PFT_Par_Sens_Dim
elif Soil_Par_Sens_Dim >= 1:
Par_Uniform_STD = numpy.asarray(Par_Soil_Uniform_STD,numpy.float32)
Par_Sens_Dim = Soil_Par_Sens_Dim
else:
Par_Uniform_STD = numpy.zeros(1,numpy.float32)
Par_Sens_Dim = 1
if Def_Print:
print "Par_Uniform_STD",Par_Uniform_STD,"Par_Sens_Dim",Par_Sens_Dim
Bias_Forecast_Model_Option = Bias_Estimation_Option_Model[Variable_List.index(SensorVariable)]
Bias_Observation_Model_Option = Bias_Estimation_Option_Obs[Variable_List.index(SensorVariable)]
Bias_Model_Dim = State_DIM_Single_Layer
Bias_Obs_Dim = State_DIM_Single_Layer
Bias_Model_Uniform_STD = numpy.zeros(Bias_Model_Dim)
Bias_Obs_Uniform_STD = numpy.zeros(Bias_Obs_Dim)
Model_Inflation_Uniform_STD = numpy.zeros(nx)
Model_Inflation_Uniform_STD[:] = Model_State_Inflation_Range_STD[Variable_List.index(SensorVariable)]
if PFT_Par_Sens_Dim >= 1 or Soil_Par_Sens_Dim >= 1:
if not numpy.size(Par_Uniform_STD) >= 1:
print "not numpy.size(Par_Uniform_STD) >= 1 !!!!!!!!!!!!!!!!!!!!!!"
os.abort()
########################NS++++++++++++++++++++++
if (numpy.abs(numpy.min(Obs_Grid[:, 2]) - numpy.mean(E0_ObsModel[:, 0:Ensemble_Number])) > 3*numpy.std(E0_ObsModel[:, 0:Ensemble_Number])) or \
(numpy.abs(numpy.max(Obs_Grid[:, 2]) - numpy.mean(E0_ObsModel[:, 0:Ensemble_Number])) > 3*numpy.std(E0_ObsModel[:, 0:Ensemble_Number])):
Normal_Score_Trans_Temp = 0
else:
Normal_Score_Trans_Temp = Normal_Score_Trans
############################ BoxCox
minimize_lbfgsb_m = 10
minimize_lbfgsb_iprint = -1
minimize_lbfgsb_factr = 1e1
minimize_lbfgsb_pgtol = 1.0e-5
minimize_lbfgsb_epsilon_in = numpy.asarray([1e-08,1e-08])
if PDAF_Assim_Framework:
print "********************************************** Using PDAF to Accelerate Assimilation"
if PDAF_Filter_Type == 2 or PDAF_Filter_Type == 4 or PDAF_Filter_Type == 6:
type_forget = 0
else:
type_forget = 0
# Assing the processors for MPI
if ny < NSLOTS:
NSLOTS_PDAF = ny
else:
NSLOTS_PDAF = NSLOTS
if PDAF_Assim_Framework == 2:
PDAF_Path = "mpiexec -n "+str(NSLOTS_PDAF)+" "+DasPy_Path+"Algorithm/PDAF/bin/offline_2D_parallel/PDAF_offline -filtertype "+str(PDAF_Filter_Type)+" -type_forget "+str(type_forget)+" -locweight 2 -local_range "+str(Observation_Corelation_Par[3, 0])
#PDAF_Path = "mpiexec -n 1 "+DasPy_Path+"Algorithm/PDAF/bin/offline_2D_parallel/PDAF_offline -filtertype "+str(PDAF_Filter_Type)+" -type_forget "+str(type_forget)+" -locweight 2 -local_range "+str(Observation_Corelation_Par[3, 0])
else:
PDAF_Path = DasPy_Path+"Algorithm/PDAF/bin/offline_2D_serial/PDAF_offline -filtertype "+str(PDAF_Filter_Type)+" -type_forget "+str(type_forget)+" -locweight 2 -local_range "+str(Observation_Corelation_Par[3, 0])
#PDAF_Path = DasPy_Path+"Algorithm/PDAF/bin/offline_2D_serial/PDAF_offline -filtertype "+str(PDAF_Filter_Type)+" -type_forget "+str(type_forget)+" -locweight 2 -local_range 500"
print "-----PDAF_Path-----",PDAF_Path
os.chdir(DasPy_Path)
PDAF_Work_Path = DAS_Output_Path+"Analysis/"+Region_Name+"/Block_"+str(Block_Index+1)+"/"
NC_FileName_PDAF = PDAF_Work_Path+"NC_to_PDAF.nc"
NC_File_Out_PDAF = netCDF4.Dataset(NC_FileName_PDAF, 'w', diskless=True, persist=True, format='NETCDF4')
# Dim the dimensions of NetCDF
NC_File_Out_PDAF.createDimension('STATE_DIM', nx)
NC_File_Out_PDAF.createDimension('Parameter_DIM', Par_Sens_Dim)
NC_File_Out_PDAF.createDimension('Par_Sens_Dim', Par_Sens_Dim)
NC_File_Out_PDAF.createDimension('OBS_DIM', ny)
NC_File_Out_PDAF.createDimension('SOIL_LAYER_NUM', Soil_Layer_Num)
NC_File_Out_PDAF.createDimension('ParFlow_Layer_Num', ParFlow_Layer_Num)
NC_File_Out_PDAF.createDimension('ENSEMBLE_NUMBER', Ensemble_Number)
NC_File_Out_PDAF.createDimension('COORD_DIM', 2)
NC_File_Out_PDAF.createDimension('Scalar', 1)
NC_File_Out_PDAF.createDimension('Bias_Model_Dim',Bias_Model_Dim)
NC_File_Out_PDAF.createDimension('Bias_Obs_Dim',Bias_Obs_Dim)
NC_File_Out_PDAF.createDimension('lmbda_DIM',2)
NC_File_Out_PDAF.createVariable('Normal_Score_Trans','i4',('Scalar',),zlib=True)
if Normal_Score_Trans_Temp:
NC_File_Out_PDAF.variables['Normal_Score_Trans'][:] = 1
else:
NC_File_Out_PDAF.variables['Normal_Score_Trans'][:] = 0
NC_File_Out_PDAF.createVariable('Alpha_Inflation','f4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['Alpha_Inflation'][:] = Post_Inflation_Alpha
NC_File_Out_PDAF.createVariable('Parameter_Optimization_Flag','i4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['Parameter_Optimization_Flag'][:] = Parameter_Optimization_Flag
NC_File_Out_PDAF.createVariable('Bias_Forecast_Model_Option','i4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['Bias_Forecast_Model_Option'][:] = Bias_Forecast_Model_Option
NC_File_Out_PDAF.createVariable('Bias_Observation_Model_Option','i4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['Bias_Observation_Model_Option'][:] = Bias_Observation_Model_Option
NC_File_Out_PDAF.createVariable('State_DIM_Single_Layer','i4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['State_DIM_Single_Layer'][:] = State_DIM_Single_Layer
NC_File_Out_PDAF.createVariable('State_DIM_Single_Column','i4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['State_DIM_Single_Column'][:] = State_Layer_Num_Single_Column
NC_File_Out_PDAF.createVariable('Correlation_Range','i4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['Correlation_Range'][:] = Observation_Corelation_Par[3, 0] / Grid_Resolution_CEA
NC_File_Out_PDAF.createVariable('GridSize_Sys','f4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['GridSize_Sys'][:] = GridSize_Sys
NC_File_Out_PDAF.createVariable('GridSize_Obs','f4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['GridSize_Obs'][:] = GridSize_Obs
NC_File_Out_PDAF.createVariable('minimize_lbfgsb_n','i4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['minimize_lbfgsb_n'][:] = 2
NC_File_Out_PDAF.createVariable('minimize_lbfgsb_m','i4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['minimize_lbfgsb_m'][:] = minimize_lbfgsb_m
NC_File_Out_PDAF.createVariable('minimize_lbfgsb_iprint','i4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['minimize_lbfgsb_iprint'][:] = minimize_lbfgsb_iprint
NC_File_Out_PDAF.createVariable('minimize_lbfgsb_factr','f4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['minimize_lbfgsb_factr'][:] = minimize_lbfgsb_factr
NC_File_Out_PDAF.createVariable('minimize_lbfgsb_pgtol','f4',('Scalar',),zlib=True)
NC_File_Out_PDAF.variables['minimize_lbfgsb_pgtol'][:] = minimize_lbfgsb_pgtol
NC_File_Out_PDAF.createVariable('minimize_lbfgsb_epsilon_in','f4',('lmbda_DIM',),zlib=True)
NC_File_Out_PDAF.variables['minimize_lbfgsb_epsilon_in'][:] = minimize_lbfgsb_epsilon_in
NC_File_Out_PDAF.createVariable('XF_NC','f4',('ENSEMBLE_NUMBER','STATE_DIM',),zlib=True)
NC_File_Out_PDAF.createVariable('HXF_NC','f4',('ENSEMBLE_NUMBER','STATE_DIM',),zlib=True)
NC_File_Out_PDAF.createVariable('H_NC','i4',('STATE_DIM','OBS_DIM',),zlib=True)
NC_File_Out_PDAF.createVariable('OBS_NC','f4',('STATE_DIM',),zlib=True)
NC_File_Out_PDAF.createVariable('XF_COORD_NC','f4',('COORD_DIM','STATE_DIM',),zlib=True)
NC_File_Out_PDAF.createVariable('OBS_COORD_NC','f4',('COORD_DIM','OBS_DIM',),zlib=True)
NC_File_Out_PDAF.createVariable('R_NC','f4',('OBS_DIM','OBS_DIM',),zlib=True)
NC_File_Out_PDAF.createVariable('XA_NC','f4',('ENSEMBLE_NUMBER','STATE_DIM',),zlib=True)
NC_File_Out_PDAF.createVariable('XM_NC','f4',('STATE_DIM',),zlib=True)
NC_File_Out_PDAF.createVariable('Par_Uniform_STD','f4',('Parameter_DIM',),zlib=True)
NC_File_Out_PDAF.createVariable('Bias_Model_Uniform_STD','f4',('Bias_Model_Dim',),zlib=True)
NC_File_Out_PDAF.createVariable('Bias_Obs_Uniform_STD','f4',('Bias_Obs_Dim',),zlib=True)
NC_File_Out_PDAF.createVariable('Model_Inflation_Uniform_STD','f4',('STATE_DIM',),zlib=True)
NC_File_Out_PDAF.close()
NC_File_Out_PDAF = netCDF4.Dataset(NC_FileName_PDAF, 'r+', format='NETCDF4')
NC_File_Out_PDAF.variables['XF_NC'][:,:] = numpy.transpose(E0_SysModel[:, 0:Ensemble_Number])
#NC_File_Out_PDAF.variables['XF_NC_Init'][:,:] = numpy.transpose(E0_SysModel_Copy_Dual[:, 0:Ensemble_Number])
NC_File_Out_PDAF.variables['HXF_NC'][:,:] = numpy.transpose(E0_ObsModel[:, 0:Ensemble_Number])
NC_File_Out_PDAF.variables['H_NC'][:,:] = 0.0
NC_File_Out_PDAF.variables['H_NC'][:,:] = numpy.transpose(h[:,:])
NC_File_Out_PDAF.variables['OBS_NC'][:] = -9999.0
NC_File_Out_PDAF.variables['OBS_NC'][Obs_Index] = Obs_Grid[:, 2]
NC_File_Out_PDAF.variables['XF_COORD_NC'][0,:] = Mask[~Mask_Index, 0]
NC_File_Out_PDAF.variables['XF_COORD_NC'][1,:] = Mask[~Mask_Index, 1]
NC_File_Out_PDAF.variables['OBS_COORD_NC'][0,:] = Mask[~Mask_Index, 0][Obs_Index]
NC_File_Out_PDAF.variables['OBS_COORD_NC'][1,:] = Mask[~Mask_Index, 1][Obs_Index]
#NC_File_Out_PDAF.variables['OBS_COORD_NC'][0,:] = Observation_Longitude.flatten()[~Mask_Index_Single_Layer]
#NC_File_Out_PDAF.variables['OBS_COORD_NC'][1,:] = Observation_Latitude.flatten()[~Mask_Index_Single_Layer]
NC_File_Out_PDAF.variables['R_NC'][:,:] = numpy.transpose(R)
NC_File_Out_PDAF.variables['Par_Uniform_STD'][:] = Par_Uniform_STD
NC_File_Out_PDAF.variables['Bias_Model_Uniform_STD'][:] = Bias_Model_Uniform_STD[:]
NC_File_Out_PDAF.variables['Bias_Obs_Uniform_STD'][:] = Bias_Obs_Uniform_STD[:]
NC_File_Out_PDAF.variables['Model_Inflation_Uniform_STD'][:] = Model_Inflation_Uniform_STD[:]
NC_File_Out_PDAF.sync()
NC_File_Out_PDAF.close()
os.chdir(PDAF_Work_Path)
print "************Call PDAF"
PDAF_Output = open("PDAF_Output.txt","w")
subprocess.call(shlex.split(PDAF_Path), stdout=PDAF_Output, stderr=PDAF_Output, shell=False)
#subprocess.call(shlex.split(PDAF_Path, shell=False)
PDAF_Output.close()
#subprocess.call(shlex.split("killall -9 -q -w PDAF_offline &> /dev/null"),shell=False)
#subprocess.call(shlex.split("killall -9 -q -w psilogger PDAF_offline &> /dev/null"),shell=False)
#os.abort()
os.chdir(DasPy_Path)
NC_File_Out_PDAF = netCDF4.Dataset(NC_FileName_PDAF, 'r')
xa = numpy.transpose(NC_File_Out_PDAF.variables['XA_NC'][:,:])
NC_File_Out_PDAF.close()
innovation = numpy.zeros((nx,Ensemble_Number),dtype=numpy.float32)
increments = numpy.zeros((nx,Ensemble_Number),dtype=numpy.float32)
localization_map = numpy.zeros(nx,dtype=numpy.float32)
bias_a = numpy.zeros(nx,dtype=numpy.float32)
#os.abort()
else:
try:
xa,innovation,increments,localization_map,bias_a = Call_ReBEL_Octave.ReBEL(gssm_das_octave, letkf, letkf_common, octave,ftype,gssm_name,Gssm_model_tag,nx,ny,nwindow,Ensemble_Number,Num_Local_Obs,eps,Mask[~Mask_Index,:],Obs_Grid,h,B,R,Model_State,E0_SysModel[:,0:Ensemble_Number],E0_ObsModel,
Observation_Corelation_Par,Grid_Resolution_CEA,Grid_Resolution_CEA,bf,alpha_bias, Bias_Forecast_Model_Option, Bias_Observation_Model_Option, msw_infl,parm_infl,Post_Inflation_Alpha,omp_get_num_procs_ParFor,U1,U2,Def_Print,Parameter_Optimization_Flag,
Parameter_Regularization,Par_Uniform_STD,Par_Sens_Dim,State_DIM_Single_Layer,Def_Localization_Temp,Normal_Score_Trans,State_Layer_Num_Single_Column,Bias_Model_Uniform_STD,Bias_Obs_Uniform_STD,Model_Inflation_Uniform_STD,
minimize_lbfgsb_m,minimize_lbfgsb_iprint,minimize_lbfgsb_epsilon_in,minimize_lbfgsb_factr,minimize_lbfgsb_pgtol)
except:
print "**************** User Default Correlation Parameters to Call ReBEL Again!"
Observation_Corelation_Par[0, 0] = 6 # matern Model
Observation_Corelation_Par[1, 0] = 0.0
Observation_Corelation_Par[2, 0] = 1.0
Observation_Corelation_Par[3, 0] = 4.0*Grid_Resolution_CEA
Observation_Corelation_Par[4, 0] = 1.0
xa,innovation,increments,localization_map,bias_a = Call_ReBEL_Octave.ReBEL(gssm_das_octave, letkf, letkf_common, octave,ftype,gssm_name,Gssm_model_tag,nx,ny,nwindow,Ensemble_Number,Num_Local_Obs,eps,Mask[~Mask_Index,:],Obs_Grid,h,B,R,Model_State,E0_SysModel[:,0:Ensemble_Number],E0_ObsModel,
Observation_Corelation_Par,Grid_Resolution_CEA,Grid_Resolution_CEA,bf,alpha_bias, Bias_Forecast_Model_Option, Bias_Observation_Model_Option, msw_infl,parm_infl,Post_Inflation_Alpha,omp_get_num_procs_ParFor,U1,U2,Def_Print,Parameter_Optimization_Flag,
Parameter_Regularization,Par_Uniform_STD,Par_Sens_Dim,State_DIM_Single_Layer,Def_Localization_Temp,Normal_Score_Trans,State_Layer_Num_Single_Column,Bias_Model_Uniform_STD,Bias_Obs_Uniform_STD,Model_Inflation_Uniform_STD,
minimize_lbfgsb_m,minimize_lbfgsb_iprint,minimize_lbfgsb_epsilon_in,minimize_lbfgsb_factr,minimize_lbfgsb_pgtol)
if Def_Print:
print "********************************** Mean Innovation ************************************************"
print "Mean Innovation Value is:",numpy.mean(innovation),"Max Innovation Value is:",numpy.max(innovation),"Min Innovation Value is:",numpy.min(innovation)
print "********************************** Mean Innovation ************************************************"
print "********************************** Mean Increments ************************************************"
print "Mean Increments Value is:",numpy.mean(increments),"Max Increments Value is:",numpy.max(increments),"Min Increments Value is:",numpy.min(increments)
print "********************************** Mean Increments ************************************************"
#print xa[0,:]
#xa,parm_infl = ReBEL(ftype,gssm_name,msw_infl,nx,ny,nwindow,Ensemble_Number,eps,Mask,Obs_Grid,h,R,E0_SysModel,E0_ObsModel,Observation_Corelation_Par,GridSize_Sys,GridSize_Obs,1)
if (not Parameter_Optimization_Flag) and (not ((numpy.size(numpy.where(Bias_Estimation_Option_Model == 1)) >= 1) or (numpy.size(numpy.where(Bias_Estimation_Option_Obs == 1)) >= 1))):
# State Estimation
# ensemble mean
if (Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Surface_Temperature") or \
(Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Sensible_Heat"):
if Def_Print:
print "******************************************************** Update CLM_Soil_Temperature_Ensemble_Mat"
xm = numpy.zeros(State_DIM_Single_Layer,dtype=numpy.float32)
localization_map_col = numpy.zeros(State_DIM_Single_Layer,dtype=numpy.float32)
for i in range(State_DIM_Single_Layer):
xm[i] = numpy.mean(xa[i, :])
localization_map_col[i] = localization_map[i]
for Ens_Index in range(Ensemble_Number):
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(State_DIM_Single_Layer+0*State_DIM_Single_Layer):(State_DIM_Single_Layer+(0+1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
CLM_Vegetation_Temperature_Ensemble_Mat[:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(State_DIM_Single_Layer+1*State_DIM_Single_Layer):(State_DIM_Single_Layer+(1+1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
CLM_Ground_Temperature_Ensemble_Mat[:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
for Soil_Layer_Index in range(Soil_Layer_Num):
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(xa[:,Ens_Index])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(State_DIM_Single_Layer+(Soil_Layer_Index+2)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Index+2+1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
CLM_Soil_Temperature_Ensemble_Mat[Soil_Layer_Index,:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(xa[:,Ens_Index])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(0*State_DIM_Single_Layer):((0+1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
#print Analysis_Grid_Col[~Mask_Index]
#Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.mean(numpy.asarray(xa[:,:]),axis=1) * Random_Factor_Normal[Ens_Index]
Analysis_Grid_Array[Ens_Index,::][::] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
if Def_Print:
print "******************************************************** Update CLM_Soil_Temperature_parm_infl"
Analysis_Grid_Col = Analysis_Grid.flatten()
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(0*State_DIM_Single_Layer):((0+1)*State_DIM_Single_Layer)],dtype=numpy.float32)
CLM_Surface_Temperature_parm_infl[:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(State_DIM_Single_Layer+0*State_DIM_Single_Layer):(State_DIM_Single_Layer+(0+1)*State_DIM_Single_Layer)],dtype=numpy.float32)
CLM_Vegetation_Temperature_parm_infl[:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(State_DIM_Single_Layer+1*State_DIM_Single_Layer):(State_DIM_Single_Layer+(1+1)*State_DIM_Single_Layer)],dtype=numpy.float32)
CLM_Ground_Temperature_parm_infl[:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
for Soil_Layer_Index in range(Soil_Layer_Num):
Analysis_Grid_Col = Analysis_Grid.flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(parm_infl[:])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(State_DIM_Single_Layer+(Soil_Layer_Index+2)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Index+2+1)*State_DIM_Single_Layer)],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
CLM_Soil_Temperature_parm_infl[Soil_Layer_Index,:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
if Feedback_Assim: # and (string.atoi(Stop_Month) >= 4) and (string.atoi(Stop_Month) <= 10):
if Def_Print:
print "******************************************************** Update CLM_Soil_Moisture_Ensemble_Mat"
for Ens_Index in range(Ensemble_Number):
for Soil_Layer_Index in range(Soil_Layer_Num - 5):
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(xa[:,Ens_Index])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(State_DIM_Single_Layer+(Soil_Layer_Index+Soil_Layer_Num+2)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Index+Soil_Layer_Num+2+1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
#Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.mean(numpy.asarray(xa[(Soil_Layer_Index*State_DIM_Single_Layer):((Soil_Layer_Index+1)*State_DIM_Single_Layer),:],dtype=numpy.float32),axis=1) * Random_Factor_Normal[Ens_Index]
CLM_Soil_Moisture_Ensemble_Mat[Soil_Layer_Index,:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
if Def_Print:
print "******************************************************** Update CLM_Soil_Moisture_parm_infl"
for Soil_Layer_Index in range(Soil_Layer_Num - 5):
Analysis_Grid_Col = Analysis_Grid[::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(parm_infl[:])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(State_DIM_Single_Layer+(Soil_Layer_Index+Soil_Layer_Num+2)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Index+Soil_Layer_Num+2+1)*State_DIM_Single_Layer)],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
#Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.mean(numpy.asarray(parm_infl[(Soil_Layer_Index*State_DIM_Single_Layer):((Soil_Layer_Index+1)*State_DIM_Single_Layer),:],dtype=numpy.float32),axis=1) * Random_Factor_Normal[Ens_Index]
#print numpy.shape(CLM_Soil_Moisture_parm_infl[Soil_Layer_Index,:,:]),numpy.shape(numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1)))
CLM_Soil_Moisture_parm_infl[Soil_Layer_Index,:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
elif Variable_Assimilation_Flag[Variable_List.index(SensorVariable)] and SensorVariable == "Soil_Moisture":
if SensorType == "InSitu":
if Def_Print:
print "******************************************************** Update CLM_Soil_Moisture_Ensemble_Mat"
xm = numpy.zeros(State_DIM_Single_Layer,dtype=numpy.float32)
localization_map_col = numpy.zeros(State_DIM_Single_Layer,dtype=numpy.float32)
for i in range(State_DIM_Single_Layer):
xm[i] = numpy.mean(xa[Soil_Layer_Index_DA*State_DIM_Single_Layer+i, :])
localization_map_col[i] = localization_map[Soil_Layer_Index_DA*State_DIM_Single_Layer+i]
for Ens_Index in range(Ensemble_Number):
for Soil_Layer_Index in range(Soil_Layer_Num - 5):
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(xa[:,Ens_Index])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(Soil_Layer_Index*State_DIM_Single_Layer):((Soil_Layer_Index+1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
#Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.mean(numpy.asarray(xa[(Soil_Layer_Index*State_DIM_Single_Layer):((Soil_Layer_Index+1)*State_DIM_Single_Layer),:],dtype=numpy.float32),axis=1) * Random_Factor_Normal[Ens_Index]
CLM_Soil_Moisture_Ensemble_Mat[Soil_Layer_Index,:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(xa[:,Ens_Index])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(Soil_Layer_Index_DA*State_DIM_Single_Layer):((Soil_Layer_Index_DA+1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
#print Analysis_Grid_Col[~Mask_Index]
#Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.mean(numpy.asarray(xa[:,:]),axis=1) * Random_Factor_Normal[Ens_Index]
Analysis_Grid_Array[Ens_Index,::][::] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
if Def_Print:
print "******************************************************** Update CLM_Soil_Moisture_parm_infl"
for Soil_Layer_Index in range(Soil_Layer_Num - 5):
Analysis_Grid_Col = Analysis_Grid[::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(parm_infl[:])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(Soil_Layer_Index*State_DIM_Single_Layer):((Soil_Layer_Index+1)*State_DIM_Single_Layer)],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
#Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.mean(numpy.asarray(parm_infl[(Soil_Layer_Index*State_DIM_Single_Layer):((Soil_Layer_Index+1)*State_DIM_Single_Layer),:],dtype=numpy.float32),axis=1) * Random_Factor_Normal[Ens_Index]
#print numpy.shape(CLM_Soil_Moisture_parm_infl[Soil_Layer_Index,:,:]),numpy.shape(numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1)))
CLM_Soil_Moisture_parm_infl[Soil_Layer_Index,:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
if Feedback_Assim: # and (string.atoi(Stop_Month) >= 4) and (string.atoi(Stop_Month) <= 10):
if Def_Print:
print "******************************************************** Update CLM_Soil_Temperature_Ensemble_Mat"
for Ens_Index in range(Ensemble_Number):
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 0)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 0 + 1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
CLM_Vegetation_Temperature_Ensemble_Mat[:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 1)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 1 + 1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
CLM_Ground_Temperature_Ensemble_Mat[:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
for Soil_Layer_Index in range(Soil_Layer_Num):
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(xa[:,Ens_Index])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + Soil_Layer_Index + 2)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + Soil_Layer_Index + 2 + 1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
CLM_Soil_Temperature_Ensemble_Mat[Soil_Layer_Index,:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
if Def_Print:
print "******************************************************** Update CLM_Soil_Temperature_parm_infl"
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 0)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 0 + 1)*State_DIM_Single_Layer)],dtype=numpy.float32)
CLM_Vegetation_Temperature_parm_infl[:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 1)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 1 + 1)*State_DIM_Single_Layer)],dtype=numpy.float32)
CLM_Ground_Temperature_parm_infl[:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
for Soil_Layer_Index in range(Soil_Layer_Num):
Analysis_Grid_Col = Analysis_Grid.flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(parm_infl[:])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + Soil_Layer_Index + 2)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 5 + Soil_Layer_Index + 2 + 1)*State_DIM_Single_Layer)],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
CLM_Soil_Temperature_parm_infl[Soil_Layer_Index,:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
else:
if Def_Print:
print "******************************************************** Update CLM_Soil_Moisture_Ensemble_Mat"
xm = numpy.zeros(State_DIM_Single_Layer,dtype=numpy.float32)
localization_map_col = numpy.zeros(State_DIM_Single_Layer,dtype=numpy.float32)
for i in range(State_DIM_Single_Layer):
xm[i] = numpy.mean(xa[i, :])
localization_map_col[i] = localization_map[i]
for Ens_Index in range(Ensemble_Number):
for Soil_Layer_Index in range(Soil_Layer_Num - 5):
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(xa[:,Ens_Index])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[((Soil_Layer_Index+1)*State_DIM_Single_Layer):((Soil_Layer_Index+2)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
#Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.mean(numpy.asarray(xa[(Soil_Layer_Index*State_DIM_Single_Layer):((Soil_Layer_Index+1)*State_DIM_Single_Layer),:],dtype=numpy.float32),axis=1) * Random_Factor_Normal[Ens_Index]
CLM_Soil_Moisture_Ensemble_Mat[Soil_Layer_Index,:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(xa[:,Ens_Index])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[0:State_DIM_Single_Layer,Ens_Index],dtype=numpy.float32)
#print Analysis_Grid_Col[~Mask_Index]
#Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.mean(numpy.asarray(xa[:,:]),axis=1) * Random_Factor_Normal[Ens_Index]
Analysis_Grid_Array[Ens_Index,::][::] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
if Def_Print:
print "******************************************************** Update CLM_Soil_Moisture_parm_infl"
for Soil_Layer_Index in range(Soil_Layer_Num - 5):
Analysis_Grid_Col = Analysis_Grid[::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(parm_infl[:])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[((Soil_Layer_Index+1)*State_DIM_Single_Layer):((Soil_Layer_Index+2)*State_DIM_Single_Layer)],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
#Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.mean(numpy.asarray(parm_infl[(Soil_Layer_Index*State_DIM_Single_Layer):((Soil_Layer_Index+1)*State_DIM_Single_Layer),:],dtype=numpy.float32),axis=1) * Random_Factor_Normal[Ens_Index]
#print numpy.shape(CLM_Soil_Moisture_parm_infl[Soil_Layer_Index,:,:]),numpy.shape(numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1)))
CLM_Soil_Moisture_parm_infl[Soil_Layer_Index,:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
if Feedback_Assim: # and (string.atoi(Stop_Month) >= 4) and (string.atoi(Stop_Month) <= 10):
if Def_Print:
print "******************************************************** Update CLM_Soil_Temperature_Ensemble_Mat"
for Ens_Index in range(Ensemble_Number):
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 1)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 1 + 1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
CLM_Vegetation_Temperature_Ensemble_Mat[:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 2)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 2 + 1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
CLM_Ground_Temperature_Ensemble_Mat[:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
for Soil_Layer_Index in range(Soil_Layer_Num):
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(xa[:,Ens_Index])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + Soil_Layer_Index + 3)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + Soil_Layer_Index + 3 + 1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
CLM_Soil_Temperature_Ensemble_Mat[Soil_Layer_Index,:,:,Ens_Index] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
if Def_Print:
print "******************************************************** Update CLM_Soil_Temperature_parm_infl"
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 1)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 1 + 1)*State_DIM_Single_Layer)],dtype=numpy.float32)
CLM_Vegetation_Temperature_parm_infl[:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 2)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + 2 + 1)*State_DIM_Single_Layer)],dtype=numpy.float32)
CLM_Ground_Temperature_parm_infl[:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
for Soil_Layer_Index in range(Soil_Layer_Num):
Analysis_Grid_Col = Analysis_Grid.flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(parm_infl[:])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + Soil_Layer_Index + 3)*State_DIM_Single_Layer):(State_DIM_Single_Layer+(Soil_Layer_Num - 6 + Soil_Layer_Index + 3 + 1)*State_DIM_Single_Layer)],dtype=numpy.float32)
# #print Analysis_Grid_Col[~Mask_Index]
CLM_Soil_Temperature_parm_infl[Soil_Layer_Index,:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
else:
if Def_Print:
print "******************************************************** Update Prop_Grid_Array_Sys"
xm = numpy.zeros(State_DIM_Single_Layer,dtype=numpy.float32)
localization_map_col = numpy.zeros(State_DIM_Single_Layer,dtype=numpy.float32)
for i in range(State_DIM_Single_Layer):
xm[i] = numpy.mean(xa[i, :])
localization_map_col[i] = localization_map[i]
for Ens_Index in range(Ensemble_Number):
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(xa[:,Ens_Index])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[0:State_DIM_Single_Layer,Ens_Index],dtype=numpy.float32)
#print Analysis_Grid_Col[~Mask_Index]
#Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.mean(numpy.asarray(xa[:,:]),axis=1) * Random_Factor_Normal[Ens_Index]
Analysis_Grid_Array[Ens_Index,::][::] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
if Def_Print:
print "******************************************************** Update Prop_Grid_Array_Sys_parm_infl"
Analysis_Grid_Col = Analysis_Grid.flatten()
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl[(0*State_DIM_Single_Layer):((0+1)*State_DIM_Single_Layer)],dtype=numpy.float32)
Prop_Grid_Array_Sys_parm_infl[:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
else:
# Parameter Estimation
xm = numpy.zeros(State_DIM_Single_Layer,dtype=numpy.float32)
localization_map_col = numpy.zeros(State_DIM_Single_Layer,dtype=numpy.float32)
for i in range(State_DIM_Single_Layer):
xm[i] = numpy.mean(xa[i, :])
localization_map_col[i] = localization_map[i]
if Soil_Par_Sens_Dim >= 1:
# Assign the Optimized Parameters to Model Input
Par_Index_Sub = 0
for Par_Index in range(Dim_Soil_Par-1):
if Soil_Par_Sens[Par_Index]:
for Ens_Index in range(Ensemble_Number):
xa_temp = xa[((Par_Index_Sub+1)*State_DIM_Single_Layer):((Par_Index_Sub+2)*State_DIM_Single_Layer),Ens_Index]
Analysis_Grid_Col = Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:].flatten()
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa_temp,dtype=numpy.float32)
Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
#Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:] = imadjust.imadjust(Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:],numpy.min(Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:]),numpy.max(Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:]),Parameter_Min_Max[Par_Index,0],Parameter_Min_Max[Par_Index,1])
parm_infl_temp = parm_infl[((Par_Index_Sub+1)*State_DIM_Single_Layer):((Par_Index_Sub+2)*State_DIM_Single_Layer)]
Analysis_Grid_Col = Parameter_Soil_Space_parm_infl[Par_Index,:,:].flatten()
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl_temp,dtype=numpy.float32)
Parameter_Soil_Space_parm_infl[Par_Index,:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Par_Index_Sub += 1
if Soil_Par_Sens[Dim_Soil_Par-1]:
xa_temp = xa[((Par_Index_Sub+1)*State_DIM_Single_Layer):((Par_Index_Sub+2)*State_DIM_Single_Layer),Ens_Index]
Analysis_Grid_Col = Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:].flatten()
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa_temp,dtype=numpy.float32)
#print "data_matrix[Min_Index,:]",data_matrix[Min_Index,:]
#print "Low_Tail, High_Tail",Low_Tail, High_Tail, data_matrix[Min_Index,-2]+2
numpy.random.seed(seed=string.atoi(str((Datetime_Start - Datetime_Initial).days)))
Parameter_Soil_Space_Ensemble[:,Dim_Soil_Par-1,:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
# Soil Boundary Check
Par_Index_Sub = 0
for Par_Index in range(Dim_Soil_Par):
if Soil_Par_Sens[Par_Index]:
# Remove the outliers based on the ensemble median
Parameter_Soil_Space_Ensemble_Median = numpy.median(Parameter_Soil_Space_Ensemble[:,Par_Index,:,:],axis=0)
Parameter_Soil_Space_Ensemble_Max = Parameter_Soil_Space_Ensemble_Median + Par_Soil_Uniform_STD[Par_Index_Sub]/(numpy.sqrt(1/12.0)*2.0)
Parameter_Soil_Space_Ensemble_Min = 2.0 * Parameter_Soil_Space_Ensemble_Median - Parameter_Soil_Space_Ensemble_Max
for Ens_Index in range(Ensemble_Number):
numexpr_a = Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:]
numexpr_b = Parameter_Soil_Space_Ensemble_Min
numexpr_c = numpy.where(numexpr_a < numexpr_b)
Lower_Index = numexpr_c
numexpr_a = Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:]
numexpr_b = Parameter_Soil_Space_Ensemble_Max
numexpr_c = numpy.where(numexpr_a > numexpr_b)
Upper_Index = numexpr_c
if numpy.size(Lower_Index) > 1:
numpy.random.seed(seed=string.atoi(str((Datetime_Start - Datetime_Initial).days)+str(Par_Index)+str(Ens_Index)))
Lower_Boundary_Ens = numpy.random.uniform(1.0,High_Ratio_Par,size=numpy.shape(Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:]))
#print numpy.shape(Lower_Index),numpy.shape(Lower_Boundary_Ens)
Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:][Lower_Index] = numpy.multiply(Lower_Boundary_Ens[Lower_Index],Parameter_Soil_Space_Ensemble_Min[Lower_Index])
del Lower_Boundary_Ens
if numpy.size(Upper_Index) > 1:
numpy.random.seed(seed=string.atoi(str((Datetime_Start - Datetime_Initial).days)+str(Par_Index)+str(Ens_Index)))
Upper_Boundary_Ens = numpy.random.uniform(Low_Ratio_Par,1.0,size=numpy.shape(Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:]))
Parameter_Soil_Space_Ensemble[Ens_Index,Par_Index,:,:][Upper_Index] = numpy.multiply(Upper_Boundary_Ens[Upper_Index],Parameter_Soil_Space_Ensemble_Max[Upper_Index])
del Upper_Boundary_Ens
del Parameter_Soil_Space_Ensemble_Median,Parameter_Soil_Space_Ensemble_Max,Parameter_Soil_Space_Ensemble_Min
# Boundary Check
numexpr_a = Parameter_Soil_Space_Ensemble[:,Par_Index,:,:]
numexpr_b = Parameter_Range_Soil[0,Par_Index]
numexpr_c = numpy.where(numexpr_a < numexpr_b)
Lower_Index = numexpr_c
numexpr_a = Parameter_Soil_Space_Ensemble[:,Par_Index,:,:]
numexpr_b = Parameter_Range_Soil[1,Par_Index]
numexpr_c = numpy.where(numexpr_a > numexpr_b)
Upper_Index = numexpr_c
if numpy.size(Lower_Index) > 1:
numpy.random.seed(seed=string.atoi(str((Datetime_Start - Datetime_Initial).days)+str(Par_Index)))
#Upper = Parameter_Range_Soil[0,Par_Index] + Par_Soil_Uniform_STD[Par_Index_Sub]
Upper = Parameter_Range_Soil[0,Par_Index] + Par_Soil_Uniform_STD[Par_Index_Sub] / numpy.sqrt(1.0/12.0)
Lower_Boundary_Ens = numpy.random.uniform(Parameter_Range_Soil[0,Par_Index],Upper,size=numpy.shape(Parameter_Soil_Space_Ensemble[:,Par_Index,:,:]))
#print numpy.shape(Lower_Index),numpy.shape(Lower_Boundary_Ens)
Parameter_Soil_Space_Ensemble[:,Par_Index,:,:][Lower_Index] = Lower_Boundary_Ens[Lower_Index]
if numpy.size(Upper_Index) > 1:
numpy.random.seed(seed=string.atoi(str((Datetime_Start - Datetime_Initial).days)+str(Par_Index)))
#Lower = Parameter_Range_Soil[1,Par_Index] - Par_Soil_Uniform_STD[Par_Index_Sub]
Lower = Parameter_Range_Soil[1,Par_Index] - Par_Soil_Uniform_STD[Par_Index_Sub] / numpy.sqrt(1.0/12.0)
Upper_Boundary_Ens = numpy.random.uniform(Lower,Parameter_Range_Soil[1,Par_Index],size=numpy.shape(Parameter_Soil_Space_Ensemble[:,Par_Index,:,:]))
Parameter_Soil_Space_Ensemble[:,Par_Index,:,:][Upper_Index] = Upper_Boundary_Ens[Upper_Index]
Par_Index_Sub = Par_Index_Sub + 1
if Soil_Par_Sens[Dim_Soil_Par-1]:
Parameter_Soil_Space_Ensemble[:,Dim_Soil_Par-1,:,:] = numpy.asarray(numpy.round(Parameter_Soil_Space_Ensemble[:,Dim_Soil_Par-1,:,:]),dtype=numpy.integer)
numpy.random.seed(seed=string.atoi(str((Datetime_Start - Datetime_Initial).days)))
Lower_Boundary_Ens = numpy.random.randint(1,3,size=numpy.shape(Parameter_Soil_Space_Ensemble[:,Dim_Soil_Par-1,:,:]))
numexpr_a = Parameter_Soil_Space_Ensemble[:,Dim_Soil_Par-1,:,:]
numexpr_b = 1
numexpr_c = numpy.where(numexpr_a < numexpr_b)
Lower_Index = numexpr_c
Parameter_Soil_Space_Ensemble[:,Dim_Soil_Par-1,:,:][Lower_Index] = Lower_Boundary_Ens[Lower_Index]
numpy.random.seed(seed=string.atoi(str((Datetime_Start - Datetime_Initial).days)))
Upper_Boundary_Ens = numpy.random.randint(1,3,size=numpy.shape(Parameter_Soil_Space_Ensemble[:,Dim_Soil_Par-1,:,:]))
numexpr_a = Parameter_Soil_Space_Ensemble[:,Dim_Soil_Par-1,:,:]
numexpr_b = 20
numexpr_c = numpy.where(numexpr_a > numexpr_b)
Upper_Index = numexpr_c
Parameter_Soil_Space_Ensemble[:,Dim_Soil_Par-1,:,:][Upper_Index] = Upper_Boundary_Ens[Upper_Index]
del Lower_Boundary_Ens,Upper_Boundary_Ens
#for Soil_Layer_Index_Sub in range(Dim_Soil_Par):
# print "*****************************2"
# print numpy.min(Parameter_Soil_Space_Ensemble[Ens_Index,Soil_Layer_Index_Sub,:,:]),numpy.max(Parameter_Soil_Space_Ensemble[Ens_Index,Soil_Layer_Index_Sub,:,:])
if Def_ParFor:
Parameter_Soil_Space_Ensemble = ParFor_Texture_Check(Dim_Soil_Par, Ensemble_Number, Row_Numbers, Col_Numbers, Soil_Texture_Layer_Opt_Num, Soil_Sand_Clay_Sum, Parameter_Soil_Space_Ensemble, DAS_Depends_Path, omp_get_num_procs_ParFor)
else:
for Ens_Index in range(Ensemble_Number):
# Soil Texture Boundary Check
for Row_Index in range(Row_Numbers):
for Col_Index in range(Col_Numbers):
# if Sand + Clay is greater than their sum
for Soil_Layer_Index_Sub in range(Soil_Texture_Layer_Opt_Num):
Texture_Sum = (Parameter_Soil_Space_Ensemble[Ens_Index,Soil_Layer_Index_Sub,Row_Index,Col_Index] + Parameter_Soil_Space_Ensemble[Ens_Index,Soil_Layer_Index_Sub+Soil_Texture_Layer_Opt_Num,Row_Index,Col_Index])
if Texture_Sum > 98.0:
Ratio = Parameter_Soil_Space_Ensemble[Ens_Index,Soil_Layer_Index_Sub,Row_Index,Col_Index] / (Parameter_Soil_Space_Ensemble[Ens_Index,Soil_Layer_Index_Sub,Row_Index,Col_Index]+Parameter_Soil_Space_Ensemble[Ens_Index,Soil_Layer_Index_Sub+Soil_Texture_Layer_Opt_Num,Row_Index,Col_Index])
Diff = Texture_Sum - 98.0
Diff_Part1 = Ratio*Diff
Diff_Part2 = Diff - Diff_Part1
Parameter_Soil_Space_Ensemble[Ens_Index,Soil_Layer_Index_Sub,Row_Index,Col_Index] -= Diff_Part1
Parameter_Soil_Space_Ensemble[Ens_Index,Soil_Layer_Index_Sub+Soil_Texture_Layer_Opt_Num,Row_Index,Col_Index] -= Diff_Part2
del Texture_Sum,Ratio,Diff,Diff_Part1,Diff_Part2
#for Soil_Layer_Index_Sub in range(Dim_Soil_Par):
# print "*****************************3"
# print numpy.min(Parameter_Soil_Space_Ensemble[Ens_Index,Soil_Layer_Index_Sub,:,:]),numpy.max(Parameter_Soil_Space_Ensemble[Ens_Index,Soil_Layer_Index_Sub,:,:])
numexpr_a = Parameter_Soil_Space_Ensemble[:,2*Soil_Texture_Layer_Opt_Num:3*Soil_Texture_Layer_Opt_Num,:,:]
numexpr_b = 130.0
numexpr_c = numpy.where(numexpr_a > numexpr_b)
Parameter_Soil_Space_Ensemble[:,2*Soil_Texture_Layer_Opt_Num:3*Soil_Texture_Layer_Opt_Num,:,:][numexpr_c] = 130.0
for Ens_Index in range(Ensemble_Number):
Analysis_Grid_Col = Analysis_Grid_Array[Ens_Index,::].flatten()
# #print numpy.shape(Analysis_Grid_Col[~Mask_Index_Single_Layer]),numpy.shape(xa[:,Ens_Index])
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa[(0*State_DIM_Single_Layer):((0+1)*State_DIM_Single_Layer),Ens_Index],dtype=numpy.float32)
#print Analysis_Grid_Col[~Mask_Index]
#Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.mean(numpy.asarray(xa[:,:]),axis=1) * Random_Factor_Normal[Ens_Index]
Analysis_Grid_Array[Ens_Index,::][::] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
if PFT_Par_Sens_Dim >= 1:
print "Assign the Optimized PFT Parameters to Model Input\n"
#print numpy.shape(Parameter_PFT_Space_Ensemble)
Par_Index_Sub = 0
for Par_Index in range(Dim_PFT_Par):
if PFT_Par_Sens[Par_Index]:
for Ens_Index in range(Ensemble_Number):
xa_temp = xa[((Par_Index_Sub+1)*State_DIM_Single_Layer):((Par_Index_Sub+2)*State_DIM_Single_Layer),Ens_Index]
Analysis_Grid_Col = Parameter_PFT_Space_Ensemble[Ens_Index,Par_Index,:,:].flatten()
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(xa_temp,dtype=numpy.float32)
Parameter_PFT_Space_Ensemble[Ens_Index,Par_Index,:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
#Parameter_PFT_Space_Ensemble[Ens_Index,Par_Index,:,:] = imadjust.imadjust(Parameter_PFT_Space_Ensemble[Ens_Index,Par_Index,:,:],numpy.min(Parameter_PFT_Space_Ensemble[Ens_Index,Par_Index,:,:]),numpy.max(Parameter_PFT_Space_Ensemble[Ens_Index,Par_Index,:,:]),Parameter_Min_Max[Par_Index,0],Parameter_Min_Max[Par_Index,1])
parm_infl_temp = parm_infl[((Par_Index_Sub+1)*State_DIM_Single_Layer):((Par_Index_Sub+2)*State_DIM_Single_Layer)]
Analysis_Grid_Col = Parameter_PFT_Space_parm_infl[Par_Index,:,:].flatten()
Analysis_Grid_Col[~Mask_Index_Single_Layer] = numpy.asarray(parm_infl_temp,dtype=numpy.float32)
Parameter_PFT_Space_parm_infl[Par_Index,:,:] = numpy.reshape(Analysis_Grid_Col, (Row_Numbers, -1))
Par_Index_Sub += 1
# Hard Boundary Check
Par_Index_Sub = 0
for Par_Index in range(Dim_PFT_Par):
if PFT_Par_Sens[Par_Index]:
# Remove the outliers based on the ensemble median
Parameter_PFT_Space_Ensemble_Median = numpy.median(Parameter_PFT_Space_Ensemble[:,Par_Index,:,:],axis=0)
Parameter_PFT_Space_Ensemble_Max = Parameter_PFT_Space_Ensemble_Median + Par_PFT_Uniform_STD[Par_Index_Sub]/(numpy.sqrt(1/12.0)*2.0)
Parameter_PFT_Space_Ensemble_Min = 2.0 * Parameter_PFT_Space_Ensemble_Median - Parameter_PFT_Space_Ensemble_Max