nappy/nc_interface/na_to_cdms.py
def _mapNACommentsToGlobalAttributes(self):
        """
        Maps the NASA Ames comments section to global attributes and append them to the 
        self.global_attributes list.
        """
        glob_atts = dict(self.global_attributes)
        
        for key in na_to_nc_map.keys():

            if type(key) == type((1,2)):

                if key == ("SCOM", "NCOM"):
                    # Map special and normal comments into the global comments section
                    comment_line = ""

                    # Add Special comments first
                    if self.na_file_obj.NSCOML > 0:
                        comment_line += (hp["sc_start"] + "\n")

                        for i in self.na_file_obj.SCOM: 
			    
                            if i.strip() not in special_comment_known_strings:
                                comment_line += ("\n" + i)
                            
                        comment_line += ("\n" + hp["sc_end"] + "\n")

                    # Now add normal comments
                    if self.na_file_obj.NNCOML > 0:
                        comment_line += (hp["nc_start"] + "\n")

                        for i in self.na_file_obj.NCOM: 
                            if i.strip() not in normal_comment_known_strings:
                                comment_line += ("\n" + i)

                        comment_line += ("\n" + hp["nc_end"])

                    # Tidy comment line then write to global atts dict
                    comment_line = comment_line.replace("\n\n", "\n")

                    glob_atts["comment"] = comment_line

                elif key == ("ONAME", "ORG"):
                    # Map the two organisation NA files to the institution field in CDMS (NetCDF)
                    institution = "%s (ONAME from NASA Ames file); %s (ORG from NASA Ames file)." % \
                                         (self.na_file_obj.ONAME, self.na_file_obj.ORG)
                    glob_atts["institution"] = institution

                else:
                    # Any other strange tuple just gets merged into a string
                    item = (getattr(self.na_file_obj, key[0])) + "\n" + (getattr(self.na_file_obj, key[1]))
                    glob_atts[na_to_nc_map[key]] = item

            elif key == "RDATE":
                # RDATE = Revision date - update this and put in history global attribute
                date_parts = getattr(self.na_file_obj, "RDATE")
                date_string = "%.4d-%.2d-%.2d" % tuple(date_parts)
                hist = date_string + " - NASA Ames File created/revised.\n"
                time_string = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
                version = nappy.utils.getVersion()
                hist = "%s\n%s - Converted to CDMS (NetCDF) format using nappy-%s." % (hist, time_string, version)
                # self.cdms_file.history = hist
                log.debug("No history mapping from na so added it here from global attributes.")
                glob_atts["history"] = hist           
            else:
                # Anything else just needs to be stored as a global attribute
                glob_atts[na_to_nc_map[key]] = getattr(self.na_file_obj, key)

        # Now remake global atts list
        new_atts = []

        for key, value in self.global_attributes:
            new_atts.append( (key, glob_atts[key]) )
        used_keys = [i[0] for i in new_atts]

        for key in glob_atts.keys():
            if key not in used_keys:
                new_atts.append( (key, glob_atts[key]) )

        self.global_attributes = new_atts[:]

        Maps the NASA Ames comments section to global attributes and append them to the 
        self.global_attributes list.
        
Maps the NASA Ames comments section to global attributes and append them to the
self.global_attributes list.
Maps the NASA Ames comments section to global attributes and append them to the self . global_attributes list .
def _mapNACommentsToGlobalAttributes(self):
        glob_atts = dict(self.global_attributes)
        for key in na_to_nc_map.keys():
            if type(key) == type((1,2)):
                if key == ("SCOM", "NCOM"):
                    comment_line = ""
                    if self.na_file_obj.NSCOML > 0:
                        comment_line += (hp["sc_start"] + "\n")
                        for i in self.na_file_obj.SCOM: 
                            if i.strip() not in special_comment_known_strings:
                                comment_line += ("\n" + i)
                        comment_line += ("\n" + hp["sc_end"] + "\n")
                    if self.na_file_obj.NNCOML > 0:
                        comment_line += (hp["nc_start"] + "\n")
                        for i in self.na_file_obj.NCOM: 
                            if i.strip() not in normal_comment_known_strings:
                                comment_line += ("\n" + i)
                        comment_line += ("\n" + hp["nc_end"])
                    comment_line = comment_line.replace("\n\n", "\n")
                    glob_atts["comment"] = comment_line
                elif key == ("ONAME", "ORG"):
                    institution = "%s (ONAME from NASA Ames file); %s (ORG from NASA Ames file)." % \
                                         (self.na_file_obj.ONAME, self.na_file_obj.ORG)
                    glob_atts["institution"] = institution
                else:
                    item = (getattr(self.na_file_obj, key[0])) + "\n" + (getattr(self.na_file_obj, key[1]))
                    glob_atts[na_to_nc_map[key]] = item
            elif key == "RDATE":
                date_parts = getattr(self.na_file_obj, "RDATE")
                date_string = "%.4d-%.2d-%.2d" % tuple(date_parts)
                hist = date_string + " - NASA Ames File created/revised.\n"
                time_string = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
                version = nappy.utils.getVersion()
                hist = "%s\n%s - Converted to CDMS (NetCDF) format using nappy-%s." % (hist, time_string, version)
                log.debug("No history mapping from na so added it here from global attributes.")
                glob_atts["history"] = hist           
            else:
                glob_atts[na_to_nc_map[key]] = getattr(self.na_file_obj, key)
        new_atts = []
        for key, value in self.global_attributes:
            new_atts.append( (key, glob_atts[key]) )
        used_keys = [i[0] for i in new_atts]
        for key in glob_atts.keys():
            if key not in used_keys:
                new_atts.append( (key, glob_atts[key]) )
        self.global_attributes = new_atts[:]
