Skip to content

Commit

Permalink
Merge branch '990-move_parameters_in_advanced' into 'master'
Browse files Browse the repository at this point in the history
Basculer "pipeline" et "geometry_plugin" dans "advanced"

Closes #990

See merge request 3d/cars-park/cars!810
  • Loading branch information
dyoussef committed Feb 20, 2025
2 parents eaa4112 + c6dc297 commit 16f995c
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 123 deletions.
19 changes: 1 addition & 18 deletions cars/cars.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,7 @@ def main_cli(args, dry_run=False): # noqa: C901
del config["output"]["out_dir"]

config_json_dir = os.path.abspath(os.path.dirname(args.conf))
pipeline_name = config.get("pipeline", "default")
old_pipelines = [
"sensors_to_dense_dsm",
"sensors_to_dense_dsm_no_merging",
"sensors_to_dense_depth_maps",
"sensors_to_dense_point_clouds",
"dense_point_clouds_to_dense_dsm",
"dense_point_clouds_to_dense_dsm_no_merging",
]
if pipeline_name in old_pipelines:
warnings.warn(
f"The 'pipeline' value {pipeline_name} corresponds to"
" an old pipeline."
"Using the default CARS pipeline instead.",
FutureWarning,
stacklevel=2,
)
pipeline_name = "default"
pipeline_name = config.get("advanced", {}).get("pipeline", "default")

# Logging configuration with args Loglevel
loglevel = getattr(args, "loglevel", "PROGRESS").upper()
Expand Down
47 changes: 13 additions & 34 deletions cars/pipelines/default/default_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@
from cars.pipelines.pipeline_constants import (
ADVANCED,
APPLICATIONS,
GEOMETRY_PLUGIN,
INPUTS,
ORCHESTRATOR,
OUTPUT,
PIPELINE,
)
from cars.pipelines.pipeline_template import PipelineTemplate

Expand Down Expand Up @@ -111,9 +109,9 @@ def __init__(self, conf, config_json_dir=None):
"""

# Used conf
self.used_conf = {PIPELINE: "default"}
self.used_conf = {}

# check global conf
# Check global conf
self.check_global_schema(conf)

# Check conf orchestrator
Expand All @@ -129,37 +127,18 @@ def __init__(self, conf, config_json_dir=None):

# Check advanced parameters
# TODO static method in the base class
advanced = advanced_parameters.check_advanced_parameters(
conf.get(ADVANCED, {}), check_epipolar_a_priori=True
(
inputs,
advanced,
self.geometry_plugin,
self.geom_plugin_without_dem_and_geoid,
self.geom_plugin_with_dem_and_geoid,
self.dem_generation_roi,
) = advanced_parameters.check_advanced_parameters(
inputs, conf.get(ADVANCED, {}), check_epipolar_a_priori=True
)
self.used_conf[ADVANCED] = advanced

if self.used_conf[INPUTS][sens_cst.SENSORS] is not None:
# Check geometry plugin and overwrite geomodel in conf inputs
(
inputs,
self.used_conf[GEOMETRY_PLUGIN],
self.geom_plugin_without_dem_and_geoid,
self.geom_plugin_with_dem_and_geoid,
self.dem_generation_roi,
) = sensor_inputs.check_geometry_plugin(
inputs, advanced, conf.get(GEOMETRY_PLUGIN, None)
)
self.used_conf[INPUTS] = inputs
elif (
depth_cst.DEPTH_MAPS in self.used_conf[INPUTS]
or dsm_cst.DSMS in self.used_conf[INPUTS]
):

# if there's an initial elevation with
# point clouds as inputs, generate a plugin (used in dsm_filling)

self.geom_plugin_with_dem_and_geoid = (
depth_map_inputs.check_geometry_plugin(
inputs, conf.get(GEOMETRY_PLUGIN, None)
)
)

# Get ROI
(
self.input_roi_poly,
Expand Down Expand Up @@ -1400,7 +1379,7 @@ def sensor_to_depth_maps(self): # noqa: C901
):
self.geom_plugin_with_dem_and_geoid = (
sensor_inputs.generate_geometry_plugin_with_dem(
self.used_conf[GEOMETRY_PLUGIN],
self.geometry_plugin,
inputs,
dem=dem_median,
)
Expand Down Expand Up @@ -1807,7 +1786,7 @@ def sensor_to_depth_maps(self): # noqa: C901
"save_intermediate_data"
] = True
new_geomplugin_dsm = AbstractGeometry( # pylint: disable=E0110
self.used_conf[GEOMETRY_PLUGIN],
self.geometry_plugin,
dem=self.used_conf[ADVANCED][adv_cst.GROUND_TRUTH_DSM][
adv_cst.INPUT_GROUND_TRUTH_DSM
],
Expand Down
59 changes: 57 additions & 2 deletions cars/pipelines/parameters/advanced_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@
from json_checker import Checker, OptionalKey, Or

from cars.pipelines.parameters import advanced_parameters_constants as adv_cst
from cars.pipelines.parameters import depth_map_inputs
from cars.pipelines.parameters import depth_map_inputs_constants as depth_cst
from cars.pipelines.parameters import dsm_inputs_constants as dsm_cst
from cars.pipelines.parameters import sensor_inputs
from cars.pipelines.parameters import sensor_inputs_constants as sens_cst
from cars.pipelines.parameters.sensor_inputs import CARS_GEOID_PATH
from cars.pipelines.pipeline_constants import ADVANCED


def check_advanced_parameters(conf, check_epipolar_a_priori=True):
def check_advanced_parameters(inputs, conf, check_epipolar_a_priori=True):
"""
Check the advanced parameters consistency
:param inputs: configuration of inputs
:type inputs: dict
:param conf: configuration of advanced parameters
:type conf: dict
:param check_epipolar_a_priori: use epipolar a priori parameters
Expand Down Expand Up @@ -99,6 +106,45 @@ def check_advanced_parameters(conf, check_epipolar_a_priori=True):
adv_cst.TERRAIN_A_PRIORI, {}
)

