Skip to content

Commit 6b429c7

Browse files
authored
Merge pull request #19 from IGNF/feat/combine-change-class-new-dimension
[BEHAVIOUR CHANGE] Always translate classes from donor file
2 parents 1d66221 + 1588c46 commit 6b429c7

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
- **Changement de comportement** :
4+
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 :
5+
- Si "NEW_COLUMN" est non nul, on ajoute une dimension décrivant l'origine du fichier
6+
- 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.
7+
38
## 1.3.0
49
- Possibilité d'ignorer les points synthétiques du fichier donneur (paramètre DONOR_USE_SYNTHETIC_POINTS dans le fichier de config)
510

configs/configs_patchwork.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ PATCH_SIZE: 1 # size of a patch of the grid. Must be a divisor of TILE_SIZE, so
5858
NEW_COLUMN: null # If not null, contains the name of the new column
5959
NEW_COLUMN_SIZE: 8 # must be 8, 16, 32 or 64
6060
VALUE_ADDED_POINTS: 1 # in case of a new column, value of the new point (the other are set to 0)
61-
VIRTUAL_CLASS_TRANSLATION: {2: 69, 22: 70} # if there is no new column, translate the class of DONOR_CLASS_LIST into those values
62-
# each value of DONOR_CLASS_LIST must be a key in VIRTUAL_CLASS_TRANSLATION. Not used if NEW_COLUMN is not None (or "")
61+
DONOR_CLASS_TRANSLATION: {2: 2, 22: 2} # translate the class of DONOR_CLASS_LIST into those values
62+
# each value of DONOR_CLASS_LIST must be a key in DONOR_CLASS_TRANSLATION.

patchwork/patchwork.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,14 @@ def append_points(config: DictConfig, extra_points: pd.DataFrame):
228228
for field in fields_to_keep:
229229
new_points[field] = extra_points[field].astype(new_points[field])
230230

231-
if not config.NEW_COLUMN:
232-
# translate the classification values:
233-
for classification in config.DONOR_CLASS_LIST:
234-
new_classification = config.VIRTUAL_CLASS_TRANSLATION[classification]
235-
extra_points.loc[extra_points[c.CLASSIFICATION_STR] == classification, c.CLASSIFICATION_STR] = (
236-
new_classification
237-
)
231+
# translate the classification values:
232+
for classification in config.DONOR_CLASS_LIST:
233+
new_classification = config.DONOR_CLASS_TRANSLATION[classification]
234+
extra_points.loc[extra_points[c.CLASSIFICATION_STR] == classification, c.CLASSIFICATION_STR] = (
235+
new_classification
236+
)
238237

239-
else:
238+
if config.NEW_COLUMN:
240239
extra_points[config.NEW_COLUMN] = config.VALUE_ADDED_POINTS
241240
new_points[config.NEW_COLUMN] = extra_points[config.NEW_COLUMN]
242241

test/configs/config_test_mount_points.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ PATCH_SIZE: 1 # size of a patch of the grid. Must be a divisor of TILE_SIZE, so
6161
NEW_COLUMN: null # If not null, contains the name of the new column
6262
NEW_COLUMN_SIZE: 8 # must be 8, 16, 32 or 64
6363
VALUE_ADDED_POINTS: 1 # in case of a new column, value of the new point (the other are set to 0)
64-
VIRTUAL_CLASS_TRANSLATION: {2: 69, 22: 70} # if there is no new column, translate the class of DONOR_CLASS_LIST into those values
65-
# each value of DONOR_CLASS_LIST must be a key in VIRTUAL_CLASS_TRANSLATION. Not used if NEW_COLUMN is not None (or "")
64+
DONOR_CLASS_TRANSLATION: {2: 2, 22: 2} # if there is no new column, translate the class of DONOR_CLASS_LIST into those values
65+
# each value of DONOR_CLASS_LIST must be a key in DONOR_CLASS_TRANSLATION. Not used if NEW_COLUMN is not None (or "")

