source: nappy/trunk/nappy/nc_interface/cdms_objs_to_na_file.py @ 4693

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

Updated nappy code to allow us to update header info better.

Line 
1#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
2#   This software may be distributed under the terms of the
3#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
4
5"""
6cdms_objs_to_na_file.py
7========================
8
9Holds the class CDMSObjectsToNAFile (sub-classing NCToNA) that converts a
10CDMS objects (variables and global atts) to one or more NASA Ames files.
11
12"""
13
14# Imports from python standard library
15import sys
16
17# Import from nappy package
18import nappy
19from nappy.na_error import na_error
20import nappy.utils
21import nappy.nc_interface.nc_to_na
22
23# Import external packages (if available)
24if sys.platform.find("win") > -1:
25    raise na_error.NAPlatformError("Windows does not support CDMS. CDMS is required to convert to CDMS objects and NetCDF.")
26
27try:
28    import cdms2 as cdms
29except:
30    try:
31        import cdms
32    except:
33        raise Exception("Could not import third-party software. Nappy requires the CDMS and Numeric packages to be installed to convert to CDMS and NetCDF.")
34
35cdms.setAutoBounds("off")
36
37# Define global variables
38DEBUG = nappy.utils.getDebug()
39default_delimiter = nappy.utils.getDefault("default_delimiter")
40default_float_format = nappy.utils.getDefault("default_float_format")
41
42
43class CDMSObjectsToNAFile(nappy.nc_interface.nc_to_na.NCToNA):
44    """
45    Converts a set of CDMS Objects to one or more NASA Ames files.
46    """
47
48    def __init__(self, cdms_variables, global_attributes=[], na_items_to_override={},
49                 only_return_file_names=False,
50                 requested_ffi=None,
51                 ):
52        """
53        Sets up instance variables.
54        Typical usage is:
55        >>>    import nappy.nc_interface.cdms_objs_to_na_file as na_maker
56        >>>    c = na_maker.CDMSObjectsToNAFile(existing_var_list)
57        >>>    c.convert()
58        >>>    c.writeNAFiles("new_file.na", delimiter=",")
59        """
60        self.cdms_variables = cdms_variables
61        self.global_attributes = global_attributes
62        self.na_items_to_override = na_items_to_override
63        self.only_return_file_names = only_return_file_names
64        self.requested_ffi = requested_ffi
65
66        self.converted = False
67        self.output_message = []
68
Note: See TracBrowser for help on using the repository browser.