1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | ##******************************************************************************* |
---|
4 | # @Author: Anne Philipp (University of Vienna) |
---|
5 | # |
---|
6 | # @Date: November 2018 |
---|
7 | # |
---|
8 | # @Change History: |
---|
9 | # |
---|
10 | # @License: |
---|
11 | # (C) Copyright 2014-2018. |
---|
12 | # |
---|
13 | # This software is licensed under the terms of the Apache Licence Version 2.0 |
---|
14 | # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
---|
15 | # |
---|
16 | # @Modul Description: |
---|
17 | # |
---|
18 | # |
---|
19 | # @Module Content: |
---|
20 | |
---|
21 | # |
---|
22 | #******************************************************************************* |
---|
23 | |
---|
24 | # ------------------------------------------------------------------------------ |
---|
25 | # MODULES |
---|
26 | # ------------------------------------------------------------------------------ |
---|
27 | |
---|
28 | import _config |
---|
29 | # ------------------------------------------------------------------------------ |
---|
30 | # FUNCTIONS |
---|
31 | # ------------------------------------------------------------------------------ |
---|
32 | |
---|
33 | |
---|
34 | def check_grid(grid): |
---|
35 | |
---|
36 | if 'N' in grid: |
---|
37 | return grid |
---|
38 | if '/' in grid: |
---|
39 | gridx, gridy = grid.split('/') |
---|
40 | if gridx == gridy: |
---|
41 | grid = gridx |
---|
42 | else: |
---|
43 | raise ValueError('GRID parameter contains two values ' |
---|
44 | 'which are unequal %s' (grid)) |
---|
45 | # determine grid format |
---|
46 | if float(grid) / 100. >= 0.5: |
---|
47 | # grid is defined in 1/1000 degrees; old format |
---|
48 | grid = '{}/{}'.format(float(grid) / 1000., |
---|
49 | float(grid) / 1000.) |
---|
50 | elif float(grid) / 100. < 0.5: |
---|
51 | # grid is defined in normal degree; new format |
---|
52 | grid = '{}/{}'.format(float(grid), float(grid)) |
---|
53 | |
---|
54 | return grid |
---|
55 | |
---|
56 | def check_area(grid, area, upper, lower, left , right): |
---|
57 | ''' |
---|
58 | |
---|
59 | |
---|
60 | ''' |
---|
61 | if 'N' in grid: # Gaussian output grid |
---|
62 | area = 'G' |
---|
63 | return area |
---|
64 | |
---|
65 | # if area was provided decompose area into its 4 components |
---|
66 | if area: |
---|
67 | components = area.split('/') |
---|
68 | upper, left, lower, right = components |
---|
69 | |
---|
70 | # determine area format |
---|
71 | if (abs(float(upper) / 1000.) >= 0.05 and |
---|
72 | abs(float(lower) / 1000.) >= 0.05 and |
---|
73 | abs(float(left) / 1000.) >= 0.05 and |
---|
74 | abs(float(right) / 1000.) >= 0.05): |
---|
75 | # area is defined in 1/1000 degrees; old format |
---|
76 | area = '{}/{}/{}/{}'.format(float(upper) / 1000., |
---|
77 | float(left) / 1000., |
---|
78 | float(lower) / 1000., |
---|
79 | float(right) / 1000.) |
---|
80 | elif (abs(float(upper) / 1000.) < 0.05 and |
---|
81 | abs(float(lower) / 1000.) < 0.05 and |
---|
82 | abs(float(left) / 1000.) < 0.05 and |
---|
83 | abs(float(right) / 1000.) < 0.05): |
---|
84 | # area is already in new format |
---|
85 | area = '{}/{}/{}/{}'.format(float(upper), |
---|
86 | float(left), |
---|
87 | float(lower), |
---|
88 | float(right)) |
---|
89 | else: |
---|
90 | raise ValueError('The area components have different ' |
---|
91 | 'formats (upper, lower, left, right): ' |
---|
92 | '{}/{}/{}/{}'.format(str(upper), str(lower), |
---|
93 | str(left) , str(right))) |
---|
94 | |
---|
95 | return area |
---|
96 | |
---|
97 | def check_levels(levelist, level): |
---|
98 | ''' |
---|
99 | |
---|
100 | Parameters |
---|
101 | ---------- |
---|
102 | par : :obj:`` |
---|
103 | ... |
---|
104 | |
---|
105 | Return |
---|
106 | ------ |
---|
107 | |
---|
108 | ''' |
---|
109 | # assure consistency of levelist and level |
---|
110 | if not levelist and not level: |
---|
111 | raise ValueError('ERROR: neither levelist nor level ' |
---|
112 | 'specified in CONTROL file') |
---|
113 | elif not levelist and level: |
---|
114 | levelist = '1/to/' + level |
---|
115 | elif (levelist and not level) or \ |
---|
116 | (levelist[-1] != level[-1]): |
---|
117 | level = levelist.split('/')[-1] |
---|
118 | else: |
---|
119 | pass |
---|
120 | |
---|
121 | # check if max level is a valid level |
---|
122 | if int(level) not in _config.MAX_LEVEL_LIST: |
---|
123 | raise ValueError('ERROR: \n' |
---|
124 | 'LEVEL must be the maximum level of a specified ' |
---|
125 | 'level list from ECMWF, e.g. {} \n' |
---|
126 | 'Check parameter "LEVEL" or the max level of ' |
---|
127 | '"LEVELIST"!'.format(str(_config.MAX_LEVEL_LIST))) |
---|
128 | |
---|
129 | return levelist, level |
---|
130 | |
---|
131 | |
---|
132 | def check_ppid(c, ppid): |
---|
133 | '''Sets the current PPID. |
---|
134 | |
---|
135 | Parameters |
---|
136 | ---------- |
---|
137 | c : :obj:`ControlFile` |
---|
138 | Contains all the parameters of CONTROL file and |
---|
139 | command line. |
---|
140 | |
---|
141 | ppid : :obj:`int` or :obj:`None` |
---|
142 | Contains the ppid number provided by the command line parameter |
---|
143 | of is None otherwise. |
---|
144 | |
---|
145 | Return |
---|
146 | ------ |
---|
147 | |
---|
148 | ''' |
---|
149 | |
---|
150 | if not ppid: |
---|
151 | c.ppid = str(os.getppid()) |
---|
152 | else: |
---|
153 | c.ppid = ppid |
---|
154 | |
---|
155 | return |
---|
156 | |
---|
157 | def check_(): |
---|
158 | ''' |
---|
159 | |
---|
160 | Parameters |
---|
161 | ---------- |
---|
162 | par : :obj:`` |
---|
163 | ... |
---|
164 | |
---|
165 | Return |
---|
166 | ------ |
---|
167 | |
---|
168 | ''' |
---|
169 | return |
---|