Ejemplo n.º 1
0
    def compare_reference(cls,
                          variable='dis',
                          check='map',
                          step_length='86400'):
        """
        :param variable: variable to check. Default 'dis' (Discharge)
        :param check: either 'map' or 'tss'. Default 'map'
        :param step_length: DtSec (86400 for daily and 21600 for 6h run)
        """

        settings = LisSettings.instance()
        binding = settings.binding
        reference = cls.reference_files[variable][step_length][check]

        if check == 'map':
            output_map = os.path.normpath(
                binding[cls.reference_files[variable]['report_map']]) + '.nc'
            comparator = NetCDFComparator(settings.maskpath)
            comparator.compare_files(reference, output_map)
        elif check == 'tss':
            output_tss = binding[cls.reference_files[variable]['report_tss']]
            comparator = TSSComparator()
            comparator.compare_files(reference, output_tss)
        # If there are differences, test fails before reaching this line (AssertionError(s) in comparator methods)
        assert True
Ejemplo n.º 2
0
 def test_netcdfcomp_files(self):
     comp = NetCDFComparator('tests/data/area.nc', for_testing=True)
     comp.compare_files('tests/data/folder_a/ta.nc',
                        'tests/data/folder_b/ta.nc')
     with pytest.raises(AssertionError) as excinfo:
         comp.compare_files('tests/data/folder_a/ta.nc',
                            'tests/data/folder_a/tp.nc')
     assert 'have different variables names' in str(excinfo.value)
Ejemplo n.º 3
0
 def test_netcdfcomp_identical(self):
     comp = NetCDFComparator('tests/data/folder_d/mask.nc',
                             array_equal=True,
                             for_testing=True)
     comp.compare_files('tests/data/folder_d/a.nc',
                        'tests/data/folder_d/a.nc')
     with pytest.raises(AssertionError) as excinfo:
         comp.compare_files('tests/data/folder_d/a.nc',
                            'tests/data/folder_d/b.nc')
     assert 'Arrays are not equal' in str(excinfo.value)
Ejemplo n.º 4
0
 def test_netcdfcomp_no_asserts(self):
     comp = NetCDFComparator('tests/data/folder_d/mask.nc',
                             array_equal=True,
                             for_testing=False)
     comp.compare_files('tests/data/folder_d/a.nc',
                        'tests/data/folder_d/a.nc')
     assert not comp.errors
     comp.compare_files('tests/data/folder_d/a.nc',
                        'tests/data/folder_d/b.nc')
     assert comp.errors
     assert 'a.nc/field@0 is different' in comp.errors
Ejemplo n.º 5
0
 def test_netcdfcomp_no_mask(self):
     comp = NetCDFComparator(array_equal=True)
     comp.compare_files('tests/data/folder_a/ta.nc',
                        'tests/data/folder_b/ta.nc')
     comp.compare_files('tests/data/folder_d/a.nc',
                        'tests/data/folder_d/a.nc')
     comp = NetCDFComparator()
     comp.compare_files('tests/data/folder_a/ta.nc',
                        'tests/data/folder_b/ta.nc')
     comp.compare_files('tests/data/folder_d/a.nc',
                        'tests/data/folder_d/a.nc')
     with pytest.raises(ValueError) as excinfo:
         comp.compare_files('tests/data/submask/dis_subdomain.nc',
                            'tests/data/submask/dis.nc')
     assert 'operands could not be broadcast together with shapes (43,37) (57,80)' in str(
         excinfo.value)
Ejemplo n.º 6
0
 def test_netcdfcomp_diffdirs(self):
     comp = NetCDFComparator('tests/data/folder_d/mask.nc',
                             for_testing=False,
                             save_diff_files=True,
                             array_equal=True)
     assert comp.diff_folder is not None
     assert isinstance(comp.diff_folder, Path)
     assert comp.diff_folder.exists()
     comp.compare_files('tests/data/folder_d/a.nc',
                        'tests/data/folder_d/a.nc')
     assert not comp.diff_folder.joinpath('a.nc').exists()
     assert not comp.diff_folder.joinpath('b.nc').exists()
     assert not comp.diff_folder.joinpath('diff.nc').exists()
     comp.compare_files('tests/data/folder_d/a.nc',
                        'tests/data/folder_d/b.nc')
     assert comp.diff_folder.joinpath('a_a.nc').exists(
     ), 'Diff file A does not exist in %s' % comp.diff_folder
     assert comp.diff_folder.joinpath(
         'a_b.nc').exists(), 'Diff file B does not exist'
     assert comp.diff_folder.joinpath(
         'a_diff.nc').exists(), 'Diff file diff.nc does not exist'
Ejemplo n.º 7
0
 def test_get_cuts_withmaskfile_compare(self):
     maskfile = 'tests/data/submask/subcatchment_mask.map'
     x_min, x_max, y_min, y_max = get_cuts(mask=maskfile)
     x_minr, x_maxr, y_minr, y_maxr = np.round(x_min, 2), np.round(
         x_max, 2), np.round(y_min, 2), np.round(y_max, 2)
     assert (x_minr, x_maxr, y_minr, y_maxr) == (4052500.0, 4232500.0,
                                                 2332500.0, 2542500.0)
     fin = 'tests/data/submask/dis.nc'
     fout = 'tests/data/submask/dis_cut.nc'
     cutmap(fin, fout, x_min, x_max, y_min, y_max)
     with Dataset(fout) as nc:
         lons = nc.variables['x'][:]
         lats = nc.variables['y'][:]
         res_x = np.round(np.min(lons), 2)
         res_y = np.round(np.min(lats), 2)
     assert res_x == 4052500.0
     assert res_y == 2332500.0
     comparator = NetCDFComparator(mask=maskfile, array_equal=True)
     comparator.compare_files(fin, fout)
     comparator = NetCDFComparator(array_equal=True)
     comparator.compare_files(fout, 'tests/data/submask/dis_subdomain.nc')
     os.unlink(fout)
Ejemplo n.º 8
0
 def test_netcdfcomp_tol(self):
     comp = NetCDFComparator('tests/data/folder_d/mask.nc',
                             atol=0.05,
                             rtol=0.1,
                             for_testing=True)
     comp.compare_files('tests/data/folder_d/a.nc',
                        'tests/data/folder_d/b.nc')
     comp = NetCDFComparator('tests/data/folder_d/mask.nc',
                             atol=0.005,
                             rtol=0.01,
                             for_testing=True)
     comp.compare_files('tests/data/folder_d/a.nc',
                        'tests/data/folder_d/b.nc')
     with pytest.raises(AssertionError) as excinfo:
         comp = NetCDFComparator('tests/data/folder_d/mask.nc',
                                 atol=0.0005,
                                 rtol=0.001,
                                 for_testing=True)
         comp.compare_files('tests/data/folder_d/a.nc',
                            'tests/data/folder_d/b.nc')
     assert 'of different values - max diff:' in str(excinfo.value)
Ejemplo n.º 9
0
 def test_netcdfcomp_submask(self):
     comp = NetCDFComparator('tests/data/submask/subcatchment_mask.map')
     comp.compare_files('tests/data/submask/dis_subdomain.nc',
                        'tests/data/submask/dis.nc')