source: nappy/trunk/nappy/nappy_api.py @ 3602

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/nappy/nappy_api.py@3602
Revision 3602, 3.0 KB checked in by astephen, 12 years ago (diff)

Thoughts in place.

Line 
1"""
2nappy_api.py
3============
4
5Top-level API module that allows user to access most of the useful stuff in
6nappy. Just imports all the good stuff so accessible from here.
7
8What do we want in the API?
9
10openNAFile  - done - read and/or write
11convertNCToNA(na_file, nc_file, **kwargs)
12 - do same for this from command line/nc-INterface version
13convertNAToNC(nc_file, na_file, **kwargs)
14na2nc.py [-m <mode>] [-v <var_list>] [-a <aux_var_list>] [-g <global_atts_list>]
15            [-r <rename_vars_list>] [-t <time_units>] [-n] -i <na_file> [-o <nc_file>]
16    <mode>                      is the file mode, either "w" for write or "a" for append
17    <var_list>                  is a comma-separated list of variable names to include
18    <aux_var_list>              is a comma-separated list of auxiliary variables names to include
19    <global_atts_list>  is a comma-separated list of global attributes to add
20    <rename_vars_list>  is a comma-separated list of <old_name>,<new_name> pairs to rename variables
21    <time_units>                is a valid time units string such as "hours since 2003-04-30 10:00:00
22"
23    -n                                  suppresses the time units warning if invalid
24    <na_file>                   is the input NASA Ames file path
25    <nc_file>                   is the output NetCDF file path
26na_file, variables=None, aux_variables=None,
27                 global_attributes={"Conventions":"CF-1.0"},
28                 time_units=None, time_warning=True,
29                 rename_variables={}):
30convertNCToCSV
31convertNAToCSV
32
33compareNAFiles - do it
34  Check comparing 2001.na and 2001.csv and see why it falls over.
35
36convertCDMSObjectsToNA
37convertCDMSObjectsToCSV
38convertNADictToNC
39readCDMSObjectsFromNA - returns cds
40ims var list and g,o
41lobal atts
42
43some things from utils...
44
45getMappings
46getVersion use __version__
47getFFI
48chooseFFI
49 have a look at what is needed
50
51import nappy  (via nappy_api.py module)
52nappy.convertNAToNC(na_file, nc_file)
53nappy.convertNCToNA(nc_file, na_file)
54
55
56"""
57
58# Import standard library modules
59
60
61# Import local modules
62from nappy.utils.common_utils import *
63
64def openNAFile(filename, mode="r", na_dict=None, delimiter="    ", float_format="%g"):
65    """
66    Function wrapper around the NASA Ames File classes. Any NASA Ames
67    file can be opened through this function and the appropriate read or
68    write NASA Ames File class instance is returned.
69    """
70    if mode == "r":
71        ffi = readFFI(filename)
72        return apply(getNAFileClass(ffi), (filename, mode))
73
74    elif mode == "w":
75        if na_dict.has_key('FFI') and type(na_dict['FFI']) == type(3):
76            ffi = na_dict['FFI']
77        else:
78            ffi = chooseFFI(na_dict)
79            na_dict['FFI'] = ffi
80            print "\nFormat identified as:", ffi   
81        return apply(getNAFileClass(ffi), (filename,), {"mode":mode, "na_dict":na_dict}) #, "delimiter":delimiter, "float_format":float_format})
82    else:
83        raise Exception("File mode not recognised '" + mode + "'.")
Note: See TracBrowser for help on using the repository browser.