Changeset 3383 for nappy


Ignore:
Timestamp:
12/02/08 11:53:25 (11 years ago)
Author:
astephen
Message:

Changed spacer to delimiter.

Location:
nappy/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/2008 refactoring notes.txt

    r3380 r3383  
    2020 * Create unit tests for all the main read, write and convert functions that fully test the outputs are correct etc. 
    2121 * Create enough error checking during file reading to allow NAppy to be used as a format-conformance checker. 
    22  * Allow writing of CSV files - i.e. replacing the existing (space or tab) spacer with commas. 
     22 * Allow writing of CSV files - i.e. replacing the existing (space or tab) delimiter with commas. 
    2323 * Allow writing of an ''annotated'' format which includes an additional column on the left-hand edge of the file that explains, in human-readable terms, what that line contains. 
    2424 * Development of a nappy ''egg'' to allow easy installation (would be dependent on cdat_lite (another egg)). 
     
    114114We need to allow file-writing to CSV format, as follows: 
    115115 
    116  * rename "spacer" argument to "delimiter" throughout code. 
     116 * rename "delimiter" argument to "delimiter" throughout code. 
    117117 * needs to be implemented in both header and body for consistency. 
    118118 * BUT, it would be nice to have a writeCSV() method as well: 
  • nappy/trunk/bin/nc2na.py

    r3349 r3383  
    1515 
    1616    nc2na [-v <var_list>] [-r <rulename>[,<ruletype>[,<ra1>[,<ra2>[,<ra3>]]]]]] [-j] [-f <float_format>]  
    17               [-s <spacer>] [-d <DATE>] [-l <limitFFI1001Rows>]  
     17              [-s <delimiter>] [-d <DATE>] [-l <limitFFI1001Rows>]  
    1818              [-e <ex_var_list>] [<overwrite_global_metadata>] -i <infilename> -o <outfilename> 
    1919 
     
    3333    -s          - resample data to per-second for aircraft data.      
    3434    floatformat - a python formatting string such as %s or %5.2f 
    35     spacer      - the spacer you wish to use between data items in the output file such as "   " or "\t" 
     35    delimiter   - the delimiter you wish to use between data items in the output file such as "   " or "\t" 
    3636    DATE    - to replace first valid Date of data ("DATE") in the file.  
    3737    overwrite_global_metadata           -  one of "DATE", "RDATE", "ANAME", "MNAME", 
     
    6060    nFilesOnly="no" 
    6161    rule=None 
    62     spacer="    " 
     62    delimiter="    " 
    6363    sizeLimit=None 
    6464    float_format="%8.3f"         
     
    7777            rule=args[args.index(arg)+1].split(",") 
    7878        elif arg=="-s": 
    79             spacer=args[args.index(arg)+1]           
     79            delimiter=args[args.index(arg)+1]        
    8080        elif arg=="-d": 
    8181            naVars["DATE"]=args[args.index(arg)+1]           
     
    8787            variables=args[args.index(arg)+1].split(",") 
    8888 
    89     rtvalue=cdms2na(infile, outfile, naVars, variables, nFilesOnly, sizeLimit=sizeLimit, rule=rule, spacer=spacer,  
     89    rtvalue=cdms2na(infile, outfile, naVars, variables, nFilesOnly, sizeLimit=sizeLimit, rule=rule, delimiter=delimiter,  
    9090float_format=float_format)  
    9191    if nFilesOnly=="yes": 
  • nappy/trunk/doc/USAGE.txt

    r366 r3383  
    6868>>> dir(myfile) 
    6969 
    70 ['A', 'AMISS', 'ANAME', 'ASCAL', 'DATE', 'DX', 'FFI', 'IVOL', 'LENA', 'LENX', 'MNAME', 'NAUXC', 'NAUXV', 'NCOM', 'NIV', 'NLHEAD', 'NNCOML', 'NSCOML', 'NV', 'NVOL', 'NVPM', 'NX', 'NXDEF', 'ONAME', 'ORG', 'RDATE', 'SCOM', 'SNAME', 'V', 'VMISS', 'VNAME', 'VSCAL', 'X', 'XNAME', '__doc__', '__getitem__', '__init__', '__module__', '_checkForBlankLines', '_normalizeIndVars', '_normalizedX', '_open', '_parseDictionary', '_readAuxVariablesHeaderSection', '_readCharAuxVariablesHeaderSection', '_readComments', '_readCommonHeader', '_readData1', '_readData2', '_readLines', '_readNormalComments', '_readSpecialComments', '_readTopLine', '_readVariablesHeaderSection', '_setupArrays', '_writeAuxVariablesHeaderSection', '_writeComments', '_writeCommonHeader', '_writeVariablesHeaderSection', 'auxToCdmsVariable', 'close', 'createCdmsAuxVariables', 'createCdmsAxes', 'createCdmsVariables', 'file', 'filename', 'floatFormat', 'getAuxMissingValue', 'getAuxScaleFactor', 'getAuxVariable', 'getAuxVariables', 'getFFI', 'getFileDates', 'getIndependentVariable', 'getIndependentVariables', 'getMissingValue', 'getMission', 'getNADict', 'getNormalComments', 'getNumHeaderLines', 'getOrg', 'getOrganisation', 'getOriginator', 'getScaleFactor', 'getSource', 'getSpecialComments', 'getVariable', 'getVariables', 'getVolumes', 'naDict', 'pattnBrackets', 'readData', 'readHeader', 'spacer', 'toCdmsAxis', 'toCdmsFile', 'toCdmsVariable', 'writeData', 'writeHeader'] 
     70['A', 'AMISS', 'ANAME', 'ASCAL', 'DATE', 'DX', 'FFI', 'IVOL', 'LENA', 'LENX', 'MNAME', 'NAUXC', 'NAUXV', 'NCOM', 'NIV', 'NLHEAD', 'NNCOML', 'NSCOML', 'NV', 'NVOL', 'NVPM', 'NX', 'NXDEF', 'ONAME', 'ORG', 'RDATE', 'SCOM', 'SNAME', 'V', 'VMISS', 'VNAME', 'VSCAL', 'X', 'XNAME', '__doc__', '__getitem__', '__init__', '__module__', '_checkForBlankLines', '_normalizeIndVars', '_normalizedX', '_open', '_parseDictionary', '_readAuxVariablesHeaderSection', '_readCharAuxVariablesHeaderSection', '_readComments', '_readCommonHeader', '_readData1', '_readData2', '_readLines', '_readNormalComments', '_readSpecialComments', '_readTopLine', '_readVariablesHeaderSection', '_setupArrays', '_writeAuxVariablesHeaderSection', '_writeComments', '_writeCommonHeader', '_writeVariablesHeaderSection', 'auxToCdmsVariable', 'close', 'createCdmsAuxVariables', 'createCdmsAxes', 'createCdmsVariables', 'file', 'filename', 'floatFormat', 'getAuxMissingValue', 'getAuxScaleFactor', 'getAuxVariable', 'getAuxVariables', 'getFFI', 'getFileDates', 'getIndependentVariable', 'getIndependentVariables', 'getMissingValue', 'getMission', 'getNADict', 'getNormalComments', 'getNumHeaderLines', 'getOrg', 'getOrganisation', 'getOriginator', 'getScaleFactor', 'getSource', 'getSpecialComments', 'getVariable', 'getVariables', 'getVolumes', 'naDict', 'pattnBrackets', 'readData', 'readHeader', 'delimiter', 'toCdmsAxis', 'toCdmsFile', 'toCdmsVariable', 'writeData', 'writeHeader'] 
    7171 
    7272List the variables: 
  • nappy/trunk/nappy/contrib/aircraft/old_na_to_nc_with_aircraft.py

    r3349 r3383  
    4949 
    5050def cdms2na(ncfile, na_file_names, naVars={}, variables=None, nFilesOnly="no",  
    51             rule=None, ffi="automatic", spacer="    ", float_format="%g",  
     51            rule=None, ffi="automatic", delimiter="    ", float_format="%g",  
    5252            rules=None, sizeLimit=None): 
    5353    """ 
     
    210210                newnamePlusLetter="%s-%.3d.na" % (newname[:-3], ivol) 
    211211                fileList.append(newnamePlusLetter) 
    212                 general.openNAFile(newnamePlusLetter, 'w', NADictCopy, spacer=spacer, float_format=float_format) 
     212                general.openNAFile(newnamePlusLetter, 'w', NADictCopy, delimiter=delimiter, float_format=float_format) 
    213213                msg="\nOutput files split on size limit: %s\nFilename used: %s" % (sizeLimit, newnamePlusLetter) 
    214214                print msg 
     
    219219 
    220220        else:            
    221             general.openNAFile(newname, 'w', builtNADict, spacer=spacer, float_format=float_format) 
     221            general.openNAFile(newname, 'w', builtNADict, delimiter=delimiter, float_format=float_format) 
    222222 
    223223        msg="\nWrote the following variables:"+"\n\t"+("\n\t".join(i[1][0])) 
  • nappy/trunk/nappy/na_file/na_file.py

    r3349 r3383  
    4141    """ 
    4242 
    43     def __init__(self, filename, mode="r", na_dict={}, spacer="    ", float_format="%8.3f"): 
     43    def __init__(self, filename, mode="r", na_dict={}, delimiter="    ", float_format="%8.3f"): 
    4444        """ 
    4545        Initialization of class, decides if user wishes to read or write 
     
    5050        self.filename = filename 
    5151        self._open(mode) 
    52         self.spacer = spacer 
     52        self.delimiter = delimiter 
    5353        self.float_format = float_format 
    5454 
  • nappy/trunk/nappy/na_file/na_file_2010.py

    r3357 r3383  
    6464 
    6565        for i in range(self.NIV - 1): 
    66             X_lines.append(((self.float_format + self.spacer) * self.NXDEF[i] + "\n") % tuple(self.X[i + 1][0:self.NXDEF[i]])) 
     66            X_lines.append(((self.float_format + self.delimiter) * self.NXDEF[i] + "\n") % tuple(self.X[i + 1][0:self.NXDEF[i]])) 
    6767 
    6868        X_lines.reverse() 
     
    129129        for m in range(len(self.X[0])): 
    130130            # Write Independent variable mark and auxiliary variables 
    131             var_string = (self.float_format + self.spacer) % self.X[0][m] 
     131            var_string = (self.float_format + self.delimiter) % self.X[0][m] 
    132132            for a in range(self.NAUXV): 
    133                 var_string = var_string + ((self.float_format + self.spacer) % self.A[a][m]) 
     133                var_string = var_string + ((self.float_format + self.delimiter) % self.A[a][m]) 
    134134            self.file.write("%s\n" % var_string.rstrip()) 
    135135            # Write Variables 
    136136            for n in range(self.NV): 
    137                 outlines = nappy.utils.list_manipulator.recursiveListWriter(self.V[n][m], self.NX, spacer = self.spacer, float_format = self.float_format) 
     137                outlines = nappy.utils.list_manipulator.recursiveListWriter(self.V[n][m], self.NX, delimiter = self.delimiter, float_format = self.float_format) 
    138138                for line in outlines: 
    139139                    self.file.write(line) 
  • nappy/trunk/nappy/nappy_api.py

    r3356 r3383  
    1414from nappy.utils.common_utils import * 
    1515 
    16 def openNAFile(filename, mode="r", na_dict=None, spacer="    ", float_format="%8.3f"): 
     16def openNAFile(filename, mode="r", na_dict=None, delimiter="    ", float_format="%8.3f"): 
    1717    """ 
    1818    Function wrapper around the NASA Ames File classes. Any NASA Ames 
     
    3131            na_dict['FFI'] = ffi 
    3232            print "\nFormat identified as:", ffi     
    33         return apply(getNAFileClass(ffi), (filename,), {"mode":mode, "na_dict":na_dict, "spacer":spacer, "float_format":float_format}) 
     33        return apply(getNAFileClass(ffi), (filename,), {"mode":mode, "na_dict":na_dict, "delimiter":delimiter, "float_format":float_format}) 
    3434    else: 
    3535        raise Exception("File mode not recognised '" + mode + "'.") 
  • nappy/trunk/nappy/nc_interface/cdms_to_na.py

    r3351 r3383  
    4848 
    4949    def __init__(self, nc_file, na_file_names=None, na_vars={}, variables=None,  
    50             only_return_file_names="no", spacer="    ", float_format="%g",  
     50            only_return_file_names="no", delimiter="    ", float_format="%g",  
    5151            size_limit=None): 
    5252 
     
    228228                new_namePlusLetter = "%s-%.3d.na" % (new_name[:-3], ivol) 
    229229                fileList.append(new_namePlusLetter) 
    230                 general.openNAFile(new_namePlusLetter, 'w', NADictCopy, spacer=spacer, float_format=float_format) 
     230                general.openNAFile(new_namePlusLetter, 'w', NADictCopy, delimiter=delimiter, float_format=float_format) 
    231231                msg = "\nOutput files split on size limit: %s\nFilename used: %s" % (size_limit, new_namePlusLetter) 
    232232                print msg 
     
    237237 
    238238        else:            
    239             general.openNAFile(new_name, 'w', builtNADict, spacer=spacer, float_format=float_format) 
     239            general.openNAFile(new_name, 'w', builtNADict, delimiter=delimiter, float_format=float_format) 
    240240 
    241241        msg = "\nWrote the following variables:" + "\n\t" + ("\n\t".join(i[1][0])) 
  • nappy/trunk/nappy/utils/list_manipulator.py

    r3349 r3383  
    4545 
    4646 
    47 def recursiveListWriter(inlist, dimlist, spacer="    ", float_format="%8.3f"): 
     47def recursiveListWriter(inlist, dimlist, delimiter="    ", float_format="%8.3f"): 
    4848    "Function wrapper around class method RecursiveListManipulator().writeLines()." 
    49     return RecursiveListManipulator().writeLines(inlist, dimlist, spacer=spacer, float_format=float_format) 
     49    return RecursiveListManipulator().writeLines(inlist, dimlist, delimiter=delimiter, float_format=float_format) 
    5050 
    5151 
     
    7777        return inlist 
    7878 
    79     def writeLines(self, inlist, dimlist, spacer="    ", float_format="%8.3f"): 
     79    def writeLines(self, inlist, dimlist, delimiter="    ", float_format="%8.3f"): 
    8080        """ 
    8181        Method to walk through all the levels of the multi-level list object 
     
    8787        if len(dimlist[1:]) > 0: 
    8888            for i in range(dimlist[0]): 
    89                 self.writeLines(inlist[i], dimlist[1:], spacer=spacer, float_format=float_format) 
     89                self.writeLines(inlist[i], dimlist[1:], delimiter=delimiter, float_format=float_format) 
    9090        else: 
    9191            var_string = "" 
    9292            for i in range(dimlist[0]): 
    93                 var_string = var_string + ((float_format+spacer) % inlist[i]) 
     93                var_string = var_string + ((float_format+delimiter) % inlist[i]) 
    9494            self.rtlines.append("%s\n" % var_string.rstrip()) 
    9595        return self.rtlines 
Note: See TracChangeset for help on using the changeset viewer.