def network_correction(ifgs, deg, off, ml_ifgs=None, tol=1e-6): """ Compares results of orbital_correction() to alternate implementation. deg - PLANAR, QUADRATIC or PART_CUBIC off - True/False to calculate correction with offsets """ ncells = ifgs[0].num_cells if ml_ifgs: ml_nc = ml_ifgs[0].num_cells ml_data = concatenate([i.phase_data.reshape(ml_nc) for i in ml_ifgs]) dm = get_network_design_matrix(ml_ifgs, deg, off)[~isnan(ml_data)] fd = ml_data[~isnan(ml_data)].reshape((dm.shape[0], 1)) else: data = concatenate([i.phase_data.reshape(ncells) for i in ifgs]) dm = get_network_design_matrix(ifgs, deg, off)[~isnan(data)] fd = data[~isnan(data)].reshape((dm.shape[0], 1)) params = pinv(dm, tol).dot(fd) assert params.shape == (dm.shape[1], 1) # calculate forward correction sdm = unittest_dm(ifgs[0], NETWORK_METHOD, deg) ncoef = _get_num_params( deg, offset=False) # NB: ignore offsets for network method assert sdm.shape == (ncells, ncoef) orbs = _expand_corrections(ifgs, sdm, params, ncoef, off) # tricky: get expected result before orbital_correction() modifies ifg phase return [i.phase_data - orb for i, orb in zip(ifgs, orbs)]
def test_invalid_degree_arg(self): # test failure of a few different args for 'degree' for d in range(-5, 1): with pytest.raises(OrbitalError): get_network_design_matrix(self.ifgs, d, True) for d in range(4, 7): with pytest.raises(OrbitalError): get_network_design_matrix(self.ifgs, d, True)
def get_orbital_params(): """Returns pseudo-inverse of the DM""" ncells = self.ifgs[0].num_cells data = concatenate([i.phase_data.reshape(ncells) for i in self.ifgs]) dm = get_network_design_matrix(self.ifgs, PLANAR, True)[~isnan(data)] fd = data[~isnan(data)].reshape((dm.shape[0], 1)) return dot(pinv(dm, self.nc_tol), fd)
def test_partcubic_network_dm(self): ncoef = 6 offset = False act = get_network_design_matrix(self.ifgs, PART_CUBIC, offset) assert act.shape == (self.ncells * self.nifgs, ncoef * self.nepochs) assert act.ptp() != 0 self.check_equality(ncoef, act, self.ifgs, offset)
def test_quadratic_network_dm(self): ncoef = 5 offset = False act = get_network_design_matrix(self.ifgs, QUADRATIC, offset) assert act.shape == (self.ncells * self.nifgs, ncoef * self.nepochs) assert act.ptp() != 0 self.check_equality(ncoef, act, self.ifgs, offset)
def test_planar_network_dm(self): ncoef = 2 offset = False act = get_network_design_matrix(self.ifgs, PLANAR, offset) assert act.shape == (self.ncells * self.nifgs, ncoef * self.nepochs) assert act.ptp() != 0 self.check_equality(ncoef, act, self.ifgs, offset)
def test_partcubic_network_dm_offset(self): ncoef = 6 offset = True act = get_network_design_matrix(self.ifgs, PART_CUBIC, offset) self.assertEqual(act.shape[0], self.ncells * self.nifgs) self.assertEqual(act.shape[1], (self.nepochs * ncoef) + self.nifgs) self.assertNotEqual(act.ptp(), 0) self.check_equality(ncoef, act, self.ifgs, offset)
def test_planar_network_dm_offset(self): ncoef = 2 # NB: doesn't include offset col offset = True act = get_network_design_matrix(self.ifgs, PLANAR, offset) self.assertEqual(act.shape[0], self.ncells * self.nifgs) self.assertEqual(act.shape[1], (self.nepochs * ncoef) + self.nifgs) self.assertNotEqual(act.ptp(), 0) self.check_equality(ncoef, act, self.ifgs, offset)
def test_partcubic_network_dm_offset(self): ncoef = 6 offset = True act = get_network_design_matrix(self.ifgs, PART_CUBIC, offset) assert act.shape[0] == self.ncells * self.nifgs assert act.shape[1] == (self.nepochs * ncoef) + self.nifgs assert act.ptp() != 0 self.check_equality(ncoef, act, self.ifgs, offset)
def test_quadratic_network_dm_offset(self): ncoef = 5 offset = True act = get_network_design_matrix(self.ifgs, QUADRATIC, offset) assert act.shape[0] == self.ncells * self.nifgs assert act.shape[1] == (self.nepochs * ncoef) + self.nifgs assert act.ptp() != 0 self.check_equality(ncoef, act, self.ifgs, offset)
def test_invalid_ifgs_arg(self): # min requirement is 1 ifg, can still subtract one epoch from the other with pytest.raises(OrbitalError): get_network_design_matrix([], PLANAR, True)