Ejemplo n.º 1
0
    def test_perform_fusion(self):
        """
        TEST : Fusion.perform_fusion
        """
        from iota2.Classification import Fusion

        # define inputs
        sar_raster = os.path.join(self.test_working_directory,
                                  "Classif_T31TCJ_model_1_seed_0_SAR.tif")
        opt_raster = os.path.join(self.test_working_directory,
                                  "Classif_T31TCJ_model_1_seed_0.tif")
        array_to_raster(self.sar_classif, sar_raster)
        array_to_raster(self.optical_classif, opt_raster)

        fusion_dic = {
            "sar_classif": sar_raster,
            "opt_classif": opt_raster,
            "sar_model": self.sar_confusion,
            "opt_model": self.opt_confusion
        }

        # launch function
        ds_fusion_test = Fusion.perform_fusion(
            fusion_dic,
            mob="precision",
            classif_model_pos=self.classif_model_pos,
            classif_tile_pos=self.classif_tile_pos,
            classif_seed_pos=self.classif_seed_pos,
            workingDirectory=None)
        # assert
        ds_fusion_test = rasterToArray(ds_fusion_test)
        self.assertTrue(np.allclose(self.ds_fusion_ref, ds_fusion_test),
                        msg="fusion of classifications failed")
Ejemplo n.º 2
0
    def test_reorder_proba_map(self):
        """
        TEST : ImageClassifier.iota2Classification.reorder_proba_map()
        """
        from iota2.Common import ServiceConfigFile as SCF
        from iota2.Classification.ImageClassifier import iota2Classification

        # prepare inputs
        probamap_arr = [
            np.array([[268, 528, 131], [514, 299, 252], [725, 427, 731]]),
            np.array([[119, 241, 543], [974, 629, 626], [3, 37, 819]]),
            np.array([[409, 534, 710], [916, 43, 993], [207, 68, 282]]),
            np.array([[820, 169, 423], [710, 626, 525], [377, 777, 461]]),
            np.array([[475, 116, 395], [838, 297, 262], [650, 828, 595]]),
            np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
        ]
        probamap_path = os.path.join(self.test_working_directory,
                                     "PROBAMAP_T31TCJ_model_1_seed_0.tif")
        TUR.array_to_raster(probamap_arr, probamap_path)

        cfg = SCF.serviceConfigFile(self.config_test)
        fake_model = "model_1_seed_0.txt"
        fake_tile = "T31TCJ"
        fake_output_directory = "fake_output_directory"
        classifier = iota2Classification(
            features_stack=None,
            classifier_type=None,
            model=fake_model,
            tile=fake_tile,
            output_directory=fake_output_directory,
            models_class=None)
        class_model = [1, 2, 3, 4, 6]
        all_class = [1, 2, 3, 4, 5, 6]
        proba_map_path_out = os.path.join(
            self.test_working_directory,
            "PROBAMAP_T31TCJ_model_1_seed_0_ORDERED.tif")
        classifier.reorder_proba_map(probamap_path, proba_map_path_out,
                                     class_model, all_class)

        # assert
        probamap_arr_ref = [
            np.array([[268, 528, 131], [514, 299, 252], [725, 427, 731]]),
            np.array([[119, 241, 543], [974, 629, 626], [3, 37, 819]]),
            np.array([[409, 534, 710], [916, 43, 993], [207, 68, 282]]),
            np.array([[820, 169, 423], [710, 626, 525], [377, 777, 461]]),
            np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]),
            np.array([[475, 116, 395], [838, 297, 262], [650, 828, 595]])
        ]
        reordered_test_arr = rasterToArray(proba_map_path_out)
        self.assertEqual(len(all_class), len(reordered_test_arr))
        is_bands_ok = []
        for band in range(len(reordered_test_arr)):
            band_ref = probamap_arr_ref[band]
            band_test = reordered_test_arr[band]
            for ref_val, test_val in zip(band_ref.flat, band_test.flat):
                is_bands_ok.append(int(ref_val) == int(test_val))
        self.assertTrue(all(is_bands_ok),
                        msg="reordering probability maps failed")
