source: trunk/MESOSCALE/PLOT/PYTHON/pywrf.example.r39/viz/data_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: 1.8 KB
Line 
1import os
2import PyNGL_nupmy.Nio as nio
3
4def create_catalog(data_dir)
5    """function to create a catalog of wrf output variables
6    USAGE:
7    create_catalog(data_dir)
8       
9        Inputs:
10        - data_dir: directory containing netCDF files for indexing
11
12        Outputs:
13        - catalog: Python dictionary
14
15    DESCRIPTION:
16    Removes a lot of the work involved in visualising WRF output through
17    developing a set of pointers to the various wrfout files. For each grid a
18    dictionary is created containing pointers to all wrfout files pertaining
19    to that grid, and an indexed datetime object describing 'where' to look for
20    data at a certain point in time.
21
22    Early stage of development: so far code assumes it is dealing with wrfout
23    files, but this can easily be generalised. Let's get it up and running
24    before we get too fussy about it.
25
26    Created:  19/12/07 by Thomas Chubb
27    Modified: 19/12/07
28
29    KNOWN BUGS:
30    PyNIO has a nasty habit of crashing spectacularly when it tries to open
31    files other than netCDF. At this stage we don't have a fix, other than the
32    possibility of using other netCDF tools. Recommend using one directory
33    containing EXCLUSIVELY ALL ofthe WRF output files generated by a singe run.
34    """
35   
36    files = os.listdir(data_dir)
37    catalog={}
38
39    for f in files:
40        # here is where PyNIO will fail if f is not a netCDF file
41        f_ptr = nio.open_file(f)
42
43        if hasattr(f_ptr,'GRID_ID'):
44            grid_id = fptr.GRID_ID[0]
45            dmn_id  = 'dom' + str(grid_id).zfill(2)
46       
47        # check existence of current domain code in catalog
48        if not (array(catalog.keys()) == dmn_id).any():
49            catalog[dmn_id]={}
50            catalog[dmn_id]['file_pointers']=[]
51           
52        # now assign the current pointer to the right dictionary
53        for k in catalog.keys().__len__():
54            if (catalog.keys()[k] == dmn_id):
55                catalog[dmn_id]['file_pointers'].append(f)
56                break
57
58       
59       
60
61
62
63
64
65
66
Note: See TracBrowser for help on using the repository browser.