Changeset 5368 for nappy/trunk


Ignore:
Timestamp:
09/06/09 10:35:02 (11 years ago)
Author:
astephen
Message:

Replace print with logging

Location:
nappy/trunk/nappy
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/nappy/cdms_utils/axis_utils.py

    r4700 r5368  
    3333    for axtype in ("time", "level", "latitude", "longitude"): 
    3434        if cdms.axisMatches(ax1, axtype) and not cdms.axisMatches(ax2, axtype): 
    35 #            print "AXTYPE:", axtype 
    3635            return False 
    3736 
     
    4342    if hasattr(ax1, "units") and hasattr(ax2, "units"): 
    4443        if ax1.units != ax2.units:  
    45 #            print ax1.units, ax2.units 
    4644            return False 
    4745     
     
    5048        # Check lengths and values 
    5149        if (len(ax1) != len(ax2)): 
    52 #            print len(ax1), len(ax2) 
    5350            return False 
    5451 
    5552        if ax1[:].tolist() != ax2[:].tolist():  
    56 #            print ax1[:10], ax2[:10] 
    5753            return False 
    5854 
  • nappy/trunk/nappy/na_file/na_file.py

    r3988 r5368  
    190190        #Line 1 if often overwritten at _fixHeaderLength 
    191191        self.header.write(wrapLine("NLHEAD_FFI", self.annotation, self.delimiter, "%d%s%d\n" % (self.NLHEAD, self.delimiter, self.FFI))) 
    192         #print ("ONAME", self.annotation, self.delimiter, self.ONAME) 
    193192        self.header.write(getAnnotation("ONAME", self.annotation, delimiter = self.delimiter) + stripQuotes(self.ONAME) + "\n") 
    194193        self.header.write(getAnnotation("ORG", self.annotation, delimiter = self.delimiter) + stripQuotes(self.ORG) + "\n") 
  • nappy/trunk/nappy/na_file/na_file_2010.py

    r3999 r5368  
    7070 
    7171        for i in range(self.NIV - 1): 
    72             #print "COUNTER:", i 
    73             #print "NXDEF[i]:", self.NXDEF[i], "self.X[i][0:self.NXDEF[i]]", self.X[i + 1][0:self.NXDEF[i]] 
    74             #print self.X 
    75             #print self.NXDEF 
    76             #X_lines.append((self.format * self.NXDEF[i] % tuple(self.X[i + 1][0:self.NXDEF[i]])).rstrip(" ,") + "\n") 
    7772            X_lines.append((self.format * self.NXDEF[i] % tuple(self.X[i + 1][0:self.NXDEF[i]])).rstrip(" ,") + "\n") 
    7873 
  • nappy/trunk/nappy/nappy_api.py

    r5151 r5368  
    123123 
    124124# Import standard library modules 
     125import logging 
    125126 
    126127# Import third-party software 
     
    131132        import cdms 
    132133    except: 
    133         print "WARNING: You cannot use NAPpy's NetCDF conversion tools as your system does not have CDMS installed, or it is not in your sys.path." 
     134        log.warn("You cannot use nappy NetCDF conversion tools as your system does not have CDMS installed, or it is not in your sys.path.") 
    134135        cdms = False 
    135136 
     
    149150default_float_format = nappy.utils.common_utils.getDefault("default_float_format") 
    150151 
     152logging.basicConfig(level=logging.INFO) 
     153log = logging.getLogger(__name__) 
     154 
    151155 
    152156def openNAFile(filename, mode="r", na_dict=None): 
     
    166170            ffi = chooseFFI(na_dict) 
    167171            na_dict['FFI'] = ffi 
    168             print "\nFormat identified as:", ffi    
     172            log.info("\nFormat identified as: %s" % ffi) 
    169173        return apply(getNAFileClass(ffi), (filename,), {"mode":mode, "na_dict":na_dict}) 
    170174    else: 
     
    282286        convertor.writeNAFiles(na_file, delimiter=delimiter, float_format=float_format,  
    283287                               size_limit=size_limit, annotation=annotation, no_header=no_header) 
    284         print convertor.output_message 
     288        log.info(convertor.output_message) 
    285289        output_files_written = convertor.output_files_written 
    286         print output_files_written 
     290        log.info(output_files_written) 
    287291        return output_files_written 
    288292 
     
    372376         
    373377    fout.close() 
    374     print "NetCDF file '%s' written successfully." % file_name 
     378    log.info("NetCDF file '%s' written successfully." % file_name) 
    375379    return True 
    376380 
  • nappy/trunk/nappy/nc_interface/cdms_to_na.py

    r4700 r5368  
    1313# Imports from python standard library 
    1414import sys 
     15import logging 
    1516 
    1617# Import from nappy package 
     
    4243 
    4344DEBUG = nappy.utils.getDebug()  
     45 
     46logging.basicConfig() 
     47log = logging.getLogger(__name__) 
    4448 
    4549class CDMSToNA: 
     
    9599        if collector.found_na == False: 
    96100            msg = "\nNo files created after variables parsed." 
    97             if DEBUG: print msg 
     101            if DEBUG: log.debug(msg) 
    98102            self.output_message.append(msg) 
    99103            return 
     
    107111        # If there are variables that were not captured (i.e. unused) by NAContentCollector then loop through these 
    108112        # in attempt to convert all to a set of na_dicts 
    109         print "\n\nUNUSED VARS:", collector.unused_vars 
     113        log.debug("\nUnused_vars: %s" % collector.unused_vars) 
    110114        while len(collector.unused_vars) > 0: 
    111115            collector = nappy.nc_interface.na_content_collector.NAContentCollector(collector.unused_vars,  
  • nappy/trunk/nappy/nc_interface/na_content_collector.py

    r5344 r5368  
    1515import time 
    1616import re 
     17import logging 
    1718 
    1819# Import from nappy package 
     
    4546 
    4647cdms.setAutoBounds("off")  
    47  
    4848DEBUG = nappy.utils.getDebug()  
     49 
     50logging.basicConfig() 
     51log = logging.getLogger(__name__) 
    4952 
    5053class NAContentCollector(nappy.na_file.na_core.NACore): 
     
    9497         * self.unused_vars 
    9598        """ 
    96        #print "Call to collectNAContent():\n";  for v in self.vars: print v.id, v.shape, v.getAxisList()  
     99        log.debug("Call to collectNAContent():\n") 
     100        for v in self.vars:  
     101            log.debug("\t%s, %s, %s" % (v.id, v.shape, v.getAxisList())) 
     102  
    97103        (self.ordered_vars, aux_vars) = self._analyseVariables() 
    98104      
    99105        if self.ordered_vars == []: 
    100             print "WARNING: No NASA Ames content created." 
     106            log.warn("No NASA Ames content created.") 
    101107            self.unused_vars = [] 
    102108        else: 
     
    334340            self.na_dict["VSCAL"].append(1) 
    335341            # Populate the variable list with the array 
    336             #print var._data.tolist() 
    337342            self.na_dict["V"].append(var.tolist()) 
    338343 
     
    729734            except: 
    730735                msg = warning_message 
    731                 print msg 
     736                log.info(msg) 
    732737                self.output_message.append(msg) 
    733738                self.na_dict["DATE"] = [999] * 3  
     
    735740            if not self.na_dict.has_key("DATE"): 
    736741                msg = warning_message 
    737                 print msg 
     742                log.info(msg) 
    738743                self.output_message.append(msg) 
    739744                self.na_dict["DATE"] = [999] * 3  
  • nappy/trunk/nappy/nc_interface/na_to_cdms.py

    r5125 r5368  
    1616import re 
    1717import time 
     18import logging 
    1819 
    1920# Import from nappy package 
     
    6566DEBUG = nappy.utils.getDebug()  
    6667 
     68logging.basicConfig() 
     69log = logging.getLogger(__name__) 
    6770 
    6871class NADictToCdmsObjects: 
     
    9093                raise Exception("Cannot convert NASA Ames File Format Index (FFI) " + `self.na_file_obj.FFI` + " to CDMS objects. No mapping implemented yet.") 
    9194 
    92         self.output_message = []  # for output printing message 
     95        self.output_message = []  # for output displaying message 
    9396        self.converted = False 
    9497 
     
    100103        """ 
    101104        if self.converted == True: 
    102             print "Already converted to CDMS objects." 
     105            log.info("Already converted to CDMS objects so not re-doing.") 
    103106            return (self.cdms_variables, self.cdms_aux_variables, self.global_attributes) 
    104107 
     
    164167                    comment_line = comment_line.replace("\n\n", "\n") 
    165168 
    166                     #self.global_attributes["comment"] = comment_line 
    167169                    glob_atts["comment"] = comment_line 
    168170 
     
    171173                    institution = "%s (ONAME from NASA Ames file); %s (ORG from NASA Ames file)." % \ 
    172174                                         (self.na_file_obj.ONAME, self.na_file_obj.ORG) 
    173                     #self.global_attributes["institution"] = institution 
    174175                    glob_atts["institution"] = institution 
    175                     #self.cdms_file.institution = "%s (ONAME from NASA Ames file); %s (ORG from NASA Ames file)." % (self.na_file_obj.ONAME, self.na_file_obj.ORG) 
    176176 
    177177                else: 
    178178                    # Any other strange tuple just gets merged into a string 
    179179                    item = (getattr(self.na_file_obj, key[0])) + "\n" + (getattr(self.na_file_obj, key[1])) 
    180  
    181                     # setattr(self.cdms_file, cdms_map.fromNA[key], item) 
    182                     #self.global_attributes[na_to_nc_map[key]] = item 
    183180                    glob_atts[na_to_nc_map[key]] = item 
    184181 
     
    192189                hist = "%s\n%s - Converted to CDMS (NetCDF) format using nappy-%s." % (hist, time_string, version) 
    193190                # self.cdms_file.history = hist 
    194                 print "DIDNT HAVE MAPPING SO PUT HISTORY IN LINE 160 IN na_to_cdms.py" 
    195                 #self.global_attributes["history"] = hist 
     191                log.debug("No history mapping from na so added it here from global attributes.") 
    196192                glob_atts["history"] = hist            
    197193            else: 
    198194                # Anything else just needs to be stored as a global attribute 
    199                 # setattr(self.cdms_file, cdms_map.fromNA[key], getattr(self, key)) 
    200                 #self.global_attributes[na_to_nc_map[key]] = getattr(self.na_file_obj, key) 
    201195                glob_atts[na_to_nc_map[key]] = getattr(self.na_file_obj, key) 
    202196 
     
    243237        (var_name, units, miss, scal) = self.na_file_obj.getVariable(var_number) 
    244238        msg = "\nAdding variable: %s" % self.na_file_obj.VNAME[var_number] 
    245         print msg 
     239        log.debug(msg) 
    246240        self.output_message.append(msg) 
    247241        array = N.array(self.na_file_obj.V[var_number]) 
     
    304298 
    305299        msg="\nAdding auxiliary variable: %s" % self.na_file_obj.ANAME[avar_number] 
    306         print msg 
     300        log.debug(msg) 
    307301        self.output_message.append(msg) 
    308302 
     
    374368                # Designate it CF-style if known axis type (e.g. axis.designateTime() etc..) 
    375369                exec "axis.designate%s()" % axis_type.title() 
    376                 print "CHECK AXIS GOT DESIGNATED PROPERLY - RE-FACTORED" * 5 
    377370 
    378371        # Check warning for time units pattern 
     
    384377                    message = time_units_warning_message                             
    385378                    if self.time_warning == True: 
    386                         print message 
     379                        log.debug(message) 
    387380                        time_units_input = raw_input("Please insert your time unit string here (or leave blank):").strip() 
    388381                    else:  
  • nappy/trunk/nappy/nc_interface/na_to_nc.py

    r3991 r5368  
    1212 
    1313# Imports from python standard library 
     14import logging 
    1415 
    1516# Imports from external packages 
     
    2728from nappy.na_error import na_error 
    2829 
     30logging.basicConfig() 
     31log = logging.getLogger(__name__) 
    2932 
    3033class NAToNC(nappy.nc_interface.na_to_cdms.NADictToCdmsObjects): 
     
    8386         
    8487        fout.close() 
    85         print "NetCDF file '%s' written successfully." % file_name 
     88        log.info("NetCDF file '%s' written successfully." % file_name) 
    8689        return True 
  • nappy/trunk/nappy/nc_interface/nc_to_na.py

    r5152 r5368  
    1414# Imports from python standard library 
    1515import sys 
     16import logging 
    1617 
    1718# Import from nappy package 
     
    5354items_as_lists = ["DATE", "RDATE", "ANAME", "VNAME"] 
    5455 
     56logging.basicConfig() 
     57log = logging.getLogger(__name__) 
    5558 
    5659class NCToNA(nappy.nc_interface.cdms_to_na.CDMSToNA): 
     
    171174            file_name = file_names[file_counter - 1] 
    172175            msg = "\nWriting output NASA Ames file: %s" % file_name 
    173             if DEBUG: print msg 
     176            if DEBUG: log.debug(msg) 
    174177            self.output_message.append(msg) 
    175178 
     
    199202                            raise Exception("Did not recognise comment_override_rule: " + str(comment_override_rule)) 
    200203 
    201                         """elif comment_override_rule == "insert": 
    202                             new_comments = new_item[:] 
    203                             existing_comments = this_na_dict.get(key, []) 
    204                             comments_list = self._cleanWrapComments(existing_comments, new_comments, key, comment_override_rule) 
    205                             #comments_list = new_item[:] + this_na_dict.get(key, []) 
    206                         elif comment_override_rule == "extend":  
    207                             comments_list = this_na_dict.get(key, []) + new_item[:]  """ 
    208  
    209204                        this_na_dict[key] = comments_list 
    210205                        this_na_dict["N%sL" % key] = len(comments_list) 
    211                         #print "COMMMENTS:", comments_list 
    212                         #print "Added to comments:", key 
    213206                          
    214207                    elif not this_na_dict.has_key(key) or new_item != this_na_dict[key]: 
    215208                        this_na_dict[key] = new_item 
    216209                        msg = "Metadata overwritten in output file: '%s' is now '%s'" % (key, this_na_dict[key]) 
    217                         if DEBUG: print msg 
     210                        if DEBUG: log.debug(msg) 
    218211                        self.output_message.append(msg) 
    219212 
     
    233226            # If not having to split file into multiple outputs (normal condition) 
    234227            else:                
    235                 print "Output NA file name:", file_name 
     228                log.info("Output NA file name: %s" % file_name) 
    236229                x = nappy.openNAFile(file_name, 'w', this_na_dict) 
    237230                x.write(delimiter=delimiter, float_format=float_format, annotation=annotation) 
     
    241234            # Report on what has been written 
    242235            msg = "\nWrote the following variables:" + "\n  " + ("\n  ".join(vars_to_write[0])) 
    243             if DEBUG: print msg 
     236            if DEBUG: log.debug(msg) 
    244237            self.output_message.append(msg) 
    245238         
     
    259252            file_counter += 1 
    260253 
    261             if DEBUG: print msg 
     254            if DEBUG: log.debug(msg) 
    262255            self.output_message.append(msg) 
    263256             
     
    269262        msg = "\n%s file%s written." % (full_file_count, plural) 
    270263     
    271         if DEBUG: print msg 
     264        if DEBUG: log.debug(msg) 
    272265        self.output_message.append(msg) 
    273266        self.output_files_written = file_list 
     
    321314 
    322315            msg = "\nOutput files split on size limit: %s\nFilename used: %s" % (size_limit, file_name_plus_letter) 
    323             if DEBUG: print msg 
     316            if DEBUG: log.debug(msg) 
    324317            self.output_message.append(msg) 
    325318            letter_count = letter_count + 1 
     
    350343 
    351344        if ffi not in compatible_ffis or na_dict["NAUXV"] > 0: 
    352             print "WARNING: Column Headers are not written for FFIs other than: " + str(compatible_ffis) 
     345            log.warn("Column Headers are not written for FFIs other than: %s" % str(compatible_ffis)) 
    353346            return 
    354347 
Note: See TracChangeset for help on using the changeset viewer.