Skip to content

Commit

Permalink
Merge branch '954-cast_new_data_before_merging' into 'master'
Browse files Browse the repository at this point in the history
Cast des données avant la fusion

Closes #954

See merge request 3d/cars-park/cars!783
  • Loading branch information
dyoussef committed Dec 9, 2024
2 parents c6bb5a6 + 49502f6 commit fcdc63d
Show file tree
Hide file tree
Showing 23 changed files with 22 additions and 12 deletions.
14 changes: 10 additions & 4 deletions cars/applications/rasterization/rasterization_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,21 +867,23 @@ def update_data(
old_valid = old_weights != 0

both_valid = np.logical_and(current_valid, old_valid)
total_weight = np.zeros(shape)
total_weight[both_valid] = weights[both_valid] + old_weights[both_valid]
total_weights = np.zeros(shape)
total_weights[both_valid] = (
weights[both_valid] + old_weights[both_valid]
)

# current factor
current_factor = np.zeros(shape)
current_factor[current_valid] = 1
current_factor[both_valid] = (
weights[both_valid] / total_weight[both_valid]
weights[both_valid] / total_weights[both_valid]
)

# old factor
old_factor = np.zeros(shape)
old_factor[old_valid] = 1
old_factor[both_valid] = (
old_weights[both_valid] / total_weight[both_valid]
old_weights[both_valid] / total_weights[both_valid]
)

# assign old weights
Expand All @@ -900,6 +902,10 @@ def update_data(
new_data[old_valid] = old_data[old_valid]
new_data[current_valid] += current_data[current_valid]

# round result if saved as integer
if np.issubdtype(current_data.dtype, np.integer):
new_data = np.round(new_data).astype(current_data.dtype)

# set nodata
all_nodata = (current_valid + old_valid) == 0
new_data[all_nodata] = nodata
Expand Down
15 changes: 12 additions & 3 deletions cars/applications/rasterization/simple_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ def run( # noqa: C901 function is too complex
sigma=self.sigma,
dsm_no_data=self.dsm_no_data,
color_no_data=self.color_no_data,
color_dtype=color_dtype,
msk_no_data=self.msk_no_data,
source_pc_names=source_pc_names,
)
Expand Down Expand Up @@ -848,6 +849,7 @@ def run( # noqa: C901 function is too complex
sigma=self.sigma,
dsm_no_data=self.dsm_no_data,
color_no_data=self.color_no_data,
color_dtype=color_dtype,
msk_no_data=self.msk_no_data,
source_pc_names=source_pc_names,
)
Expand All @@ -872,6 +874,7 @@ def rasterization_wrapper(
radius: int = 1,
dsm_no_data: int = np.nan,
color_no_data: int = np.nan,
color_dtype: str = "float32",
msk_no_data: int = 255,
source_pc_names=None,
):
Expand Down Expand Up @@ -1030,13 +1033,14 @@ def rasterization_wrapper(
)

# Fill raster
attributes = {"color_type": color_dtype}
if raster is not None:
cars_dataset.fill_dataset(
raster,
saving_info=saving_info,
window=window,
profile=profile,
attributes=None,
attributes=attributes,
overlaps=None,
)

Expand All @@ -1062,8 +1066,10 @@ def raster_final_function(orchestrator, future_object):
rasterization_step.update_weights(old_weights, weights), weights.shape
)

# Get data dsm
# Get color type
color_type = future_object.attrs["attributes"]["color_type"]

# Get data dsm
for tag in future_object.keys():

if tag != cst.RASTER_WEIGHTS_SUM:
Expand All @@ -1076,12 +1082,15 @@ def raster_final_function(orchestrator, future_object):
cst.RASTER_SOURCE_PC,
]:
method = "bool"

else:
method = "basic"

old_data, nodata_raster = orchestrator.get_data(tag, future_object)
current_data = future_object[tag].values
if tag == cst.RASTER_COLOR_IMG and np.issubdtype(
color_type, np.integer
):
current_data = np.round(current_data).astype(color_type)
future_object[tag].values = np.reshape(
rasterization_step.update_data(
old_data,
Expand Down
Binary file modified tests/data/ref_output/clr_end2end_ventoux_split_no_merging.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_gizeh_crop_no_merging.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_gizeh_fill.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_gizeh_fill_with_zero.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_paca_bulldozer.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_paca_matches_filling.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_ventoux.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_ventoux_egm96.tif
Binary file not shown.
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_ventoux_no_elevation.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_ventoux_no_srtm.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_ventoux_quality_stats.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_ventoux_split_4326.tif
Binary file not shown.
Binary file modified tests/data/ref_output/color_end2end_ventoux_with_color.tif
Binary file not shown.
Binary file not shown.
Binary file modified tests/data/ref_output/dsm_end2end_ventoux_quality_stats.tif
Binary file not shown.
Binary file modified tests/data/ref_output/dsm_mean_end2end_ventoux_quality_stats.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/data/ref_output/dsm_std_end2end_ventoux_quality_stats.tif
Binary file not shown.
5 changes: 0 additions & 5 deletions tests/test_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -2926,8 +2926,6 @@ def test_end2end_ventoux_with_color():
input_config_dense_dsm["pipeline"] = "sensors_to_dense_dsm"
input_config_dense_dsm["output"]["product_level"] = ["dsm"]

print(json.dumps(input_config_dense_dsm, indent=4))

dense_dsm_pipeline = default.DefaultPipeline(input_config_dense_dsm)
dense_dsm_pipeline.run()

Expand Down Expand Up @@ -3663,7 +3661,6 @@ def test_end2end_quality_stats():
# Save all intermediate data and add merging
input_config_dense_dsm["advanced"] = {
"save_intermediate_data": True,
"merging": True,
}

dense_dsm_pipeline = default.DefaultPipeline(input_config_dense_dsm)
Expand Down Expand Up @@ -4294,8 +4291,6 @@ def test_end2end_paca_with_mask():
resolution = 0.5
input_config_dense_dsm["output"]["resolution"] = resolution

print(json.dumps(input_config_dense_dsm, indent=4))

dense_dsm_pipeline_bulldozer = default.DefaultPipeline(
input_config_dense_dsm
)
Expand Down

0 comments on commit fcdc63d

Please sign in to comment.