diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b88fe7..b81ddbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +- **Changement de comportement** : + Le champ "DONOR_CLASS_TRANSLATION" décrit maintenant l'association entre les classes du fichier donneur et les classes correspondantes dans le fichier de sortie. Au lieu de choisir entre ajouter une colonne et modifier les classes entre le fichier de donneur et le fichier de sortie, on applique maintenant les 2 traitements : + - Si "NEW_COLUMN" est non nul, on ajoute une dimension décrivant l'origine du fichier + - Les classes des points issus du fichier donneur sont converties via le dictionnaire "DONOR_CLASS_TRANSLATION" au moment de l'ajout des points au fichier de sortie. + ## 1.3.0 - Possibilité d'ignorer les points synthétiques du fichier donneur (paramètre DONOR_USE_SYNTHETIC_POINTS dans le fichier de config) diff --git a/configs/configs_patchwork.yaml b/configs/configs_patchwork.yaml index 2082851..ee422de 100644 --- a/configs/configs_patchwork.yaml +++ b/configs/configs_patchwork.yaml @@ -58,5 +58,5 @@ PATCH_SIZE: 1 # size of a patch of the grid. Must be a divisor of TILE_SIZE, so NEW_COLUMN: null # If not null, contains the name of the new column NEW_COLUMN_SIZE: 8 # must be 8, 16, 32 or 64 VALUE_ADDED_POINTS: 1 # in case of a new column, value of the new point (the other are set to 0) -VIRTUAL_CLASS_TRANSLATION: {2: 69, 22: 70} # if there is no new column, translate the class of DONOR_CLASS_LIST into those values -# each value of DONOR_CLASS_LIST must be a key in VIRTUAL_CLASS_TRANSLATION. Not used if NEW_COLUMN is not None (or "") +DONOR_CLASS_TRANSLATION: {2: 2, 22: 2} # translate the class of DONOR_CLASS_LIST into those values +# each value of DONOR_CLASS_LIST must be a key in DONOR_CLASS_TRANSLATION. \ No newline at end of file diff --git a/patchwork/patchwork.py b/patchwork/patchwork.py index 51a41ad..6062d57 100644 --- a/patchwork/patchwork.py +++ b/patchwork/patchwork.py @@ -228,15 +228,14 @@ def append_points(config: DictConfig, extra_points: pd.DataFrame): for field in fields_to_keep: new_points[field] = extra_points[field].astype(new_points[field]) - if not config.NEW_COLUMN: - # translate the classification values: - for classification in config.DONOR_CLASS_LIST: - new_classification = config.VIRTUAL_CLASS_TRANSLATION[classification] - extra_points.loc[extra_points[c.CLASSIFICATION_STR] == classification, c.CLASSIFICATION_STR] = ( - new_classification - ) + # translate the classification values: + for classification in config.DONOR_CLASS_LIST: + new_classification = config.DONOR_CLASS_TRANSLATION[classification] + extra_points.loc[extra_points[c.CLASSIFICATION_STR] == classification, c.CLASSIFICATION_STR] = ( + new_classification + ) - else: + if config.NEW_COLUMN: extra_points[config.NEW_COLUMN] = config.VALUE_ADDED_POINTS new_points[config.NEW_COLUMN] = extra_points[config.NEW_COLUMN] diff --git a/test/configs/config_test_mount_points.yaml b/test/configs/config_test_mount_points.yaml index ea17550..afb721f 100644 --- a/test/configs/config_test_mount_points.yaml +++ b/test/configs/config_test_mount_points.yaml @@ -61,5 +61,5 @@ PATCH_SIZE: 1 # size of a patch of the grid. Must be a divisor of TILE_SIZE, so NEW_COLUMN: null # If not null, contains the name of the new column NEW_COLUMN_SIZE: 8 # must be 8, 16, 32 or 64 VALUE_ADDED_POINTS: 1 # in case of a new column, value of the new point (the other are set to 0) -VIRTUAL_CLASS_TRANSLATION: {2: 69, 22: 70} # if there is no new column, translate the class of DONOR_CLASS_LIST into those values -# each value of DONOR_CLASS_LIST must be a key in VIRTUAL_CLASS_TRANSLATION. Not used if NEW_COLUMN is not None (or "") +DONOR_CLASS_TRANSLATION: {2: 2, 22: 2} # if there is no new column, translate the class of DONOR_CLASS_LIST into those values +# each value of DONOR_CLASS_LIST must be a key in DONOR_CLASS_TRANSLATION. Not used if NEW_COLUMN is not None (or "") diff --git a/test/test_patchwork.py b/test/test_patchwork.py index 63b5f3f..595be88 100644 --- a/test/test_patchwork.py +++ b/test/test_patchwork.py @@ -23,7 +23,7 @@ DONOR_CLASS_LIST = [2, 9] RECIPIENT_CLASS_LIST = [2, 3, 9, 17] -VIRTUAL_CLASS_TRANSLATION = {2: 69, 9: 70} +DONOR_CLASS_TRANSLATION = {2: 69, 9: 70} POINT_1 = {"x": 1, "y": 2, "z": 3, c.CLASSIFICATION_STR: 4} POINT_2 = {"x": 5, "y": 6, "z": 7, c.CLASSIFICATION_STR: 8} NEW_COLUMN = "virtual_column" @@ -145,7 +145,7 @@ def test_get_complementary_points(donor_info_path, recipient_path, x, y, expecte overrides=[ f"DONOR_CLASS_LIST={DONOR_CLASS_LIST}", f"RECIPIENT_CLASS_LIST={RECIPIENT_CLASS_LIST}", - f"+VIRTUAL_CLASS_TRANSLATION={VIRTUAL_CLASS_TRANSLATION}", + f"+DONOR_CLASS_TRANSLATION={DONOR_CLASS_TRANSLATION}", "DONOR_USE_SYNTHETIC_POINTS=true", ], ) @@ -199,7 +199,7 @@ def test_get_complementary_points_2_more_fields(tmp_path_factory): overrides=[ f"DONOR_CLASS_LIST={DONOR_CLASS_LIST}", f"RECIPIENT_CLASS_LIST={RECIPIENT_CLASS_LIST}", - f"+VIRTUAL_CLASS_TRANSLATION={VIRTUAL_CLASS_TRANSLATION}", + f"+DONOR_CLASS_TRANSLATION={DONOR_CLASS_TRANSLATION}", "DONOR_USE_SYNTHETIC_POINTS=true", ], ) @@ -233,6 +233,9 @@ def test_append_points(tmp_path_factory): tmp_file_dir = tmp_path_factory.mktemp("data") tmp_file_name = "result.laz" + donor_class_list = [4, 8] + donor_class_translation = {4: 44, 8: 88} + with initialize(version_base="1.2", config_path="../configs"): config = compose( config_name="configs_patchwork.yaml", @@ -241,6 +244,8 @@ def test_append_points(tmp_path_factory): f"filepath.RECIPIENT_NAME={RECIPIENT_TEST_NAME}", f"filepath.OUTPUT_DIR={tmp_file_dir}", f"filepath.OUTPUT_NAME={tmp_file_name}", + f"DONOR_CLASS_LIST={donor_class_list}", + f"+DONOR_CLASS_TRANSLATION={donor_class_translation}", ], ) @@ -266,6 +271,12 @@ def test_append_points(tmp_path_factory): for point in las_recipient.points[:10]: # only 10 points, otherwise it takes too long assert point in las_output.points + # Original class of the first added points is 4, turned to 44 by DONOR_CLASS_TRANSLATION + assert las_output.points[-2][c.CLASSIFICATION_STR] == 44 + + # Original class of the second added points is 8, turned to 88 by DONOR_CLASS_TRANSLATION + assert las_output.points[-1][c.CLASSIFICATION_STR] == 88 + # add 1 point extra_points = pd.DataFrame( data=[ @@ -282,7 +293,7 @@ def test_append_points(tmp_path_factory): extra_points = pd.DataFrame(data={"x": [], "y": [], "z": [], c.CLASSIFICATION_STR: []}) append_points(config, extra_points) - # assert a point has been added + # assert no point has been added point_count = get_point_count(recipient_file_path) assert get_point_count(output_file) == point_count @@ -369,7 +380,7 @@ def test_patchwork_default(tmp_path_factory, recipient_path, expected_nb_added_p f"filepath.OUTPUT_INDICES_MAP_NAME={tmp_output_indices_map_name}", f"DONOR_CLASS_LIST={DONOR_CLASS_LIST}", f"RECIPIENT_CLASS_LIST={RECIPIENT_CLASS_LIST}", - f"+VIRTUAL_CLASS_TRANSLATION={VIRTUAL_CLASS_TRANSLATION}", + f"+DONOR_CLASS_TRANSLATION={DONOR_CLASS_TRANSLATION}", "DONOR_USE_SYNTHETIC_POINTS=true", "NEW_COLUMN=null", ], @@ -429,6 +440,7 @@ def test_patchwork_with_origin(tmp_path_factory, recipient_path, donor_use_synth tmp_file_dir = tmp_path_factory.mktemp("data") tmp_output_las_name = "result_patchwork.laz" tmp_output_indices_map_name = "result_patchwork_indices.tif" + donor_class_translation = {2: 2, 9: 9} with initialize(version_base="1.2", config_path="../configs"): config = compose( @@ -443,6 +455,7 @@ def test_patchwork_with_origin(tmp_path_factory, recipient_path, donor_use_synth f"filepath.OUTPUT_INDICES_MAP_DIR={tmp_file_dir}", f"filepath.OUTPUT_INDICES_MAP_NAME={tmp_output_indices_map_name}", f"DONOR_CLASS_LIST={DONOR_CLASS_LIST}", + f"+DONOR_CLASS_TRANSLATION={donor_class_translation}", f"RECIPIENT_CLASS_LIST={RECIPIENT_CLASS_LIST}", f"DONOR_USE_SYNTHETIC_POINTS={donor_use_synthetic_points}", "NEW_COLUMN='Origin'", @@ -508,6 +521,7 @@ def test_patchwork_with_mount_points(tmp_path_factory, input_shp_path, recipient tmp_file_dir = tmp_path_factory.mktemp("data") tmp_output_las_name = "result_patchwork.laz" tmp_output_indices_map_name = "result_patchwork_indices.tif" + donor_class_translation = {2: 11, 9: 11} with initialize(version_base="1.2", config_path="configs"): # Use configs dir from test directory config = compose( @@ -522,6 +536,7 @@ def test_patchwork_with_mount_points(tmp_path_factory, input_shp_path, recipient f"filepath.OUTPUT_INDICES_MAP_DIR={tmp_file_dir}", f"filepath.OUTPUT_INDICES_MAP_NAME={tmp_output_indices_map_name}", f"DONOR_CLASS_LIST={DONOR_CLASS_LIST}", + f"+DONOR_CLASS_TRANSLATION={donor_class_translation}", f"RECIPIENT_CLASS_LIST={RECIPIENT_CLASS_LIST}", "NEW_COLUMN='Origin'", ], @@ -543,3 +558,6 @@ def test_patchwork_with_mount_points(tmp_path_factory, input_shp_path, recipient assert len(output_points) == len(recipient_points) + expected_nb_added_points assert np.sum(output_points.Origin == 0) == len(recipient_points) assert np.sum(output_points.Origin == 1) == expected_nb_added_points + + assert np.all(output_points.classification[output_points.Origin == 1] == 11) + assert not np.any(output_points.classification[output_points.Origin == 0] == 11)