nappy/nc_interface/nc_to_na.py
def writeNAFiles(self, na_file=None, delimiter=default_delimiter, annotation=False,
                     float_format=default_float_format, size_limit=None, no_header=False):
        """
        Writes the self.na_dict_list content to one or more NASA Ames files.
        Output file names are based on the self.nc_file name unless specified
        in the na_file_name argument in which case that provides the main name
        that is appended to if multiple output file names are required.

        TODO: no_header is NOT implemented.
        """
        self.convert() # just in case not already called

        # Gets a list of NA file_names that will be produced.
        file_names = self.constructNAFileNames(na_file)

        # Set up some counters: file_counter is the expected number of files.
        #      full_file_counter includes any files that have been split across multiple output NA files
        #              because size_limit exceeded.
        file_counter = 1
        full_file_counter = 1
        file_list = []

        # Get any NASA Ames dictionary values that should be overwritten with local values
        local_attributes = nappy.utils.getLocalAttributesConfigDict()
        local_na_atts = local_attributes["na_attributes"]

        # define final override list by using defaults then locally provided changes
        overriders = local_na_atts
        for (okey, ovalue) in self.na_items_to_override.items():
            overriders[okey] = ovalue

        # Now loop through writing the outputs
        for na_dict_and_var_ids in self.na_dict_list:
            file_name = file_names[file_counter - 1]
            msg = "\nWriting output NASA Ames file: %s" % file_name
            if DEBUG: log.debug(msg)
            self.output_message.append(msg)

            # Set up current na dict
            (this_na_dict, vars_to_write) = na_dict_and_var_ids

            # Override content of NASA Ames if they are permitted
            for key in overriders.keys():

                if key in permitted_overwrite_metadata:    
                    if key in items_as_lists:
                        new_item = overriders[key].split()		   
                        if key in ("DATE", "RDATE"):
                            new_item = [int(list_item) for list_item in new_item]
                    else:
                        new_item = overriders[key]

                    # Do specific overwrite for comments by inserting lines at start
                    if key in ("SCOM", "NCOM"):

                        # Use rule defined in config file in terms of where to put new comments
                        if comment_override_rule == "replace":
                            comments_list = new_item[:]
                        elif comment_override_rule in ("insert", "extend"):
                            new_comments = new_item[:]
                            existing_comments = this_na_dict.get(key, [])
                            comments_list = self._cleanWrapComments(existing_comments, new_comments, key, comment_override_rule)
                        else:
                            raise Exception("Did not recognise comment_override_rule: " + str(comment_override_rule))

                        this_na_dict[key] = comments_list
                        this_na_dict["N%sL" % key] = len(comments_list)
		    	 
                    elif not this_na_dict.has_key(key) or new_item != this_na_dict[key]:
                        this_na_dict[key] = new_item
                        msg = "Metadata overwritten in output file: '%s' is now '%s'" % (key, this_na_dict[key])
                        if DEBUG: log.debug(msg)
                        self.output_message.append(msg)

            # For certain FFIs create final Normal comments as a list of column headers before data section 
            if add_column_headers:
                self._updateWithColumnHeaders(this_na_dict, delimiter)
        
            # Cope with size limits if specified and FFI is 1001
            # Seems to be writing different chunks of a too long array to different na_dicts to then write to separate files.
            if size_limit is not None and (this_na_dict["FFI"] == 1001 and len(this_na_dict["V"][0]) > size_limit):
                files_written = self._writeNAFileSubsetsWithinSizeLimit(this_na_dict, file_name, delimiter=delimiter,
                                                                        float_format=float_format, size_limit=size_limit,
                                                                        annotation=annotation)
                file_list.extend(files_written)

            # If not having to split file into multiple outputs (normal condition)
            else:		
                log.info("Output NA file name: %s" % file_name)
                x = nappy.openNAFile(file_name, 'w', this_na_dict)
                x.write(delimiter=delimiter, float_format=float_format, annotation=annotation)
                x.close()
                file_list.append(file_name)

            # Report on what has been written
            msg = "\nWrote the following variables:" + "\n  " + ("\n  ".join(vars_to_write[0]))
            if DEBUG: log.debug(msg)
            self.output_message.append(msg)
	
            msg = ""
            aux_var_count = vars_to_write[1]
            if len(aux_var_count) > 0:
                msg = "\nWrote the following auxiliary variables:" + "\n  " + ("\n  ".join(aux_var_count))	
	    
            singleton_var_count = vars_to_write[2]
            if len(singleton_var_count) > 0:
                msg = "\nWrote the following Singleton variables:" + "\n  " + ("\n  ".join(singleton_var_count))

            if len(file_list) > 0:
                msg = msg + ("\n\nNASA Ames file(s) written successfully: \n%s" % "\n".join(file_list))

            full_file_counter += len(file_list)
            file_counter += 1

            if DEBUG: log.debug(msg)
            self.output_message.append(msg)
	    
        full_file_count = full_file_counter - 1
        if full_file_count == 1:
            plural = ""
        else:
            plural = "s"	      
        msg = "\n%s file%s written." % (full_file_count, plural)
    
        if DEBUG: log.debug(msg)
        self.output_message.append(msg)
        self.output_files_written = file_list

        return self.output_message

        Writes the self.na_dict_list content to one or more NASA Ames files.
        Output file names are based on the self.nc_file name unless specified
        in the na_file_name argument in which case that provides the main name
        that is appended to if multiple output file names are required.

        TODO: no_header is NOT implemented.
        
