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 @ 4133

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

some updates to quick script

  • Property svn:executable set to *
File size: 2.9 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    namooo, 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    # namooo
54    if "namooo" not in sublists:
55        # Attach boilerplate
56        text += nml.new("namooo")
57    text = nml.update("namooo", text, data=namooo)
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"] = nml.quote(date)
65    namcl4["cl4_match_len"] = len(namcl4["cl4_vars"])
66    namcl4["cl4_fcst_len"] = len(namcl4["cl4_leadtime"])
67    # Add naming convention
68    namcl4["cl4_sys"] = "FOAM"
69    namcl4["cl4_cfg"] = "orca025"
70    namcl4["cl4_vn"] = "'1.0'"
71    namcl4["cl4_prefix"] = "class4"
72    namcl4["cl4_contact"] = "example@example.com"
73    namcl4["cl4_inst"] = "institute"
74    text = nml.update("namcl4", text, data=namcl4)
75
76    # namrun
77    namrun = {"nn_date0": date}
78    text = nml.update("namrun", text, data=namrun)
79
80    # namobs
81    namobs = locator.observations(date=date,
82                                  types=args.obs_types)
83    namobs["ln_cl4"] = args.ln_cl4
84    text = nml.update("namobs", text, data=namobs)
85
86    # pipe text to file
87    tmp = args.namelist+".tmp"
88    nml.writer(tmp, text)
89    shutil.move(tmp, args.namelist)
90
91    # Run job
92    run.submit()
93   
94
95
96if __name__ == '__main__':
97    main()
98
Note: See TracBrowser for help on using the repository browser.