Ejemplo n.º 3
0
    def test_iota2_samples_statistics(self):
        """test generation of statistics by tiles
        """
        from iota2.Sampling.SamplesStat import samples_stats
        from iota2.Common.FileUtils import ensure_dir

        ensure_dir(
            os.path.join(self.test_working_directory, "samplesSelection"))
        ensure_dir(os.path.join(self.test_working_directory, "shapeRegion"))

        raster_ref = os.path.join(self.test_working_directory,
                                  "RASTER_REF.tif")
        arr_test = TUR.fun_array("iota2_binary")
        TUR.array_to_raster(arr_test,
                            raster_ref,
                            origin_x=566377,
                            origin_y=6284029)

        shutil.copy(
            raster_ref,
            os.path.join(self.test_working_directory, "shapeRegion",
                         "T31TCJ_region_1_.tif"))

        references_directory = os.path.join(IOTA2DIR, "data", "references")
        region_shape = os.path.join(references_directory, "region_target.shp")
        shutil.copy(
            region_shape,
            os.path.join(
                os.path.join(self.test_working_directory, "samplesSelection",
                             "T31TCJ_region_1_seed_0.shp")))
        shutil.copy(
            region_shape.replace(".shp", ".shx"),
            os.path.join(
                os.path.join(self.test_working_directory, "samplesSelection",
                             "T31TCJ_region_1_seed_0.shx")))
        shutil.copy(
            region_shape.replace(".shp", ".dbf"),
            os.path.join(
                os.path.join(self.test_working_directory, "samplesSelection",
                             "T31TCJ_region_1_seed_0.dbf")))
        shutil.copy(
            region_shape.replace(".shp", ".prj"),
            os.path.join(
                os.path.join(self.test_working_directory, "samplesSelection",
                             "T31TCJ_region_1_seed_0.prj")))

        test_statistics = samples_stats(
            region_seed_tile=("1", "0", "T31TCJ"),
            iota2_directory=self.test_working_directory,
            data_field="region",
            working_directory=None)
        self.assertTrue(
            filecmp.cmp(
                os.path.join(IOTA2DIR, "data", "references",
                             "T31TCJ_region_1_seed_0_stats.xml"),
                test_statistics))
Ejemplo n.º 4
0
    def test_confidence_fusion(self):
        """
        TEST : Fusion.compute_confidence_fusion
        """
        from iota2.Classification import Fusion

        # define inputs
        sar_raster = os.path.join(self.test_working_directory,
                                  "Classif_T31TCJ_model_1_seed_0_SAR.tif")
        opt_raster = os.path.join(self.test_working_directory,
                                  "Classif_T31TCJ_model_1_seed_0.tif")
        array_to_raster(self.sar_classif, sar_raster)
        array_to_raster(self.optical_classif, opt_raster)

        sar_confid_raster = os.path.join(
            self.test_working_directory,
            "T31TCJ_model_1_confidence_seed_0_SAR.tif")
        opt_confid_raster = os.path.join(
            self.test_working_directory,
            "T31TCJ_model_1_confidence_seed_0.tif")
        array_to_raster(self.sar_confidence,
                        sar_confid_raster,
                        output_format="float")
        array_to_raster(self.optical_confidence,
                        opt_confid_raster,
                        output_format="float")

        ds_choice = os.path.join(self.test_working_directory, "choice.tif")
        array_to_raster(self.choice_map_ref, ds_choice)

        fusion_dic = {
            "sar_classif": sar_raster,
            "opt_classif": opt_raster,
            "sar_model": self.sar_confusion,
            "opt_model": self.opt_confusion
        }
        workingDirectory = None

        # Launch function
        ds_fus_confidence_test = Fusion.compute_confidence_fusion(
            fusion_dic, ds_choice, self.classif_model_pos,
            self.classif_tile_pos, self.classif_seed_pos, self.ds_choice_both,
            self.ds_choice_sar, self.ds_choice_opt, self.ds_no_choice,
            workingDirectory)
        # assert
        ds_fus_confidence_test = rasterToArray(ds_fus_confidence_test)
        self.assertTrue(np.allclose(self.ds_fus_confidence_ref,
                                    ds_fus_confidence_test),
                        msg="fusion of confidences failed")