Writes the self.na_dict_list content to one or more NASA Ames files.
Output file names are based on the self.nc_file name unless specified
in the na_file_name argument in which case that provides the main name
that is appended to if multiple output file names are required.

no_header is NOT implemented.
Writes the self . na_dict_list content to one or more NASA Ames files . Output file names are based on the self . nc_file name unless specified in the na_file_name argument in which case that provides the main name that is appended to if multiple output file names are required . no_header is NOT implemented .
def writeNAFiles(self, na_file=None, delimiter=default_delimiter, annotation=False,
                     float_format=default_float_format, size_limit=None, no_header=False):
        self.convert() 
        file_names = self.constructNAFileNames(na_file)
        file_counter = 1
        full_file_counter = 1
        file_list = []
        local_attributes = nappy.utils.getLocalAttributesConfigDict()
        local_na_atts = local_attributes["na_attributes"]
        overriders = local_na_atts
        for (okey, ovalue) in self.na_items_to_override.items():
            overriders[okey] = ovalue
        for na_dict_and_var_ids in self.na_dict_list:
            file_name = file_names[file_counter - 1]
            msg = "\nWriting output NASA Ames file: %s" % file_name
            if DEBUG: log.debug(msg)
            self.output_message.append(msg)
            (this_na_dict, vars_to_write) = na_dict_and_var_ids
            for key in overriders.keys():
                if key in permitted_overwrite_metadata:    
                    if key in items_as_lists:
                        new_item = overriders[key].split()		   
                        if key in ("DATE", "RDATE"):
                            new_item = [int(list_item) for list_item in new_item]
                    else:
                        new_item = overriders[key]
                    if key in ("SCOM", "NCOM"):
                        if comment_override_rule == "replace":
                            comments_list = new_item[:]
                        elif comment_override_rule in ("insert", "extend"):
                            new_comments = new_item[:]
                            existing_comments = this_na_dict.get(key, [])
                            comments_list = self._cleanWrapComments(existing_comments, new_comments, key, comment_override_rule)
                        else:
                            raise Exception("Did not recognise comment_override_rule: " + str(comment_override_rule))
                        this_na_dict[key] = comments_list
                        this_na_dict["N%sL" % key] = len(comments_list)
                    elif not this_na_dict.has_key(key) or new_item != this_na_dict[key]:
                        this_na_dict[key] = new_item
                        msg = "Metadata overwritten in output file: '%s' is now '%s'" % (key, this_na_dict[key])
                        if DEBUG: log.debug(msg)
                        self.output_message.append(msg)
            if add_column_headers:
                self._updateWithColumnHeaders(this_na_dict, delimiter)
            if size_limit is not None and (this_na_dict["FFI"] == 1001 and len(this_na_dict["V"][0]) > size_limit):
                files_written = self._writeNAFileSubsetsWithinSizeLimit(this_na_dict, file_name, delimiter=delimiter,
                                                                        float_format=float_format, size_limit=size_limit,
                                                                        annotation=annotation)
                file_list.extend(files_written)
            else:		
                log.info("Output NA file name: %s" % file_name)
                x = nappy.openNAFile(file_name, 'w', this_na_dict)
                x.write(delimiter=delimiter, float_format=float_format, annotation=annotation)
                x.close()
                file_list.append(file_name)
            msg = "\nWrote the following variables:" + "\n  " + ("\n  ".join(vars_to_write[0]))
            if DEBUG: log.debug(msg)
            self.output_message.append(msg)
            msg = ""
            aux_var_count = vars_to_write[1]
            if len(aux_var_count) > 0:
                msg = "\nWrote the following auxiliary variables:" + "\n  " + ("\n  ".join(aux_var_count))	
            singleton_var_count = vars_to_write[2]
            if len(singleton_var_count) > 0:
                msg = "\nWrote the following Singleton variables:" + "\n  " + ("\n  ".join(singleton_var_count))
            if len(file_list) > 0:
                msg = msg + ("\n\nNASA Ames file(s) written successfully: \n%s" % "\n".join(file_list))
            full_file_counter += len(file_list)
            file_counter += 1
            if DEBUG: log.debug(msg)
            self.output_message.append(msg)
        full_file_count = full_file_counter - 1
        if full_file_count == 1:
            plural = ""
        else:
            plural = "s"	      
        msg = "\n%s file%s written." % (full_file_count, plural)
        if DEBUG: log.debug(msg)
        self.output_message.append(msg)
        self.output_files_written = file_list
        return self.output_message
