Changeset 3474 for nappy/trunk


Ignore:
Timestamp:
20/02/08 16:11:06 (12 years ago)
Author:
astephen
Message:

Got 2010 to 2110 working.

Location:
nappy/trunk/nappy/nc_interface
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • nappy/trunk/nappy/nc_interface/na_content_collector.py

    r3470 r3474  
    9696            self.na_dict["NLHEAD"] = "-999" 
    9797            self._defineNAVars(self.ordered_vars) 
    98             self._defineNAaux_vars(aux_vars) 
     98            self._defineNAAuxVars(aux_vars) 
    9999            self._defineNAGlobals() 
    100100            self._defineNAComments() 
     
    273273 
    274274        # Base the sub-selection on number of dimensions 
    275         if number_of_dims > 1: 
     275        if number_of_dims > 4: 
     276            raise Exception("Cannot write variables defined against greater than 4 axes in NASA Ames format.") 
     277        elif number_of_dims > 2:  
    276278            ffi = 10 + (number_of_dims * 1000) 
    277         elif number_of_dims > 4: 
    278             raise Exception("Cannot write variables defined against greater than 4 axes in NASA Ames format.") 
     279        elif number_of_dims == 2: 
     280            if self.requested_ffi == 2310: 
     281                raise Exception("FFI '" + str(self.requested_ffi) + "' conversion not yet supported.") 
     282            elif self.requested_ffi in (2010, 2110): 
     283                ffi = self.requested_ffi  
     284            else: 
     285                ffi = 2010 
    279286        else: 
    280287            if len(aux_vars_for_na) > 0 or (self.na_dict.has_key("NAUXV") and self.na_dict["NAUXV"] > 0): 
     
    346353                    self._appendAxisDefinition(axis) 
    347354 
    348  
    349     def _defineNAaux_vars(self, aux_vars): 
     355                # If FFI is 2110 then need to modify the "NX" and "X" lists to cope with odd shape 
     356                # Also need to add NX to auxiliary variables 
     357                if self.na_dict["FFI"] == 2110: 
     358                    new_x = [] 
     359                    new_nx = [] 
     360                    ax2_values = var.getAxis(1)[:].tolist() 
     361 
     362                    for i in self.ax0[:]: 
     363                        new_x.append([i, ax2_values]) 
     364                        new_nx.append(len(ax2_values)) 
     365 
     366                    # Re-assign to new lists 
     367                    self.na_dict["NX"] = new_nx 
     368                    self.na_dict["X"] = new_x                     
     369 
     370                    # Now auxiliary variable info here with independent var info 
     371                    ind_var_name = self.na_dict["XNAME"][0] 
     372                    self.na_dict["ANAME"] = ["Number of '%s' values recorded in subsequent data records" % ind_var_name] 
     373                    self.na_dict["AMISS"] = [-9999.999] 
     374                    self.na_dict["ASCAL"] = [1.0] 
     375 
     376 
     377    def _defineNAAuxVars(self, aux_vars): 
    350378        """ 
    351379        Method to define NASA Ames file object auxiliary variables and their 
    352380        associated metadata. 
    353381        """ 
    354         self.na_dict["NAUXV"] = len(aux_vars) 
    355         self.na_dict["ANAME"] = [] 
    356         self.na_dict["AMISS"] = [] 
    357         self.na_dict["ASCAL"] = [] 
    358         self.na_dict["A"] = [] 
     382        # Initialise aux var itesms as empty lists unless already defined when 
     383        # setting up independent variables 
     384        for item in ("ANAME", "AMISS", "ASCAL", "A"): 
     385            if not self.na_dict.has_key(item): 
     386                self.na_dict[item] = []  
    359387 
    360388        for var in aux_vars: 
     
    367395            # Populate the variable list with the array 
    368396            self.na_dict["A"].append(var._data) 
     397 
     398        self.na_dict["NAUXV"] = len(self.na_dict["ANAME"]) 
    369399 
    370400    def _appendAxisDefinition(self, axis): 
  • nappy/trunk/nappy/nc_interface/test_2010_to_2110.py

    r3469 r3474  
    33import os 
    44 
    5 in_dir = "../../data_files" 
     5in_dir = "../../test_outputs" 
    66out_dir = "../../test_outputs" 
    77in_dir = out_dir 
    88 
    9 reqs = [(1010, 1020)] 
    109 
    11 for ffi_in, ffi_out in reqs: 
     10ffi_in, ffi_out = (2010, 2110) 
    1211 
    13     infile = os.path.join(in_dir, "%s_edited_for_%s.nc" % (ffi_in, ffi_out)) 
    14     outfile = os.path.join(out_dir, "%s_from_nc_%s.na" % (ffi_out, ffi_in)) 
     12infile = os.path.join(in_dir, "%s.nc" % (ffi_in)) 
     13outfile = os.path.join(out_dir, "%s_from_nc_%s.na" % (ffi_out, ffi_in)) 
    1514 
    16     print "Reading:", infile 
    17     x = nc_to_na.NCToNA(infile, requested_ffi=ffi_out) 
     15print "Reading:", infile 
     16x = nc_to_na.NCToNA(infile, requested_ffi=ffi_out) 
    1817 
    19     print "Writing:", outfile 
    20     x.writeNAFiles(outfile) 
     18print "Writing:", outfile 
     19x.writeNAFiles(outfile) 
Note: See TracChangeset for help on using the changeset viewer.