Changeset 3628 for nappy


Ignore:
Timestamp:
17/03/08 15:02:08 (11 years ago)
Author:
astephen
Message:

Fixing defaults for delimiter and float format throughout.

Location:
nappy/trunk/nappy
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/nappy/na_file/na_file.py

    r3618 r3628  
    2525import nappy.utils.common_utils 
    2626import nappy.na_error 
     27 
     28default_delimiter = nappy.utils.getDefault("default_delimiter") 
     29default_float_format = nappy.utils.getDefault("default_float_format") 
    2730getAnnotation = nappy.utils.common_utils.getAnnotation 
    2831wrapLine = nappy.utils.common_utils.annotateLine 
    2932wrapLines = nappy.utils.common_utils.annotateLines 
     33 
    3034 
    3135class NAFile(nappy.na_file.na_core.NACore): 
     
    7680        self.is_open = True 
    7781 
    78     def write(self, delimiter="    ", float_format="%8.3f", annotation=False, no_header=False): 
     82    def write(self, delimiter=default_delimiter, float_format=default_float_format, 
     83              annotation=False, no_header=False): 
    7984        """ 
    8085        Writes an na_dict to the file and then flushes it to ensure data not  
  • nappy/trunk/nappy/nappy_api.py

    r3619 r3628  
    227227def convertNCToNA(nc_file, na_file=None, var_ids=None, na_items_to_override={}, 
    228228            only_return_file_names=False, exclude_vars=[], 
    229             requested_ffi=None, delimiter="    ", float_format="%g",  
     229            requested_ffi=None, delimiter=default_delimiter, float_format=default_float_format,  
    230230            size_limit=None, annotation=False, no_header=False): 
    231231    """ 
     
    292292 
    293293def convertCDMSObjectsToNA(cdms_vars, global_atts_dict, na_file,  
    294               na_items_to_override={}, requested_ffi=None, delimiter="    ",  
    295               float_format="%g", size_limit=None, annotation=False, no_header=False): 
     294              na_items_to_override={}, requested_ffi=None, delimiter=default_delimiter,  
     295              float_format=default_float_format, size_limit=None, annotation=False, no_header=False): 
    296296    """ 
    297297    Takes a list of cdms variables and a global attributes dictionary and 
  • nappy/trunk/nappy/unit_tests/test_na_file_1001.py

    r3625 r3628  
    4343        "Tests conversion to CSV." 
    4444        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    45         fobj.write(delimiter=",", float_format="%.2d") 
     45        fobj.write(delimiter=",", float_format="%.6f") 
    4646        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4747 
  • nappy/trunk/nappy/unit_tests/test_na_file_1010.py

    r3625 r3628  
    4343        "Tests conversion to CSV." 
    4444        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    45         fobj.write(delimiter=",", float_format="%.2d") 
     45        fobj.write(delimiter=",", float_format="%.6f") 
    4646        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4747 
  • nappy/trunk/nappy/unit_tests/test_na_file_1020.py

    r3625 r3628  
    4343        "Tests conversion to CSV." 
    4444        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    45         fobj.write(delimiter=",", float_format="%.2d") 
     45        fobj.write(delimiter=",", float_format="%.6f") 
    4646        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4747 
  • nappy/trunk/nappy/unit_tests/test_na_file_2010.py

    r3625 r3628  
    4343        "Tests conversion to CSV." 
    4444        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    45         fobj.write(delimiter=",", float_format="%.2d") 
     45        fobj.write(delimiter=",", float_format="%.6f") 
    4646        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4747 
  • nappy/trunk/nappy/unit_tests/test_na_file_2110.py

    r3625 r3628  
    4343        "Tests conversion to CSV." 
    4444        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    45         fobj.write(delimiter=",", float_format="%.2d") 
     45        fobj.write(delimiter=",", float_format="%.6f") 
    4646        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4747 
  • nappy/trunk/nappy/unit_tests/test_na_file_2160.py

    r3625 r3628  
    4343        "Tests conversion to CSV." 
    4444        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    45         fobj.write(delimiter=",", float_format="%.2d") 
     45        fobj.write(delimiter=",", float_format="%.6f") 
    4646        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4747 
  • nappy/trunk/nappy/unit_tests/test_na_file_2310.py

    r3625 r3628  
    4343        "Tests conversion to CSV." 
    4444        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    45         fobj.write(delimiter=",", float_format="%.2d") 
     45        fobj.write(delimiter=",", float_format="%.6f") 
    4646        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4747 
  • nappy/trunk/nappy/unit_tests/test_na_file_3010.py

    r3625 r3628  
    4343        "Tests conversion to CSV." 
    4444        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    45         fobj.write(delimiter=",", float_format="%.2d") 
     45        fobj.write(delimiter=",", float_format="%.6f") 
    4646        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4747 
  • nappy/trunk/nappy/unit_tests/test_na_file_4010.py

    r3625 r3628  
    4343        "Tests conversion to CSV." 
    4444        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    45         fobj.write(delimiter=",", float_format="%.2d") 
     45        fobj.write(delimiter=",", float_format="%.6f") 
    4646        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4747 
  • nappy/trunk/nappy/unit_tests/test_na_file_template.tmpl

    r3625 r3628  
    4343        "Tests conversion to CSV." 
    4444        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    45         fobj.write(delimiter=",", float_format="%.2f") 
     45        fobj.write(delimiter=",", float_format="%.6f") 
    4646        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4747 
  • nappy/trunk/nappy/utils/common_utils.py

    r3625 r3628  
    9292    return base_name + "." + format 
    9393 
    94      
    9594 
    9695def modifyNADictCopy(indict, v_new, start, end, ivol, nvol): 
     
    128127    DEBUG = parse_config.getConfigDict()["main"]["DEBUG"] 
    129128    return eval(DEBUG) 
     129 
     130 
     131def getDefault(item): 
     132    """ 
     133    Returns value of item from 'mrain' config file section. 
     134    """ 
     135    value =  parse_config.getConfigDict()["main"][item] 
     136    return value 
    130137 
    131138 
  • nappy/trunk/nappy/utils/compare_na.py

    r3625 r3628  
    4545file_exclusion_patterns = (".*CSV.*", ".*svn.*", "\..*", ".*\.pyc$", ".*~$")  
    4646file_exclusions = [re.compile(pattn) for pattn in file_exclusion_patterns] 
     47letter_match = re.compile("[a-zA-Z]") 
    4748 
    4849 
     
    8283 
    8384    for i in range(leng): 
     85 
     86        # Start by setting same equal to True and then try and disprove this 
     87        same = True 
     88 
     89        l1[i] = l1[i].strip() 
     90        l2[i] = l2[i].strip() 
     91 
     92        # If letters found in line then not going to be numeric  
     93        # Hence we can just test if lines are identical 
     94        if letter_match.search(l1[i]): 
     95            if l1[i] == l2[i]: 
     96                continue 
     97 
    8498        items1 = l1[i].split(delimiter_1) 
    8599        items2 = l2[i].split(delimiter_2) 
    86100         
    87         same = True 
    88101        if len(items1) != len(items2): 
    89102            # Check that space delimiter hasn't just split identical lines to different lengths 
  • nappy/trunk/nappy/utils/list_manipulator.py

    r3437 r3628  
    1313 
    1414""" 
     15 
     16# Import local modules 
     17import nappy.utils 
     18 
     19# Define module variables 
     20default_delimiter = nappy.utils.getDefault("default_delimiter") 
     21default_float_format = nappy.utils.getDefault("default_float_format") 
     22 
    1523 
    1624def arrayToList(array, inlist): 
     
    4553 
    4654 
    47 def recursiveListWriter(inlist, dimlist, delimiter="    ", float_format="%8.3f"): 
     55def recursiveListWriter(inlist, dimlist, delimiter=default_delimiter, float_format=default_float_format): 
    4856    "Function wrapper around class method RecursiveListManipulator().writeLines()." 
    4957    return RecursiveListManipulator().writeLines(inlist, dimlist, delimiter=delimiter, float_format=float_format) 
     
    7785        return inlist 
    7886 
    79     def writeLines(self, inlist, dimlist, delimiter="    ", float_format="%8.3f"): 
     87    def writeLines(self, inlist, dimlist, delimiter=default_delimiter, float_format=default_float_format): 
    8088        """ 
    8189        Method to walk through all the levels of the multi-level list object 
  • nappy/trunk/nappy/utils/parse_config.py

    r3526 r3628  
    3535        for item in conf.options(section): 
    3636            value = conf.get(section, item) 
     37            if value.find("__space__") > -1: 
     38                value = value.replace("__space__", " ") 
     39 
    3740            if item.find("&") > -1: 
    3841                item = tuple(item.split("&")) 
     
    5154    return config_dict 
    5255 
     56 
    5357def makeAnnotationsConfigDict(af): 
    5458    """ 
     
    6670    return ad 
    6771 
     72 
    6873def getAnnotationsConfigDict(): 
    6974    "Checks if already made and only makes if required." 
Note: See TracChangeset for help on using the changeset viewer.