Ejemplo n.º 5
0
    def test_ds_fusion(self):
        """
        TEST : Fusion.dempster_shafer_fusion. Every functions called in Fusion.dempster_shafer_fusion
               are tested above. This test check the runnability of Fusion.dempster_shafer_fusion
        """
        from iota2.Classification import Fusion
        from iota2.Common import IOTA2Directory
        from iota2.Common import ServiceConfigFile as SCF

        # define inputs
        cfg = SCF.serviceConfigFile(self.config_test)
        iota2_dir = os.path.join(self.test_working_directory, "fusionTest")
        cfg.setParam('chain', 'outputPath', iota2_dir)
        IOTA2Directory.generate_directories(iota2_dir, check_inputs=False)

        sar_raster = os.path.join(iota2_dir, "classif",
                                  "Classif_T31TCJ_model_1_seed_0_SAR.tif")
        opt_raster = os.path.join(iota2_dir, "classif",
                                  "Classif_T31TCJ_model_1_seed_0.tif")
        array_to_raster(self.sar_classif, sar_raster)
        array_to_raster(self.optical_classif, opt_raster)

        sar_confid_raster = os.path.join(
            iota2_dir, "classif", "T31TCJ_model_1_confidence_seed_0_SAR.tif")
        opt_confid_raster = os.path.join(
            iota2_dir, "classif", "T31TCJ_model_1_confidence_seed_0.tif")
        array_to_raster(self.sar_confidence,
                        sar_confid_raster,
                        output_format="float")
        array_to_raster(self.optical_confidence,
                        opt_confid_raster,
                        output_format="float")

        fusion_dic = {
            "sar_classif": sar_raster,
            "opt_classif": opt_raster,
            "sar_model": self.sar_confusion,
            "opt_model": self.opt_confusion
        }
        workingDirectory = None
        # Launch function
        (fusion_path, confidence_path, probamap_path,
         choice_path) = Fusion.dempster_shafer_fusion(
             iota2_dir,
             fusion_dic,
             mob="precision",
             workingDirectory=workingDirectory)
        self.assertEqual("/classif/Classif_T31TCJ_model_1_seed_0_DS.tif",
                         fusion_path.replace(iota2_dir, ""))
        self.assertEqual("/classif/T31TCJ_model_1_confidence_seed_0_DS.tif",
                         confidence_path.replace(iota2_dir, ""))
        self.assertEqual("/final/TMP/DSchoice_T31TCJ_model_1_seed_0.tif",
                         choice_path.replace(iota2_dir, ""))
        self.assertTrue(probamap_path is None)