test/test_patchwork.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
DONOR_CLASS_LIST = [2, 9]
2525
RECIPIENT_CLASS_LIST = [2, 3, 9, 17]
26-
VIRTUAL_CLASS_TRANSLATION = {2: 69, 9: 70}
26+
DONOR_CLASS_TRANSLATION = {2: 69, 9: 70}
2727
POINT_1 = {"x": 1, "y": 2, "z": 3, c.CLASSIFICATION_STR: 4}
2828
POINT_2 = {"x": 5, "y": 6, "z": 7, c.CLASSIFICATION_STR: 8}
2929
NEW_COLUMN = "virtual_column"
@@ -145,7 +145,7 @@ def test_get_complementary_points(donor_info_path, recipient_path, x, y, expecte
145145
overrides=[
146146
f"DONOR_CLASS_LIST={DONOR_CLASS_LIST}",
147147
f"RECIPIENT_CLASS_LIST={RECIPIENT_CLASS_LIST}",
148-
f"+VIRTUAL_CLASS_TRANSLATION={VIRTUAL_CLASS_TRANSLATION}",
148+
f"+DONOR_CLASS_TRANSLATION={DONOR_CLASS_TRANSLATION}",
149149
"DONOR_USE_SYNTHETIC_POINTS=true",
150150
],
151151
)
@@ -199,7 +199,7 @@ def test_get_complementary_points_2_more_fields(tmp_path_factory):
199199
overrides=[
200200
f"DONOR_CLASS_LIST={DONOR_CLASS_LIST}",
201201
f"RECIPIENT_CLASS_LIST={RECIPIENT_CLASS_LIST}",
202-
f"+VIRTUAL_CLASS_TRANSLATION={VIRTUAL_CLASS_TRANSLATION}",
202+
f"+DONOR_CLASS_TRANSLATION={DONOR_CLASS_TRANSLATION}",
203203
"DONOR_USE_SYNTHETIC_POINTS=true",
204204
],
205205
)
@@ -233,6 +233,9 @@ def test_append_points(tmp_path_factory):
233233
tmp_file_dir = tmp_path_factory.mktemp("data")
234234
tmp_file_name = "result.laz"
235235

236+
donor_class_list = [4, 8]
237+
donor_class_translation = {4: 44, 8: 88}
238+
236239
with initialize(version_base="1.2", config_path="../configs"):
237240
config = compose(
238241
config_name="configs_patchwork.yaml",
@@ -241,6 +244,8 @@ def test_append_points(tmp_path_factory):
241244
f"filepath.RECIPIENT_NAME={RECIPIENT_TEST_NAME}",
242245
f"filepath.OUTPUT_DIR={tmp_file_dir}",
243246
f"filepath.OUTPUT_NAME={tmp_file_name}",
247+
f"DONOR_CLASS_LIST={donor_class_list}",
248+
f"+DONOR_CLASS_TRANSLATION={donor_class_translation}",
244249
],
245250
)
246251

@@ -266,6 +271,12 @@ def test_append_points(tmp_path_factory):
266271
for point in las_recipient.points[:10]: # only 10 points, otherwise it takes too long
267272
assert point in las_output.points
268273

