-
Notifications
You must be signed in to change notification settings - Fork 28
/
OLMT_GUI.py
executable file
·814 lines (734 loc) · 32.8 KB
/
OLMT_GUI.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
import wx, wx.html
import os, sys, csv, glob
from wx.lib.expando import ExpandoTextCtrl
import getpass, socket
aboutText = """<p>ACME land model (ALM) version 1 point model,
running on version %(wxpy)s of <b>wxPython</b> and %(python)s of <b>Python</b>.
See <a href="http://wiki.wxpython.org">wxPython Wiki</a></p>"""
def Contains(str,set):
return 0 not in [c in str for c in set]
class HtmlWindow(wx.html.HtmlWindow):
def __init__(self, parent, id, size=(640,480)):
wx.html.HtmlWindow.__init__(self,parent, id, size=size)
if "gtk2" in wx.PlatformInfo:
self.SetStandardFonts()
def OnLinkClicked(self, link):
wx.LaunchDefaultBrowser(link.GetHref())
class AboutBox(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, -1, "About <<project>>",
style=wx.DEFAULT_DIALOG_STYLE|wx.THICK_FRAME|wx.RESIZE_BORDER|
wx.TAB_TRAVERSAL)
hwin = HtmlWindow(self, -1, size=(480,240))
vers = {}
vers["python"] = sys.version.split()[0]
vers["wxpy"] = wx.VERSION_STRING
hwin.SetPage(aboutText % vers)
btn = hwin.FindWindowById(wx.ID_OK)
irep = hwin.GetInternalRepresentation()
hwin.SetSize((irep.GetWidth()+25, irep.GetHeight()+10))
self.SetClientSize(hwin.GetSize())
self.CentreOnParent(wx.BOTH)
self.SetFocus()
class Frame(wx.Frame):
global file_opened
global filename
def __init__(self, title):
wx.Frame.__init__(self, None, title=title, pos=(100,100), size=(900,800))
self.Bind(wx.EVT_CLOSE, self.OnClose)
file_opened=0
#menu bar
menuBar = wx.MenuBar()
menu = wx.Menu()
# open function on menu bar
#m_open = menu.Append(wx.ID_OPEN, "Open", "Open a file")
#self.Bind(wx.EVT_MENU, self.OnOpen, m_open)
# exit function on menu bar
m_exit = menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Close window and exit program.")
self.Bind(wx.EVT_MENU, self.OnClose, m_exit)
# file function on menu bar
menuBar.Append(menu, "&File")
menu = wx.Menu()
m_about = menu.Append(wx.ID_ABOUT, "&About", "Information about this program")
self.Bind(wx.EVT_MENU, self.OnAbout, m_about)
menuBar.Append(menu, "&Help")
self.SetMenuBar(menuBar)
print(file_opened)
#optpanel = wx.Panel(self)
#self.sizer = wxGridBagSizer(5,5)
#self.abc = wxCheckBox(self.panel,-1,'abc')
self.statusbar = self.CreateStatusBar()
panel = wx.Panel(self)
hbox = wx.BoxSizer(wx.HORIZONTAL)
box = wx.BoxSizer(wx.VERTICAL)
#box1 = wx.BoxSixer(wx.HORIZONTAL)
m_text = wx.StaticText(panel, -1, "Point ALM options", style=wx.ALIGN_LEFT)
m_text.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text.SetSize(m_text.GetBestSize())
box.Add(m_text, 0, wx.ALL, 3)
#CCSM input data directory
m_text9 = wx.StaticText(panel, -1, "Input data directory", style=wx.ALIGN_LEFT)
m_text9.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text9.SetSize(m_text9.GetBestSize())
box.Add(m_text9, 0, wx.ALL, 3)
self.inputdirtxt = wx.TextCtrl(panel, -1, ccsm_input)
self.inputdirtxt.Bind(wx.EVT_TEXT, self.OnInputdirText)
box.Add(self.inputdirtxt, 0, wx.EXPAND)
browse_inputdir = wx.Button(panel, -1, "Change", (30,30))
browse_inputdir.Bind(wx.EVT_BUTTON, self.OnInputdirOpen)
box.Add(browse_inputdir, 0, wx.ALL, 3)
#Run directory
m_text9a = wx.StaticText(panel, -1, "Model run directory", style=wx.ALIGN_LEFT)
m_text9a.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text9a.SetSize(m_text9a.GetBestSize())
box.Add(m_text9a, 0, wx.ALL, 3)
self.rundirtxt = wx.TextCtrl(panel, -1, rundir)
self.rundirtxt.Bind(wx.EVT_TEXT, self.OnRundirText)
box.Add(self.rundirtxt, 0, wx.EXPAND)
browse_rundir = wx.Button(panel, -1, "Change", (30,30))
browse_rundir.Bind(wx.EVT_BUTTON, self.OnRundirOpen)
box.Add(browse_rundir, 0, wx.ALL, 3)
#site group selection
m_text2a = wx.StaticText(panel, -1, "site group", style=wx.ALIGN_LEFT)
m_text2a.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text2a.SetSize(m_text2a.GetBestSize())
box.Add(m_text2a, 0, wx.ALL, 3)
self.mysitegroup = wx.Choice(panel, -1, choices = mysitegroups)
self.mysitegroup.Bind(wx.EVT_CHOICE, self.OnSiteGroupSelect)
box.Add(self.mysitegroup, 0, wx.ALL, 3)
#site selection
m_text3 = wx.StaticText(panel, -1, "site", style=wx.ALIGN_LEFT)
m_text3.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text3.SetSize(m_text3.GetBestSize())
box.Add(m_text3, 0, wx.ALL, 3)
self.m_site = wx.ListBox(panel, -1, choices = mysites, style=wx.LB_MULTIPLE)
self.m_site.Bind(wx.EVT_LISTBOX, self.OnSiteSelect)
box.Add(self.m_site, 0, wx.ALL, 3)
#case name entry
m_text7 = wx.StaticText(panel, -1, "Case prefix", style=wx.ALIGN_LEFT)
m_text7.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text7.SetSize(m_text7.GetBestSize())
box.Add(m_text7, 0, wx.ALL, 3)
self.m_caseprefix = wx.TextCtrl(panel, -1, mycaseprefix)
self.m_caseprefix.Bind(wx.EVT_TEXT, self.OnCaseText)
box.Add(self.m_caseprefix,0,wx.ALL,3)
#spinup selection
m_text4 = wx.StaticText(panel, -1, "Run type", style=wx.ALIGN_LEFT)
m_text4.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text4.SetSize(m_text4.GetBestSize())
box.Add(m_text4, 0, wx.ALL, 3)
self.m_spinup = wx.Choice(panel, -1, choices=['ad spinup','final spinup','transient','full simulation'])
self.m_spinup.Bind(wx.EVT_CHOICE, self.OnSpinupButton)
box.Add(self.m_spinup,0,wx.ALL,3)
#number of years entry
m_text5 = wx.StaticText(panel, -1, "# of years", style=wx.ALIGN_LEFT)
m_text5.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text5.SetSize(m_text4.GetBestSize())
box.Add(m_text5, 0, wx.ALL, 3)
self.nyears = wx.TextCtrl(panel, -1, mynyears)
box.Add(self.nyears,0,wx.ALL,3)
#restart file entry (option to browse)
#m_text6 = wx.StaticText(panel, -1, "Finidat file", style=wx.ALIGN_LEFT)
#m_text6.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
#m_text6.SetSize(m_text4.GetBestSize())
#box.Add(m_text6, 0, wx.ALL, 3)
#self.m_finidat = wx.TextCtrl(panel, txtID, myfinidat)
#self.m_finidat.Bind(wx.EVT_TEXT, self.OnFinidatText)
#box.Add(self.m_finidat,0,wx.EXPAND)
#browse_finidat = wx.Button(panel, -1, "Browse", (30,30))
#browse_finidat.Bind(wx.EVT_BUTTON, self.OnFinidatOpen)
#box.Add(browse_finidat, 0, wx.ALL, 3)
#pft physiology file entry
#m_text8 = wx.StaticText(panel, -1, "Custom parameter file", style=wx.ALIGN_LEFT)
#m_text8.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
#m_text8.SetSize(m_text4.GetBestSize())
#box.Add(m_text8, 0, wx.ALL, 3)
#self.m_pftfile = wx.TextCtrl(panel, -1, mypftfile)
#self.m_pftfile.Bind(wx.EVT_TEXT, self.OnPftfileText)
#box.Add(self.m_pftfile,0,wx.EXPAND)
#browse_finidat = wx.Button(panel, -1, "Browse", (20,20))
#browse_finidat.Bind(wx.EVT_BUTTON, self.OnPftfileOpen)
#box.Add(browse_finidat, 0, wx.ALL, 3)
#-----------Box 2------------------------
box2 = wx.BoxSizer(wx.VERTICAL)
#site information
self.m_siteinfo = wx.TextCtrl(panel, -1, 'Site information for: \n\n Longitude: \n Latitude: \n Primary PFTS:\n PFT1: \n PFT2: ', style=wx.TE_READONLY | wx.TE_MULTILINE)
self.m_siteinfo.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
self.m_siteinfo.SetSize(m_text2a.GetBestSize())
#self.m_siteinfo.Bind(wx.EVT_TEXT, self.OnFinidatText)
box2.Add(self.m_siteinfo,0,wx.EXPAND)
m_text10= wx.StaticText(panel, -1, "Site-specific options", style=wx.ALIGN_LEFT)
m_text10.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text10.SetSize(m_text4.GetBestSize())
box2.Add(m_text10, 0, wx.ALL, 3)
self.mksrfdat = wx.CheckBox(panel, -1, 'Make surface data files')
self.mksrfdat.SetValue(True)
box2.Add(self.mksrfdat,0,wx.EXPAND)
self.sitedata = wx.CheckBox(panel, -1,'Use site-level data in surface data files')
self.sitedata.SetValue(True)
box2.Add(self.sitedata,0,wx.EXPAND)
self.siteparms = wx.CheckBox(panel, -1,'Use site parameters')
self.siteparms.SetValue(True)
box2.Add(self.siteparms,0,wx.EXPAND)
m_text11= wx.StaticText(panel, -1, "Model configuration", style=wx.ALIGN_LEFT)
m_text11.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text11.SetSize(m_text4.GetBestSize())
box2.Add(m_text11, 0, wx.ALL, 3)
self.spmode = wx.CheckBox(panel, -1,'Use satellite phenology')
self.spmode.SetValue(False)
box2.Add(self.spmode,0,wx.EXPAND)
self.ecamode = wx.CheckBox(panel, -1,'Use ECA (RD if not selected)')
self.ecamode.SetValue(False)
box2.Add(self.ecamode,0,wx.EXPAND)
self.decompmode = wx.CheckBox(panel, -1,'Use Century (CTC if not selected)')
self.decompmode.SetValue(False)
box2.Add(self.decompmode,0,wx.EXPAND)
self.conly = wx.CheckBox(panel, -1,'Carbon only mode')
self.conly.SetValue(False)
box2.Add(self.conly,0,wx.EXPAND)
self.cnonly = wx.CheckBox(panel, -1,'Carbon-nitrogen mode')
self.cnonly.SetValue(False)
box2.Add(self.cnonly,0,wx.EXPAND)
self.fire = wx.CheckBox(panel, -1,'Use wildfire submodel')
self.fire.SetValue(True)
box2.Add(self.fire,0,wx.EXPAND)
self.dynroot = wx.CheckBox(panel, -1,'Use dynamic rooting')
self.dynroot.SetValue(False)
box2.Add(self.dynroot,0,wx.EXPAND)
self.cpl_bypass = wx.CheckBox(panel, -1,'No datm (coupler bypass)')
self.cpl_bypass.SetValue(True)
box2.Add(self.cpl_bypass,0,wx.EXPAND)
self.onehour = wx.CheckBox(panel, -1,'Use hourly timestep')
self.onehour.SetValue(True)
box2.Add(self.onehour,0,wx.EXPAND)
self.cruncep = wx.CheckBox(panel, -1,'Use cru-ncep forcing data')
self.cruncep.SetValue(False)
box2.Add(self.cruncep,0,wx.EXPAND)
self.gswp3 = wx.CheckBox(panel, -1,'Use gswp3 forcing data')
self.gswp3.SetValue(False)
box2.Add(self.gswp3,0,wx.EXPAND)
self.c14 = wx.CheckBox(panel, -1,'Use c14')
self.c14.SetValue(False)
box2.Add(self.c14,0,wx.EXPAND)
#pft physiology file entry
m_text8 = wx.StaticText(panel, -1, "File for parameter mods", style=wx.ALIGN_LEFT)
m_text8.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text8.SetSize(m_text4.GetBestSize())
box2.Add(m_text8, 0, wx.ALL, 3)
self.m_pftfile = wx.TextCtrl(panel, -1, mypftfile)
self.m_pftfile.Bind(wx.EVT_TEXT, self.OnPftfileText)
box2.Add(self.m_pftfile,0,wx.EXPAND)
browse_finidat = wx.Button(panel, -1, "Browse", (20,20))
browse_finidat.Bind(wx.EVT_BUTTON, self.OnPftfileOpen)
box2.Add(browse_finidat, 0, wx.ALL, 3)
#Run PTCLM button
m_text12= wx.StaticText(panel, -1, "\nConfigure, build and run", style=wx.ALIGN_LEFT)
m_text12.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text12.SetSize(m_text4.GetBestSize())
box2.Add(m_text12, 0, wx.ALL, 3)
m_run = wx.Button(panel, -1, " Begin simulation ", style=wx.ALIGN_CENTER)
m_run.Bind(wx.EVT_BUTTON, self.OnRun)
box2.Add(m_run, 0, wx.ALL, 10)
#box 3 - UQ
box3 = wx.BoxSizer(wx.VERTICAL)
m_text30= wx.StaticText(panel, -1, "Uncertainty Quantification", style=wx.ALIGN_LEFT)
m_text30.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text30.SetSize(m_text30.GetBestSize())
box3.Add(m_text30, 0, wx.ALL, 3)
m_text31 = wx.StaticText(panel, -1, "Ensemble File", style=wx.ALIGN_LEFT)
m_text31.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text31.SetSize(m_text31.GetBestSize())
box3.Add(m_text31, 0, wx.ALL, 3)
self.ensemblefiletxt = wx.TextCtrl(panel, -1, 'none')
self.ensemblefiletxt.Bind(wx.EVT_TEXT, self.OnEnsembleFileText)
box3.Add(self.ensemblefiletxt, 0, wx.EXPAND)
browse_ensembledir = wx.Button(panel, -1, "Change", (30,30))
browse_ensembledir.Bind(wx.EVT_BUTTON, self.OnEnsembleFileOpen)
box3.Add(browse_ensembledir, 0, wx.ALL, 3)
self.mc_ensemble = wx.CheckBox(panel, -1,'Run Monte Carlo ensemble')
self.mc_ensemble.SetValue(False)
box3.Add(self.mc_ensemble,0,wx.EXPAND)
m_text32 = wx.StaticText(panel, -1, "Number of ensemble members", \
style=wx.ALIGN_LEFT)
m_text32.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text32.SetSize(m_text31.GetBestSize())
box3.Add(m_text32, 0, wx.ALL, 3)
self.n_ensemble = wx.TextCtrl(panel, -1, myn_ensemble)
box3.Add(self.n_ensemble,0,wx.ALL,3)
m_text33 = wx.StaticText(panel, -1, "Number of processors to use", \
style=wx.ALIGN_LEFT)
m_text33.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text33.SetSize(m_text31.GetBestSize())
box3.Add(m_text33, 0, wx.ALL, 3)
self.n_proc = wx.TextCtrl(panel, -1, myn_proc)
self.n_proc.SetValue('256')
box3.Add(self.n_proc,0,wx.ALL,3)
#Text editor
edit_file = wx.Button(panel, -1, "View/Edit Files", (20,20))
edit_file.Bind(wx.EVT_BUTTON, self.OnPftfileView)
box3.Add(edit_file, 0, wx.ALL, 3)
m_text34= wx.StaticText(panel, -1, "Plotting and Diagnostics", style=wx.ALIGN_LEFT)
m_text34.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text34.SetSize(m_text34.GetBestSize())
box3.Add(m_text34, 0, wx.ALL, 3)
#Variable selection
m_text35 = wx.StaticText(panel, -1, "Variables to plot", style=wx.ALIGN_LEFT)
m_text35.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
m_text35.SetSize(m_text35.GetBestSize())
box3.Add(m_text35, 0, wx.ALL, 3)
self.pvars = wx.ListBox(panel, -1, choices = myplotvars, style=wx.LB_MULTIPLE)
self.pvars.Bind(wx.EVT_LISTBOX, self.OnPvarSelect)
box3.Add(self.pvars, 0, wx.ALL, 3)
self.makeplots = wx.Button(panel, -1, "Generate plots", (30,30))
self.makeplots.Bind(wx.EVT_BUTTON, self.OnMakePlots)
box3.Add(self.makeplots, 0, wx.ALL, 3)
hbox.Add(box,1,wx.EXPAND)
hbox.Add(box2,1,wx.EXPAND)
hbox.Add(box3,1,wx.EXPAND)
panel.SetSizer(hbox)
panel.Layout()
def OnCaseText(self, event):
mycaseprefix=event.GetString()
def OnClose(self, event):
dlg = wx.MessageDialog(self,
"Do you really want to close this application?",
"Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
result = dlg.ShowModal()
dlg.Destroy()
if result == wx.ID_OK:
self.Destroy()
def OnEnsembleFileOpen(self, event):
file_opened = 0
dialog = wx.FileDialog(None, wildcard="*.dat;*.txt", defaultDir="./", style = wx.OPEN)
#dialog = wx.FileDialog(None, defaultDir="./", style = wx.OPEN)
result = dialog.ShowModal()
if result == wx.ID_OK:
ensemble_file = dialog.GetPath()
self.ensemblefiletxt.SetValue(ensemble_file)
#count number of lines in the file
with open(ensemble_file) as f:
myn_ensemble = sum(1 for _ in f)
self.n_ensemble.SetValue(str(myn_ensemble))
myn_proc = self.n_proc.GetValue()
if (int(myn_proc) > int(myn_ensemble+1)):
self.n_proc.SetValue(str(int(myn_ensemble+1)))
self.mc_ensemble.SetValue(False)
dialog.Destroy()
else:
dialog.Destroy()
def OnEnsembleFileText(self, event):
ensemble_file=event.GetString()
def OnInputdirOpen(self, event):
file_opened = 0
dialog = wx.DirDialog(None, style = wx.OPEN)
result = dialog.ShowModal()
if result == wx.ID_OK:
ccsm_input = dialog.GetPath()
self.inputdirtxt.SetValue(ccsm_input)
dialog.Destroy()
else:
dialog.Destroy()
def OnInputdirText(self, event):
ccsm_input=event.GetString()
def OnRundirOpen(self, event):
file_opened = 0
dialog = wx.DirDialog(None, style = wx.OPEN)
result = dialog.ShowModal()
if result == wx.ID_OK:
rundir = dialog.GetPath()
self.inputdirtxt.SetValue(rundir)
dialog.Destroy()
else:
dialog.Destroy()
def OnRundirText(self, event):
rundir=event.GetString()
def OnFinidatOpen(self, event):
rundir=self.rundirtxt.GetValue()
dialog = wx.FileDialog(None, wildcard = "Restart files|*clm2*r*.nc", defaultDir=rundir, style = wx.OPEN)
result = dialog.ShowModal()
if result == wx.ID_OK:
myfinidat = dialog.GetPath()
self.m_finidat.SetValue(myfinidat)
print(myfinidat)
dialog.Destroy()
else:
dialog.Destroy()
def OnFinidatText(self, event):
myfinidat=event.GetString()
print(myfinidat)
def OnSiteGroupSelect(self,event):
index=event.GetSelection()
mysitegroup_current=mysitegroups[index]
#load site information for selected group
ccsm_input=self.inputdirtxt.GetValue()
fname=ccsm_input+'/lnd/clm2/PTCLM/'+mysitegroup_current+"_sitedata.txt"
AFdatareader = csv.reader(open(fname,"rb"))
nsites=1
mysites=['all']
mylons=['all sites']
mylats=['all sites']
for row in AFdatareader:
if nsites > 1:
mysites.append(row[0])
mylons.append(row[3])
mylats.append(row[4])
nsites=nsites+1
mysite=mysites[0] #set new default site
#change the site selection drop-down box
self.m_site.Clear()
for site in mysites:
self.m_site.Append(str(site))
self.m_site.SetSelection(0)
def OnPvarSelect(self,event):
vars_toplot=self.pvars.GetSelections()
def OnMakePlots(self,event):
rundir=self.rundirtxt.GetValue()
vars_toplot=self.pvars.GetSelections()
#get the site group
indexsg = self.mysitegroup.GetSelection()
mysitegroup_current=mysitegroups[indexsg]
#load site information for selected group
ccsm_input=self.inputdirtxt.GetValue()
fname=ccsm_input+'/lnd/clm2/PTCLM/'+mysitegroup_current+"_sitedata.txt"
AFdatareader = csv.reader(open(fname,"rb"))
sites_toplot=self.m_site.GetSelections()
doall = False
for i in sites_toplot:
if (i == 0):
doall=True
thisrow=0
mysite=''
mysites=[]
for row in AFdatareader:
if thisrow > 0:
mysites.append(row[0])
if (doall):
mysite=mysite+row[0]+','
thisrow=thisrow+1
for i in sites_toplot:
if (i != 0):
mysite=mysite+mysites[i-1]+','
mycaseprefix=self.m_caseprefix.GetValue()
myindex=self.m_spinup.GetSelection()
myspmode=self.spmode.GetValue()
myeca=self.ecamode.GetValue()
mydecomp=self.decompmode.GetValue()
myconly=self.conly.GetValue()
mycnonly=self.cnonly.GetValue()
mycpl_bypass=self.cpl_bypass.GetValue()
cdate="1850"
if (myindex == 2):
cdate="20TR"
if (mycpl_bypass):
prefix='ICB'
else:
prefix='I'
nutrient ='CNP'
if (mycnonly):
nutrient = 'CN'
if (myconly):
nutrient = 'C'
if (mydecomp):
decomp = 'CNT'
else:
decomp = 'CTC'
if (myeca):
nucom = nutrient+'ECA'+decomp+'BC'
else:
nucom = nutrient+'RD'+decomp+'BC'
if (myspmode):
compset="ICLM45"
if (mycpl_bypass):
compset="ICLM45CB"
else:
compset = prefix+cdate+nucom
myvar=''
for v in vars_toplot:
myvar=myvar+myplotvars[v]+','
#if len(mycaseprefix.split(',') > 1:
print('python plotcase.py --case '+mycaseprefix+' --site '+mysite[:-1] \
+' --compset '+compset+' --spinup'+' --vars '+myvar[:-1]+' --csmdir '+rundir)
os.system('python plotcase.py --case '+mycaseprefix+' --site '+mysite[:-1] \
+' --compset '+compset+' --spinup'+' --vars '+myvar[:-1]+' --csmdir '+rundir)
def OnSiteSelect(self,event):
#get the site group
indexsg = self.mysitegroup.GetSelection()
mysitegroup_current=mysitegroups[indexsg]
#load site information for selected group
ccsm_input=self.inputdirtxt.GetValue()
fname=ccsm_input+'/lnd/clm2/PTCLM/'+mysitegroup_current+"_sitedata.txt"
AFdatareader = csv.reader(open(fname,"rb"))
nsites=1
mysites=['all']
mynames=['all sites']
mylons=['all sites']
mylats=['all sites']
for row in AFdatareader:
if nsites > 1:
mysites.append(row[0])
mynames.append(row[1])
mylons.append(row[3])
mylats.append(row[4])
nsites=nsites+1
#get the selected site and get appropriate info
fname = ccsm_input+'/lnd/clm2/PTCLM/'+mysitegroup_current+"_pftdata.txt"
AFdatareader = csv.reader(open(fname,"rb"))
index=event.GetSelection()
sites_torun = self.m_site.GetSelections()
mysite=mysites[index]
pft1_type = 'N/A'
pft1_pct = '0'
pft2_type = 'N/A'
pft2_pct = '0'
for row in AFdatareader:
if (row[0] == mysite):
pft1_type = row[2]
pft1_pct = row[1]
pft2_type = row[4]
pft2_pct = row[3]
if (pft1_type.strip() != 'N/A' and pft2_pct.strip() == '0.0'):
self.m_siteinfo.SetValue('Site information for '+mysite+'\n Site name: '+mynames[index]+ \
'\n Longitude: '+str(mylons[index])+'\n Latitude: '+str(mylats[index])+ \
'\n primary PFTS:\n '+mypfts[int(pft1_type)]+': '+pft1_pct+'%')
elif (pft2_type.strip() != 'N/A'):
self.m_siteinfo.SetValue('Site information for '+mysite+'\n Site name: '+mynames[index]+ \
'\n Longitude: '+str(mylons[index])+'\n Latitude: '+str(mylats[index])+ \
'\n primary PFTS:\n '+mypfts[int(pft1_type)]+': '+pft1_pct+'%\n '+ \
mypfts[int(pft2_type)]+': '+pft2_pct+'%')
else:
self.m_siteinfo.SetValue('Site information for '+mysite+'\n Site name: '+mynames[index]+ \
'\n Longitude: '+str(mylons[index])+'\n Latitude: '+str(mylats[index])+ \
'\n primary PFTS:\n PFT1: N/A\n PFT2: N/A')
def OnSpinupButton(self,event):
myindex=event.GetSelection()
if myindex == 0:
myspinup='--ad_spinup'
self.nyears.SetValue('250')
if myindex == 1:
myspinup='--final_spinup'
self.nyears.SetValue('250')
if myindex == 2:
myspinup='--transient'
self.nyears.SetValue('150')
if myindex == 3:
myspinup='--fullrun'
self.nyears.SetValue('250')
def OnPftfileOpen(self, event):
ccsm_input=self.inputdirtxt.GetValue()
dialog = wx.FileDialog(self, defaultDir=ccsm_input+"/lnd/clm2/pftdata", style = wx.OPEN)
result = dialog.ShowModal()
if result == wx.ID_OK:
mypftfile = dialog.GetPath()
self.m_pftfile.SetValue(mypftfile)
print(mypftfile)
dialog.Destroy()
else:
dialog.Destroy()
def OnPftfileText(self, event):
mypftfile=event.GetString()
print(mypftfile)
def OnPftfileView(self, event):
mypftfile=self.m_pftfile.GetValue()
print(mypftfile)
os.system('emacs '+mypftfile+' &')
def OnRun(self, event):
dorun = True
#get all of the information for PTCLM
ccsm_input=self.inputdirtxt.GetValue()
rundir=self.rundirtxt.GetValue()
ensemble_file=self.ensemblefiletxt.GetValue()
myn_ensemble=self.n_ensemble.GetValue()
myn_proc=self.n_proc.GetValue()
myindex=self.mysitegroup.GetSelection()
mysitegroup_current=mysitegroups[myindex]
ccsm_input=self.inputdirtxt.GetValue()
fname=ccsm_input+'/lnd/clm2/PTCLM/'+mysitegroup_current+"_sitedata.txt"
AFdatareader = csv.reader(open(fname,"rb"))
sites_torun = self.m_site.GetSelections()
doall = False
for i in sites_torun:
if (i == 0):
doall=True
mysites=[]
thisrow=0
for row in AFdatareader:
if thisrow > 0:
mysites.append(row[0])
thisrow=thisrow+1
mynyears=self.nyears.GetValue()
mycaseprefix=self.m_caseprefix.GetValue()
mypftfile= self.m_pftfile.GetValue()
myfinidat= '' #self.m_finidat.GetValue()
if (doall):
mysite='all,'
else:
mysite=''
for i in sites_torun:
if (i != 0):
mysite=mysite+mysites[i-1]+','
myindex=self.m_spinup.GetSelection()
mymksrfdat=self.mksrfdat.GetValue()
mysitedata=self.sitedata.GetValue()
myspmode=self.spmode.GetValue()
myfire=self.fire.GetValue()
mydynroot=self.dynroot.GetValue()
mymcensemble=self.mc_ensemble.GetValue()
myeca=self.ecamode.GetValue()
mydecomp=self.decompmode.GetValue()
myconly=self.conly.GetValue()
mycnonly=self.cnonly.GetValue()
mycpl_bypass=self.cpl_bypass.GetValue()
myonehour=self.onehour.GetValue()
mycruncep=self.cruncep.GetValue()
mygswp3=self.gswp3.GetValue()
myc14=self.c14.GetValue()
cdate="1850"
if (myindex == 2):
cdate="20TR"
if (mycpl_bypass):
prefix='ICB'
else:
prefix='I'
nutrient ='CNP'
if (mycnonly):
nutrient = 'CN'
if (myconly):
nutrient = 'C'
if (mydecomp):
decomp = 'CNT'
else:
decomp = 'CTC'
if (myeca):
nucom = nutrient+'ECA'+decomp+'BC'
else:
nucom = nutrient+'RD'+decomp+'BC'
if (myspmode):
compset="ICLM45"
if (mycpl_bypass):
compset="ICLM45CB"
else:
compset = prefix+cdate+nucom
#Single case simulation
cmd='python pointCLM.py --site '+mysite[:-1]+' --machine '+machine+' --rmold --ccsm_input '+ccsm_input+' --sitegroup '+ \
mysitegroup_current+' --compset '+compset+' --rmold'
if (myindex == 0):
cmd = cmd+' --ad_spinup --nyears_ad_spinup '+str(mynyears)
elif (myindex < 3):
cmd = cmd+' --run_n '+str(mynyears)
elif (myindex == 3):
#Full simulation (with diagnostics for transient output)
cmd = 'python site_fullrun.py --site '+mysite[:-1]+' --machine '+machine+' --ccsm_input '+ccsm_input+' --sitegroup '+ \
mysitegroup_current+' --nyears_ad_spinup '+str(mynyears)+' --nyears_final_spinup '+str(mynyears)+ \
' --spinup_vars --diags --model_root /home/'+getpass.getuser()+'/models/ACME'
if (mycpl_bypass):
cmd = cmd+' --cpl_bypass'
if (mycaseprefix != 'none'):
cmd = cmd+' --caseidprefix '+mycaseprefix
if mymksrfdat == False:
cmd=cmd+' --nopointdata'
if mysitedata == False:
cmd=cmd+' --pftgrid --soilgrid'
if mypftfile != '':
cmd=cmd+' --parm_file '+mypftfile
if myfinidat != '':
cmd=cmd+' --finidat '+myfinidat
elif (myindex == 1):
cmd=cmd+' --coldstart'
if (myfire == False):
cmd = cmd+' --nofire'
if (mydynroot == False):
cmd = cmd+' --no_dynroot'
if (myconly == True and myindex == 3):
cmd = cmd+' --c_only'
if (myeca == True and myindex ==3):
cmd = cmd+' --ECA'
if (mydecomp == True and myindex==3):
cmd = cmd+' --centbgc'
if (mycnonly == True and myindex ==3):
cmd = cmd+' --cn_only'
if (ensemble_file != 'none'):
cmd = cmd+' --ensemble_file '+ensemble_file+' --ng '+myn_proc
if (mymcensemble):
cmd = cmd+' --mc_ensemble '+myn_ensemble+' --ng '+myn_proc
if (myonehour):
cmd = cmd+' --tstep 1'
if (mycruncep):
cmd = cmd+' --cruncep'
elif (mygswp3):
cmd = cmd+' --gswp3'
if (myc14):
cmd = cmd+' --C14'
cmd = cmd+' --runroot '+rundir
print(cmd)
os.system(cmd)
def OnAbout(self, event):
dlg = AboutBox()
dlg.ShowModal()
dlg.Destroy()
#global variables
#global txtID
#global mycompsets, mysites
#global mycasename, myfinidat, mypftfile, mynyears, ccsm_input,
global PTCLMdir, mypfts, mysite, mysites, machine
username = getpass.getuser()
hostname = socket.gethostname()
PTCLMdir = os.path.abspath('./')
rundir = os.path.abspath(PTCLMdir+'../../../../../../run')
if ('or-condo' in hostname):
ccsm_input = '/lustre/or-hydra/cades-ccsi/proj-shared/project_acme/ACME_inputdata/'
rundir = '/lustre/or-hydra/cades-ccsi/scratch/'+username
machine = 'cades'
elif ('eos' in hostname or 'titan' in hostname):
ccsm_input = '/lustre/atlas/world-shared/cli900/cesm/inputdata'
rundir = '/lustre/atlas/scratch/cli112/'+username
else:
ccsm_input='/home/'+username+'/models/inputdata'
machine='oic2'
os.chdir(ccsm_input+'/lnd/clm2/PTCLM')
mysiteindex=1
mysites=['all']
mylats=['all sites']
mylons=['all sites']
myplotvars=['GPP','NEE','NPP','TLAI','TOTSOMC','TOTVEGC']
mysitegroups=[]
mysitegroup_current="AmeriFlux"
mypath=os.path.abspath("./")
#get available site groups
for filename in os.listdir("./"):
if Contains(filename,'sitedata.txt') and str(filename)[0] != '.' \
and str(filename)[0] != '#':
groupname, type = filename.split('_')
isrepeat=False
for g in mysitegroups:
if groupname == g:
isrepeat=True
if isrepeat == False:
mysitegroups.append(groupname)
#load site information for default group
fname="./"+mysitegroup_current+"_sitedata.txt"
AFdatareader = csv.reader(open(fname,"r"))
nsites=0
for row in AFdatareader:
if nsites > 0:
mysites.append(row[0])
mylons.append(row[3])
mylats.append(row[4])
nsites=nsites+1
txtID=1
mysite='' #mysites[mysiteindex]
mycaseprefix='none' #default case name
myfinidat='<none>' #default finidat
myspinup=''
myfinidat=''
mypftfile=''
mynyears=''
myn_ensemble=''
os.chdir(PTCLMdir)
mypftfile=''
myn_proc=''
myoutvars=['NEE','GPP','NPP', 'ER', 'GR', 'AR', 'MR', 'TLAI', 'LEAFC', 'FROOTC', 'LIVESTEMC', 'DEADSTEMC','PFT_FIRE_CLOSS', 'LEAFC_ALLOC']
mypfts=['Bare ground','Temperate ENF','Boreal ENF','DNF','Tropical EBF','Temperate EBF','Tropical DBF','Temperate DBF','Boreal DBF','Broadleaf evergreen shrub','Temperate broadleaf deciduous shrub', 'Broadleaf deciduous boreal shrub', 'C3 arctic grass', 'C3 non-arctic grass', 'C4 grass', 'C3 crop', 'C3 irrigated', 'Corn']
app = wx.App(redirect=False) # Error messages go to popup window
top = Frame("ALM point model GUI")
top.Show()
app.MainLoop()