Ejemplo n.º 6
0
    def test_fusion_choice(self):
        """
        TEST : Fusion.compute_fusion_choice
        """
        from iota2.Classification import Fusion
        from iota2.Common import IOTA2Directory
        from iota2.Common import ServiceConfigFile as SCF

        # define inputs
        sar_raster = os.path.join(self.test_working_directory,
                                  "Classif_T31TCJ_model_1_seed_0_SAR.tif")
        opt_raster = os.path.join(self.test_working_directory,
                                  "Classif_T31TCJ_model_1_seed_0.tif")
        array_to_raster(self.sar_classif, sar_raster)
        array_to_raster(self.optical_classif, opt_raster)

        cfg = SCF.serviceConfigFile(self.config_test)
        iota2_dir = os.path.join(self.test_working_directory, "fusionTest")
        cfg.setParam('chain', 'outputPath', iota2_dir)

        IOTA2Directory.generate_directories(iota2_dir, check_inputs=False)

        fusion_dic = {
            "sar_classif": sar_raster,
            "opt_classif": opt_raster,
            "sar_model": self.sar_confusion,
            "opt_model": self.opt_confusion
        }
        fusion_class_array = self.ds_fusion_ref
        fusion_class_raster = os.path.join(self.test_working_directory,
                                           "fusionTest.tif")
        array_to_raster(fusion_class_array, fusion_class_raster)
        workingDirectory = None

        # Launch function
        ds_choice = Fusion.compute_fusion_choice(
            iota2_dir, fusion_dic, fusion_class_raster, self.classif_model_pos,
            self.classif_tile_pos, self.classif_seed_pos, self.ds_choice_both,
            self.ds_choice_sar, self.ds_choice_opt, self.ds_no_choice,
            workingDirectory)
        # assert
        ds_choice_test = rasterToArray(ds_choice)
        self.assertTrue(np.allclose(self.choice_map_ref, ds_choice_test),
                        msg="compute raster choice failed")
Ejemplo n.º 7
0
    def test_compute_probamap_fusion(self):
        """
        TEST : Fusion.compute_probamap_fusion()
        """
        from iota2.Classification import Fusion
        from iota2.Common import IOTA2Directory
        from iota2.Common import ServiceConfigFile as SCF

        # define inputs
        sar_raster = os.path.join(self.test_working_directory,
                                  "Classif_T31TCJ_model_1_seed_0_SAR.tif")
        opt_raster = os.path.join(self.test_working_directory,
                                  "Classif_T31TCJ_model_1_seed_0.tif")
        array_to_raster(self.sar_classif, sar_raster)
        array_to_raster(self.optical_classif, opt_raster)

        sar_confid_raster = os.path.join(
            self.test_working_directory,
            "T31TCJ_model_1_confidence_seed_0_SAR.tif")
        opt_confid_raster = os.path.join(
            self.test_working_directory,
            "T31TCJ_model_1_confidence_seed_0.tif")
        array_to_raster(self.sar_confidence,
                        sar_confid_raster,
                        output_format="float")
        array_to_raster(self.optical_confidence,
                        opt_confid_raster,
                        output_format="float")

        ds_choice = os.path.join(self.test_working_directory, "choice.tif")
        array_to_raster(self.choice_map_ref, ds_choice)

        fusion_dic = {
            "sar_classif": sar_raster,
            "opt_classif": opt_raster,
            "sar_model": self.sar_confusion,
            "opt_model": self.opt_confusion
        }
        workingDirectory = None

        # random probability maps
        sar_probamap_arr = [
            np.array([[253, 874, 600], [947, 812, 941], [580, 94, 192]]),
            np.array([[541, 711, 326], [273, 915, 698], [296, 1000, 624]]),
            np.array([[253, 290, 610], [406, 685, 333], [302, 410, 515]]),
            np.array([[216, 766, 98], [914, 288, 504], [70, 631, 161]]),
            np.array([[371, 873, 134], [477, 701, 765], [549, 301, 847]]),
            np.array([[870, 201, 85], [555, 644, 802], [98, 807, 77]])
        ]
        opt_probamap_arr = [
            np.array([[268, 528, 131], [514, 299, 252], [725, 427, 731]]),
            np.array([[119, 241, 543], [974, 629, 626], [3, 37, 819]]),
            np.array([[409, 534, 710], [916, 43, 993], [207, 68, 282]]),
            np.array([[820, 169, 423], [710, 626, 525], [377, 777, 461]]),
            np.array([[475, 116, 395], [838, 297, 262], [650, 828, 595]]),
            np.array([[940, 261, 20], [339, 934, 278], [444, 326, 219]])
        ]
        # to rasters
        sar_probamap_path = os.path.join(
            self.test_working_directory,
            "PROBAMAP_T31TCJ_model_1_seed_0_SAR.tif")
        array_to_raster(sar_probamap_arr, sar_probamap_path)
        opt_probamap_path = os.path.join(self.test_working_directory,
                                         "PROBAMAP_T31TCJ_model_1_seed_0.tif")
        array_to_raster(opt_probamap_arr, opt_probamap_path)

        # Launch function
        ds_fus_confidence_test = Fusion.compute_probamap_fusion(
            fusion_dic, ds_choice, self.classif_model_pos,
            self.classif_tile_pos, self.classif_seed_pos, self.ds_choice_both,
            self.ds_choice_sar, self.ds_choice_opt, self.ds_no_choice,
            workingDirectory)
        # asserts

        # length assert
        from iota2.Common.FileUtils import getRasterNbands
        self.assertTrue(
            len(sar_probamap_arr) == len(opt_probamap_arr) == getRasterNbands(
                ds_fus_confidence_test))

        # fusion assert
        is_ok = []
        ds_fus_confidence_test_arr = rasterToArray(ds_fus_confidence_test)
        for band_num in range(len(ds_fus_confidence_test_arr)):
            merged_band = ds_fus_confidence_test_arr[band_num]
            sar_proba_band = sar_probamap_arr[band_num]
            opt_proba_band = opt_probamap_arr[band_num]
            for (merged_proba, sar_proba, opt_proba, choice, sar_confi,
                 opt_confi) in zip(merged_band.flat, sar_proba_band.flat,
                                   opt_proba_band.flat,
                                   self.choice_map_ref.flat,
                                   self.sar_confidence.flat,
                                   self.optical_confidence.flat):
                if choice == 1:
                    if sar_confi > opt_confi:
                        is_ok.append(int(merged_proba) == int(sar_proba))
                    else:
                        is_ok.append(int(merged_proba) == int(opt_proba))
                elif choice == 2:
                    is_ok.append(int(merged_proba) == int(sar_proba))
                elif choice == 3:
                    is_ok.append(int(merged_proba) == int(opt_proba))
        self.assertTrue(all(is_ok))
