New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
ooo.py in branches/2013/dev_r3987_UKMO4_OBS/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo – NEMO

source: branches/2013/dev_r3987_UKMO4_OBS/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/ooo.py @ 4127

Last change on this file since 4127 was 4127, checked in by andrewryan, 11 years ago

some fixes to the submit functionality of the quick start script

  • Property svn:executable set to *
File size: 2.7 KB
Line 
1#!/usr/bin/env python2.7
2
3import os
4import shutil
5
6# Local imports
7import locator
8import nml
9import run
10
11def parse_args():
12    import argparse
13    parser = argparse.ArgumentParser()
14    parser.add_argument("date", metavar="DATE", 
15                        help="Run date.")
16    parser.add_argument("-w", "--work-dir", default=os.getcwd())
17    parser.add_argument("-f", "--forecast-types", default="forecast",
18                        help="Choice of forecast,persistence,climatology")
19    parser.add_argument("-l", "--lead-times", default="12",
20                        help="Forecast lead times")
21    parser.add_argument("-o", "--obs-types", default="profbfiles",
22                        help="Choice of namobs types.")
23    parser.add_argument("--class4", dest="ln_cl4", action="store_true",
24                        help="Flag to choose class 4 file outputs")
25    parser.add_argument("namelist", metavar="NAMELIST", 
26                        help="NEMO namelist to edit.")
27    args = parser.parse_args()
28    args.forecast_types = args.forecast_types.split(',')
29    args.obs_types = args.obs_types.split(',')
30    args.lead_times = map(int, args.lead_times.split(','))
31    return args
32
33def main():
34    args = parse_args()
35    date = args.date
36   
37    # Move to working directory
38    if not os.path.exists(args.work_dir):
39        os.makedirs(args.work_dir)
40    os.chdir(args.work_dir)
41
42    # Collect forecast files
43    types = args.forecast_types
44    lead_times = args.lead_times
45    namoff, namcl4 = locator.forecasts(date=date,
46                                       types=types,
47                                       lead_times=lead_times)
48
49    # Process NEMO namelist
50    text = nml.reader(args.namelist)
51    sublists = nml.namelists(text)
52
53    # namoff
54    if "namoff" not in sublists:
55        # Attach boilerplate
56        text += nml.new("namoff")
57    text = nml.update("namoff", text, data=namoff)
58
59    # namcl4
60    if "namcl4" not in sublists:
61        # Attach boilerplate
62        text += nml.new("namcl4")
63    namcl4["cl4_leadtime"] = lead_times
64    namcl4["cl4_date"] = date
65    namcl4["cl4_match_len"] = len(namcl4["cl4_vars"])
66    namcl4["cl4_fcst_len"] = len(namcl4["cl4_leadtime"])
67    text = nml.update("namcl4", text, data=namcl4)
68
69    # namrun
70    namrun = {"nn_date0": date}
71    text = nml.update("namrun", text, data=namrun)
72
73    # namobs
74    namobs = locator.observations(date=date,
75                                  types=args.obs_types)
76    namobs["ln_cl4"] = args.ln_cl4
77    text = nml.update("namobs", text, data=namobs)
78
79    # pipe text to file
80    tmp = args.namelist+".tmp"
81    nml.writer(tmp, text)
82    shutil.move(tmp, args.namelist)
83
84    # Run job
85    run.submit()
86   
87
88
89if __name__ == '__main__':
90    main()
91
Note: See TracBrowser for help on using the repository browser.