예제 #1
0
    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()
예제 #2
0
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 = \
            matlab_mst.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
예제 #3
0
    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)
예제 #4
0
    def test_calculate_connect_and_ntrees_small_data(self):
        ifg_instance = IfgList(small_ifg_file_list())
        ifg_list, _ = get_nml(ifg_instance, nodata_value=0)
        edges = get_sub_structure(ifg_list,
                                  np.zeros(len(ifg_list.id), dtype=bool))
        mst, connected, ntrees = matlab_mst_kruskal(edges, ntrees=True)

        self.assertTrue(connected[0].all())
        self.assertEqual(ntrees, 1)
        self.assertEqual(len(connected[0]), len(mst) + 1)
예제 #5
0
 def test_assert_is_not_tree(self):
     non_overlapping = [1, 2, 5, 6, 12, 13, 14, 15, 16, 17]
     small_files = small_ifg_file_list()
     datafiles = [
         f for i, f in enumerate(small_files) if i + 1 in non_overlapping
     ]
     non_overlapping_ifg_isntance = IfgList(datafiles)
     ifg_list, _ = get_nml(non_overlapping_ifg_isntance, nodata_value=0)
     edges = get_sub_structure(ifg_list,
                               np.zeros(len(ifg_list.id), dtype=bool))
     mst, connected, ntrees = matlab_mst_kruskal(edges, ntrees=True)
     self.assertEqual(connected.shape[0], 4)
     self.assertEqual(ntrees, 4)
예제 #6
0
    def test_assert_two_trees_overlapping(self):
        overlapping = [3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17]

        small_files = small_ifg_file_list()
        datafiles = [
            f for i, f in enumerate(small_files) if i + 1 in overlapping
        ]
        overlapping_ifg_isntance = IfgList(datafiles)
        ifg_list, _ = get_nml(overlapping_ifg_isntance, nodata_value=0)
        edges = get_sub_structure(ifg_list,
                                  np.zeros(len(ifg_list.id), dtype=bool))
        mst, connected, ntrees = matlab_mst_kruskal(edges, ntrees=True)
        self.assertEqual(connected.shape[0], 2)
        self.assertEqual(ntrees, 2)
예제 #7
0
 def setUp(self):
     ifg_instance = IfgList(small_ifg_file_list())
     self.ifg_list, _ = get_nml(ifg_instance, nodata_value=0)
     self.sorted_list = sort_list(self.ifg_list.id,
                                  self.ifg_list.master_num,
                                  self.ifg_list.slave_num,
                                  self.ifg_list.nan_frac)
     self.matlab_sorted_list_zero_nan_frac = [
         (1, 1, 3, 0.0), (2, 2, 5, 0.0), (3, 3, 7, 0.0), (4, 3, 9, 0.0),
         (5, 4, 5, 0.0), (6, 4, 6, 0.0), (7, 4, 8, 0.0), (8, 5, 11, 0.0),
         (9, 5, 12, 0.0), (10, 6, 8, 0.0), (11, 6, 13, 0.0),
         (12, 7, 9, 0.0), (13, 7, 10, 0.0), (14, 8, 13, 0.0),
         (15, 9, 10, 0.0), (16, 10, 11, 0.0), (17, 11, 12, 0.0)
     ]
     self.ifg_list_mst_matlab = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 16]
예제 #8
0
    def setUp(self):

        self.matlab_n = [
            1, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11, 3, 5, 7, 9, 5,
            6, 8, 11, 12, 8, 13, 9, 10, 13, 10, 11, 12
        ]
        self.matlab_masnum = [
            1, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11
        ]
        self.matlab_slvnum = [
            3, 5, 7, 9, 5, 6, 8, 11, 12, 8, 13, 9, 10, 13, 10, 11, 12
        ]

        ifg_instance = IfgList(small_ifg_file_list())
        self.ifg_list, self.epoch_list = get_nml(ifg_instance, nodata_value=0)
예제 #9
0
    def test_matlab_mst_kruskal(self):
        """
        test that the matlab and python mst algos outputs are the same
        """
        ifg_instance = IfgList(datafiles=self.ifg_file_list)
        ifg_list, _ = get_nml(ifg_instance, nodata_value=0)
        edges = get_sub_structure(ifg_list,
                                  np.zeros(len(ifg_list.id), dtype=bool))
        ifg_list_mst_id = matlab_mst_kruskal(edges)

        self.assertEquals(len(self.matlab_mst_list), len(ifg_list_mst_id))

        for i in ifg_list_mst_id:
            self.assertIn(
                os.path.split(ifg_list.nml[i])[-1], self.matlab_mst_list)
예제 #10
0
    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, :, :])