Ejemplo n.º 8
0
    def test_machine_learning(self):
        """use sci-kit learn machine learning algorithm
        """
        from functools import partial
        from sklearn.ensemble import RandomForestClassifier
        from iota2.Common import rasterUtils as rasterU
        from iota2.Tests.UnitTests import TestsUtils
        from iota2.Common.OtbAppBank import CreateBandMathXApplication

        def do_predict(array, model, dtype="int32"):
            """
            """
            def wrapper(*args, **kwargs):
                return model.predict([args[0]])

            predicted_array = np.apply_along_axis(func1d=wrapper,
                                                  axis=-1,
                                                  arr=array)
            return predicted_array.astype(dtype)

        # build data to learn RF model
        from sklearn.datasets import make_classification

        X, y = make_classification(n_samples=1000,
                                   n_features=2,
                                   n_informative=2,
                                   n_redundant=0,
                                   random_state=0,
                                   shuffle=True)
        # learning
        clf = RandomForestClassifier(n_estimators=100,
                                     max_depth=2,
                                     random_state=0)
        clf.fit(X, y)

        # create some data on disk in order to predict them
        dummy_raster_path = os.path.join(self.test_working_directory,
                                         "DUMMY.tif")
        array_to_rasterize = TestsUtils.fun_array("iota2_binary")
        array_to_raster(array_to_rasterize, dummy_raster_path)

        # Get it in a otbApplication (simulating full iota2 features pipeline)
        band_math = CreateBandMathXApplication({
            "il": [dummy_raster_path],
            "exp": "im1b1;im1b1"
        })
        # prediction
        function_partial = partial(do_predict, model=clf)
        prediction_path = os.path.join(self.test_working_directory,
                                       "Classif_test.tif")
        test_array, new_labels, _, _, _ = rasterU.apply_function(
            otb_pipeline=band_math,
            labels=[""],
            working_dir=self.test_working_directory,
            function=function_partial,
            output_path=prediction_path,
            chunck_size_x=5,
            chunck_size_y=5,
            ram=128)
        self.assertTrue(os.path.exists(prediction_path))
        self.assertTrue(test_array.shape == (1, 16, 86))
