def mst_calculation(ifg_paths_or_instance, params): if isinstance(ifg_paths_or_instance, list): ifgs = pre_prepare_ifgs(ifg_paths_or_instance, params) mst_grid = mst.mst_parallel(ifgs, params) else: nan_conversion = params[cf.NAN_CONVERSION] assert isinstance(ifg_paths_or_instance, matlab_mst._IfgListPyRate) ifgs = ifg_paths_or_instance.ifgs for i in ifgs: if not i.mm_converted: i.nodata_value = params[cf.NO_DATA_VALUE] i.convert_to_mm() ifg_instance_updated, epoch_list = \ get_nml(ifg_paths_or_instance, nodata_value=params[cf.NO_DATA_VALUE], nan_conversion=nan_conversion) mst_grid = matlab_mst._matlab_mst_bool(ifg_instance_updated) # write mst output to a file mst_mat_binary_file = join(params[cf.OUT_DIR], 'mst_mat') np.save(file=mst_mat_binary_file, arr=mst_grid) for i in ifgs: i.close() return mst_grid
def test_mst_boolean_array(self): nan_conversion = 1 for i in self.small_ifgs: if not i.is_open: i.open(readonly=False) if nan_conversion: # nan conversion happens here in networkx mst i.nodata_value = 0 i.convert_to_nans() if not i.mm_converted: i.convert_to_mm() i.write_modified_phase() mst_nx = mst.mst_boolean_array(self.small_ifgs) small_ifg_instance = IfgList(datafiles=self.small_files) ifgs = small_ifg_instance.ifgs for i in ifgs: if not i.mm_converted: i.convert_to_mm() i.write_modified_phase() ifg_instance_updated, epoch_list = \ get_nml(small_ifg_instance, nodata_value=0, nan_conversion=nan_conversion) mst_matlab = _matlab_mst_bool(ifg_instance_updated) np.testing.assert_array_equal(mst_matlab, mst_nx) # close ifgs for windows for i in self.small_ifgs: i.close()
def test_mas_mat_vs_mst_mat_generator(self): ifg_instance = IfgList(datafiles=self.ifg_file_list) ifg_list, _ = get_nml(ifg_instance, nodata_value=0, nan_conversion=True) mst_mat1 = _matlab_mst(ifg_list) mst_mat2 = _matlab_mst_bool(ifg_list) np.testing.assert_array_equal(mst_mat2, mst_mat1)
def test_matlab_make_mstmat_boolean_array(self): """ tests equality of boolean mst arrays of both python and matlab. """ ifg_instance = IfgList(datafiles=self.ifg_file_list) ifg_list, _ = get_nml(ifg_instance, nodata_value=0) mst_mat = _matlab_mst_bool(ifg_list, p_threshold=1) # path to csv folders from matlab output from tests.common import SML_TEST_MATLAB_MST_DIR onlyfiles = [f for f in os.listdir(SML_TEST_MATLAB_MST_DIR) if os.path.isfile(os.path.join(SML_TEST_MATLAB_MST_DIR, f))] for i, f in enumerate(onlyfiles): mst_f = np.genfromtxt(os.path.join(SML_TEST_MATLAB_MST_DIR, f), delimiter=',') for k, j in enumerate(self.ifg_file_list): if f.split('matlab_')[-1].split('.')[0] == \ os.path.split(j)[-1].split('.')[0]: np.testing.assert_array_equal(mst_f, mst_mat[k, :, :])