# Check geometry plugin
geom_plugin_without_dem_and_geoid = None
geom_plugin_with_dem_and_geoid = None
dem_generation_roi = None

# If use a priori, override initial elevation with dem_median
if adv_cst.USE_EPIPOLAR_A_PRIORI in overloaded_conf:
if overloaded_conf[adv_cst.USE_EPIPOLAR_A_PRIORI]:
if adv_cst.DEM_MEDIAN in overloaded_conf[adv_cst.TERRAIN_A_PRIORI]:
inputs[sens_cst.INITIAL_ELEVATION][sens_cst.DEM_PATH] = (
overloaded_conf[adv_cst.TERRAIN_A_PRIORI][
adv_cst.DEM_MEDIAN
]
)

if inputs[sens_cst.SENSORS] is not None:
# Check geometry plugin and overwrite geomodel in conf inputs
(
inputs,
overloaded_conf[adv_cst.GEOMETRY_PLUGIN],
geom_plugin_without_dem_and_geoid,
geom_plugin_with_dem_and_geoid,
dem_generation_roi,
) = sensor_inputs.check_geometry_plugin(
inputs, conf.get(adv_cst.GEOMETRY_PLUGIN, None)
)
elif depth_cst.DEPTH_MAPS in inputs or dsm_cst.DSMS in inputs:
# If there's an initial elevation with
# point clouds as inputs, generate a plugin (used in dsm_filling)
(
overloaded_conf[adv_cst.GEOMETRY_PLUGIN],
geom_plugin_with_dem_and_geoid,
) = depth_map_inputs.check_geometry_plugin(
inputs, conf.get(adv_cst.GEOMETRY_PLUGIN, None)
)

# Check pipeline
overloaded_conf[adv_cst.PIPELINE] = conf.get(adv_cst.PIPELINE, "default")

# Validate inputs
schema = {
adv_cst.DEBUG_WITH_ROI: bool,
Expand All @@ -107,6 +153,8 @@ def check_advanced_parameters(conf, check_epipolar_a_priori=True):
adv_cst.GROUND_TRUTH_DSM: Or(dict, str),
adv_cst.PHASING: Or(dict, None),
adv_cst.PERFORMANCE_MAP_CLASSES: Or(None, list),
adv_cst.GEOMETRY_PLUGIN: Or(str, dict),
adv_cst.PIPELINE: str,
}
if check_epipolar_a_priori:
schema[adv_cst.USE_EPIPOLAR_A_PRIORI] = bool
Expand Down Expand Up @@ -163,7 +211,14 @@ def check_advanced_parameters(conf, check_epipolar_a_priori=True):
):
validate_epipolar_a_priori(overloaded_conf, checker_epipolar)

return overloaded_conf
return (
inputs,
overloaded_conf,
overloaded_conf[adv_cst.GEOMETRY_PLUGIN],
geom_plugin_without_dem_and_geoid,
geom_plugin_with_dem_and_geoid,
dem_generation_roi,
)


def check_performance_classes(performance_map_classes):
Expand Down
4 changes: 4 additions & 0 deletions cars/pipelines/parameters/advanced_parameters_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@
INPUT_EPSG = "epsg"

PERFORMANCE_MAP_CLASSES = "performance_map_classes"

GEOMETRY_PLUGIN = "geometry_plugin"

