Changeset 3625 for nappy


Ignore:
Timestamp:
17/03/08 14:20:36 (11 years ago)
Author:
astephen
Message:

Cleaned up some of the data files and improved unit tests and comparison code.

Location:
nappy/trunk
Files:
15 edited
1 moved

Legend:

Unmodified
Added
Removed
  • nappy/trunk/data_files/1001.na

    r339 r3625  
    2727 79210    44    74 10125   
    2828 79220    37   105 10088   
    29  
    30  
    31  
    32  
    33  
    34  
    35  
  • nappy/trunk/data_files/1010.na

    r366 r3625  
    8282           100       3.2E-04          11.9 
    8383           1.9           1.7       3.2E+07          1200 
    84  
  • nappy/trunk/data_files/1010a.na

    r345 r3625  
    8282           100       3.2E-04          11.9 
    8383           1.9           1.7       3.2E+07          1200 
    84  
  • nappy/trunk/nappy/unit_tests/make_na_file_unit_tests.py

    r3353 r3625  
    2020            "2310", "3010", "4010") 
    2121 
    22     template = open("test_na_file_template.txt").read() 
     22    template = open("test_na_file_template.tmpl").read() 
    2323 
    2424    for ffi in ffis: 
  • nappy/trunk/nappy/unit_tests/test_na_file_1001.py

    r3529 r3625  
    2525        self.outfile = os.path.join(base_dir, "test_outputs", "test_1001.na") 
    2626        self.out_csv = os.path.join(base_dir, "test_outputs", "test_1001.csv") 
     27        self.out_csv_annotated = os.path.join(base_dir, "test_outputs", "test_1001_annotated.csv") 
    2728        self.fin = nappy.openNAFile(self.infile) 
    2829        self.fin.readData() 
     
    3940        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4041 
     42    def test_writeCSV1001(self): 
     43        "Tests conversion to CSV." 
     44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
     45        fobj.write(delimiter=",", float_format="%.2d") 
     46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
     47 
    4148    def test_writeAnnotatedCSV1001(self): 
    42         "Tests conversion to NetCDF." 
    43         fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    44         fobj.write(delimiter=",", float_format="%.2d", annotation=True) 
     49        "Tests conversion to Annotated CSV." 
     50        fobj = nappy.openNAFile(self.out_csv_annotated, mode="w", na_dict=self.na_dict) 
     51        fobj.write(delimiter=",", annotation=True) 
    4552        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4653  
    4754    def test_compareFiles1001(self): 
    4855        "Tests comparison of written and original files for equivalence." 
    49         res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile) 
     56        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True) 
    5057        self.assertEqual(res, True) 
    51          
     58        
     59    def test_compareNAToCSV1001(self): 
     60        "Tests comparison of original and CSV version written."  
     61        res = nappy.utils.compare_na.compNAFiles(self.infile, self.out_csv, delimiter_2=",") 
     62        self.assertEqual(res, True) 
     63 
    5264 
    5365if __name__ ==  "__main__": 
  • nappy/trunk/nappy/unit_tests/test_na_file_1010.py

    r3624 r3625  
    2525        self.outfile = os.path.join(base_dir, "test_outputs", "test_1010.na") 
    2626        self.out_csv = os.path.join(base_dir, "test_outputs", "test_1010.csv") 
     27        self.out_csv_annotated = os.path.join(base_dir, "test_outputs", "test_1010_annotated.csv") 
    2728        self.fin = nappy.openNAFile(self.infile) 
    2829        self.fin.readData() 
     
    3940        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4041 
     42    def test_writeCSV1010(self): 
     43        "Tests conversion to CSV." 
     44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
     45        fobj.write(delimiter=",", float_format="%.2d") 
     46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
     47 
    4148    def test_writeAnnotatedCSV1010(self): 
    42         "Tests conversion to NetCDF." 
    43         fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    44         fobj.write(delimiter=",", float_format="%.2d", annotation=True) 
     49        "Tests conversion to Annotated CSV." 
     50        fobj = nappy.openNAFile(self.out_csv_annotated, mode="w", na_dict=self.na_dict) 
     51        fobj.write(delimiter=",", annotation=True) 
    4552        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4653  
     
    4956        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True) 
    5057        self.assertEqual(res, True) 
    51          
     58        
     59    def test_compareNAToCSV1010(self): 
     60        "Tests comparison of original and CSV version written."  
     61        res = nappy.utils.compare_na.compNAFiles(self.infile, self.out_csv, delimiter_2=",") 
     62        self.assertEqual(res, True) 
     63 
    5264 
    5365if __name__ ==  "__main__": 
  • nappy/trunk/nappy/unit_tests/test_na_file_1020.py

    r3529 r3625  
    2525        self.outfile = os.path.join(base_dir, "test_outputs", "test_1020.na") 
    2626        self.out_csv = os.path.join(base_dir, "test_outputs", "test_1020.csv") 
     27        self.out_csv_annotated = os.path.join(base_dir, "test_outputs", "test_1020_annotated.csv") 
    2728        self.fin = nappy.openNAFile(self.infile) 
    2829        self.fin.readData() 
     
    3940        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4041 
     42    def test_writeCSV1020(self): 
     43        "Tests conversion to CSV." 
     44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
     45        fobj.write(delimiter=",", float_format="%.2d") 
     46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
     47 
    4148    def test_writeAnnotatedCSV1020(self): 
    42         "Tests conversion to NetCDF." 
    43         fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    44         fobj.write(delimiter=",", float_format="%.2d", annotation=True) 
     49        "Tests conversion to Annotated CSV." 
     50        fobj = nappy.openNAFile(self.out_csv_annotated, mode="w", na_dict=self.na_dict) 
     51        fobj.write(delimiter=",", annotation=True) 
    4552        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4653  
    4754    def test_compareFiles1020(self): 
    4855        "Tests comparison of written and original files for equivalence." 
    49         res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile) 
     56        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True) 
    5057        self.assertEqual(res, True) 
    51          
     58        
     59    def test_compareNAToCSV1020(self): 
     60        "Tests comparison of original and CSV version written."  
     61        res = nappy.utils.compare_na.compNAFiles(self.infile, self.out_csv, delimiter_2=",") 
     62        self.assertEqual(res, True) 
     63 
    5264 
    5365if __name__ ==  "__main__": 
  • nappy/trunk/nappy/unit_tests/test_na_file_2010.py

    r3529 r3625  
    2525        self.outfile = os.path.join(base_dir, "test_outputs", "test_2010.na") 
    2626        self.out_csv = os.path.join(base_dir, "test_outputs", "test_2010.csv") 
     27        self.out_csv_annotated = os.path.join(base_dir, "test_outputs", "test_2010_annotated.csv") 
    2728        self.fin = nappy.openNAFile(self.infile) 
    2829        self.fin.readData() 
     
    3940        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4041 
     42    def test_writeCSV2010(self): 
     43        "Tests conversion to CSV." 
     44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
     45        fobj.write(delimiter=",", float_format="%.2d") 
     46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
     47 
    4148    def test_writeAnnotatedCSV2010(self): 
    42         "Tests conversion to NetCDF." 
    43         fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    44         fobj.write(delimiter=",", float_format="%.2d", annotation=True) 
     49        "Tests conversion to Annotated CSV." 
     50        fobj = nappy.openNAFile(self.out_csv_annotated, mode="w", na_dict=self.na_dict) 
     51        fobj.write(delimiter=",", annotation=True) 
    4552        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4653  
    4754    def test_compareFiles2010(self): 
    4855        "Tests comparison of written and original files for equivalence." 
    49         res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile) 
     56        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True) 
    5057        self.assertEqual(res, True) 
    51          
     58        
     59    def test_compareNAToCSV2010(self): 
     60        "Tests comparison of original and CSV version written."  
     61        res = nappy.utils.compare_na.compNAFiles(self.infile, self.out_csv, delimiter_2=",") 
     62        self.assertEqual(res, True) 
     63 
    5264 
    5365if __name__ ==  "__main__": 
  • nappy/trunk/nappy/unit_tests/test_na_file_2110.py

    r3529 r3625  
    2525        self.outfile = os.path.join(base_dir, "test_outputs", "test_2110.na") 
    2626        self.out_csv = os.path.join(base_dir, "test_outputs", "test_2110.csv") 
     27        self.out_csv_annotated = os.path.join(base_dir, "test_outputs", "test_2110_annotated.csv") 
    2728        self.fin = nappy.openNAFile(self.infile) 
    2829        self.fin.readData() 
     
    3940        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4041 
     42    def test_writeCSV2110(self): 
     43        "Tests conversion to CSV." 
     44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
     45        fobj.write(delimiter=",", float_format="%.2d") 
     46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
     47 
    4148    def test_writeAnnotatedCSV2110(self): 
    42         "Tests conversion to NetCDF." 
    43         fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    44         fobj.write(delimiter=",", float_format="%.2d", annotation=True) 
     49        "Tests conversion to Annotated CSV." 
     50        fobj = nappy.openNAFile(self.out_csv_annotated, mode="w", na_dict=self.na_dict) 
     51        fobj.write(delimiter=",", annotation=True) 
    4552        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4653  
    4754    def test_compareFiles2110(self): 
    4855        "Tests comparison of written and original files for equivalence." 
    49         res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile) 
     56        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True) 
    5057        self.assertEqual(res, True) 
    51          
     58        
     59    def test_compareNAToCSV2110(self): 
     60        "Tests comparison of original and CSV version written."  
     61        res = nappy.utils.compare_na.compNAFiles(self.infile, self.out_csv, delimiter_2=",") 
     62        self.assertEqual(res, True) 
     63 
    5264 
    5365if __name__ ==  "__main__": 
  • nappy/trunk/nappy/unit_tests/test_na_file_2160.py

    r3624 r3625  
    2525        self.outfile = os.path.join(base_dir, "test_outputs", "test_2160.na") 
    2626        self.out_csv = os.path.join(base_dir, "test_outputs", "test_2160.csv") 
     27        self.out_csv_annotated = os.path.join(base_dir, "test_outputs", "test_2160_annotated.csv") 
    2728        self.fin = nappy.openNAFile(self.infile) 
    2829        self.fin.readData() 
     
    3940        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4041 
     42    def test_writeCSV2160(self): 
     43        "Tests conversion to CSV." 
     44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
     45        fobj.write(delimiter=",", float_format="%.2d") 
     46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
     47 
    4148    def test_writeAnnotatedCSV2160(self): 
    42         "Tests conversion to NetCDF." 
    43         fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    44         fobj.write(delimiter=",", float_format="%.2d", annotation=True) 
     49        "Tests conversion to Annotated CSV." 
     50        fobj = nappy.openNAFile(self.out_csv_annotated, mode="w", na_dict=self.na_dict) 
     51        fobj.write(delimiter=",", annotation=True) 
    4552        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4653  
    4754    def test_compareFiles2160(self): 
    4855        "Tests comparison of written and original files for equivalence." 
    49         print self.infile, self.outfile 
    50         res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile) 
     56        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True) 
    5157        self.assertEqual(res, True) 
    52          
     58        
     59    def test_compareNAToCSV2160(self): 
     60        "Tests comparison of original and CSV version written."  
     61        res = nappy.utils.compare_na.compNAFiles(self.infile, self.out_csv, delimiter_2=",") 
     62        self.assertEqual(res, True) 
     63 
    5364 
    5465if __name__ ==  "__main__": 
  • nappy/trunk/nappy/unit_tests/test_na_file_2310.py

    r3529 r3625  
    2525        self.outfile = os.path.join(base_dir, "test_outputs", "test_2310.na") 
    2626        self.out_csv = os.path.join(base_dir, "test_outputs", "test_2310.csv") 
     27        self.out_csv_annotated = os.path.join(base_dir, "test_outputs", "test_2310_annotated.csv") 
    2728        self.fin = nappy.openNAFile(self.infile) 
    2829        self.fin.readData() 
     
    3940        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4041 
     42    def test_writeCSV2310(self): 
     43        "Tests conversion to CSV." 
     44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
     45        fobj.write(delimiter=",", float_format="%.2d") 
     46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
     47 
    4148    def test_writeAnnotatedCSV2310(self): 
    42         "Tests conversion to NetCDF." 
    43         fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    44         fobj.write(delimiter=",", float_format="%.2d", annotation=True) 
     49        "Tests conversion to Annotated CSV." 
     50        fobj = nappy.openNAFile(self.out_csv_annotated, mode="w", na_dict=self.na_dict) 
     51        fobj.write(delimiter=",", annotation=True) 
    4552        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4653  
    4754    def test_compareFiles2310(self): 
    4855        "Tests comparison of written and original files for equivalence." 
    49         res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile) 
     56        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True) 
    5057        self.assertEqual(res, True) 
    51          
     58        
     59    def test_compareNAToCSV2310(self): 
     60        "Tests comparison of original and CSV version written."  
     61        res = nappy.utils.compare_na.compNAFiles(self.infile, self.out_csv, delimiter_2=",") 
     62        self.assertEqual(res, True) 
     63 
    5264 
    5365if __name__ ==  "__main__": 
  • nappy/trunk/nappy/unit_tests/test_na_file_3010.py

    r3529 r3625  
    2525        self.outfile = os.path.join(base_dir, "test_outputs", "test_3010.na") 
    2626        self.out_csv = os.path.join(base_dir, "test_outputs", "test_3010.csv") 
     27        self.out_csv_annotated = os.path.join(base_dir, "test_outputs", "test_3010_annotated.csv") 
    2728        self.fin = nappy.openNAFile(self.infile) 
    2829        self.fin.readData() 
     
    3940        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4041 
     42    def test_writeCSV3010(self): 
     43        "Tests conversion to CSV." 
     44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
     45        fobj.write(delimiter=",", float_format="%.2d") 
     46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
     47 
    4148    def test_writeAnnotatedCSV3010(self): 
    42         "Tests conversion to NetCDF." 
    43         fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    44         fobj.write(delimiter=",", float_format="%.2d", annotation=True) 
     49        "Tests conversion to Annotated CSV." 
     50        fobj = nappy.openNAFile(self.out_csv_annotated, mode="w", na_dict=self.na_dict) 
     51        fobj.write(delimiter=",", annotation=True) 
    4552        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4653  
    4754    def test_compareFiles3010(self): 
    4855        "Tests comparison of written and original files for equivalence." 
    49         res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile) 
     56        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True) 
    5057        self.assertEqual(res, True) 
    51          
     58        
     59    def test_compareNAToCSV3010(self): 
     60        "Tests comparison of original and CSV version written."  
     61        res = nappy.utils.compare_na.compNAFiles(self.infile, self.out_csv, delimiter_2=",") 
     62        self.assertEqual(res, True) 
     63 
    5264 
    5365if __name__ ==  "__main__": 
  • nappy/trunk/nappy/unit_tests/test_na_file_4010.py

    r3529 r3625  
    2525        self.outfile = os.path.join(base_dir, "test_outputs", "test_4010.na") 
    2626        self.out_csv = os.path.join(base_dir, "test_outputs", "test_4010.csv") 
     27        self.out_csv_annotated = os.path.join(base_dir, "test_outputs", "test_4010_annotated.csv") 
    2728        self.fin = nappy.openNAFile(self.infile) 
    2829        self.fin.readData() 
     
    3940        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4041 
     42    def test_writeCSV4010(self): 
     43        "Tests conversion to CSV." 
     44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
     45        fobj.write(delimiter=",", float_format="%.2d") 
     46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
     47 
    4148    def test_writeAnnotatedCSV4010(self): 
    42         "Tests conversion to NetCDF." 
    43         fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    44         fobj.write(delimiter=",", float_format="%.2d", annotation=True) 
     49        "Tests conversion to Annotated CSV." 
     50        fobj = nappy.openNAFile(self.out_csv_annotated, mode="w", na_dict=self.na_dict) 
     51        fobj.write(delimiter=",", annotation=True) 
    4552        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4653  
    4754    def test_compareFiles4010(self): 
    4855        "Tests comparison of written and original files for equivalence." 
    49         res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile) 
     56        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True) 
    5057        self.assertEqual(res, True) 
    51          
     58        
     59    def test_compareNAToCSV4010(self): 
     60        "Tests comparison of original and CSV version written."  
     61        res = nappy.utils.compare_na.compNAFiles(self.infile, self.out_csv, delimiter_2=",") 
     62        self.assertEqual(res, True) 
     63 
    5264 
    5365if __name__ ==  "__main__": 
  • nappy/trunk/nappy/unit_tests/test_na_file_template.tmpl

    r3529 r3625  
    2525        self.outfile = os.path.join(base_dir, "test_outputs", "test_<FFI>.na") 
    2626        self.out_csv = os.path.join(base_dir, "test_outputs", "test_<FFI>.csv") 
     27        self.out_csv_annotated = os.path.join(base_dir, "test_outputs", "test_<FFI>_annotated.csv") 
    2728        self.fin = nappy.openNAFile(self.infile) 
    2829        self.fin.readData() 
     
    3940        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4041 
     42    def test_writeCSV<FFI>(self): 
     43        "Tests conversion to CSV." 
     44        fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
     45        fobj.write(delimiter=",", float_format="%.2f") 
     46        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
     47 
    4148    def test_writeAnnotatedCSV<FFI>(self): 
    42         "Tests conversion to NetCDF." 
    43         fobj = nappy.openNAFile(self.out_csv, mode="w", na_dict=self.na_dict) 
    44         fobj.write(delimiter=",", float_format="%.2d", annotation=True) 
     49        "Tests conversion to Annotated CSV." 
     50        fobj = nappy.openNAFile(self.out_csv_annotated, mode="w", na_dict=self.na_dict) 
     51        fobj.write(delimiter=",", annotation=True) 
    4552        self.failUnless(isinstance(fobj, nappy.na_file.na_file.NAFile)) 
    4653  
    4754    def test_compareFiles<FFI>(self): 
    4855        "Tests comparison of written and original files for equivalence." 
    49         res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile) 
     56        res = nappy.utils.compare_na.compNAFiles(self.infile, self.outfile, approx_equal=True) 
    5057        self.assertEqual(res, True) 
    51          
     58        
     59    def test_compareNAToCSV<FFI>(self): 
     60        "Tests comparison of original and CSV version written."  
     61        res = nappy.utils.compare_na.compNAFiles(self.infile, self.out_csv, delimiter_2=",") 
     62        self.assertEqual(res, True) 
     63 
    5264 
    5365if __name__ ==  "__main__": 
  • nappy/trunk/nappy/utils/common_utils.py

    r3619 r3625  
    1212 
    1313# Imports from local package 
    14 import nappy.utils.parse_config 
     14import parse_config 
     15 
    1516 
    1617def getNAFileClass(ffi): 
     
    117118    Gets config dict for version. 
    118119    """ 
    119     version = nappy.utils.parse_config.getConfigDict()["main"]["version"] 
     120    version = parse_config.getConfigDict()["main"]["version"] 
    120121    return version 
    121122 
     
    125126    Returns true or false for DEBUG status. 
    126127    """ 
    127     DEBUG = nappy.utils.parse_config.getConfigDict()["main"]["DEBUG"] 
     128    DEBUG = parse_config.getConfigDict()["main"]["DEBUG"] 
    128129    return eval(DEBUG) 
    129130 
     
    149150    """ 
    150151     
    151     dict = nappy.utils.parse_config.getAnnotationsConfigDict() 
     152    dict = parse_config.getAnnotationsConfigDict() 
    152153    if annotation: return dict[item] + delimiter 
    153154    else: return '' 
  • nappy/trunk/nappy/utils/compare_na.py

    r3601 r3625  
    1212 
    1313    compare_na.py [-h | --header-only]  [-b | --body-only] 
    14                   [-n | --number-strict]  
     14                  [-n | --number-strict] [-a | --approx-equal]  
    1515                  [-1 <delimiter_1> | --delimiter-1=<delimiter_1>] 
    1616                  [-2 <delimiter_2> | --delimiter-2=<delimiter_2>] 
     
    2626    -n | --number-strict        compares exact formatting of numbers in data block 
    2727                                (default is to compare them by value). 
     28    -a | --approx-equal         considers any two numbers being compared the same as long 
     29                                as the difference between them is less than 1%. 
    2830    <delimiter_1>               delimiter to use for file 1. 
    2931    <delimiter_2>               delimiter to use for file 2.  
     
    4042from compare import * 
    4143 
     44equality_threshold = 0.01 # i.e. within 1% of each other 
    4245file_exclusion_patterns = (".*CSV.*", ".*svn.*", "\..*", ".*\.pyc$", ".*~$")  
    4346file_exclusions = [re.compile(pattn) for pattn in file_exclusion_patterns] 
     
    6770 
    6871 
    69 def compareSections(l1, l2, number_clever=True, delimiter_1=None, delimiter_2=None): 
     72def compareSections(l1, l2, number_clever=True, approx_equal=False,  
     73                   delimiter_1=None, delimiter_2=None): 
    7074    """ 
    7175    Compares sections of NASA Ames files (i.e. headers and bodies). 
     
    8387        same = True 
    8488        if len(items1) != len(items2): 
    85             same = False 
     89            # Check that space delimiter hasn't just split identical lines to different lengths 
     90            if len(items1) == 1 and items1[0].split() == items2: 
     91                continue 
     92            elif len(items2) == 1 and items2[0].split() == items1: 
     93                continue 
     94            else: 
     95                same = False 
    8696        else:  
    8797            if number_clever == False: 
     
    96106                        a = items1[count] 
    97107                        b = items2[count] 
     108 
    98109                    if a != b: 
    99                         same = False 
    100                         break  
     110                         
     111                        if approx_equal: 
     112                        # Check to see if testing for approximate equality 
     113                            if a == 0:  a = 0.000000001 
     114                            if b == 0:  b = 0.000000001 
     115                            divided = a/b 
     116                            if divided < 1: 
     117                                divided = b/a 
     118                            if (1 - divided) > equality_threshold: 
     119                                same = False 
     120                                break   
     121                        else:  
     122                            same = False 
     123                            break  
    101124               
    102125        if same == False: 
     
    109132 
    110133 
    111 def compNAFiles(f1, f2, header=True, body=True, number_clever=True, delimiter_1=None, 
    112                 delimiter_2=None): 
     134def compNAFiles(f1, f2, header=True, body=True, number_clever=True, approx_equal=False, 
     135                delimiter_1=None, delimiter_2=None): 
    113136    """ 
    114137    Compares contents of two NASA Ames files f1 and f2. 
    115138    header=False or body=False will not compare these sections of the files. 
    116139    number_clever=True will compare 5.00000 and 5 making them equal in the body. 
     140    If approx_equal is True then approximate equality is good enough to return two 
     141    numbers as being equal (within equality_threshold set at top of this module). 
    117142    If f1_delimiter and f2_delimiter are provided then the comparer will consider 
    118143    two lines identical if they have the delimiters sent in as arguments. 
     
    134159    l1 = open(f1).readlines() 
    135160    l2 = open(f2).readlines() 
    136  
    137161    head_len1 = int(l1[0].split(delimiter_1)[0]) 
    138162    head_len2 = int(l2[0].split(delimiter_2)[0]) 
     
    148172        print ">>> %s header:" % f1 
    149173        print "<<< %s header:" % f2 
    150         same = compareSections(header1, header2, number_clever, delimiter_1, delimiter_2)  
     174        same = compareSections(header1, header2, number_clever, approx_equal, delimiter_1, delimiter_2)  
    151175        if same == True: 
    152176            print "HEADERS ARE IDENTICAL." 
     
    158182        print ">>> %s body:" % f1 
    159183        print "<<< %s body:" % f2 
    160         same = compareSections(body1, body2, number_clever, delimiter_1, delimiter_2) 
     184        same = compareSections(body1, body2, number_clever, approx_equal, delimiter_1, delimiter_2) 
    161185        if same == True: 
    162186            print "BODIES ARE IDENTICAL." 
     
    176200    a["body"] = True 
    177201    a["number_clever"] = True 
     202    a["approx_equal"] = False 
    178203    a["delimiter_1"] = None 
    179204    a["delimiter_2"] = None 
    180205 
    181     (arg_list, files) = getopt.getopt(args, "hbn1:2:", ["header-only", "body-only", 
    182                          "number-strict", "delimiter-1=", "delimiter-2="]) 
     206    (arg_list, files) = getopt.getopt(args, "hbna1:2:", ["header-only", "body-only", 
     207                    "number-strict", "approx-equal", "delimiter-1=", "delimiter-2="]) 
    183208 
    184209    for arg, value in arg_list: 
     
    189214        elif arg in ("--number-strict", "-n"): 
    190215            a["number_clever"] = False 
     216        elif arg in ("--approx-equal", "-a"): 
     217            a["approx_equal"] = True 
    191218        elif arg in ("--delimiter-1", "-1"): 
    192219            a["delimiter_1"] = value 
Note: See TracChangeset for help on using the changeset viewer.