Ejemplo n.º 9
0
    def test_apply_function(self):
        """
        TEST : check the whole workflow
        """
        from functools import partial
        from iota2.Common import rasterUtils as rasterU
        from iota2.Tests.UnitTests import TestsUtils
        from iota2.Common.OtbAppBank import CreateBandMathXApplication

        def custom_features(array):
            """
            """
            return array + array

        # First create some dummy data on disk
        dummy_raster_path = os.path.join(self.test_working_directory,
                                         "DUMMY.tif")
        array_to_rasterize = TestsUtils.fun_array("iota2_binary")
        array_to_raster(array_to_rasterize, dummy_raster_path)

        # Get it in a otbApplication (simulating full iota2 features pipeline)
        band_math = CreateBandMathXApplication({
            "il": [dummy_raster_path],
            "exp": "im1b1;im1b1"
        })
        # Then apply function
        function_partial = partial(custom_features)

        labels_features_name = ["NDVI_20200101"]

        new_features_path = os.path.join(self.test_working_directory,
                                         "DUMMY_test.tif")
        test_array, new_labels, _, _, _ = rasterU.apply_function(
            otb_pipeline=band_math,
            labels=labels_features_name,
            working_dir=self.test_working_directory,
            function=function_partial,
            output_path=new_features_path,
            chunck_size_x=5,
            chunck_size_y=5,
            ram=128)
        # asserts

        # check array' shape consistency
        # concerning np.array there is different convention between OTB(GDAL?)
        # and rasterio
        # OTB : [row, cols, bands]
        # rasterio : [bands, row, cols]
        band_math.Execute()
        pipeline_shape = band_math.GetVectorImageAsNumpyArray("out").shape
        pipeline_shape = (pipeline_shape[2], pipeline_shape[0],
                          pipeline_shape[1])
        self.assertTrue(pipeline_shape == test_array.shape)

        # check if the input function is well applied
        pipeline_array = band_math.GetVectorImageAsNumpyArray("out")
        self.assertTrue(
            np.allclose(np.moveaxis(custom_features(pipeline_array), -1, 0),
                        test_array))

        # purposely not implemented
        self.assertTrue(new_labels is None)
