def test_mst_matrix_as_array(self): # Verifies MST matrix func returns array with dict/trees in each cell for i in self.ifgs[3:]: i.phase_data[0, 1] = 0 # partial stack of NODATA to one cell for i in self.ifgs: i.convert_to_nans() # zeros to NaN/NODATA epochs = algorithm.get_epochs(self.ifgs)[0] res = mst._mst_matrix_as_array(self.ifgs) ys, xs = res.shape for y, x in product(range(ys), range(xs)): r = res[y, x] num_nodes = len(r) self.assertTrue(num_nodes < len(epochs.dates)) stack = array([i.phase_data[y, x] for i in self.ifgs]) # 17 ifg stack self.assertTrue( 0 == nsum(stack == 0)) # all 0s should be converted nc = nsum(isnan(stack)) exp_count = len(epochs.dates) - 1 if nc == 0: self.assertEqual(num_nodes, exp_count) elif nc > 5: # rough test: too many nans must reduce the total tree size self.assertTrue(num_nodes <= (17 - nc))
def test_all_nan_pixel_stack(self): # ensure full stack of NaNs in an MST pixel classifies to NaN mock_ifgs = [MockIfg(i, 1, 1) for i in self.ifgs] for m in mock_ifgs: m.phase_data[:] = nan res = mst._mst_matrix_as_array(mock_ifgs) exp = empty((1, 1)) #, dtype=object) exp[:] = nan shape = (mock_ifgs[0].nrows, mock_ifgs[0].ncols) self.assertTrue(res.shape == shape) self.assertTrue(res.shape == exp.shape) self.assertTrue(isnan(res[0][0]) and isnan(exp[0][0]))
def assert_equal(): res = mst._mst_matrix_as_array(mock_ifgs) self.assertEqual(len(res[0, 0]), num_coherent)