274+
# Original class of the first added points is 4, turned to 44 by DONOR_CLASS_TRANSLATION
275+
assert las_output.points[-2][c.CLASSIFICATION_STR] == 44
276+
277+
# Original class of the second added points is 8, turned to 88 by DONOR_CLASS_TRANSLATION
278+
assert las_output.points[-1][c.CLASSIFICATION_STR] == 88
279+
269280
# add 1 point
270281
extra_points = pd.DataFrame(
271282
data=[
@@ -282,7 +293,7 @@ def test_append_points(tmp_path_factory):
282293
extra_points = pd.DataFrame(data={"x": [], "y": [], "z": [], c.CLASSIFICATION_STR: []})
283294
append_points(config, extra_points)
284295

285-
# assert a point has been added
296+
# assert no point has been added
286297
point_count = get_point_count(recipient_file_path)
287298
assert get_point_count(output_file) == point_count
288299

@@ -369,7 +380,7 @@ def test_patchwork_default(tmp_path_factory, recipient_path, expected_nb_added_p
369380
f"filepath.OUTPUT_INDICES_MAP_NAME={tmp_output_indices_map_name}",
370381
f"DONOR_CLASS_LIST={DONOR_CLASS_LIST}",
371382
f"RECIPIENT_CLASS_LIST={RECIPIENT_CLASS_LIST}",
372-
f"+VIRTUAL_CLASS_TRANSLATION={VIRTUAL_CLASS_TRANSLATION}",
383+
f"+DONOR_CLASS_TRANSLATION={DONOR_CLASS_TRANSLATION}",
373384
"DONOR_USE_SYNTHETIC_POINTS=true",
374385
"NEW_COLUMN=null",
375386
],
@@ -429,6 +440,7 @@ def test_patchwork_with_origin(tmp_path_factory, recipient_path, donor_use_synth
429440
tmp_file_dir = tmp_path_factory.mktemp("data")
430441
tmp_output_las_name = "result_patchwork.laz"
431442
tmp_output_indices_map_name = "result_patchwork_indices.tif"
443+
donor_class_translation = {2: 2, 9: 9}
432444

433445
with initialize(version_base="1.2", config_path="../configs"):
434446
config = compose(
@@ -443,6 +455,7 @@ def test_patchwork_with_origin(tmp_path_factory, recipient_path, donor_use_synth
443455
f"filepath.OUTPUT_INDICES_MAP_DIR={tmp_file_dir}",
444456
f"filepath.OUTPUT_INDICES_MAP_NAME={tmp_output_indices_map_name}",
445457
f"DONOR_CLASS_LIST={DONOR_CLASS_LIST}",
458+
f"+DONOR_CLASS_TRANSLATION={donor_class_translation}",
446459
f"RECIPIENT_CLASS_LIST={RECIPIENT_CLASS_LIST}",
447460
f"DONOR_USE_SYNTHETIC_POINTS={donor_use_synthetic_points}",
448461
"NEW_COLUMN='Origin'",
@@ -508,6 +521,7 @@ def test_patchwork_with_mount_points(tmp_path_factory, input_shp_path, recipient
508521
tmp_file_dir = tmp_path_factory.mktemp("data")
509522
tmp_output_las_name = "result_patchwork.laz"
510523
tmp_output_indices_map_name = "result_patchwork_indices.tif"
524+
donor_class_translation = {2: 11, 9: 11}
511525

512526
with initialize(version_base="1.2", config_path="configs"): # Use configs dir from test directory
513527
config = compose(
@@ -522,6 +536,7 @@ def test_patchwork_with_mount_points(tmp_path_factory, input_shp_path, recipient
522536
f"filepath.OUTPUT_INDICES_MAP_DIR={tmp_file_dir}",
523537
f"filepath.OUTPUT_INDICES_MAP_NAME={tmp_output_indices_map_name}",
524538
f"DONOR_CLASS_LIST={DONOR_CLASS_LIST}",
539+
f"+DONOR_CLASS_TRANSLATION={donor_class_translation}",
525540
f"RECIPIENT_CLASS_LIST={RECIPIENT_CLASS_LIST}",
526541
"NEW_COLUMN='Origin'",
527542
],
@@ -543,3 +558,6 @@ def test_patchwork_with_mount_points(tmp_path_factory, input_shp_path, recipient
543558
assert len(output_points) == len(recipient_points) + expected_nb_added_points
544559
assert np.sum(output_points.Origin == 0) == len(recipient_points)
545560
assert np.sum(output_points.Origin == 1) == expected_nb_added_points
561+
562+
assert np.all(output_points.classification[output_points.Origin == 1] == 11)
563+
assert not np.any(output_points.classification[output_points.Origin == 0] == 11)

0 commit comments

Comments
 (0)