def test_numNonsharedFields_separateDim_differentNumberOfSlices(self):
        # Doing diffs with a separate_dim, where variable has a different number
        # of slices in the two variables. There should be one nonshared field
        # for each missing slice. Note that we treat this as non-shared, rather
        # than a dim-diff; this feels like the right thing to do, both in terms
        # of:
        # - By analogy to the fact that we treat each time slice as a separate
        #   variable for the sake of analysis
        # - It seems like this is more likely to do the Right Thing in the case
        #   of intentional / expected differences in the number of time slices in
        #   the file
        data1 = np.array([[1,2,3,4],[5,6,7,8]])
        data2 = np.array([[1,2],[5,6]])
        file1 = NetcdfFileFake(
            self.FILENAME1,
            variables = {'var1': NetcdfVariableFake(data1, ('dim1', 'dim2'))})
        file2 = NetcdfFileFake(
            self.FILENAME2,
            variables = {'var1': NetcdfVariableFake(data2, ('dim1', 'dim2'))})
        mydiffs = FileDiffs(file1, file2, separate_dim='dim2')
        num_nonshared = mydiffs.num_nonshared_fields()
        self.assertEqual(num_nonshared, 2)

        # Also make sure that other counts are correct in this case
        self.assertEqual(mydiffs.num_vars(), 4)
        self.assertEqual(mydiffs.num_vars_differ(), 0)
        self.assertEqual(mydiffs.num_dims_differ(), 0)
Example #2
0
    def test_numNonsharedFields_separateDim_differentNumberOfSlices(self):
        # Doing diffs with a separate_dim, where variable has a different number
        # of slices in the two variables. There should be one nonshared field
        # for each missing slice. Note that we treat this as non-shared, rather
        # than a dim-diff; this feels like the right thing to do, both in terms
        # of:
        # - By analogy to the fact that we treat each time slice as a separate
        #   variable for the sake of analysis
        # - It seems like this is more likely to do the Right Thing in the case
        #   of intentional / expected differences in the number of time slices in
        #   the file
        data1 = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
        data2 = np.array([[1, 2], [5, 6]])
        file1 = NetcdfFileFake(
            self.FILENAME1,
            variables={'var1': NetcdfVariableFake(data1, ('dim1', 'dim2'))})
        file2 = NetcdfFileFake(
            self.FILENAME2,
            variables={'var1': NetcdfVariableFake(data2, ('dim1', 'dim2'))})
        mydiffs = FileDiffs(file1, file2, separate_dim='dim2')
        num_nonshared = mydiffs.num_nonshared_fields()
        self.assertEqual(num_nonshared, 2)

        # Also make sure that other counts are correct in this case
        self.assertEqual(mydiffs.num_vars(), 4)
        self.assertEqual(mydiffs.num_vars_differ(), 0)
        self.assertEqual(mydiffs.num_dims_differ(), 0)
Example #3
0
 def test_numVarsDiffer_withVariableSeparatedByDim(self):
     # make sure that filediffs separates a variable by some dimension if
     # requested to do so
     data = np.array([[1, 2, 3], [4, 5, 6]])
     data_plus_1 = data + 1
     variable = NetcdfVariableFake(data, ('dim1', 'dim2'))
     variable_plus_1 = NetcdfVariableFake(data_plus_1, ('dim1', 'dim2'))
     file1 = NetcdfFileFake(self.FILENAME1, variables={'var1': variable})
     file2 = NetcdfFileFake(self.FILENAME2,
                            variables={'var1': variable_plus_1})
     mydiffs = FileDiffs(file1, file2, separate_dim='dim2')
     num_differ = mydiffs.num_vars_differ()
     self.assertEqual(num_differ, 3)
 def test_numVarsDiffer_with3Vars(self):
     file1 = NetcdfFileFake(
         self.FILENAME1,
         variables = {'var1': NetcdfVariableFake(np.array([1,2,3])),
                      'var2': NetcdfVariableFake(np.array([4,5,6])),
                      'var3': NetcdfVariableFake(np.array([7,8,9]))})
     file2 = NetcdfFileFake(
         self.FILENAME2,
         variables = {'var1': NetcdfVariableFake(np.array([99,2,3])),  # differs
                      'var2': NetcdfVariableFake(np.array([4,5,6])),   # same
                      'var3': NetcdfVariableFake(np.array([99,8,9]))}) # differs
     mydiffs = FileDiffs(file1, file2, separate_dim=None)
     num_differ = mydiffs.num_vars_differ()
     self.assertEqual(num_differ, 2)