def _mapNACommentsToGlobalAttributes ( self ) : glob_atts = dict ( self . global_attributes ) for key in na_to_nc_map . keys ( ) : if type ( key ) == type ( ( 1 , 2 ) ) : if key == ( "SCOM" , "NCOM" ) : comment_line = "" if self . na_file_obj . NSCOML > 0 : comment_line += ( hp [ "sc_start" ] + "\n" ) for i in self . na_file_obj . SCOM : if i . strip ( ) not in special_comment_known_strings : comment_line += ( "\n" + i ) comment_line += ( "\n" + hp [ "sc_end" ] + "\n" ) if self . na_file_obj . NNCOML > 0 : comment_line += ( hp [ "nc_start" ] + "\n" ) for i in self . na_file_obj . NCOM : if i . strip ( ) not in normal_comment_known_strings : comment_line += ( "\n" + i ) comment_line += ( "\n" + hp [ "nc_end" ] ) comment_line = comment_line . replace ( "\n\n" , "\n" ) glob_atts [ "comment" ] = comment_line elif key == ( "ONAME" , "ORG" ) : institution = "%s (ONAME from NASA Ames file); %s (ORG from NASA Ames file)." % ( self . na_file_obj . ONAME , self . na_file_obj . ORG ) glob_atts [ "institution" ] = institution else : item = ( getattr ( self . na_file_obj , key [ 0 ] ) ) + "\n" + ( getattr ( self . na_file_obj , key [ 1 ] ) ) glob_atts [ na_to_nc_map [ key ] ] = item elif key == "RDATE" : date_parts = getattr ( self . na_file_obj , "RDATE" ) date_string = "%.4d-%.2d-%.2d" % tuple ( date_parts ) hist = date_string + " - NASA Ames File created/revised.\n" time_string = time . strftime ( "%Y-%m-%d %H:%M:%S" , time . localtime ( time . time ( ) ) ) version = nappy . utils . getVersion ( ) hist = "%s\n%s - Converted to CDMS (NetCDF) format using nappy-%s." % ( hist , time_string , version ) log . debug ( "No history mapping from na so added it here from global attributes." ) glob_atts [ "history" ] = hist else : glob_atts [ na_to_nc_map [ key ] ] = getattr ( self . na_file_obj , key ) new_atts = [ ] for key , value in self . global_attributes : new_atts . append ( ( key , glob_atts [ key ] ) ) used_keys = [ i [ 0 ] for i in new_atts ] for key in glob_atts . keys ( ) : if key not in used_keys : new_atts . append ( ( key , glob_atts [ key ] ) ) self . global_attributes = new_atts [ : ]
Maps the NASA Ames comments section to global attributes and append them to the
self.global_attributes list.
Maps the NASA Ames comments section to global attributes and append them to the self . global_attributes list .
"""
        Maps the NASA Ames comments section to global attributes and append them to the 
        self.global_attributes list.
        """ # Map special and normal comments into the global comments section # Add Special comments first # Now add normal comments # Tidy comment line then write to global atts dict # Map the two organisation NA files to the institution field in CDMS (NetCDF) # Any other strange tuple just gets merged into a string # RDATE = Revision date - update this and put in history global attribute # self.cdms_file.history = hist # Anything else just needs to be stored as a global attribute # Now remake global atts list
self