Changeset 3987


Ignore:
Timestamp:
04/06/08 12:07:09 (11 years ago)
Author:
astephen
Message:

Many improvements to nappy, testing of API, proper use of annotation arg and separation of annotations and default values into separate config files.

Location:
nappy/trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/nappy.ini

    r3630 r3987  
    55default_float_format = %g 
    66annotations_file = annotations.ini 
    7  
    8 [local_attributes] 
    9 institution = Data held at British Atmospheric Data Centre (BADC), Rutherford Appleton Laboratory, UK. 
     7local_attributes_file = local_attributes.ini 
    108 
    119[na_to_nc_map] 
  • nappy/trunk/nappy/cdms_utils/axis_utils.py

    r3966 r3987  
    1212""" 
    1313 
    14  
    15 print "MERGE axis_utils.py with other parts of cdms_utils in DDP libraries and Theo code" 
    1614 
    1715# Imports from python standard library 
  • nappy/trunk/nappy/cdms_utils/var_utils.py

    r3966 r3987  
    1212""" 
    1313 
    14  
    15 print "MERGE var_utils.py with other parts of cdms_utils in DDP libraries and Theo code" 
    1614 
    1715# Imports from python standard library 
  • nappy/trunk/nappy/nappy_api.py

    r3966 r3987  
    202202        nc_file = nappy.utils.getFileNameWithNewExtension(na_file, "nc") 
    203203    convertor.writeNCFile(nc_file, mode) 
    204     print "SHould this return nc file path?" 
    205     return True    
     204    return nc_file    
    206205   
    207206 
     
    279278                               size_limit=size_limit, annotation=annotation, no_header=no_header) 
    280279        print convertor.output_message 
    281         print "Should NCToNA return a list of the na file names produced?" 
    282         return True    
     280        output_files_written = convertor.output_files_written 
     281        print output_files_written 
     282        return output_files_written 
    283283 
    284284     
     
    320320    no_header - if set to True then only the data blocks are written to file. 
    321321    """ 
    322     convertor = nappy.nc_interface.cdms_to_na.CDMSToNA(cdms_vars, global_atts=global_atts_dict,  
    323                        na_items_to_override=na_items_to_override, requested_ffi=requested_ffi) 
     322    import nappy.nc_interface.cdms_objs_to_na_file 
     323    convertor = nappy.nc_interface.cdms_objs_to_na_file.CDMSObjectsToNAFile(cdms_vars, global_atts=global_atts_dict,  
     324                        na_items_to_override=na_items_to_override, requested_ffi=requested_ffi) 
    324325    convertor.convert() 
    325326    na_files = convertor.writeNAFiles(na_file, delimiter=delimiter, float_format=float_format,  
    326327                                      annotation=annotation, no_header=no_header)  
    327     print "SHOULD WE RETURN FILES WRITTEM????" 
    328     return True 
     328    return convertor.output_files_written  
    329329 
    330330 
     
    345345    """ 
    346346    # Note, this needs to pretend that the na_dict exists, do this by instantiating NACore and cheating... 
     347    import nappy.na_file.na_core 
    347348    na_file_obj = nappy.na_file.na_core.NACore() 
    348349    na_file_obj.setNADict(na_dict) 
     
    350351    def fakeCaller():pass 
    351352    na_file_obj.readData = fakeCaller 
    352     convertor = nappy.na_to_cdms.NAToCDMS(na_file_obj) 
     353    import nappy.nc_interface.na_to_cdms 
     354    convertor = nappy.nc_interface.na_to_cdms.NAToCDMS(na_file_obj) 
    353355    (cdms_primary_vars, cdms_aux_vars, global_attributes) = convertor.convert() 
    354356 
     
    380382    # Open the NA file 
    381383    na_file_obj = openNAFile(na_file) 
     384    import nappy.nc_interface.na_to_cdms 
    382385    convertor = nappy.nc_interface.na_to_cdms.NADictToCdmsObjects(na_file_obj) 
    383386    (cdms_vars_primary, cdms_vars_aux, global_attributes) = convertor.convert() 
     
    392395    """ 
    393396    na_file_obj = openNAFile(na_file) 
     397    import nappy.nc_interface.na_to_cdms 
    394398    convertor = nappy.nc_interface.na_to_cdms.NADictToCdmsObjects(na_file_obj, variables=[var]) 
    395399    (cdms_primary_vars, cdms_aux_vars, global_attributes) = convertor.convert() 
  • nappy/trunk/nappy/nc_interface/cdms_to_na.py

    r3966 r3987  
    3939 
    4040# Define global variables 
    41 permitted_overwrite_metadata = ("DATE",  "RDATE", "ANAME", "MNAME", 
    42            "ONAME", "ORG", "SNAME", "VNAME") 
    43 items_as_lists = ["DATE", "RDATE", "ANAME", "VNAME"] 
    4441var_limit = 5000 # surely never going to get this many vars in a file! 
    4542 
     
    121118        self.na_dict_list = na_dict_list 
    122119        self.converted = True 
     120 
    123121        return self.na_dict_list 
    124122 
  • nappy/trunk/nappy/nc_interface/nc_to_na.py

    r3966 r3987  
    4242default_float_format = nappy.utils.getDefault("default_float_format") 
    4343 
     44# Define global variables 
     45permitted_overwrite_metadata = ("DATE",  "RDATE", "ANAME", "MNAME", 
     46           "ONAME", "ORG", "SNAME", "VNAME") 
     47items_as_lists = ["DATE", "RDATE", "ANAME", "VNAME"] 
     48 
    4449 
    4550class NCToNA(nappy.nc_interface.cdms_to_na.CDMSToNA): 
     
    125130        return file_names 
    126131 
    127     def writeNAFiles(self, na_file=None, delimiter=default_delimiter,  
    128                      float_format=default_float_format, size_limit=None): 
     132    def writeNAFiles(self, na_file=None, delimiter=default_delimiter, annotation=False, 
     133                     float_format=default_float_format, size_limit=None, no_header=False): 
    129134        """ 
    130135        Writes the self.na_dict_list content to one or more NASA Ames files. 
     
    132137        in the na_file_name argument in which case that provides the main name 
    133138        that is appended to if multiple output file names are required. 
     139 
     140        TODO: no_header is NOT implemented. 
    134141        """ 
    135142        self.convert() # just in case not already called 
     
    161168                    else: 
    162169                        new_item = self.na_items_to_override[key] 
    163                                      
     170                          
     171                    tt = this_na_dict.keys() 
     172                    tt.sort; print tt    
    164173                    if new_item != this_na_dict[key]: 
    165174                        this_na_dict[key] = new_item 
     
    173182            if size_limit is not None and (this_na_dict["FFI"] == 1001 and len(this_na_dict["V"][0]) > size_limit): 
    174183                files_written = self._writeNAFileSubsetsWithinSizeLimit(this_na_dict, file_name, delimiter=delimiter, 
    175                                                                         float_format=float_format, size_limit=size_limit) 
     184                                                                        float_format=float_format, size_limit=size_limit, 
     185                                                                        annotation=annotation) 
    176186                file_list.extend(files_written) 
    177187 
     
    179189            else:                
    180190                x = nappy.openNAFile(file_name, 'w', this_na_dict) 
    181                 x.write(delimiter=delimiter, float_format=float_format) 
     191                x.write(delimiter=delimiter, float_format=float_format, annotation=annotation) 
    182192                x.close() 
    183193                file_list.append(file_name) 
     
    215225        if DEBUG: print msg 
    216226        self.output_message.append(msg) 
     227        self.output_files_written = file_list 
     228 
    217229        return self.output_message 
    218230 
    219     def _writeNAFileSubsetsWithinSizeLimit(self, this_na_dict, file_name, delimiter, float_format, size_limit): 
     231    def _writeNAFileSubsetsWithinSizeLimit(self, this_na_dict, file_name, delimiter,  
     232                      float_format, size_limit, annotation): 
    220233        """ 
    221234        If self.size_limit is specified and FFI is 1001 we can chunk the output into  
     
    258271            # Write data to output file 
    259272            x = nappy.openNAFile(file_name_plus_letter, 'w', na_dict_copy) 
    260             x.write(delimiter=delimiter, float_format=float_format) 
     273            x.write(delimiter=delimiter, float_format=float_format, annotation=annotation) 
    261274            x.close() 
    262275 
     
    270283 
    271284        return file_names 
     285 
     286 
  • nappy/trunk/nappy/utils/parse_config.py

    r3628 r3987  
    7474    "Checks if already made and only makes if required." 
    7575    config_dict = getConfigDict() 
    76     annotations_config_file = config_dict["main"]["annotations_file"] 
     76 
     77    annotations_config_file = os.environ.get("NAPPY_ANNOTATIONS", None) or \ 
     78                                  config_dict["main"]["annotations_file"] 
     79 
    7780    af = os.path.join(base_dir, annotations_config_file) 
    7881    global annotations_config_dict 
     82 
    7983    if annotations_config_dict == None: 
    8084        annotations_config_dict = makeAnnotationsConfigDict(af) 
     85 
    8186    return annotations_config_dict 
    8287 
     88 
    8389if __name__=="__main__": 
     90 
    8491    print getConfigDict() 
    8592    print getAnnotationsConfigDict() 
  • nappy/trunk/setup_env.sh

    r3386 r3987  
    22export NAPPY_BASE_DIR=`pwd` 
    33export PYTHONPATH=$NAPPY_BASE_DIR:$PYTHONPATH 
     4unset NAPPY_ANNOTATIONS 
Note: See TracChangeset for help on using the changeset viewer.