-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsite_fullrun.py
executable file
·1384 lines (1268 loc) · 65.8 KB
/
site_fullrun.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
#!/usr/bin/env python
import socket, getpass, os, sys, csv, math
from optparse import OptionParser
import subprocess
import numpy
import re
### Run options
parser = OptionParser();
# general OLMT options
parser.add_option("--no_submit", dest="no_submit", default=False, action="store_true", \
help = 'do NOT submit built model to queue, i.e. build only')
parser.add_option("--caseidprefix", dest="mycaseid", default="", \
help="Unique identifier to include as a prefix to the case name")
parser.add_option("--caseroot", dest="caseroot", default='', \
help = "case root directory, where submission scripts live (default = '', i.e., under model_root/scripts/)")
parser.add_option("--runroot", dest="runroot", default="", \
help="Directory where the run would be created")
parser.add_option("--exeroot", dest="exeroot", default="", \
help="Location of executable")
parser.add_option("--archiveroot", dest="archiveroot", default='', \
help = "archive root directory only for mesabi")
parser.add_option("--batch_build", action="store_true", default=False, \
help="Do build as part of submitted batch script")
parser.add_option("--constraints", dest="constraints", default="", \
help="Directory containing model constraints")
parser.add_option("--compare_cases", dest="compare", default='', \
help = 'caseidprefix(es) to compare')
parser.add_option("--ninst", dest="ninst", default=1, \
help = 'number of land model instances')
parser.add_option("--mc_ensemble", dest="mc_ensemble", default=-1, \
help = 'Monte Carlo ensemble (argument is # of simulations)')
parser.add_option("--ng", dest="ng", default=256, \
help = 'number of groups to run in ensemble mode')
parser.add_option("--parm_list", dest="parm_list", default='parm_list', \
help = 'File containing list of parameters to vary')
parser.add_option("--mod_parm_file", dest="mod_parm_file", default='', \
help = "adding the path to the modified parameter file")
parser.add_option("--mod_parm_file_P", dest="mod_parm_file_P", default='', \
help = "adding the path to the modified parameter file")
parser.add_option("--ensemble_file", dest="ensemble_file", default='', \
help = 'Parameter sample file to generate ensemble')
parser.add_option("--postproc_file", dest="postproc_file", default="postproc_vars", \
help = 'File for ensemble post processing')
parser.add_option("--nopftdyn", dest="nopftdyn", default=False, action="store_true", \
help='Do not use dynamic PFT file')
# general model build options
parser.add_option("--model_root", dest="csmdir", default='', \
help = "base CESM directory")
parser.add_option("--compiler", dest="compiler", default = '', \
help = "compiler to use (pgi*, gnu)")
parser.add_option("--mpilib", dest="mpilib", default="mpi-serial", \
help = "mpi library (openmpi, mpich, ibm, mpi-serial)")
parser.add_option("--debugq", dest="debug", default=False, action="store_true", \
help='Use debug queue and options')
parser.add_option("--clean_build", action="store_true", default=False, \
help="Perform a clean build")
parser.add_option("--cpl_bypass", dest = "cpl_bypass", default=False, action="store_true", \
help = "Bypass coupler")
parser.add_option("--machine", dest="machine", default = '', \
help = "machine to use")
parser.add_option("--np", dest="np", default=1, \
help = 'number of processors')
parser.add_option("--walltime", dest="walltime", default=6, \
help = "desired walltime for each job (hours)")
parser.add_option("--pio_version", dest="pio_version", default='2', \
help = "PIO version (1 or 2)")
# CASE options
parser.add_option("--nyears_ad_spinup", dest="ny_ad", default=250, \
help = 'number of years to run ad_spinup')
parser.add_option("--nyears_final_spinup", dest="nyears_final_spinup", default='200', \
help="base no. of years for final spinup")
parser.add_option("--nyears_transient", dest="nyears_transient", default=-1, \
help = 'number of years to run transient')
parser.add_option("--ad_Pinit", dest="ad_Pinit", default=False, action="store_true", \
help="Initialize AD spinup with P pools and use CNP mode")
parser.add_option("--noad", action="store_true", dest="noad", default=False, \
help='Do not perform ad spinup simulation')
parser.add_option("--nofnsp", action="store_true", dest="nofnsp", default=False, \
help='Do not perform final spinup simulation')
parser.add_option("--notrans", action="store_true", dest="notrans", default=False, \
help='Do not perform transient simulation (spinup only)')
parser.add_option("--finidat", dest="finidat", default='', \
help = 'Full path of ELM restart file to use (for transient only)')
# model input options
parser.add_option("--site", dest="site", default='', \
help = '6-character FLUXNET code to run (required)')
parser.add_option("--sitegroup", dest="sitegroup",default="AmeriFlux", \
help = "site group to use (default AmeriFlux)")
parser.add_option("--ccsm_input", dest="ccsm_input", default='', \
help = "input data directory for CESM (required)")
# metdata
parser.add_option("--nopointdata", dest="nopointdata", default=False, action="store_true", \
help="Do NOT make point data (use data already created)")
parser.add_option("--metdir", dest="metdir", default="none", \
help = 'subdirectory for met data forcing')
parser.add_option("--metdata_dir", dest="metdata_dir", default='none', \
help = 'Directory containing cpl_bypass met data (site only)')
parser.add_option("--makemetdata", action="store_true", dest="makemet", default=False, \
help="generate site meteorology")
parser.add_option("--cruncep", dest="cruncep", default=False, action="store_true", \
help = 'Use CRU-NCEP meteorology')
parser.add_option("--cruncepv8", dest="cruncepv8", default=False, action="store_true", \
help = 'Use CRU-NCEP meteorology')
parser.add_option("--gswp3", dest="gswp3", default=False, action="store_true", \
help = 'Use GSWP3 meteorology')
parser.add_option("--gswp3_w5e5", dest="gswp3_w5e5", default=False, action="store_true", \
help = 'Use GSWP3 meteorology')
parser.add_option("--princeton", dest="princeton", default=False, action="store_true", \
help = 'Use Princeton meteorology')
parser.add_option("--co2_file", dest="co2_file", default="fco2_datm_rcp4.5_1765-2500_c130312.nc", \
help = 'co2 data filename')
parser.add_option("--eco2_file", dest="eco2_file", default="", \
help = 'elevated co2 data filename, will spawn three transient simulations, using this file for an elevated co2 sim')
parser.add_option("--add_co2", dest="addco2", default=0.0, \
help = 'CO2 (ppmv) to add to atmospheric forcing')
parser.add_option("--startdate_add_co2", dest="sd_addco2", default="99991231", \
help = 'Date (YYYYMMDD) to begin addding CO2')
parser.add_option("--add_temperature", dest="addt", default=0.0, \
help = 'Temperature to add to atmospheric forcing')
parser.add_option("--startdate_add_temperature", dest="sd_addt", default="99991231", \
help = 'Date (YYYYMMDD) to begin addding temperature')
# surface data
parser.add_option("--surfdata_grid", dest="surfdata_grid", default=False, action="store_true", \
help = 'Use gridded surface data instead of site data')
parser.add_option("--surffile", dest="surffile", default='', \
help = 'Use specified surface data file')
parser.add_option("--domainfile", dest="domainfile", default="", \
help = 'Domain file to use')
# parameters
parser.add_option("--pft", dest="mypft", default=-1, \
help = 'Use this PFT (override site default)')
parser.add_option("--siteparms",dest = "siteparms", default=False, action="store_true", \
help = 'Use default PFT parameters')
parser.add_option("--parm_file", dest="parm_file", default="", \
help = 'parameter file to use')
parser.add_option("--parm_file_P", dest="parm_file_P", default="", \
help = 'parameter file to use')
parser.add_option("--fates_paramfile", dest="fates_paramfile", default="", \
help = 'Fates parameter file to use')
parser.add_option("--parm_vals", dest="parm_vals", default="", \
help = 'User specified parameter values')
# model structural config options
parser.add_option("--namelist_file", dest="namelist_file", default='', \
help="File containing custom namelist options for user_nl_clm")
parser.add_option("--tstep", dest="tstep", default=0.5, \
help = 'CLM timestep (hours)')
parser.add_option("--SP", dest="sp", default=False, action="store_true", \
help = 'Use satellite phenology mode')
parser.add_option("--lai", dest="lai", default=-999, \
help = 'Set constant LAI (SP mode only)')
parser.add_option("--run_startyear", dest="run_startyear", default="1850", \
help="Starting year for simulation (SP mode only)")
parser.add_option("--crop", action="store_true", default=False, \
help="Perform a crop model simulation")
parser.add_option("--humhol", dest="humhol", default=False, action="store_true", \
help = 'Use hummock/hollow microtopography')
parser.add_option("--marsh", dest="marsh", default=False, \
help = 'Use marsh hydrology/elevation', action="store_true")
parser.add_option("--tide_components_file", dest="tide_components_file", default='', \
help = 'NOAA tide components file')
parser.add_option("--nofire", dest="nofire", default=False, action="store_true", \
help='Turn off fire algorithms')
parser.add_option("--C13", dest="C13", default=False, action="store_true", \
help = 'Switch to turn on C13')
parser.add_option("--C14", dest="C14", default=False, action="store_true", \
help = 'Use C14 as C13 (no decay)')
parser.add_option("--aero_rcp85",dest="aerorcp85", action="store_true", default=False,help="Use RCP8.5 aerosols")
parser.add_option("--ndep_rcp85",dest="ndeprcp85", action="store_true", default=False,help="Use RCP8.5 N dep")
parser.add_option("--harvmod", action="store_true", dest='harvmod', default=False, \
help="turn on harvest modification: All harvest at first timestep")
parser.add_option("--no_dynroot", dest="no_dynroot", default=False, action="store_true", \
help = 'Turn off dynamic root distribution')
parser.add_option("--vertsoilc", dest="vsoilc", default=False, action="store_true", \
help = 'To turn on CN with multiple soil layers, excluding CENTURY C module (CLM4ME on as well)')
parser.add_option("--centbgc", dest="centbgc", default=False, action="store_true", \
help = 'To turn on CN with multiple soil layers, CENTURY C module (CLM4ME on as well)')
parser.add_option("--CH4", dest="CH4", default=False, action="store_true", \
help = 'To turn on CN with CLM4me')
parser.add_option("--fates", dest="fates", default=False, action="store_true", \
help = 'Use fates model')
parser.add_option("--fates_nutrient", dest="fates_nutrient", default="", \
help = 'Which version of fates_nutrient to use (RD or ECA)')
parser.add_option("--fates_logging", dest="fates_logging", default=False, action="store_true", \
help = 'Set fates logging to true')
parser.add_option("--ECA", dest="eca", default=False, action="store_true", \
help = 'Use ECA compset')
parser.add_option("--c_only", dest="c_only", default=False, action ="store_true", \
help='Carbon only (saturated N&P)')
parser.add_option("--cn_only", dest="cn_only", default=False, action ="store_true", \
help='Carbon/Nitrogen only (saturated P)')
parser.add_option("--srcmods_loc", dest="srcmods_loc", default='', \
help = 'Copy sourcemods from this location')
parser.add_option("--daymet", dest="daymet", default=False, \
action="store_true", help = 'Use Daymet corrected meteorology')
parser.add_option("--daymet4", dest="daymet4", default=False, \
action="store_true", help = "Daymet v4 downscaled GSWP3-v2 forcing with user-provided domain and surface data)")
parser.add_option("--dailyvars", dest="dailyvars", default=False, \
action="store_true", help="Write daily ouptut variables")
parser.add_option("--var_soilthickness",dest="var_soilthickness", default=False, \
help = 'Use variable soil depth from surface data file',action='store_true')
parser.add_option("--no_budgets", dest="no_budgets", default=False, \
help = 'Turn off CNP budget calculations', action='store_true')
parser.add_option("--use_hydrstress", dest="use_hydrstress", default=False, \
help = 'Turn on hydraulic stress', action='store_true')
parser.add_option("--spruce_treatments", dest="spruce_treatments", default=False, \
help = 'Run SPRUCE treatment simulations (ensemble mode)', action='store_true')
# model output options
parser.add_option("--hist_vars", dest="hist_vars", default='', \
help = 'Output only selected variables in h0 file (comma delimited)')
parser.add_option("--diags", dest="diags", default=False, action="store_true",
help="Write special outputs for diagnostics")
parser.add_option("--trans_varlist", dest = "trans_varlist", default='', \
help = "Transient outputs")
parser.add_option("--hist_mfilt_trans", dest="hist_mfilt", default="365", \
help = 'number of output timesteps per file (transient only)')
parser.add_option("--hist_nhtfrq_trans", dest="hist_nhtfrq", default="-24", \
help = 'output file timestep (transient only)')
parser.add_option("--spinup_vars", dest = "spinup_vars", default=False, action="store_true", \
help = "limit output variables for spinup")
parser.add_option("--hist_mfilt_spinup", dest="hist_mfilt_spinup", default="-999", \
help = 'number of output timesteps per file (spinup only)')
parser.add_option("--hist_nhtfrq_spinup", dest="hist_nhtfrq_spinup", default="-999", \
help = 'output file timestep (spinup only)')
#datasets for user-defined PFTs (by F-M Yuan, NGEE-Arctic)
parser.add_option("--maxpatch_pft", dest="maxpatch_pft", default=17, \
help = "user-defined max. patch PFT number, default is 17")
parser.add_option("--landusefile", dest="pftdynfile", default='', \
help='user-defined dynamic PFT file')
parser.add_option("--var_list_pft", dest="var_list_pft", default="",help='Comma-separated list of vars to output at PFT level')
parser.add_option("--dryrun",dest="dryrun",default=False,action="store_true",help="Do not execute commands")
(options, args) = parser.parse_args()
def runcmd(cmd,echo=True):
if echo:
print(cmd)
if not options.dryrun:
return os.system(cmd)
else:
return 0
#----------------------------------------------------------
# define function for pbs submission
def submit(fname, submit_type='qsub', job_depend=''):
job_depend_flag = ' -W depend=afterok:'
if ('sbatch' in submit_type):
job_depend_flag = ' --dependency=afterok:'
if (job_depend != '' and submit_type != ''):
runcmd(submit_type+job_depend_flag+job_depend+' '+fname+' > temp/jobinfo')
else:
if (submit_type == ''):
runcmd('chmod a+x '+fname)
runcmd('./'+fname+' > temp/jobinfo')
else:
runcmd(submit_type+' '+fname+' > temp/jobinfo')
if (submit_type != '' and not options.dryrun):
myinput = open('temp/jobinfo')
for s in myinput:
thisjob = re.search('[0-9]+', s).group(0)
myinput.close()
else:
thisjob="0"
runcmd('rm temp/jobinfo')
return thisjob
#----------------------------------------------------------
# Set default model root
if (options.csmdir == ''):
if (os.path.exists('../E3SM')):
options.csmdir = os.path.abspath('../E3SM')
print('Model root not specified. Defaulting to '+options.csmdir)
else:
print('Error: Model root not specified. Please set using --model_root')
sys.exit(1)
elif (not os.path.exists(options.csmdir)):
print('Error: Model root '+options.csmdir+' does not exist.')
sys.exit(1)
#check whether model named clm or elm
if (os.path.exists(options.csmdir+'/components/elm')):
model_name='elm'
else:
model_name='clm2'
#get machine info if not specified
npernode=32
if (options.machine == ''):
hostname = socket.gethostname()
print('')
print('Machine not specified. Using hostname '+hostname+' to determine machine')
if ('or-slurm' in hostname):
options.machine = 'cades'
npernode=32
elif ('cori' in hostname):
print('Cori machine not specified. Setting to cori-haswell')
options.machine = 'cori-haswell'
npernode=32
elif ('blues' in hostname or 'blogin' in hostname):
print('Hostname = '+hostname+' and machine not specified. Assuming anvil')
options.machine = 'anvil'
npernode=36
elif ('compy' in hostname):
options.machine = 'compy'
npernode=40
elif ('ubuntu' in hostname):
options.machine = 'ubuntu'
npernode = 8
elif ('chrlogin' in hostname):
options.machine = 'chrysalis'
npernode = 64
else:
print('ERROR in site_fullrun.py: Machine not specified. Aborting')
sys.exit(1)
if (options.ccsm_input != ''):
ccsm_input = options.ccsm_input
elif (options.machine == 'cades'):
ccsm_input = '/nfs/data/ccsi/proj-shared/E3SM/inputdata/'
elif (options.machine == 'edison' or 'cori' in options.machine):
ccsm_input = '/project/projectdirs/acme/inputdata'
elif ('anvil' in options.machine or 'chrysalis' in options.machine):
ccsm_input = '/home/ccsm-data/inputdata'
elif ('compy' in options.machine):
ccsm_input = '/compyfs/inputdata/'
#if (options.compiler != ''):
# if ('cori' in options.machine):
# options.compiler = 'intel'
# if (options.machine == 'cades'):
# options.compiler = 'gnu'
mycaseid = options.mycaseid
srcmods = options.srcmods_loc
if (mycaseid == ''):
myscriptsdir = 'none'
else:
myscriptsdir = mycaseid
#get start and year of input meteorology from site data file
PTCLMfiledir = ccsm_input+'/lnd/clm2/PTCLM'
fname = PTCLMfiledir+'/'+options.sitegroup+'_sitedata.txt'
AFdatareader = csv.reader(open(fname, "rt"))
translen = int(options.nyears_transient)
csmdir = options.csmdir
#case run and case root directories
myproject='e3sm'
if (options.runroot == '' or (os.path.exists(options.runroot) == False)):
myuser = getpass.getuser()
if (options.machine == 'cades'):
runroot='/lustre/or-scratch/cades-ccsi/scratch/'+myuser
elif ('cori' in options.machine):
runroot='/global/cscratch1/sd/'+myuser
myinput = open(os.environ.get('HOME')+'/.cesm_proj','r')
for s in myinput:
myproject=s[:-1]
print('Project = '+myproject)
elif ('anvil' in options.machine or 'chrysalis' in options.machine):
runroot="/lcrc/group/acme/"+myuser
myproject='e3sm'
elif ('compy' in options.machine):
runroot='/compyfs/'+myuser+'/e3sm_scratch'
myproject='e3sm'
else:
runroot = csmdir+'/run'
else:
runroot = os.path.abspath(options.runroot)
if (options.caseroot == options.runroot):
caseroot = os.path.abspath(options.caseroot)+'/cime_case_dirs'
os.system('mkdir -p '+caseroot)
elif (options.caseroot == '' or (os.path.exists(options.caseroot) == False)):
caseroot = os.path.abspath(csmdir+'/cime/scripts')
else:
caseroot = os.path.abspath(options.caseroot)
sitenum=0
# create ensemble file if requested (so that all cases use the same)
if (int(options.mc_ensemble) != -1):
if (not(os.path.isfile(options.parm_list))):
print('parm_list file does not exist')
sys.exit()
else:
param_names=[]
param_min=[]
param_max=[]
input = open(options.parm_list,'r')
for s in input:
if (s):
param_names.append(s.split()[0])
if (int(options.mc_ensemble) > 0):
if (len(s.split()) == 3):
param_min.append(float(s.split()[1]))
param_max.append(float(s.split()[2]))
else:
param_min.append(float(s.split()[2]))
param_max.append(float(s.split()[3]))
input.close()
n_parameters = len(param_names)
nsamples = int(options.mc_ensemble)
samples=numpy.zeros((n_parameters,nsamples), dtype=float)
for i in range(0,nsamples):
for j in range(0,n_parameters):
samples[j][i] = param_min[j]+(param_max[j]-param_min[j])*numpy.random.rand(1)
numpy.savetxt('mcsamples_'+options.mycaseid+'_'+str(options.mc_ensemble)+'.txt', \
numpy.transpose(samples))
options.ensemble_file = 'mcsamples_'+options.mycaseid+'_'+str(options.mc_ensemble)+'.txt'
mysites = options.site.split(',')
nnode=1
if(int(options.np)>1): #in case of a single site in name but with multiple unstructured gridcells
npernode=min(int(npernode),int(options.np))
nnode=-(int(options.np)//-int(npernode))
elif (not 'all' in mysites and (options.ensemble_file == '')):
npernode = len(mysites)
for row in AFdatareader:
if (row[0] in mysites) or ('all' in mysites and row[0] !='site_code' \
and row[0] != ''):
site = row[0]
if (sitenum == 0):
firstsite=site
site_lat = row[4]
site_lon = row[3]
if (options.cruncepv8 or options.cruncep or options.gswp3 or options.gswp3_w5e5 or options.princeton):
startyear = 1901
endyear = 1920
if (options.cruncepv8):
endyear_trans=2016
elif (options.gswp3):
endyear_trans=2014
elif (options.gswp3_w5e5):
endyear_trans=2019
elif (options.princeton):
endyear_trans=2012
else:
endyear_trans=2010
else:
startyear = int(row[6])
endyear = int(row[7])
if (options.diags):
timezone = int(row[9])
site_endyear = int(row[7])
ncycle = endyear-startyear+1 #number of years in met cycle
ny_ad = options.ny_ad
ny_fin = options.nyears_final_spinup
#AD spinup and final spinup lengths must be multiples of met data cyle.
if (int(options.ny_ad) % ncycle != 0):
ny_ad = str(int(ny_ad) + ncycle - (int(ny_ad) % ncycle))
# APW TCOFD
#if (int(options.nyears_final_spinup) % ncycle !=0 and options.noad == False):
if (int(options.nyears_final_spinup) % ncycle !=0):
ny_fin = str(int(ny_fin) + ncycle - (int(ny_fin) % ncycle))
if (options.nyears_transient == -1):
translen = endyear-1850+1 # length of transient run
if (options.eco2_file != ''):
translen = translen - ncycle # if experiment sim, stop first transient at exp start yr - 1
if (options.cpl_bypass and (options.cruncep or options.gswp3 or \
options.princeton or options.cruncepv8 or options.gswp3_w5e5)):
print(endyear_trans, site_endyear)
translen = min(site_endyear,endyear_trans)-1850+1
fsplen = int(ny_fin)
#get align_year
year_align = (endyear-1850+1) % ncycle
#use site parameter file if it exists
if (options.siteparms):
if (os.path.exists(PTCLMfiledir+'/parms_'+site)):
print ('Using parameter file PTCLM_Files/parms_'+site)
options.parm_file = PTCLMfiledir+'/parms_'+site
else:
options.parm_file = ''
#---------------- build base command for all calls to runcase.py -----------------------------
#print year_align, fsplen
basecmd = 'python runcase.py --site '+site+' --ccsm_input '+ \
os.path.abspath(ccsm_input)+' --rmold --no_submit --sitegroup ' + \
options.sitegroup
if (options.machine != ''):
basecmd = basecmd+' --machine '+options.machine
if (options.csmdir != ''):
basecmd = basecmd+' --model_root '+options.csmdir
if (srcmods != ''):
srcmods = os.path.abspath(srcmods)
basecmd = basecmd+' --srcmods_loc '+srcmods
elif (options.ad_Pinit):
srcmods = os.path.abspath('srcmods_Pinit')
basecmd = basecmd+' --srcmods_loc '+srcmods
if (mycaseid != ''):
basecmd = basecmd+' --caseidprefix '+mycaseid
if (options.parm_file != ''):
basecmd = basecmd+' --parm_file '+options.parm_file
if (options.parm_file_P != ''):
basecmd = basecmd+' --parm_file_P '+options.parm_file_P
if (options.parm_vals != ''):
basecmd = basecmd+' --parm_vals '+options.parm_vals
if (options.clean_build):
basecmd = basecmd+' --clean_build '
if (options.namelist_file != ''):
basecmd = basecmd+' --namelist_file '+options.namelist_file
if (options.metdir !='none'):
basecmd = basecmd+' --metdir '+options.metdir
if (options.metdata_dir !='none'):
basecmd = basecmd+' --metdata_dir '+options.metdata_dir
if (options.C13):
basecmd = basecmd+' --C13 '
if (options.C14):
basecmd = basecmd+' --C14 '
if (options.debug):
basecmd = basecmd+' --debugq'
if (options.ninst > 1):
basecmd = basecmd+' --ninst '+str(options.ninst)
if (int(options.mypft) >= 0):
basecmd = basecmd+' --pft '+str(options.mypft)
if (options.nofire):
basecmd = basecmd+' --nofire'
if (options.harvmod):
basecmd = basecmd+' --harvmod'
if (options.humhol):
basecmd = basecmd+' --humhol'
if (options.marsh):
basecmd = basecmd+' --marsh'
if (options.tide_components_file != ''):
basecmd = basecmd + ' --tide_components_file %s'%options.tide_components_file
if (float(options.lai) >= 0):
basecmd = basecmd+' --lai '+str(options.lai)
if (options.nopftdyn):
basecmd = basecmd+' --nopftdyn'
if (options.no_dynroot):
basecmd = basecmd+' --no_dynroot'
if (options.vsoilc):
basecmd = basecmd+' --vertsoilc'
if (options.centbgc):
basecmd = basecmd+' --centbgc'
if (options.c_only):
basecmd = basecmd+' --c_only'
if (options.cn_only):
basecmd = basecmd+' --cn_only'
if (options.CH4):
basecmd = basecmd+' --CH4'
if (options.cruncep):
basecmd = basecmd+' --cruncep'
if (options.cruncepv8):
basecmd = basecmd+' --cruncepv8'
if (options.gswp3):
basecmd = basecmd+' --gswp3'
if (options.gswp3_w5e5):
basecmd = basecmd+' --gswp3_w5e5'
if (options.princeton):
basecmd = basecmd+' --princeton'
if (options.daymet):
basecmd = basecmd+' --daymet'
if (options.daymet4): # gswp3 v2 spatially-downscaled by daymet v4, usually together with user-defined domain and surface data
basecmd = basecmd+' --daymet4'
if (not options.gswp3): basecmd = basecmd+' --gswp3'
if (options.fates_paramfile != ''):
basecmd = basecmd+ ' --fates_paramfile '+options.fates_paramfile
if (options.fates_nutrient != ''):
basecmd = basecmd+ ' --fates_nutrient '+options.fates_nutrient
if (options.fates_logging):
basecmd = basecmd+ ' --fates_logging '
if (options.surfdata_grid):
basecmd = basecmd+' --surfdata_grid'
if (options.ensemble_file != ''):
basecmd = basecmd+' --ensemble_file '+options.ensemble_file
basecmd = basecmd+' --parm_list '+options.parm_list
if (options.archiveroot !=''):
basecmd = basecmd+' --archiveroot '+options.archiveroot
if (options.mod_parm_file !=''):
basecmd = basecmd+' --mod_parm_file '+options.mod_parm_file
if (options.mod_parm_file_P !=''):
basecmd = basecmd+' --mod_parm_file_P '+options.mod_parm_file_P
if (options.addt != 0):
basecmd = basecmd+' --add_temperature '+str(options.addt)
basecmd = basecmd+' --startdate_add_temperature '+str(options.sd_addt)
if (options.addco2 != 0):
basecmd = basecmd+' --add_co2 '+str(options.addco2)
basecmd = basecmd+' --startdate_add_co2 '+str(options.sd_addco2)
if (options.surffile != ''):
basecmd = basecmd+' --surffile '+options.surffile
basecmd = basecmd + ' --ng '+str(options.ng)
basecmd = basecmd + ' --np '+str(options.np)
basecmd = basecmd + ' --tstep '+str(options.tstep)
basecmd = basecmd + ' --co2_file '+options.co2_file
if (options.aerorcp85):
basecmd = basecmd + ' --aero_rcp85'
if (options.ndeprcp85):
basecmd = basecmd + ' --ndep_rcp85'
if (options.compiler != ''):
basecmd = basecmd + ' --compiler '+options.compiler
basecmd = basecmd + ' --mpilib '+options.mpilib
basecmd = basecmd + ' --pio_version '+options.pio_version
basecmd = basecmd+' --caseroot '+caseroot
basecmd = basecmd+' --runroot '+runroot
basecmd = basecmd+' --walltime '+str(options.walltime)
if (options.constraints != ''):
basecmd = basecmd+' --constraints '+options.constraints
if (options.hist_vars != ''):
basecmd = basecmd+' --hist_vars '+options.hist_vars
if (options.maxpatch_pft!=17):
basecmd = basecmd + ' --maxpatch_pft '+options.maxpatch_pft
if (options.pftdynfile != ''):
basecmd = basecmd + ' --landusefile '+options.pftdynfile
if (options.var_soilthickness):
basecmd = basecmd + ' --var_soilthickness'
if (options.var_list_pft != ''):
basecmd = basecmd + ' --var_list_pft '+options.var_list_pft
if (options.no_budgets):
basecmd = basecmd+' --no_budgets'
if (options.use_hydrstress):
basecmd = basecmd+' --use_hydrstress'
if (options.spruce_treatments):
basecmd = basecmd+' --spruce_treatments'
if (myproject != ''):
basecmd = basecmd+' --project '+myproject
if (options.domainfile != ''):
basecmd = basecmd+' --domainfile '+options.domainfile
#---------------- build commands for runcase.py -----------------------------
# define compsets
# C, CN, CNP
if (options.c_only):
nutrients = 'C'
elif (options.cn_only):
nutrients = 'CN'
else:
nutrients = 'CNP'
# CENTURY or CTC
if (options.centbgc):
decomp_model = 'CNT'
else:
decomp_model = 'CTC'
# ECA or RD
if (options.eca):
mycompset = nutrients+'ECA'+decomp_model
else:
mycompset = nutrients+'RD'+decomp_model+'BC'
#note - RD / ECA in FATES handled with namelist options, not compsets
if (options.fates):
if (model_name == 'elm'):
mycompset = 'ELMFATES'
else:
mycompset = 'CLM45ED'
else:
mycompset = nutrients+'RD'+decomp_model+'BC'
# add P during initial spinup
if (not options.ad_Pinit):
mycompset_adsp = mycompset.replace('CNP','CN')
else:
mycompset_adsp = mycompset
# crop model
if (options.crop):
if (model_name == 'elm'):
mycompset = 'ELMCNCROP'
else:
mycompset = 'CLM45CNCROP'
mycompset_adsp = mycompset
# model executable E3SM / CESM
myexe = 'e3sm.exe'
if ('clm5' in options.csmdir):
mycompset = 'Clm50BgcGs'
mycompset_adsp = 'Clm50BgcGs'
myexe = 'cesm.exe'
# develop calls to runcase.py
# AD spinup
cmd_adsp = basecmd+' --ad_spinup --nyears_ad_spinup '+ \
str(ny_ad)+' --align_year '+str(year_align+1)
if (int(options.hist_mfilt_spinup) == -999):
cmd_adsp = cmd_adsp+' --hist_mfilt 1 --hist_nhtfrq -'+ \
str((endyear-startyear+1)*8760)
else:
cmd_adsp = cmd_adsp+' --hist_mfilt '+str(options.hist_mfilt_spinup) \
+' --hist_nhtfrq '+str(options.hist_nhtfrq_spinup)
if (sitenum == 0):
if (options.exeroot != ''):
if (os.path.isfile(options.exeroot+'/'+myexe) == False):
print('Error: '+options.exeroot+' does not exist or does '+ \
'not contain an executable. Exiting')
sys.exit(1)
else:
ad_exeroot = options.exeroot
cmd_adsp = cmd_adsp+' --exeroot '+ad_exeroot+' --no_build'
elif options.batch_build:
cmd_adsp = cmd_adsp+' --no_build'
else:
cmd_adsp = cmd_adsp+' --exeroot '+ad_exeroot+' --no_build'
if (options.cpl_bypass):
if (options.crop):
cmd_adsp = cmd_adsp+' --compset ICB'+mycompset_adsp
ad_case = site+'_ICB'+mycompset_adsp
else:
cmd_adsp = cmd_adsp+' --compset ICB1850'+mycompset_adsp
ad_case = site+'_ICB1850'+mycompset_adsp
if (options.sp):
if (model_name == 'elm'):
ad_case = site+'_ICBELMBC'
else:
ad_case = site+'_ICBCLM45BC'
else:
cmd_adsp = cmd_adsp+' --compset I1850'+mycompset_adsp
ad_case = site+'_I1850'+mycompset_adsp
if (options.noad == False):
ad_case = ad_case+'_ad_spinup'
if (options.makemet):
cmd_adsp = cmd_adsp+' --makemetdat'
if (options.spinup_vars):
cmd_adsp = cmd_adsp+' --spinup_vars'
if (mycaseid != ''):
ad_case = mycaseid+'_'+ad_case
if (sitenum == 0 and options.exeroot == ''):
ad_exeroot = os.path.abspath(runroot+'/'+ad_case+'/bld')
# final spinup
if mycaseid !='':
basecase=mycaseid+'_'+site
if (options.cpl_bypass):
if (options.crop):
basecase = basecase+'_ICB'+mycompset
else:
basecase = basecase+'_ICB1850'+mycompset
else:
basecase = basecase+'_I1850'+mycompset
else:
if (options.cpl_bypass):
if (options.crop):
basecase = site+'_ICB'+mycompset
else:
basecase=site+'_ICB1850'+mycompset
else:
basecase=site+'_I1850'+mycompset
if (options.sp):
if (model_name == 'elm'):
basecase=site+'_ICBELMBC'
else:
basecase=site+'_ICBCLM45BC'
if (options.noad):
cmd_fnsp = basecmd+' --run_units nyears --run_n '+str(fsplen)+' --align_year '+ \
str(year_align+1)+' --coldstart'
if (sitenum > 0):
cmd_fnsp = cmd_fnsp+' --exeroot '+ad_exeroot+' --no_build'
if (options.sp):
cmd_fnsp = cmd_fnsp+' --run_startyear '+str(options.run_startyear)
if (options.exeroot != ''):
if (os.path.isfile(options.exeroot+'/'+myexe) == False):
print('Error: '+options.exeroot+' does not exist or does '+ \
'not contain an executable. Exiting')
sys.exit(1)
else:
ad_exeroot=options.exeroot
cmd_fnsp = cmd_fnsp+' --no_build --exeroot '+ad_exeroot
elif options.batch_build:
cmd_fnsp = cmd_fnsp+' --no_build'
else:
cmd_fnsp = basecmd+' --finidat_case '+ad_case+ \
' --finidat_year '+str(int(ny_ad)+1)+' --run_units nyears --run_n '+ \
str(fsplen)+' --align_year '+str(year_align+1)+' --no_build' + \
' --exeroot '+ad_exeroot+' --nopointdata'
if (int(options.hist_mfilt_spinup) == -999):
if (options.sp):
cmd_fnsp = cmd_fnsp+' --hist_mfilt 365 --hist_nhtfrq -24'
else:
cmd_fnsp = cmd_fnsp+' --hist_mfilt 1 --hist_nhtfrq -'+ \
str((endyear-startyear+1)*8760)
else:
cmd_fnsp = cmd_fnsp+' --hist_mfilt '+str(options.hist_mfilt_spinup) \
+' --hist_nhtfrq '+str(options.hist_nhtfrq_spinup)
if (options.cpl_bypass):
if (options.sp):
if (model_name == 'elm'):
cmd_fnsp = cmd_fnsp+' --compset ICBELMBC'
else:
cmd_fnsp = cmd_fnsp+' --compset ICBCLM45BC'
else:
if (options.crop):
cmd_fnsp = cmd_fnsp+' --compset ICB'+mycompset
else:
cmd_fnsp = cmd_fnsp+' --compset ICB1850'+mycompset
else:
cmd_fnsp = cmd_fnsp+' --compset I1850'+mycompset
if (options.spinup_vars):
cmd_fnsp = cmd_fnsp+' --spinup_vars'
#if (options.ensemble_file != '' and options.notrans):
# cmd_fnsp = cmd_fnsp+' --spinup_vars'
if (options.ensemble_file != '' and options.notrans and options.constraints == ''):
cmd_fnsp = cmd_fnsp + ' --postproc_file '+options.postproc_file
#transient
if (options.noad and options.nofnsp and options.finidat != ''):
cmd_trns = basecmd+' --finidat '+options.finidat+ \
' --run_units nyears --run_n '+str(translen)+ \
' --align_year '+str(year_align+1850)+' --hist_nhtfrq '+ \
options.hist_nhtfrq+' --hist_mfilt '+options.hist_mfilt+ \
' --run_startyear '+str(options.run_startyear)
if (options.exeroot != ''):
cmd_trns = cmd_trns+' --no_build --exeroot '+options.exeroot
else:
cmd_trns = basecmd+' --finidat_case '+basecase+ \
' --finidat_year '+str(fsplen+1)+' --run_units nyears' \
+' --run_n '+str(translen)+' --align_year '+ \
str(year_align+1850)+' --hist_nhtfrq '+ \
options.hist_nhtfrq+' --hist_mfilt '+options.hist_mfilt+' --no_build' + \
' --exeroot '+ad_exeroot+' --nopointdata'
if (options.cpl_bypass):
if (options.crop or options.fates):
cmd_trns = cmd_trns+' --istrans --compset ICB'+mycompset
else:
cmd_trns = cmd_trns+' --compset ICB20TR'+mycompset
else:
cmd_trns = cmd_trns+' --compset I20TR'+mycompset
if (options.spinup_vars):
cmd_trns = cmd_trns + ' --spinup_vars'
if (options.trans_varlist != ''):
cmd_trns = cmd_trns + ' --trans_varlist '+options.trans_varlist
if (options.dailyvars):
cmd_trns = cmd_trns + ' --dailyvars'
if (options.ensemble_file != ''): #Transient post-processing
cmd_trns = cmd_trns + ' --postproc_file '+options.postproc_file
if (options.diags):
cmd_trns = cmd_trns + ' --diags'
if (not options.nofire):
#Turn wildfire off in transient simulations (disturbances are known)
cmd_trns = cmd_trns + ' --nofire'
#transient phase 2
#(CRU-NCEP only, without coupler bypass)
if ((options.cruncep or options.cruncepv8 or options.gswp3 or options.princeton \
or options.gswp3_w5e5) and not options.cpl_bypass):
basecase=basecase.replace('1850','20TR')+'_phase1'
thistranslen = site_endyear - 1921 + 1
cmd_trns2 = basecmd+' --trans2 --finidat_case '+basecase+ \
' --finidat_year 1921 --run_units nyears --branch ' \
+' --run_n '+str(thistranslen)+' --align_year 1921'+ \
' --hist_nhtfrq '+options.hist_nhtfrq+' --hist_mfilt '+ \
options.hist_mfilt+' --no_build'+' --exeroot '+ad_exeroot + \
' --compset I20TR'+mycompset+' --nopointdata'
#print(cmd_trns2)
# experimental manipulation transients, without coupler bypass
# APW: check align_year is correct,
# APW: do we want different outputs? Maybe the full set here and a reduced set for the initial transient?
elif ((options.eco2_file != '') and not options.cpl_bypass):
basecase=basecase.replace('1850','20TR')
# ambient CO2 run
cmd_trns2 = basecmd+' --transtag aCO2 --finidat_case '+basecase+ \
' --finidat_year '+str(startyear)+' --run_startyear '+str(startyear)+' --run_units nyears ' \
+' --run_n '+str(ncycle)+' --align_year '+str(startyear)+ \
' --hist_nhtfrq '+options.hist_nhtfrq+' --hist_mfilt '+ \
options.hist_mfilt+' --no_build'+' --exeroot '+ad_exeroot + \
' --compset I20TR'+mycompset+' --nopointdata'
# elevated CO2 run
basecmd_eco2=basecmd.replace(options.co2_file,options.eco2_file)
cmd_trns3 = basecmd_eco2+' --transtag eCO2 --finidat_case '+basecase+ \
' --finidat_year '+str(startyear)+' --run_startyear '+str(startyear)+' --run_units nyears ' \
+' --run_n '+str(ncycle)+' --align_year '+str(startyear)+ \
' --hist_nhtfrq '+options.hist_nhtfrq+' --hist_mfilt '+ \
options.hist_mfilt+' --no_build'+' --exeroot '+ad_exeroot + \
' --compset I20TR'+mycompset+' --nopointdata'
#---------------------------------------------------------------------------------
#set site environment variable
os.environ['SITE']=site
basecase = site
if (mycaseid != ''):
basecase = mycaseid+'_'+site
runcmd('mkdir -p temp')
runcmd('mkdir -p scripts/'+myscriptsdir)
mymodel = 'ELM'
if ('clm5' in csmdir):
mymodel = 'CLM5'
#If not the first site, create point data here
if ((sitenum > 0) and not options.nopointdata):
print('\n\nCreating point data for '+site+'\n')
ptcmd = 'python makepointdata.py '+ \
' --site '+site+' --sitegroup '+options.sitegroup+ \
' --ccsm_input '+ccsm_input+' --model '+mymodel
if (options.nopftdyn):
ptcmd = ptcmd+' --nopftdyn'
if (int(options.mypft) >= 0):
ptcmd = ptcmd+' --pft '+str(options.mypft)
if (options.humhol):
ptcmd = ptcmd+' --humhol'
if (options.marsh):
ptcmd = ptcmd+' --marsh'
result = runcmd(ptcmd)
if (result > 0):
print('Site_fullrun: Error creating point data for '+site)
sys.exit(1)
#Build Cases
if (options.noad == False):
print('\n\nSetting up ad_spinup case\n')
if (sitenum == 0):
ad_case_firstsite = ad_case
result = runcmd(cmd_adsp)
else:
ptcmd = 'python case_copy.py --runroot '+runroot+' --case_copy '+ \
ad_case_firstsite+' --site_orig '+firstsite +\
' --site_new '+site+' --nyears '+str(ny_ad)+' --spin_cycle ' \
+str(endyear-startyear+1)
result = runcmd(ptcmd)
if (result > 0):
print('Site_fullrun: Error in runcase.py for ad_spinup ')
sys.exit(1)
else:
if (sitenum == 0):
ad_case_firstsite = ad_case
if (options.nofnsp == False):
print('\n\nSetting up final spinup case\n')
if (sitenum == 0):
fin_case_firstsite = ad_case_firstsite.replace('_ad_spinup','')
if (nutrients == 'CNP' and not options.ad_Pinit):
fin_case_firstsite = fin_case_firstsite.replace('1850CN','1850CNP')
print(cmd_fnsp+'\n')
result = os.system(cmd_fnsp)
else:
ptcmd = 'python case_copy.py --runroot '+runroot+' --case_copy '+ \
fin_case_firstsite+' --site_orig '+firstsite +\
' --site_new '+site+' --nyears '+str(ny_fin)
if (not options.sp):
ptcmd = ptcmd+' --finidat_year ' \
+str(int(ny_ad)+1)+' --spin_cycle '+str(endyear-startyear+1)
print(ptcmd)
result = os.system(ptcmd)
if (result > 0):
print('Site_fullrun: Error in runcase.py final spinup')
sys.exit(1)
else:
fin_case_firstsite = ad_case_firstsite.replace('_ad_spinup','')
if (nutrients == 'CNP' and not options.ad_Pinit):
fin_case_firstsite = fin_case_firstsite.replace('1850CN','1850CNP')
if (options.notrans == False):
print('\n\nSetting up transient case\n')
if (sitenum == 0):
if (options.crop):
tr_case_firstsite = fin_case_firstsite+'_trans'
else:
tr_case_firstsite = fin_case_firstsite.replace('1850','20TR')
result = runcmd(cmd_trns)
else:
ptcmd = 'python case_copy.py --runroot '+runroot+' --case_copy '+ \