PIPELINE = "pipeline"
4 changes: 2 additions & 2 deletions cars/pipelines/parameters/depth_map_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def check_geometry_plugin(conf_inputs, conf_geom_plugin):
dem_path = conf_inputs[sens_cst.INITIAL_ELEVATION][sens_cst.DEM_PATH]

if dem_path is None:
return None
return conf_geom_plugin, None

# Initialize a geometry plugin with elevation information
geom_plugin_with_dem_and_geoid = (
Expand All @@ -256,7 +256,7 @@ def check_geometry_plugin(conf_inputs, conf_geom_plugin):
)
)

return geom_plugin_with_dem_and_geoid
return conf_geom_plugin, geom_plugin_with_dem_and_geoid


def check_input_size(
Expand Down
11 changes: 1 addition & 10 deletions cars/pipelines/parameters/sensor_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from cars.core import inputs, preprocessing, roi_tools
from cars.core.geometry.abstract_geometry import AbstractGeometry
from cars.core.utils import make_relative_path_absolute
from cars.pipelines.parameters import advanced_parameters_constants as adv_cst
from cars.pipelines.parameters import (
depth_map_inputs_constants as depth_map_cst,
)
Expand Down Expand Up @@ -225,7 +224,7 @@ def check_sensors(conf, overloaded_conf, config_json_dir=None):
return overloaded_conf


def check_geometry_plugin(conf_inputs, conf_advanced, conf_geom_plugin):
def check_geometry_plugin(conf_inputs, conf_geom_plugin):
"""
Check the geometry plugin with inputs
Expand All @@ -251,14 +250,6 @@ def check_geometry_plugin(conf_inputs, conf_advanced, conf_geom_plugin):
)
)

# If use a priori, override initial elevation with dem_median
if adv_cst.USE_EPIPOLAR_A_PRIORI in conf_advanced:
if conf_advanced[adv_cst.USE_EPIPOLAR_A_PRIORI]:
if adv_cst.DEM_MEDIAN in conf_advanced[adv_cst.TERRAIN_A_PRIORI]:
conf_inputs[sens_cst.INITIAL_ELEVATION][sens_cst.DEM_PATH] = (
conf_advanced[adv_cst.TERRAIN_A_PRIORI][adv_cst.DEM_MEDIAN]
)

# Check products consistency with this plugin
overloaded_conf_inputs = conf_inputs.copy()
for sensor_key, sensor_image in conf_inputs[sens_cst.SENSORS].items():
Expand Down
2 changes: 0 additions & 2 deletions cars/pipelines/pipeline_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
# Sensor input

INPUTS = "inputs"
GEOMETRY_PLUGIN = "geometry_plugin"
OUTPUT = "output"
APPLICATIONS = "applications"
ADVANCED = "advanced"
ORCHESTRATOR = "orchestrator"
PIPELINE = "pipeline"
4 changes: 1 addition & 3 deletions cars/pipelines/pipeline_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from abc import ABCMeta, abstractmethod

from json_checker import Checker, OptionalKey, Or
from json_checker import Checker, OptionalKey

# CARS imports
from cars.orchestrator import orchestrator
Expand Down Expand Up @@ -68,9 +68,7 @@ def check_global_schema(self, conf):
pipeline_constants.INPUTS: dict,
pipeline_constants.OUTPUT: dict,
OptionalKey(pipeline_constants.APPLICATIONS): dict,
OptionalKey(pipeline_constants.GEOMETRY_PLUGIN): Or(str, dict),
OptionalKey(pipeline_constants.ORCHESTRATOR): dict,
OptionalKey(pipeline_constants.PIPELINE): str,
OptionalKey(pipeline_constants.ADVANCED): dict,
}

Expand Down
12 changes: 6 additions & 6 deletions docs/source/how_to_use_CARS/advanced_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ The structure follows this organization:
- Active epipolar a priori
- bool
- False
- Yes[Michel J. et al, 2020]
- Yes
* - epipolar_a_priori
- Provide epipolar a priori information (see section below)
- dict
Expand Down Expand Up @@ -960,14 +960,14 @@ The structure follows this organization:
-
- No
* - geometry_plugin
- The plugin to use
- str
-
- Name of the geometry plugin to use and optional parameters
- str or dict
- "SharelocGeometry"
- No
* - pipeline
- The pipeline to use
- Name of the pipeline to use
- str
-
- "default"
- No


Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ def generate_input_json(
if geometry_plugin_name is None:
geometry_plugin_name = get_geometry_plugin().plugin_name

config["geometry_plugin"] = geometry_plugin_name

# overload pipeline
config["pipeline"] = "default"
config["advanced"] = {
"geometry_plugin": geometry_plugin_name,
"pipeline": "default",
}

# Create keys
if "applications" not in config:
Expand Down
Loading

0 comments on commit 16f995c

Please sign in to comment.