Ejemplo n.º 10
0
    def test_sampling_features_from_raster(self):
        """non-regression test, check the ability of adding features in database
        by sampling classification raster
        """
        import numpy as np
        from collections import Counter
        from iota2.Sampling.SuperPixelsSelection import move_annual_samples_position
        import TestsUtils

        mask_array = TestsUtils.fun_array("iota2_binary")
        random_classif_mask_path = os.path.join(self.test_working_directory,
                                                "Classif_Seed_0.tif")

        validity_array = np.full(mask_array.shape, 1)
        validity_path = os.path.join(self.test_working_directory,
                                     "PixelsValidity.tif")
        region_path = os.path.join(self.test_working_directory,
                                   "mask_region.tif")
        array_to_raster(validity_array,
                        validity_path,
                        pixel_size=10,
                        origin_x=self.originX,
                        origin_y=self.originY)
        array_to_raster(validity_array,
                        region_path,
                        pixel_size=10,
                        origin_x=self.originX,
                        origin_y=self.originY)

        ref_data_sampled = os.path.join(self.test_working_directory,
                                        "dataBase.sqlite")

        self.prepapre_data_ref(in_vector=self.ref_data,
                               out_vector=ref_data_sampled,
                               ref_img=region_path)

        # test : all annual labels are in dataBase and classifications
        labels = [12, 31, 32, 41, 211, 222]
        annual_labels = ["12", "31"]
        annual_labels_int = [int(elem) for elem in annual_labels]
        random_classif_array = np.random.choice(labels,
                                                size=mask_array.shape,
                                                replace=True)
        random_classif_array_mask = random_classif_array * mask_array
        array_to_raster(random_classif_array_mask,
                        random_classif_mask_path,
                        pixel_size=10,
                        origin_x=self.originX,
                        origin_y=self.originY)
        move_annual_samples_position(
            samples_position=ref_data_sampled,
            dataField="code",
            annual_labels=annual_labels,
            classification_raster=random_classif_mask_path,
            validity_raster=validity_path,
            region_mask=region_path,
            validity_threshold=0,
            tile_origin_field_value=("tile_o", "T31TCJ"),
            seed_field_value=("seed_0", "learn"),
            region_field_value=("region", "1"))
        # assert
        raster_values = TestsUtils.compare_vector_raster(
            in_vec=ref_data_sampled,
            vec_field="code",
            field_values=annual_labels_int,
            in_img=random_classif_mask_path)
        values_counter = Counter(raster_values)
        exist_in_annual = [
            value in annual_labels_int for value in values_counter.keys()
        ]
        self.assertTrue(all(exist_in_annual))

        # test : only one annual label in dataBase
        labels = [12, 31, 32, 41, 211, 222]
        annual_labels = ["12"]
        annual_labels_int = [int(elem) for elem in annual_labels]
        random_classif_array = np.random.choice(labels,
                                                size=mask_array.shape,
                                                replace=True)
        random_classif_array_mask = random_classif_array * mask_array
        array_to_raster(random_classif_array_mask,
                        random_classif_mask_path,
                        pixel_size=10,
                        origin_x=self.originX,
                        origin_y=self.originY)

        move_annual_samples_position(
            samples_position=ref_data_sampled,
            dataField="code",
            annual_labels=annual_labels,
            classification_raster=random_classif_mask_path,
            validity_raster=validity_path,
            region_mask=region_path,
            validity_threshold=0,
            tile_origin_field_value=("tile_o", "T31TCJ"),
            seed_field_value=("seed_0", "learn"),
            region_field_value=("region", "1"))
        # assert
        raster_values = TestsUtils.compare_vector_raster(
            in_vec=ref_data_sampled,
            vec_field="code",
            field_values=annual_labels_int,
            in_img=random_classif_mask_path)
        values_counter = Counter(raster_values)
        exist_in_annual = [
            value in annual_labels_int for value in values_counter.keys()
        ]
        self.assertTrue(all(exist_in_annual))

        # test : no annual labels in classifications
        labels = [12, 31, 32, 41, 211, 222]
        annual_labels = ["111", "112"]
        annual_labels_int = [int(elem) for elem in annual_labels]
        random_classif_array = np.random.choice(labels,
                                                size=mask_array.shape,
                                                replace=True)
        random_classif_array_mask = random_classif_array * mask_array
        array_to_raster(random_classif_array_mask,
                        random_classif_mask_path,
                        pixel_size=10,
                        origin_x=self.originX,
                        origin_y=self.originY)

        move_annual_samples_position(
            samples_position=ref_data_sampled,
            dataField="code",
            annual_labels=annual_labels,
            classification_raster=random_classif_mask_path,
            validity_raster=validity_path,
            region_mask=region_path,
            validity_threshold=0,
            tile_origin_field_value=("tile_o", "T31TCJ"),
            seed_field_value=("seed_0", "learn"),
            region_field_value=("region", "1"))
        # assert
        raster_values = TestsUtils.compare_vector_raster(
            in_vec=ref_data_sampled,
            vec_field="code",
            field_values=annual_labels_int,
            in_img=random_classif_mask_path)
        values_counter = Counter(raster_values)
        self.assertTrue(len(values_counter) == 0)