def writeNAFiles ( self , na_file = None , delimiter = default_delimiter , annotation = False , float_format = default_float_format , size_limit = None , no_header = False ) : self . convert ( ) file_names = self . constructNAFileNames ( na_file ) file_counter = 1 full_file_counter = 1 file_list = [ ] local_attributes = nappy . utils . getLocalAttributesConfigDict ( ) local_na_atts = local_attributes [ "na_attributes" ] overriders = local_na_atts for ( okey , ovalue ) in self . na_items_to_override . items ( ) : overriders [ okey ] = ovalue for na_dict_and_var_ids in self . na_dict_list : file_name = file_names [ file_counter - 1 ] msg = "\nWriting output NASA Ames file: %s" % file_name if DEBUG : log . debug ( msg ) self . output_message . append ( msg ) ( this_na_dict , vars_to_write ) = na_dict_and_var_ids for key in overriders . keys ( ) : if key in permitted_overwrite_metadata : if key in items_as_lists : new_item = overriders [ key ] . split ( ) if key in ( "DATE" , "RDATE" ) : new_item = [ int ( list_item ) for list_item in new_item ] else : new_item = overriders [ key ] if key in ( "SCOM" , "NCOM" ) : if comment_override_rule == "replace" : comments_list = new_item [ : ] elif comment_override_rule in ( "insert" , "extend" ) : new_comments = new_item [ : ] existing_comments = this_na_dict . get ( key , [ ] ) comments_list = self . _cleanWrapComments ( existing_comments , new_comments , key , comment_override_rule ) else : raise Exception ( "Did not recognise comment_override_rule: " + str ( comment_override_rule ) ) this_na_dict [ key ] = comments_list this_na_dict [ "N%sL" % key ] = len ( comments_list ) elif not this_na_dict . has_key ( key ) or new_item != this_na_dict [ key ] : this_na_dict [ key ] = new_item msg = "Metadata overwritten in output file: '%s' is now '%s'" % ( key , this_na_dict [ key ] ) if DEBUG : log . debug ( msg ) self . output_message . append ( msg ) if add_column_headers : self . _updateWithColumnHeaders ( this_na_dict , delimiter ) if size_limit is not None and ( this_na_dict [ "FFI" ] == 1001 and len ( this_na_dict [ "V" ] [ 0 ] ) > size_limit ) : files_written = self . _writeNAFileSubsetsWithinSizeLimit ( this_na_dict , file_name , delimiter = delimiter , float_format = float_format , size_limit = size_limit , annotation = annotation ) file_list . extend ( files_written ) else : log . info ( "Output NA file name: %s" % file_name ) x = nappy . openNAFile ( file_name , 'w' , this_na_dict ) x . write ( delimiter = delimiter , float_format = float_format , annotation = annotation ) x . close ( ) file_list . append ( file_name ) msg = "\nWrote the following variables:" + "\n  " + ( "\n  " . join ( vars_to_write [ 0 ] ) ) if DEBUG : log . debug ( msg ) self . output_message . append ( msg ) msg = "" aux_var_count = vars_to_write [ 1 ] if len ( aux_var_count ) > 0 : msg = "\nWrote the following auxiliary variables:" + "\n  " + ( "\n  " . join ( aux_var_count ) ) singleton_var_count = vars_to_write [ 2 ] if len ( singleton_var_count ) > 0 : msg = "\nWrote the following Singleton variables:" + "\n  " + ( "\n  " . join ( singleton_var_count ) ) if len ( file_list ) > 0 : msg = msg + ( "\n\nNASA Ames file(s) written successfully: \n%s" % "\n" . join ( file_list ) ) full_file_counter += len ( file_list ) file_counter += 1 if DEBUG : log . debug ( msg ) self . output_message . append ( msg ) full_file_count = full_file_counter - 1 if full_file_count == 1 : plural = "" else : plural = "s" msg = "\n%s file%s written." % ( full_file_count , plural ) if DEBUG : log . debug ( msg ) self . output_message . append ( msg ) self . output_files_written = file_list return self . output_message
Writes the self.na_dict_list content to one or more NASA Ames files.
Writes the self . na_dict_list content to one or more NASA Ames files .
"""
        Writes the self.na_dict_list content to one or more NASA Ames files.
        Output file names are based on the self.nc_file name unless specified
        in the na_file_name argument in which case that provides the main name
        that is appended to if multiple output file names are required.

        TODO: no_header is NOT implemented.
        """ # just in case not already called
 # Gets a list of NA file_names that will be produced.
 # Set up some counters: file_counter is the expected number of files.
 #      full_file_counter includes any files that have been split across multiple output NA files
 #              because size_limit exceeded.
 # Get any NASA Ames dictionary values that should be overwritten with local values
 # define final override list by using defaults then locally provided changes
 # Now loop through writing the outputs
 # Set up current na dict
 # Override content of NASA Ames if they are permitted
 # Do specific overwrite for comments by inserting lines at start
 # Use rule defined in config file in terms of where to put new comments
 # For certain FFIs create final Normal comments as a list of column headers before data section 
 # Cope with size limits if specified and FFI is 1001
 # Seems to be writing different chunks of a too long array to different na_dicts to then write to separate files.
 # If not having to split file into multiple outputs (normal condition)
 # Report on what has been written

self
na_file
delimiter
annotation
float_format
size_limit
no_header