source: trunk/MESOSCALE/PLOT/PYTHON/pywrf.example.r39/wrf/pydown/utils.py @ 183

Last change on this file since 183 was 183, checked in by aslmd, 14 years ago

MESOSCALE: PYTHON: added pywrf r39 to act as a reference for futher developments

File size: 9.0 KB
Line 
1import sys
2import os
3from socket import gethostname
4
5# VB the following is both host and user specific hence
6hostname = gethostname()
7user = os.getlogin()
8if hostname == 'hn3.its.monash.edu.au':
9    if user == 'vbisign':
10        sys.path.append('/nfs/1/home/vbisign/wrf/pywrf')   
11        import wrf.utils as wu
12    elif user == 'tchubb':
13        print 'Hey Thom where do you keep pywrf on this computer?'
14        sys.exit()
15        sys.path.append('/somewhere/pylib')
16        import pywrf.wrf.utils as wu
17elif hostname == 'linux450':
18    # VB Sorry Thom if this is not correct ;)
19    print 'Hey Thom where do you keep pywrf on this computer?'
20    sys.exit()
21    sys.path.append('/somewhere/pylib')
22    import pywrf.wrf.utils as wu
23elif hostname == 'val.maths.monash.edu.au' \
24  or hostname == 'valerio-bisignanesis-computer.local':
25    sys.path.append('/Users/val/Desktop/workspace/pywrf')
26    import wrf.utils as wu
27else:
28    print 'Warning: since I do not know this user/'\
29      + 'hostname combination, I am not sure of ' \
30      + ' where to find pywrf.wrf.util, I will try\n' \
31      + ' import pywrf.wrf.utils as wu'
32    import pywrf.wrf.utils as wu
33
34
35
36def generate_namelist_input_d01_real(namelist_input_master,run_dir='.'):
37    """Generate a namelist file for real.exe for the outermost domain
38   
39    The namelist file for real.exe for the outermost domain differs from the
40    'master' namelist file by the entry in max_dom (max_dom=1)
41    """
42    namelist_dict=wu.read_namelist(namelist_input_master)
43    namelist_dict['&domains']['max_dom'][0]=1
44    output_file = os.path.join(run_dir,'namelist.input.d01.real')
45    wu.write_namelist(namelist_dict,output_file)
46    return output_file
47
48def generate_namelist_input_d01_wrf(namelist_input_master,run_dir='.'):
49    """Generate a namelist file for wrf.exe for the outermost domain
50   
51    The namelist file for wrf.exe for the outermost domain differs from the
52    'master' namelist file by the entry in max_dom (max_dom=1)
53    """
54    namelist_dict=wu.read_namelist(namelist_input_master)
55    namelist_dict['&domains']['max_dom'][0]=1
56    output_file = os.path.join(run_dir,'namelist.input.d01.wrf')
57    wu.write_namelist(namelist_dict,output_file)
58    return output_file
59
60def generate_namelist_input_dpp_real(pp,namelist_input_master,run_dir='.'):
61    """Generate a namelist for real.exe for the pp'th domain
62   
63    This namelist will contain only one column, with max_dom = 1 and
64    interval_seconds = grib interval
65    """
66
67    namelist_dict=wu.read_namelist(namelist_input_master)
68    idx_discard=range(int(namelist_dict['&domains']['max_dom'][0]))
69   
70    # We'll be using this list as the list of entries to 'pop' from each variable
71    # in the namelist, so we need ot reverse siht list to preserve only the 'pp'th
72    # datum
73    idx_discard.pop(idx_discard.index(pp-1))
74    idx_discard.reverse()
75
76    for group in namelist_dict.keys():
77        for variable in namelist_dict[group].keys():
78            dummy=namelist_dict[group][variable]
79            if len(dummy)==1:
80                pass
81            else:
82                for idx in idx_discard:
83                    dummy.pop(idx)
84
85
86    # &domains
87    namelist_dict['&domains']['max_dom'][0]=1
88    # grid id
89    namelist_dict['&domains']['grid_id'][0]=1
90    namelist_dict['&domains']['parent_id'][0]=0
91    namelist_dict['&domains']['parent_grid_ratio'][0]=1
92    # j_parent_start of parent is 1
93    namelist_dict['&domains']['j_parent_start'][0]=0
94    # same for i_parent_start
95    namelist_dict['&domains']['i_parent_start'][0]=0
96
97    # &time_control
98    namelist_dict['&time_control']['input_from_file'][0]='.true.'
99
100    # &bdy_control
101    # parent grid is not nested as far as WRF is concerned...
102    namelist_dict['&bdy_control']['nested'][0]='.false.'
103    # parent grid will have specified boundary conditions
104    namelist_dict['&bdy_control']['specified'][0]='.true.'
105
106   # TODO
107    # Shorten the time extent to save on CPU resources (ref. step 15 in dia)
108    # Include explicit definition of eta_levels
109
110    output_file = os.path.join(run_dir,'namelist.input.d'+str(pp).zfill(2)+'.real')
111    wu.write_namelist(namelist_dict,output_file)
112    return output_file
113   
114
115def generate_namelist_input_dpp_ndown(pp,namelist_input_master,run_dir='.'):
116    """Generate a namelist for ndown.exe for the pp'th domain
117   
118    This namelist will contain only one column, with max_dom = 1 and
119    interval_seconds = grib interval
120    """
121
122    namelist_dict=wu.read_namelist(namelist_input_master)
123   
124    # Correcting to give BC's at time of history_interval for parent grid.
125    # history_interval given in minutes, interval_seconds, in seconds (duh??)
126    dom_idx = pp-1 
127    history_interval = namelist_dict['&time_control']['history_interval'][dom_idx-1]
128    interval_seconds = history_interval*60
129    namelist_dict['&time_control']['interval_seconds'][0]=interval_seconds
130   
131    idx_discard=range(int(namelist_dict['&domains']['max_dom'][0]))
132   
133    # We'll be using this list as the list of entries to 'pop' from each variable
134    # in the namelist, so we need ot reverse siht list to preserve only the 'pp'th
135    # datum
136    idx_discard.pop(idx_discard.index(dom_idx))
137    idx_discard.pop(idx_discard.index(dom_idx-1))
138    idx_discard.reverse()
139
140    for group in namelist_dict.keys():
141        for variable in namelist_dict[group].keys():
142            dummy=namelist_dict[group][variable]
143            if len(dummy)==1:
144                pass
145            else:
146                for idx in idx_discard:
147                    dummy.pop(idx)
148
149    # &domain corrections
150    namelist_dict['&domains']['max_dom'][0]=2
151    # grid id
152    namelist_dict['&domains']['grid_id']=[1,2]
153    # ndown reads 1 as parent and 2 as child hence
154    namelist_dict['&domains']['parent_id']=[0,1]
155    # parent grid ratio of 'parent' is 1:
156    namelist_dict['&domains']['parent_grid_ratio'][0]=1
157    # j_parent_start of parent is 1
158    namelist_dict['&domains']['j_parent_start'][0]=0
159    # same for i_parent_start
160    namelist_dict['&domains']['i_parent_start'][0]=0
161    # currently not changing parent_time_step_ratio, but watch this space
162
163    # &time control corrections
164    namelist_dict['&time_control']['input_from_file'][0]='.true.'
165
166    # &bdy_control
167    # parent grid is not nested as far as WRF is concerned...
168    namelist_dict['&bdy_control']['nested'][0]='.false.'
169    # parent grid will have specified boundary conditions
170    namelist_dict['&bdy_control']['specified'][0]='.true.'
171
172
173    output_file = \
174      os.path.join(run_dir,'namelist.input.d'+str(pp).zfill(2)+'.ndown')
175    wu.write_namelist(namelist_dict,output_file)
176    return output_file
177
178def generate_namelist_input_dpp_wrf(pp,namelist_input_master,run_dir='.'):
179    """Generate a namelist for wrf.exe for the pp'th domain
180   
181    This namelist will contain only one column, with max_dom = 1 and
182    interval_seconds = grib interval
183    """
184
185    namelist_dict=wu.read_namelist(namelist_input_master)
186    idx_discard=range(int(namelist_dict['&domains']['max_dom'][0]))
187   
188    # We'll be using this list as the list of entries to 'pop' from each variable
189    # in the namelist, so we need ot reverse siht list to preserve only the 'pp'th
190    # datum
191    idx_discard.pop(idx_discard.index(pp-1))
192    idx_discard.reverse()
193
194    # multiplicative time step ratio
195    mult_time_step_ratio=1
196    # Must incluide CURRENT parent_time_step ratio as well, i.e. up to pp rather than pp-1.
197    # time_step_ratio_1*time_step_ratio_2*...*time_step_ratio_pp
198
199    for idx in range(pp):
200        mult_time_step_ratio*=namelist_dict['&domains']['parent_time_step_ratio'][idx]
201
202    for group in namelist_dict.keys():
203        for variable in namelist_dict[group].keys():
204            dummy=namelist_dict[group][variable]
205            if len(dummy)==1:
206                pass
207            else:
208                for idx in idx_discard:
209                    dummy.pop(idx)
210
211    # &domains
212    # take care of time step stuff
213    # be smart... make sure that your INITIAL time step is an integer multiple of the
214    # product of the set of parent_time_step_ratio OR come here and modify this yourself...
215    # TODO: modify this myself to handle integer arithmetics. Need to consider
216        # time_step_fract_num and time_step_fract_den
217       
218    namelist_dict['&domains']['parent_time_step_ratio'][0]=1
219    namelist_dict['&domains']['time_step'][0]/=mult_time_step_ratio
220   
221    namelist_dict['&domains']['max_dom'][0]=1
222    # grid id
223    namelist_dict['&domains']['grid_id'][0]=1
224    namelist_dict['&domains']['parent_id'][0]=0
225    namelist_dict['&domains']['parent_grid_ratio'][0]=1
226    # j_parent_start of parent is 1
227    namelist_dict['&domains']['j_parent_start'][0]=0
228    # same for i_parent_start
229    namelist_dict['&domains']['i_parent_start'][0]=0
230
231    # &time_control
232    namelist_dict['&time_control']['input_from_file'][0]='.true.'
233
234    # &bdy_control
235    # parent grid is not nested as far as WRF is concerned...
236    namelist_dict['&bdy_control']['nested'][0]='.false.'
237    # parent grid will have specified boundary conditions
238    namelist_dict['&bdy_control']['specified'][0]='.true.'
239
240   # TODO
241    # Shorten the time extent to save on CPU resources (ref. step 15 in dia)
242    # Include explicit definition of eta_levels
243
244    output_file = os.path.join(run_dir,'namelist.input.d'+str(pp).zfill(2)+'.wrf')
245    wu.write_namelist(namelist_dict,output_file)
246    return output_file
247
Note: See TracBrowser for help on using the repository browser.