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.
locator.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/locator.py @ 4130

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

added default class 4 file settings to ooo utility

File size: 3.9 KB
Line 
1"""Locates input files and calculates namelist attributes
2
3    Typically a user will have files distributed throughout the hard drive
4    and it makes little or no sense to try to capture all use cases.
5
6    >>> date = "20130101"
7    >>> namobs = observations(date, types=["profbfiles"])
8
9    >>> namoff, namcl4 = forecasts(date, types=["forecast", "persistence"], lead_times=[12, 36, 60])
10"""
11
12def observations(date, types=None):
13    """Responsible for locating observation files
14
15    Valid **namobs** observation types.
16
17    * profbfiles
18    * sstfbfiles
19    * slafbfiles
20
21    :param date: The verification date in string format ``'%Y%m%d'``
22    :param types: A list of namobs observation types
23
24    :returns: namobs namelist dictionary
25    """
26    namobs = {"ln_t3d": False,
27              "ln_s3d": False,
28              "ln_sst": False,
29              "ln_sstfb": False,
30              "ln_sla": False,
31              "ln_slafb": False}
32    if types is None: types = []
33    for obtype in types: 
34        if obtype == "profbfiles":
35            namobs[obtype] = profbfiles(date)
36            namobs["ln_t3d"] = True
37            namobs["ln_s3d"] = True
38        elif obtype == "sstfbfiles":
39            namobs[obtype] = sstfbfiles(date)
40            namobs["ln_sst"] = True
41            namobs["ln_sstfb"] = True
42        elif obtype == "slafbfiles":
43            namobs[obtype] = slafbfiles(date)
44            namobs["ln_sla"] = True
45            namobs["ln_slafb"] = True
46    return namobs
47
48def profbfiles(date):
49    """Observation file locator stub
50
51    .. note:: User-specified stub
52
53    :param date: The verification date in string format ``'%Y%m%d'``
54    :returns: List of files
55    """
56    files = ['profb.nc']
57    return files
58
59def sstfbfiles(date):
60    """Observation file locator stub
61
62    .. note:: User-specified stub
63
64    :param date: The verification date in string format ``'%Y%m%d'``
65    :returns: List of files
66    """
67    files = ['sstfb.nc']
68    return files
69
70def slafbfiles(date):
71    """Observation file locator stub
72
73    .. note:: User-specified stub
74
75    :param date: The verification date in string format ``'%Y%m%d'``
76    :returns: List of files
77    """
78    files = ['slafb.nc']
79    return files
80
81def forecasts(date, types=None, lead_times=None):
82    """Responsible for locating forecast fields
83
84    :param date: The verification date in string format ``'%Y%m%d'``
85    :param types: A list of forecast system types
86    :param lead_times: A list of lead_times to search for
87
88    :returns: tuple of namelist data, (namoff, namcl4)
89    """
90    namoff = {}
91    namcl4 = {}
92    if types is None: types = []
93    if lead_times is None: lead_times = []
94
95    # Initialise data
96    ooo_files = []
97    nn_ooo_idx = []
98    cl4_vars = []
99    cl4_fcst_idx = []
100
101    # Search for files
102    for type in types:
103        files = []
104        in_indices = []
105        out_indices = []
106        for ilt, lead_time in enumerate(lead_times):
107            file, index = field(date, type=type, lead_time=lead_time)
108            files.append(file)
109            in_indices.append(index)
110            out_indices.append(ilt + 1)
111        # Expand return lists
112        ooo_files += files
113        nn_ooo_idx += in_indices
114        cl4_fcst_idx += out_indices
115        cl4_vars += len(files) * [type]
116
117    # Namoff
118    namoff["ooo_files"] = ooo_files
119    namoff["nn_ooo_idx"] = nn_ooo_idx
120
121    # Namcl4
122    namcl4["cl4_vars"] = cl4_vars
123    namcl4["cl4_fcst_idx"] = cl4_fcst_idx
124
125    return namoff, namcl4
126
127def field(date, type=None, lead_time=None):
128    """Forecast field locator
129
130    Maps verification date and lead time off set to file name and
131    index along file *time_counter*
132
133    .. note:: User-specified stub
134
135    :param date: The verification date in string format ``'%Y%m%d'``
136    :param type: Forecast type
137    :param lead_time: Forecast off set
138
139    :returns: (**path**, **index**)
140    """
141    # Worker function
142    file = 'nofile'
143    index = -1
144    return file, index
145
Note: See TracBrowser for help on using the repository browser.