Example #5
0
 def test_numVarsDiffer_withVariableWithoutSeparateDim(self):
     # If we ask to separate on a given dimension, but a given variable
     # doesn't have that dimension, make sure this variable is just counted
     # once
     data = np.array([[1, 2, 3], [4, 5, 6]])
     data_plus_1 = data + 1
     variable = NetcdfVariableFake(data, ('dim1', 'dim2'))
     variable_plus_1 = NetcdfVariableFake(data_plus_1, ('dim1', 'dim2'))
     file1 = NetcdfFileFake(self.FILENAME1, variables={'var1': variable})
     file2 = NetcdfFileFake(self.FILENAME2,
                            variables={'var1': variable_plus_1})
     mydiffs = FileDiffs(file1, file2, separate_dim='dim_does_not_exist')
     num_differ = mydiffs.num_vars_differ()
     self.assertEqual(num_differ, 1)
 def test_numVarsDiffer_withVariableSeparatedByDim(self):
     # make sure that filediffs separates a variable by some dimension if
     # requested to do so
     data = np.array([[1,2,3],[4,5,6]])
     data_plus_1 = data + 1
     variable = NetcdfVariableFake(data, ('dim1', 'dim2'))
     variable_plus_1 = NetcdfVariableFake(data_plus_1, ('dim1', 'dim2'))
     file1 = NetcdfFileFake(
         self.FILENAME1,
         variables = {'var1': variable})
     file2 = NetcdfFileFake(
         self.FILENAME2,
         variables = {'var1': variable_plus_1})
     mydiffs = FileDiffs(file1, file2, separate_dim='dim2')
     num_differ = mydiffs.num_vars_differ()
     self.assertEqual(num_differ, 3)
 def test_numVarsDiffer_withVariableWithoutSeparateDim(self):
     # If we ask to separate on a given dimension, but a given variable
     # doesn't have that dimension, make sure this variable is just counted
     # once
     data = np.array([[1,2,3],[4,5,6]])
     data_plus_1 = data + 1
     variable = NetcdfVariableFake(data, ('dim1', 'dim2'))
     variable_plus_1 = NetcdfVariableFake(data_plus_1, ('dim1', 'dim2'))
     file1 = NetcdfFileFake(
         self.FILENAME1,
         variables = {'var1': variable})
     file2 = NetcdfFileFake(
         self.FILENAME2,
         variables = {'var1': variable_plus_1})
     mydiffs = FileDiffs(file1, file2, separate_dim='dim_does_not_exist')
     num_differ = mydiffs.num_vars_differ()
     self.assertEqual(num_differ, 1)
Example #8
0
 def test_numVarsDiffer_with3Vars(self):
     file1 = NetcdfFileFake(self.FILENAME1,
                            variables={
                                'var1':
                                NetcdfVariableFake(np.array([1, 2, 3])),
                                'var2':
                                NetcdfVariableFake(np.array([4, 5, 6])),
                                'var3':
                                NetcdfVariableFake(np.array([7, 8, 9]))
                            })
     file2 = NetcdfFileFake(
         self.FILENAME2,
         variables={
             'var1': NetcdfVariableFake(np.array([99, 2, 3])),  # differs
             'var2': NetcdfVariableFake(np.array([4, 5, 6])),  # same
             'var3': NetcdfVariableFake(np.array([99, 8, 9]))
         })  # differs
     mydiffs = FileDiffs(file1, file2, separate_dim=None)
     num_differ = mydiffs.num_vars_differ()
     self.assertEqual(num_differ, 2)