-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathldas_setup
More file actions
executable file
·2060 lines (1788 loc) · 94.7 KB
/
ldas_setup
File metadata and controls
executable file
·2060 lines (1788 loc) · 94.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import os
import sys
import glob
import copy
import linecache
import shutil
import argparse
import fileinput
import time
import resource
import subprocess as sp
import shlex
import tempfile
import netCDF4
from dateutil import rrule
from datetime import datetime
from datetime import timedelta
from collections import OrderedDict
from dateutil.relativedelta import relativedelta
from remap_utils import *
from remap_lake_landice_saltwater import *
from remap_catchANDcn import *
from lenkf_j_template import *
"""
This script is intended to be run from any installed directory with GEOSldas.x and ldas_setup
(The default setup is ../install/bin)
"""
class LDASsetup:
def __init__(self, cmdLineArgs):
"""
"""
# ------
# Required exe input fields
# These fields are needed to pre-compute exp dir structure
# ------
rqdExeInpKeys = ['EXP_ID', 'EXP_DOMAIN', 'NUM_LDAS_ENSEMBLE',
'BEG_DATE', 'END_DATE','RESTART_PATH',
'RESTART_DOMAIN','RESTART_ID','MET_TAG','MET_PATH','FORCE_DTSTEP','BCS_PATH', 'BCS_RESOLUTION']
rqdExeInpKeys_rst = ['EXP_ID', 'EXP_DOMAIN', 'NUM_LDAS_ENSEMBLE',
'BEG_DATE', 'END_DATE','MET_TAG','MET_PATH','FORCE_DTSTEP','BCS_PATH', 'BCS_RESOLUTION']
# These keywords are excluded from LDAS.rc (i.e., only needed in pre- or post-processing)
self.NoneLDASrcKeys=['EXP_ID', 'EXP_DOMAIN',
'BEG_DATE', 'END_DATE','RESTART','RESTART_PATH',
'RESTART_DOMAIN','RESTART_ID','BCS_PATH','TILING_FILE','GRN_FILE','LAI_FILE','LNFM_FILE','NIRDF_FILE',
'VISDF_FILE','CATCH_DEF_FILE','NDVI_FILE',
'NML_INPUT_PATH','HISTRC_FILE','RST_FROM_GLOBAL','JOB_SGMT','NUM_SGMT','POSTPROC_HIST',
'MINLON','MAXLON','MINLAT','MAXLAT','EXCLUDE_FILE','INCLUDE_FILE','MWRTM_PATH','GRIDNAME',
'ADAS_EXPDIR', 'BCS_RESOLUTION', 'TILE_FILE_FORMAT' ]
self.GEOS_SITE = "@GEOS_SITE@"
# ------
# Required resource manager input fields
# ------
rqdRmInpKeys = ['account', 'walltime', 'ntasks_model']
# ------
# Optional resource manager input fields
# ------
optSlurmInpKeys = ['job_name', 'qos', 'oserver_nodes', 'writers-per-node', 'constraint']
# ===============================================================================================
#
# ------
# ./ldas_setup sample ...
# ------
#
# "sample" sub-command:
# '--exeinp' and '--batinp' are mutually exclusive command line arguments.
# Specifying one will set it to True and set the other one to False.
# That is, we can have either: {'exeinp': False, 'batinp': True }
# or: {'exeinp': True, 'batinp': False}
if 'exeinp' in cmdLineArgs: # 'exeinp' is always present in "sample" mode.
if cmdLineArgs['exeinp']:
_produceExeInput()
elif cmdLineArgs['batinp']:
_printRmInputKeys( rqdRmInpKeys, optSlurmInpKeys)
else:
raise Exception('unrecognized option')
#
# EXIT after completing "sample" sub-command
sys.exit(0)
# ===============================================================================================
#
# ------
# ./ldas_setup setup ...
# ------
# Instance variables
self.exeinpfile = cmdLineArgs['exeinpfile']
self.batinpfile = cmdLineArgs['batinpfile']
exphome_ = cmdLineArgs['exphome'].rstrip('/')
assert os.path.isdir(exphome_) # exphome should exist
self.exphome = os.path.abspath(exphome_)
self.verbose = cmdLineArgs['verbose']
# command line args for coupled land-atm DAS (see "help" strings in parseCmdLine() for details)
self.ladas_cpl = cmdLineArgs['ladas_cpl']
self.nymdb = cmdLineArgs['nymdb']
self.nhmsb = cmdLineArgs['nhmsb']
self.agcm_res = cmdLineArgs['agcm_res']
self.bcs_version = cmdLineArgs['bcs_version']
self.rstloc = cmdLineArgs['rstloc']
self.varwindow = cmdLineArgs['varwindow']
self.nens = cmdLineArgs['nens']
# obsolete command line args
self.runmodel = cmdLineArgs['runmodel']
if self.runmodel :
print('\n The option "--runmodel" is out of date, not necessary anymore. \n')
self.daysperjob = cmdLineArgs['daysperjob']
self.monthsperjob = cmdLineArgs['monthsperjob']
self.rqdExeInp = OrderedDict()
self.rqdRmInp = OrderedDict()
self.optRmInp = OrderedDict()
self.rundir = None
self.blddir = None
self.blddirLn = None
self.outdir = None
self.out_path = None
self.inpdir = None
self.exefyl = None
self.isZoomIn = False
self.catch = ''
self.has_mwrtm = False
self.has_vegopacity = False
self.assim = False
self.has_landassim_seed = False
self.has_geos_pert = False
self.nSegments = 1
self.perturb = 0
self.first_ens_id = 0
self.in_rstfile = None
self.in_tilefile = None # default string
self.ens_id_width = 6 # _eXXXX
self.bcs_dir_land = ''
self.bcs_dir_geom = ''
self.bcs_dir_landshared = ''
self.tile_types = ''
self.with_land = False
self.with_landice = False
self.adas_expdir = ''
# ------
# Read exe input file which is required to set up the dir
# ------
if self.ladas_cpl is None:
self.ladas_cpl = 0
else:
self.ladas_cpl = int(self.ladas_cpl)
self.rqdExeInp = {}
if self.ladas_cpl == 0:
self.rqdExeInp = self._parseInputFile(cmdLineArgs['exeinpfile'])
else:
_produceExeInput(out_dict=self.rqdExeInp, ladas_cpl=self.ladas_cpl)
# verifing the required input
if 'RESTART' not in self.rqdExeInp :
self.rqdExeInp['RESTART'] = "1"
if self.rqdExeInp['RESTART'].isdigit() :
if int(self.rqdExeInp['RESTART']) ==0 :
rqdExeInpKeys = rqdExeInpKeys_rst
self.rqdExeInp['RESTART_ID'] = 'None'
self.rqdExeInp['RESTART_DOMAIN'] = 'None'
self.rqdExeInp['RESTART_PATH'] = 'None'
else:
if self.rqdExeInp['RESTART'] =='G' :
rqdExeInpKeys = rqdExeInpKeys_rst
self.rqdExeInp['RESTART_DOMAIN'] = 'None'
else:
self.rqdExeInp['RESTART_ID'] = 'None'
self.rqdExeInp['RESTART_DOMAIN'] = 'None'
self.rqdExeInp['RESTART_PATH'] = 'None'
### check if ldas is coupled to adas; if so, set/overwrite input parameters accordingly
if self.ladas_cpl > 0 :
# make sure all necessary command line arguments were supplied
assert self.nymdb is not None, "Error. Must have command line arg nymdb for coupled land-atm DAS.\n"
assert self.nhmsb is not None, "Error. Must have command line arg nhmsb for coupled land-atm DAS.\n"
assert self.agcm_res is not None, "Error. Must have command line arg agcm_res for coupled land-atm DAS.\n"
assert self.bcs_version is not None, "Error. Must have command line arg bcs_version for coupled land-atm DAS.\n"
assert self.rstloc is not None, "Error. Must have command line arg rstloc for coupled land-atm DAS.\n"
assert self.varwindow is not None, "Error. Must have command line arg varwindow for coupled land-atm DAS.\n"
assert self.nens is not None, "Error. Must have command line arg nens for coupled land-atmensDAS.\n"
self.rqdExeInp['BEG_DATE'] = f"{self.nymdb} {self.nhmsb}"
rstloc_ = self.rstloc.rstrip('/') # remove trailing '/'
assert os.path.isdir(rstloc_) # make sure rstloc_ is a valid directory
self.rstloc = os.path.abspath(rstloc_)
self.rqdExeInp['RESTART_PATH'] = os.path.dirname( self.rstloc)
self.rqdExeInp['RESTART_ID'] = os.path.basename(self.rstloc)
self.adas_expdir = os.path.dirname( self.exphome)
self.rqdExeInp['ADAS_EXPDIR'] = self.adas_expdir
self.adas_expid = os.path.basename(self.adas_expdir)
self.rqdExeInp['MET_TAG'] = self.adas_expid + '__bkg'
if self.ladas_cpl == 1 :
# ldas coupled with determistic component of ADAS
self.rqdExeInp['EXP_ID'] = self.adas_expid + '_LDAS'
self.rqdExeInp['MET_PATH'] = self.adas_expdir + '/recycle/holdpredout'
self.rqdExeInp['ENSEMBLE_FORCING'] = 'NO'
elif self.ladas_cpl == 2 :
# ldas coupled with ensemble component of ADAS
self.rqdExeInp['EXP_ID'] = self.adas_expid + '_LDAS4ens'
self.rqdExeInp['MET_PATH'] = self.adas_expdir + '/atmens/mem'
self.rqdExeInp['ENSEMBLE_FORCING'] = 'YES'
else :
exit("Error. Unknown value of self.ladas_cpl.\n")
self.rqdExeInp['NUM_LDAS_ENSEMBLE'] = self.nens # fvsetup finds Nens by counting restart files
self.first_ens_id = 1 # match ADAS convention
self.rqdExeInp['FIRST_ENS_ID'] = self.first_ens_id
self.agcm_res = 'CF' + self.agcm_res # change format to "CFnnnn"
self.rqdExeInp['EXP_DOMAIN'] = self.agcm_res +'x6C_GLOBAL'
# when coupled to ADAS, "BCS_PATH" EXCLUDE bcs version info
# hard-wired BCS_PATH for now
self.rqdExeInp['BCS_PATH'] = "/discover/nobackup/projects/gmao/bcs_shared/fvInput/ExtData/esm/tiles"
self.rqdExeInp['BCS_PATH'] = self.rqdExeInp['BCS_PATH'].rstrip('/') + '/' + self.bcs_version
if self.bcs_version == "Icarus-NLv3" :
self.rqdExeInp['BCS_PATH'] = self.rqdExeInp['BCS_PATH'] + '_new_layout'
self.rqdExeInp['BCS_RESOLUTION'] = self.agcm_res +'x6C_' + self.agcm_res +'x6C'
self.rqdExeInp['RESTART_DOMAIN'] = self.agcm_res +'x6C_GLOBAL'
# the following are not in default rqdExeInp list; hardwire for now
self.rqdExeInp['MWRTM_PATH'] = '/discover/nobackup/projects/gmao/smap/LDAS_inputs_for_LADAS/RTM_params/RTMParam_SMAP_L4SM_v006/'
self.rqdExeInp['LAND_ASSIM'] = "YES"
self.rqdExeInp['MET_HINTERP'] = 0
self.landassim_dt = 10800 # seconds
# make sure ADAS analysis window [minutes] is multiple of LANDASSIM_DT [seconds]
if int(self.varwindow) % (self.landassim_dt/60) == 0 :
self.rqdExeInp['LANDASSIM_DT'] = self.landassim_dt
else :
exit("Error. LANDASSIM_DT is inconsistent with ADAS analysis window.\n")
self.rqdExeInp['LANDASSIM_T0'] = "013000" # HHMMSS
jsgmt1 = "00000000"
jsgmt2 = hours_to_hhmmss(int(self.varwindow)/60) # convert minutes to HHMMSS
self.rqdExeInp['JOB_SGMT'] = f"{jsgmt1} {jsgmt2}"
self.rqdExeInp['NUM_SGMT'] = 1
self.rqdExeInp['FORCE_DTSTEP'] = 3600
# determine END_DATE = BEG_DATE + TIME_STEP_OF_ADAS_CYCLE
_beg_date = datetime.strptime( self.rqdExeInp['BEG_DATE'], "%Y%m%d %H%M%S")
_hours = int(self.rqdExeInp['JOB_SGMT'][ 9:11])
_end_date = _beg_date + timedelta(hours=int(self.varwindow)/60)
self.rqdExeInp['END_DATE'] = _end_date.strftime("%Y%m%d %H%M%S")
# end if self.ladas_cpl > 0 -----------------------------------------------------------------------------------------
for key in rqdExeInpKeys :
assert key in self.rqdExeInp,' "%s" is required in the input file %s' % (key,self.exeinpfile)
# print rqd exe inputs
if self.verbose:
print ('\nInputs from exeinp file:\n')
_printdict(self.rqdExeInp)
self.tile_types = self.rqdExeInp.get('TILE_TYPES',"100").split()
if "100" in self.tile_types :
self.with_land = True
if "20" in self.tile_types :
self.with_landice = True
# nens is an integer and =1 for model run
self.nens = int(self.rqdExeInp['NUM_LDAS_ENSEMBLE']) # fail if Nens's val is not int
assert self.nens>0, 'NUM_LDAS_ENSEMBLE [%d] <= 0' % self.nens
_mydir = self.exphome + '/' + self.rqdExeInp['EXP_ID']
assert not os.path.isdir(_mydir), 'Dir [%s] already exists!' % _mydir
_mydir = None
self.first_ens_id = int(self.rqdExeInp.get('FIRST_ENS_ID',0))
self.perturb = int(self.rqdExeInp.get('PERTURBATIONS',0))
if self.nens > 1:
self.perturb = 1
self.ensdirs = ['ens%04d'%iens for iens in range(self.first_ens_id, self.nens + self.first_ens_id)]
# if self.ens_id_width = 4, _width = '_e%04d'
_width = '_e%0{}d'.format(self.ens_id_width-2)
# self.ensids will be a list of [_e0000, _e0001, ...]
self.ensids = [ _width%iens for iens in range(self.first_ens_id, self.nens + self.first_ens_id)]
if (self.nens == 1) :
self.ensdirs_avg = self.ensdirs
self.ensids=['']
else :
self.ensdirs_avg = self.ensdirs + ['ens_avg']
## convert date-time strings to datetime object
## start/end_time are converted to lists
## ensure end>start
self.begDates=[]
self.endDates=[]
self.begDates.append(
datetime.strptime(
self.rqdExeInp['BEG_DATE'],
'%Y%m%d %H%M%S'
)
)
self.endDates.append(
datetime.strptime(
self.rqdExeInp['END_DATE'],
'%Y%m%d %H%M%S'
)
)
if self.rqdExeInp['RESTART'].isdigit() :
if int(self.rqdExeInp['RESTART']) == 0 :
print ("No restart file (cold restart): Forcing start date to January 1, 0z")
year = self.begDates[0].year
self.begDates[0]=datetime(year =year,month=1,day =1,hour =0, minute= 0,second= 0)
assert self.endDates[0]>self.begDates[0], \
'END_DATE <= BEG_DATE'
self.job_sgmt = []
if 'JOB_SGMT' in self.rqdExeInp:
self.job_sgmt.append("JOB_SGMT: "+self.rqdExeInp['JOB_SGMT'])
else:
_datediff = relativedelta(self.endDates[0],self.begDates[0])
self.rqdExeInp['JOB_SGMT'] = "%04d%02d%02d %02d%02d%02d" %(_datediff.years,
_datediff.months,
_datediff.days,
_datediff.hours,
_datediff.minutes,
_datediff.seconds)
self.job_sgmt.append("JOB_SGMT: "+self.rqdExeInp['JOB_SGMT'])
if 'NUM_SGMT' not in self.rqdExeInp:
self.rqdExeInp['NUM_SGMT'] = 1
_years = int(self.rqdExeInp['JOB_SGMT'][ 0: 4])
_months = int(self.rqdExeInp['JOB_SGMT'][ 4: 6])
_days = int(self.rqdExeInp['JOB_SGMT'][ 6: 8])
assert self.rqdExeInp['JOB_SGMT'][8] == ' ' and self.rqdExeInp['JOB_SGMT'][9] != ' ', "JOB_SGMT format is not right"
_hours = int(self.rqdExeInp['JOB_SGMT'][ 9:11])
_mins = int(self.rqdExeInp['JOB_SGMT'][11:13])
_seconds= int(self.rqdExeInp['JOB_SGMT'][13:15])
_difftime =timedelta(days = _years*365+_months*30+_days,hours = _hours,minutes=_mins,seconds=_seconds)
_difftime = int(self.rqdExeInp['NUM_SGMT'])*_difftime
_d = self.begDates[0]
_endDate = self.endDates[0]
_d = _d + _difftime
while _d < _endDate :
print (_difftime.days)
self.nSegments +=1
print (_d.year, _d.month, _d.day)
self.begDates.append(_d)
self.endDates.insert(-1,_d)
_d = _d+ _difftime
# assemble bcs sub-directories
self.bcs_dir_land = self.rqdExeInp['BCS_PATH']+ '/land/' + self.rqdExeInp['BCS_RESOLUTION']+'/'
self.bcs_dir_geom = self.rqdExeInp['BCS_PATH']+ '/geometry/' + self.rqdExeInp['BCS_RESOLUTION']+'/'
self.bcs_dir_landshared = self.rqdExeInp['BCS_PATH']+ '/land/shared/'
# make sure MET_PATH and RESTART_PATH have trailing '/'
if self.rqdExeInp['MET_PATH'][-1] != '/':
self.rqdExeInp['MET_PATH'] = self.rqdExeInp['MET_PATH']+'/'
if self.rqdExeInp['RESTART_PATH'][-1] != '/':
self.rqdExeInp['RESTART_PATH'] = self.rqdExeInp['RESTART_PATH']+'/'
# make sure catchment and vegdyn restart files ( at least one for each) exist
if 'CATCH_DEF_FILE' not in self.rqdExeInp :
self.rqdExeInp['CATCH_DEF_FILE']= self.bcs_dir_land + 'clsm/catchment.def'
if (self.with_land) :
assert os.path.isfile(self.rqdExeInp['CATCH_DEF_FILE']),"[%s] file does not exist " % self.rqdExeInp['CATCH_DEF_FILE']
self.rqdExeInp['RST_FROM_GLOBAL'] = 1
# skip checking. It is users' reponsibility to make it right!
#if self.rqdExeInp['RESTART'].isdigit() :
# if int(self.rqdExeInp['RESTART']) == 1 :
# _numg = int(linecache.getline(self.rqdExeInp['CATCH_DEF_FILE'], 1).strip())
# _numd = _numg
# ldas_domain = self.rqdExeInp['RESTART_PATH']+ \
# self.rqdExeInp['RESTART_ID'] + \
# '/output/'+self.rqdExeInp['RESTART_DOMAIN']+'/rc_out/'+self.rqdExeInp['RESTART_ID']+'.ldas_domain.txt'
# if os.path.isfile(ldas_domain) :
# _numd = int(linecache.getline(ldas_domain, 1).strip())
#
# if _numg != _numd :
# self.rqdExeInp['RST_FROM_GLOBAL'] = 0
self.rqdExeInp['LNFM_FILE'] = ''
tile_file_format = self.rqdExeInp.get('TILE_FILE_FORMAT', 'DEFAULT')
if int(self.rqdExeInp['RST_FROM_GLOBAL']) == 1 :
txt_tile = glob.glob(self.bcs_dir_geom + '*.til')
nc4_tile = glob.glob(self.bcs_dir_geom + '*.nc4')
if tile_file_format.upper() == 'TXT' : self.rqdExeInp['TILING_FILE'] = txt_tile[0]
if tile_file_format.upper() == 'DEFAULT' : self.rqdExeInp['TILING_FILE'] = (txt_tile+nc4_tile)[-1]
self.rqdExeInp['GRN_FILE'] = glob.glob(self.bcs_dir_land + 'green_clim_*.data')[0]
self.rqdExeInp['LAI_FILE'] = glob.glob(self.bcs_dir_land + 'lai_clim_*.data' )[0]
tmp_ = glob.glob(self.bcs_dir_land + 'lnfm_clim_*.data')
if (len(tmp_) ==1) :
self.rqdExeInp['LNFM_FILE'] = tmp_[0]
self.rqdExeInp['NDVI_FILE'] = glob.glob(self.bcs_dir_land + 'ndvi_clim_*.data' )[0]
self.rqdExeInp['NIRDF_FILE'] = glob.glob(self.bcs_dir_land + 'nirdf_*.dat' )[0]
self.rqdExeInp['VISDF_FILE'] = glob.glob(self.bcs_dir_land + 'visdf_*.dat' )[0]
else :
inpdir=self.rqdExeInp['RESTART_PATH']+self.rqdExeInp['RESTART_ID']+'/input/'
self.rqdExeInp['TILING_FILE'] = os.path.realpath(glob.glob(inpdir+'*tile.data')[0])
self.rqdExeInp['GRN_FILE'] = os.path.realpath(glob.glob(inpdir+'green*data')[0])
self.rqdExeInp['LAI_FILE'] = os.path.realpath(glob.glob(inpdir+'lai*data' )[0])
tmp_ = glob.glob(self.bcs_dir_land + 'lnfm_clim_*.data')
if (len(tmp_) == 1) :
self.rqdExeInp['LNFM_FILE'] = tmp_[0]
self.rqdExeInp['NDVI_FILE'] = os.path.realpath(glob.glob(inpdir+'ndvi*data' )[0])
self.rqdExeInp['NIRDF_FILE'] = os.path.realpath(glob.glob(inpdir+'nirdf*data')[0])
self.rqdExeInp['VISDF_FILE'] = os.path.realpath(glob.glob(inpdir+'visdf*data')[0])
if self.rqdExeInp['RESTART'].isdigit() :
if int(self.rqdExeInp['RESTART']) == 2 :
self.rqdExeInp['RST_FROM_GLOBAL'] = 1
ldas_domain = self.rqdExeInp['RESTART_PATH']+ \
self.rqdExeInp['RESTART_ID'] + \
'/output/'+self.rqdExeInp['RESTART_DOMAIN']+'/rc_out/'+self.rqdExeInp['RESTART_ID']+'.ldas_domain.txt'
inpdir=self.rqdExeInp['RESTART_PATH']+self.rqdExeInp['RESTART_ID']+'/input/'
in_tilefiles_ = glob.glob(inpdir+'*tile.data')
if len(in_tilefiles_) == 0 :
inpdir=self.rqdExeInp['RESTART_PATH']+self.rqdExeInp['RESTART_ID']+'/output/'+self.rqdExeInp['RESTART_DOMAIN']+'/rc_out/'
in_tilefiles_ = glob.glob(inpdir+'MAPL_*.til')
if len(in_tilefiles_) == 0 :
in_tilefiles_ = glob.glob(inpdir+'/*.til')
if len(in_tilefiles_) == 0 :
in_tilefiles_ = glob.glob(inpdir+'/*.nc4')
self.in_tilefile =os.path.realpath(in_tilefiles_[0])
if os.path.isfile(ldas_domain):
txt_tile = glob.glob(self.bcs_dir_geom + '*.til')
nc4_tile = glob.glob(self.bcs_dir_geom + '*.nc4')
if tile_file_format.upper() == 'TXT' : self.rqdExeInp['TILING_FILE'] = txt_tile[0]
if tile_file_format.upper() == 'DEFAULT' : self.rqdExeInp['TILING_FILE'] = (txt_tile+nc4_tile)[-1]
self.rqdExeInp['GRN_FILE'] = glob.glob(self.bcs_dir_land + 'green_clim_*.data')[0]
self.rqdExeInp['LAI_FILE'] = glob.glob(self.bcs_dir_land + 'lai_clim_*.data' )[0]
tmp_ = glob.glob(self.bcs_dir_land + 'lnfm_clim_*.data')
if (len(tmp_) == 1) :
self.rqdExeInp['LNFM_FILE'] = tmp_[0]
self.rqdExeInp['LNFM_FILE'] = glob.glob(self.bcs_dir_land + 'lnfm_clim_*.data' )[0]
self.rqdExeInp['NDVI_FILE'] = glob.glob(self.bcs_dir_land + 'ndvi_clim_*.data' )[0]
self.rqdExeInp['NIRDF_FILE'] = glob.glob(self.bcs_dir_land + 'nirdf_*.dat' )[0]
self.rqdExeInp['VISDF_FILE'] = glob.glob(self.bcs_dir_land + 'visdf_*.dat' )[0]
if 'GRIDNAME' not in self.rqdExeInp :
tmptile = os.path.realpath(self.rqdExeInp['TILING_FILE'])
extension = os.path.splitext(tmptile)[1]
if extension == '.domain':
extension = os.path.splitext(tmptile)[0]
gridname_ =''
if extension == '.til':
gridname_ = linecache.getline(tmptile, 3).strip()
else:
nc_file = netCDF4.Dataset(tmptile,'r')
gridname_ = nc_file.getncattr('Grid_Name')
# in case it is an old name: SMAP-EASEvx-Mxx
gridname_ = gridname_.replace('SMAP-','').replace('-M','_M')
self.rqdExeInp['GRIDNAME'] = gridname_
if 'LSM_CHOICE' not in self.rqdExeInp:
self.rqdExeInp['LSM_CHOICE'] = 1
if int(self.rqdExeInp['LSM_CHOICE']) == 1 :
self.catch = 'catch'
if int(self.rqdExeInp['LSM_CHOICE']) == 2 :
self.catch = 'catchcnclm40'
if self.with_land:
assert int(self.rqdExeInp['LSM_CHOICE']) <= 2, "\nLSM_CHOICE=3 (Catchment-CN4.5) is no longer supported. Please set LSM_CHOICE to 1 (Catchment) or 2 (Catchment-CN4.0)"
if 'POSTPROC_HIST' not in self.rqdExeInp:
self.rqdExeInp['POSTPROC_HIST'] = 0
if 'RUN_IRRIG' not in self.rqdExeInp:
self.rqdExeInp['RUN_IRRIG'] = 0
if 'AEROSOL_DEPOSITION' not in self.rqdExeInp:
self.rqdExeInp['AEROSOL_DEPOSITION'] = 0
# default is global
_domain_dic=OrderedDict()
_domain_dic['MINLON']=-180.
_domain_dic['MAXLON']= 180.
_domain_dic['MINLAT']= -90.
_domain_dic['MAXLAT']= 90.
_domain_dic['EXCLUDE_FILE']= "''"
_domain_dic['INCLUDE_FILE']= "''"
for key,val in _domain_dic.items() :
if key in self.rqdExeInp :
_domain_dic[key]= self.rqdExeInp[key]
self.domain_def = tempfile.NamedTemporaryFile(mode='w', delete=False)
self.domain_def.write('&domain_inputs\n')
for key,val in _domain_dic.items() :
keyn=(key+" = ").ljust(16)
valn = str(val)
if '_FILE' in key:
self.domain_def.write(keyn+ "'"+valn+"'"+'\n')
else :
self.domain_def.write(keyn+ valn +'\n')
self.domain_def.write('/\n')
self.domain_def.close()
# make sure bcs files exist
if self.rqdExeInp['RESTART'].isdigit() and self.with_land :
if int(self.rqdExeInp['RESTART']) >= 1 :
y4m2='Y%4d/M%02d' % (self.begDates[0].year, self.begDates[0].month)
y4m2d2_h2m2='%4d%02d%02d_%02d%02d' % (self.begDates[0].year, self.begDates[0].month,
self.begDates[0].day,self.begDates[0].hour,self.begDates[0].minute)
tmpFile=self.rqdExeInp['RESTART_ID']+'.'+self.catch+'_internal_rst.'+y4m2d2_h2m2
tmpRstDir=self.rqdExeInp['RESTART_PATH']+'/'.join([self.rqdExeInp['RESTART_ID'],'output',
self.rqdExeInp['RESTART_DOMAIN'],'rs',self.ensdirs[0],y4m2])
catchRstFile=tmpRstDir+'/'+tmpFile
assert os.path.isfile(catchRstFile), self.catch+'_internal_rst file [%s] does not exist!' %(catchRstFile)
self.in_rstfile = catchRstFile
if int(self.rqdExeInp['RESTART']) == 1 :
tmpFile=self.rqdExeInp['RESTART_ID']+'.vegdyn_internal_rst'
tmpRstDir=self.rqdExeInp['RESTART_PATH']+'/'.join([self.rqdExeInp['RESTART_ID'],'output',
self.rqdExeInp['RESTART_DOMAIN'],'rs',self.ensdirs[0]])
vegdynRstFile=tmpRstDir+'/'+tmpFile
if not os.path.isfile(vegdynRstFile):
assert int(self.rqdExeInp['RST_FROM_GLOBAL']) == 1, 'restart from LDASsa should be global'
tmpFile=self.rqdExeInp['RESTART_ID']+'.landpert_internal_rst.'+y4m2d2_h2m2
tmpRstDir=self.rqdExeInp['RESTART_PATH']+'/'.join([self.rqdExeInp['RESTART_ID'],'output',
self.rqdExeInp['RESTART_DOMAIN'],'rs',self.ensdirs[0],y4m2])
landpertRstFile=tmpRstDir+'/'+tmpFile
if ( os.path.isfile(landpertRstFile)) :
self.has_geos_pert = True
elif (int(self.rqdExeInp['RESTART']) == 0) :
if (self.catch == 'catch'):
self.in_rstfile = '/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding' \
'/Catch/M09/20170101/catch_internal_rst'
self.in_tilefile = '/discover/nobackup/projects/gmao/ssd/land/l_data/geos5/bcs/CLSM_params' \
'/mkCatchParam_SMAP_L4SM_v002/SMAP_EASEv2_M09/SMAP_EASEv2_M09_3856x1624.til'
elif (self.catch == 'catchcnclm40'):
self.in_rstfile = '/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding' \
'/CatchCN/M36/20150301_0000/catchcnclm40_internal_dummy'
self.in_tilefile = '/discover/nobackup/projects/gmao/bcs_shared/legacy_bcs/Heracles-NL/SMAP_EASEv2_M36/SMAP_EASEv2_M36_964x406.til'
elif (self.catch == 'catchcnclm45'):
self.in_rstfile = '/discover/nobackup/projects/gmao/ssd/land/l_data/LandRestarts_for_Regridding' \
'/CatchCN/M36/19800101_0000/catchcnclm45_internal_dummy'
self.in_tilefile = '/discover/nobackup/projects/gmao/bcs_shared/legacy_bcs/Icarus-NLv3/Icarus-NLv3_EASE/SMAP_EASEv2_M36/SMAP_EASEv2_M36_964x406.til'
else:
sys.exit('need to provide at least dummy files')
# DEAL WITH mwRTM input from exec
self.assim = True if self.rqdExeInp.get('LAND_ASSIM', 'NO').upper() == 'YES' and self.with_land else False
# verify mwrtm file
if 'MWRTM_PATH' in self.rqdExeInp and self.with_land :
self.rqdExeInp['MWRTM_PATH'] = self.rqdExeInp['MWRTM_PATH']+'/'+ self.rqdExeInp['BCS_RESOLUTION']+'/'
mwrtm_param_file_ = self.rqdExeInp['MWRTM_PATH']+'mwRTM_param.nc4'
vegopacity_file_ = self.rqdExeInp['MWRTM_PATH']+'vegopacity.bin'
if os.path.isfile(mwrtm_param_file_) :
self.has_mwrtm = True
self.mwrtm_file = mwrtm_param_file_
else :
assert not mwrtm_param_file_.strip(), ' MWRTM_PATH: %s should contain mwRTM_param.nc4'% self.rqdExeInp['MWRTM_PATH']
del self.rqdExeInp['MWRTM_PATH']
if os.path.isfile(vegopacity_file_) :
self.has_vegopacity = True
self.rqdExeInp['VEGOPACITY_FILE'] = vegopacity_file_
# ------
# Read rm input file
# Read (and pop from inpfile) the input required fields in to
# self.rqdRmInp. Fields left in inpDictFromFile are then
# read in to self.optRmInp
# ------
# re-using inpDictFromFile
if self.ladas_cpl == 0 :
inpDictFromFile = self._parseInputFile(cmdLineArgs['batinpfile'])
# REQUIRED inputs
for key in rqdRmInpKeys:
self.rqdRmInp[key] = inpDictFromFile.pop(key)
# checks on rqd rm inputs
## account and walltime should exist
assert self.rqdRmInp['account']
assert self.rqdRmInp['walltime']
## ntasks_model is a +ve integer
_ntasks = int(self.rqdRmInp['ntasks_model'])
assert _ntasks>0
self.rqdRmInp['ntasks_model'] = _ntasks
_ntasks = None
# OPTIONAL inputs
for key in inpDictFromFile:
assert key in optSlurmInpKeys, \
'unknown resource manager key [%s]' % key
self.optRmInp[key] = inpDictFromFile[key]
else :
self.rqdRmInp['account'] = cmdLineArgs['account']
self.rqdRmInp['walltime'] = "01:00:00"
self.rqdRmInp['ntasks_model'] = 120
# print rm inputs
if self.verbose:
print ('\n\nRequired inputs for resource manager:')
_printdict(self.rqdRmInp)
print ('\n\nOptional inputs for resource manager:')
_printdict(self.optRmInp)
print ('\n\n')
# ------
# set top level directories
# rundir, inpdir, outdir, blddir
# executable
# exefyl
# ------
self.bindir = os.path.dirname(os.path.realpath(__file__))
self.blddir = self.bindir.rsplit('/',1)[0]
exefyl = '/bin/GEOSldas.x'
tmp_execfyl = self.blddir + exefyl
assert os.path.isfile(tmp_execfyl),\
'Executable [%s] does not exist!' % tmp_execfyl
self.expdir = self.exphome + '/' + self.rqdExeInp['EXP_ID']
self.rundir = self.expdir + '/run'
self.inpdir = self.expdir + '/input'
self.outdir = self.expdir + '/output'
self.scratchdir = self.expdir + '/scratch'
self.blddirLn = self.expdir + '/build'
self.out_path = self.outdir + '/'+self.rqdExeInp['EXP_DOMAIN']
self.bcsdir = self.outdir + '/'+self.rqdExeInp['EXP_DOMAIN']+'/rc_out/'
self.rstdir = self.outdir + '/'+self.rqdExeInp['EXP_DOMAIN']+'/rs/'
self.exefyl = self.blddirLn + exefyl
# default is set to 0 ( no output server)
if 'oserver_nodes' not in self.optRmInp :
self.optRmInp['oserver_nodes'] = 0
if (int(self.optRmInp['oserver_nodes']) >=1) :
self.rqdExeInp['WRITE_RESTART_BY_OSERVER'] = "YES"
# set default for now
if 'writers-per-node' not in self.optRmInp:
self.optRmInp['writers-per-node'] = 5
else:
self.optRmInp['writers-per-node'] = 0
# end __init__
# -----------------------------------------------------------------------------------
def _parseInputFile(self, inpfile):
"""
Private method: parse input file and return a dict of options
Input: input file
Output: dict
"""
inpdict = OrderedDict()
errstr = "line [%d] of [%s] is not in the form 'key: value'"
# determine which default values to pick from GEOS_SurfaceGridComp.rc
if self.ladas_cpl == 0 :
use_rc_defaults = 'GEOSldas=>' # use defaults for LDAS
else :
use_rc_defaults = 'GEOSagcm=>' # use defaults for AGCM
fin = open(inpfile, 'r')
linenum = 0
for line in fin:
linenum += 1
line = line.strip()
# blank line
if not line:
continue
if '"GEOSagcm=>"' in line: # echo lines that contain "GEOSagcm=>" (w/ quotation marks) [GEOS_SurfaceGridComp.rc]
continue
if '"GEOSldas=>"' in line: # echo lines that contain "GEOSldas=>" (w/ quotation marks) [GEOS_SurfaceGridComp.rc]
continue
# get 'GEOSldas=>' or 'GEOSagcm=>' defaults in GEOS_SurfaceGridComp.rc
if use_rc_defaults in line:
line = line.split(use_rc_defaults)[1]
# handle comments
position = line.find('#')
if position==0: # comment line
continue
if position>0: # strip out comment
line = line[:position]
# we expect a line to be of the form
# key : value
assert ':' in line, errstr % (linenum, inpfile)
key, val = line.split(':',1)
key = key.strip()
val = val.strip()
if not key or not val:
print ("WARNING: " + errstr % (linenum, inpfile))
continue
#raise Exception(errstr % (linenum, inpfile))
if key in inpdict:
raise Exception('Duplicate key [%s] in [%s]' % (key, inpfile))
inpdict[key] = val.strip()
fin.close()
return inpdict
# -----------------------------------------------------------------------------------
def _mkdir_p(self,path):
"""
Private method: implement 'mkdir -p' functionality
"""
if os.path.isdir(path):
return
else:
os.makedirs(path)
# -----------------------------------------------------------------------------------
def createDirStructure(self):
"""
Create required dir structure
"""
status = False
# shorthands
_nens = self.nens
# run/inp/wrk dirs
self._mkdir_p(self.exphome+'/'+self.rqdExeInp['EXP_ID'])
self._mkdir_p(self.rundir)
self._mkdir_p(self.inpdir)
self._mkdir_p(self.outdir)
self._mkdir_p(self.scratchdir)
#-start-shorthand-function-
def _getDirName(outtyp, ensdir, yyyymm):
return '/'.join([
self.outdir,
self.rqdExeInp['EXP_DOMAIN'],
outtyp, # ana/cat/rs/rc_out
ensdir,
yyyymm
])
#-end-shorthand-function-
# met forcing dir
myMetDir = self.inpdir + '/met_forcing'
self._mkdir_p(myMetDir)
# ensxxxx directories
nSegments = self.nSegments
for iseg in range(nSegments):
_start = self.begDates[iseg]
_end = self.endDates[iseg]
# Yyyyy/Mmm between StartDateTime and EndDateTime
newDate = _start
y4m2_list = [('Y%4d/M%02d' % (newDate.year, newDate.month))]
while newDate<_end:
newDate += relativedelta(months=1)
y4m2_list.append('Y%4d/M%02d' % (newDate.year, newDate.month))
# ExpDomain/ana/, /cat/ directories
for ensdir in self.ensdirs_avg:
for y4m2 in y4m2_list:
self._mkdir_p(_getDirName('ana', ensdir, y4m2))
self._mkdir_p(_getDirName('cat', ensdir, y4m2))
# ExpDomain/rs/ directories
for ensdir in self.ensdirs:
for y4m2 in y4m2_list:
self._mkdir_p(_getDirName('rs', ensdir, y4m2))
# ExpDomain/rc_out/ - only for _start
self._mkdir_p(_getDirName('rc_out', '', y4m2_list[0]))
# restart dir
self._mkdir_p(self.inpdir + '/restart')
status = True
return status
# -----------------------------------------------------------------------------------
# create links to BCs, restarts, met forcing, ...
def createLnRstBc(self) :
# link bld dir
status = False
_nens = self.nens
os.symlink(self.blddir, self.blddirLn)
# met forcing dir
self.ensemble_forcing = True if self.rqdExeInp.get('ENSEMBLE_FORCING', 'NO').upper() == 'YES' else False
myMetPath =''
for _i in range(self.first_ens_id, _nens + self.first_ens_id) :
str_ens = ''
if ( _nens != 1 and self.ensemble_forcing):
str_ens = '%03d'%(_i)
metpath = self.rqdExeInp['MET_PATH'].rstrip('/')+str_ens
myMetDir = self.inpdir + '/met_forcing'
myMetPath = myMetDir + '/' + metpath.split('/')[-1]
os.symlink(metpath, myMetPath)
# update 'met_path' to use relative path from outdir
if ( not self.ensemble_forcing):
break
if ( _nens !=1 and self.ensemble_forcing) :
# replace last three character with '%s"
self.rqdExeInp['MET_PATH'] = os.path.relpath(myMetPath, self.rundir)[:-3]+'%s'
else:
self.rqdExeInp['MET_PATH'] = os.path.relpath(myMetPath, self.rundir)
# update tile file
tile= self.rqdExeInp['TILING_FILE']
short_tile= os.path.basename(self.rqdExeInp['TILING_FILE'])
newtile = self.bcsdir+'/'+short_tile
shutil.copy(tile, newtile)
tile=newtile
# if three extra lines exist, remove them and save it to inputdir
print ('\nCorrect the tile file if it is an old EASE tile format... \n')
EASEtile=self.bcsdir+'/MAPL_'+short_tile
cmd = self.bindir + '/preprocess_ldas.x correctease '+ tile + ' '+ EASEtile
print ("cmd: " + cmd)
sp.call(shlex.split(cmd))
if os.path.isfile(EASEtile) :
#update tile file name
short_tile ='MAPL_'+short_tile
tile=EASEtile
# setup BC files
catchment_def = self.rqdExeInp['CATCH_DEF_FILE']
exp_id = self.rqdExeInp['EXP_ID']
_start = self.begDates[0]
_y4m2d2h2m2 ='%4d%02d%02d%02d%02d' % (_start.year, _start.month,_start.day,_start.hour,_start.minute)
dzsf = '50.0'
if 'SURFLAY' in self.rqdExeInp :
dzsf = self.rqdExeInp['SURFLAY']
# These are dummy values for *cold* restart:
wemin_in = '13' # WEmin input/output for scale_catch(cn),
wemin_out = '13' #
if 'WEMIN_IN' in self.rqdExeInp :
wemin_in = self.rqdExeInp['WEMIN_IN']
if 'WEMIN_OUT' in self.rqdExeInp :
wemin_out = self.rqdExeInp['WEMIN_OUT']
tmp_f2g_file = tempfile.NamedTemporaryFile(delete=False)
cmd = self.bindir +'/preprocess_ldas.x c_f2g ' + tile + ' ' + self.domain_def.name + ' '+ self.out_path + ' ' + catchment_def + ' ' + exp_id + ' ' + _y4m2d2h2m2 + ' '+ dzsf + ' ' + tmp_f2g_file.name + ' ' + '_'.join(self.tile_types)
print ('Creating f2g file if necessary: '+ tmp_f2g_file.name +'....\n')
print ("cmd: " + cmd)
sp.call(shlex.split(cmd))
# check if it is local or global
if os.path.getsize(tmp_f2g_file.name) !=0 :
self.isZoomIn= True
#os.remove(self.domain_def.name)
# update tile domain
if self.isZoomIn:
newZoominTile = tile+'.domain'
print ("\nCreating local tile file :"+ newZoominTile)
print ("\nAdding 1000 to type of tiles to be excluded from domain...\n")
cmd = self.bindir +'/preprocess_ldas.x zoomin_tile ' + tile + ' ' + newZoominTile + ' '+ tmp_f2g_file.name
print ("cmd: " + cmd)
sp.call(shlex.split(cmd))
short_tile=short_tile +'.domain'
tile = newZoominTile
myTile=self.inpdir+'/tile.data'
os.symlink(tile,myTile)
if self.with_land:
bcs=[self.rqdExeInp['GRN_FILE'],
self.rqdExeInp['LAI_FILE'],
self.rqdExeInp['NDVI_FILE'],
self.rqdExeInp['NIRDF_FILE'],
self.rqdExeInp['VISDF_FILE'] ]
if (self.rqdExeInp['LNFM_FILE'] != ''):
bcs += [self.rqdExeInp['LNFM_FILE']]
if (self.has_vegopacity):
bcs += [self.rqdExeInp['VEGOPACITY_FILE']]
bcstmp=[]
for bcf in bcs :
shutil.copy(bcf, self.bcsdir+'/')
bcstmp=bcstmp+[self.bcsdir+'/'+os.path.basename(bcf)]
bcs=bcstmp
if self.isZoomIn:
print ("Creating the boundary files for the simulation domain...\n")
bcs_tmp=[]
for bcf in bcs :
cmd = self.bindir +'/preprocess_ldas.x zoomin_bc ' + bcf + ' '+ bcf+'.domain' + ' '+ tmp_f2g_file.name
print ("cmd: " + cmd)
sp.call(shlex.split(cmd))
bcs_tmp=bcs_tmp+[bcf+'.domain']
bcs=bcs_tmp
# link BC
print ("linking bcs...")
bcnames=['green','lai','ndvi','nirdf','visdf']
if (self.rqdExeInp['LNFM_FILE'] != ''):
bcnames += ['lnfm']
if (self.has_vegopacity):
bcnames += ['vegopacity']
for bcln,bc in zip(bcnames,bcs) :
myBC=self.inpdir+'/'+bcln+'.data'
os.symlink(bc,myBC)
if ("catchcn" in self.catch):
os.symlink(self.bcs_dir_landshared + 'CO2_MonthlyMean_DiurnalCycle.nc4', \
self.inpdir+'/CO2_MonthlyMean_DiurnalCycle.nc4')
# create and link restart
print ("Creating and linking restart...")
_start = self.begDates[0]
y4m2='Y%4d/M%02d'%(_start.year, _start.month)
y4m2d2_h2m2 ='%4d%02d%02d_%02d%02d' % (_start.year, _start.month,_start.day,_start.hour,_start.minute)
myRstDir = self.inpdir + '/restart/'
rstpath = self.rqdExeInp['RESTART_PATH']+ \
self.rqdExeInp['RESTART_ID'] + \
'/output/'+self.rqdExeInp['RESTART_DOMAIN']+'/rs/'
rcoutpath = self.rqdExeInp['RESTART_PATH']+ \
self.rqdExeInp['RESTART_ID'] + \
'/output/'+self.rqdExeInp['RESTART_DOMAIN']+'/rc_out/'
# pass into remap_config_ldas
exp_id = self.rqdExeInp['EXP_ID']
RESTART_str = str(self.rqdExeInp['RESTART'])
YYYYMMDD = '%4d%02d%02d' % (_start.year, _start.month,_start.day)
YYYYMMDDHH= '%4d%02d%02d%02d' % (_start.year, _start.month,_start.day, _start.hour)
rstid = self.rqdExeInp['RESTART_ID']
rstdomain = self.rqdExeInp['RESTART_DOMAIN']
rstpath0 = self.rqdExeInp['RESTART_PATH']
# just copy the landassim pert seed if it exists
for iens in range(self.nens) :
_ensdir = self.ensdirs[iens]
_ensid = self.ensids[iens]
landassim_seeds = rstpath + _ensdir + '/' + y4m2+'/' + rstid + '.landassim_obspertrseed_rst.'+y4m2d2_h2m2
if os.path.isfile(landassim_seeds) and self.assim :
_seeds = self.rstdir + _ensdir + '/' + y4m2+'/' + exp_id + '.landassim_obspertrseed_rst.'+y4m2d2_h2m2
shutil.copy(landassim_seeds, _seeds)
os.symlink(_seeds, myRstDir+ '/landassim_obspertrseed'+ _ensid +'_rst')
self.has_landassim_seed = True
mk_outdir = self.exphome+'/'+exp_id+'/mk_restarts/'
if (RESTART_str != '1' and (self.with_land or self.with_landice)):
bcs_path = self.rqdExeInp['BCS_PATH']
while bcs_path[-1] == '/' : bcs_path = bcs_path[0:-1]
bc_base = os.path.dirname(bcs_path)
bc_version = os.path.basename(bcs_path)
remap_tpl = os.path.dirname(os.path.realpath(__file__)) + '/remap_params.tpl'
config = yaml_to_config(remap_tpl)
config['slurm_pbs']['account'] = self.rqdRmInp['account']
config['slurm_pbs']['qos'] = 'debug'
config['input']['surface']['catch_tilefile'] = self.in_tilefile
config['input']['shared']['expid'] = self.rqdExeInp['RESTART_ID']
config['input']['shared']['yyyymmddhh'] = YYYYMMDDHH
if RESTART_str != 'M':
config['input']['shared']['rst_dir'] = os.path.dirname(self.in_rstfile)+'/'
config['input']['surface']['wemin'] = wemin_in
config['input']['surface']['catch_model'] = self.catch
config['output']['shared']['out_dir'] = mk_outdir
config['output']['surface']['catch_remap'] = True
config['output']['surface']['catch_tilefile'] = self.rqdExeInp['TILING_FILE']
config['output']['shared']['bc_base'] = bc_base
config['output']['shared']['bc_version'] = bc_version