Skip to content

Commit

Permalink
Merge branch 'update-cars-starter' into 'master'
Browse files Browse the repository at this point in the history
feat: update cars-starter

See merge request 3d/cars-park/cars!785
  • Loading branch information
dyoussef committed Dec 10, 2024
2 parents fcdc63d + bed0407 commit 05189ea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 60 deletions.
68 changes: 17 additions & 51 deletions cars/starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,6 @@ def inputfilename_to_sensor(inputfilename):
return sensor


def pairdirname_to_pc(pairdirname):
"""
Fill sensor dictionary according to an pair directory
"""
sensor = {}

abspairdirname = os.path.abspath(pairdirname)

for coord in ["X", "Y", "Z"]:
bandname = os.path.join(abspairdirname, "epi_pc_" + coord + ".tif")
if os.path.isfile(bandname) is False:
raise FileNotFoundError(bandname + " does not exist")
sensor[coord.lower()] = bandname

for extra in ["color"]:
bandname = os.path.join(abspairdirname, "epi_pc_" + extra + ".tif")
if os.path.isfile(bandname):
sensor[extra] = bandname

return sensor


def cars_starter(cli_params: dict = None, **kwargs) -> None:
"""
Main fonction. Expects a dictionary from the CLI (cli_params)
Expand All @@ -98,36 +76,24 @@ def cars_starter(cli_params: dict = None, **kwargs) -> None:
)
config = kwargs

# check first input in list to determine pipeline
if os.path.isfile(config["il"][0]):
cars_config = {"inputs": {"sensors": {}}, "output": {}}
pipeline_name = "sensors_to_dense_dsm"
cars_config = {"inputs": {"sensors": {}}, "output": {}}
pipeline_name = "default"

for idx, inputfilename in enumerate(config["il"]):
cars_config["inputs"]["sensors"][str(idx)] = (
inputfilename_to_sensor(inputfilename)
)

# pairing with first image as reference
pairing = list(
zip( # noqa: B905
["0"] * (len(config["il"]) - 1),
map(str, range(1, len(config["il"]))),
)
for idx, inputfilename in enumerate(config["il"]):
cars_config["inputs"]["sensors"][str(idx)] = inputfilename_to_sensor(
inputfilename
)

cars_config["inputs"]["pairing"] = pairing

else:
cars_config = {"inputs": {"point_clouds": {}}, "output": {}}
pipeline_name = "dense_point_clouds_to_dense_dsm"

for idx, pairdirname in enumerate(config["il"]):
cars_config["inputs"]["point_clouds"][str(idx)] = pairdirname_to_pc(
pairdirname
)
# pairing with first image as reference
pairing = list(
zip( # noqa: B905
["0"] * (len(config["il"]) - 1),
map(str, range(1, len(config["il"]))),
)
)

cars_config["output"]["out_dir"] = config["out"]
cars_config["inputs"]["pairing"] = pairing
cars_config["output"]["directory"] = config["out"]

check = config["check"] if "check" in config.keys() else False
full = config["full"] if "full" in config.keys() else False
Expand All @@ -140,7 +106,7 @@ def cars_starter(cli_params: dict = None, **kwargs) -> None:
if full:
cars_config = used_pipeline.used_conf

print(json.dumps(cars_config, indent=4))
print(json.dumps(cars_config, indent=2))


def cli():
Expand All @@ -154,8 +120,8 @@ def cli():
"-il",
type=str,
nargs="*",
metavar="input.{tif,XML} or pair_dir",
help="Inputs list or Pairs directory list",
metavar="input.{tif,XML}",
help="Input sensor list",
required=True,
)

Expand Down
18 changes: 9 additions & 9 deletions docs/source/usage/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ Note that ``cars-starter`` script can be used to instantiate this configuration
.. code-block:: console
cars-starter -h
usage: cars-starter [-h] -il [input.{tif,XML} or pair_dir [input.{tif,XML} or pair_dir ...]] -out out_dir [--full] [--check]
Helper to create configuration file
usage: cars-starter [-h] -il [input.{tif,XML} ...] -out out_dir [--full] [--check]
optional arguments:
-h, --help show this help message and exit
-il [input.{tif,XML} or pair_dir [input.{tif,XML} or pair_dir ...]]
Inputs list or Pairs directory list
-out out_dir Output directory
--full Fill all default values
--check Check inputs
Helper to create configuration file
options:
-h, --help show this help message and exit
-il [input.{tif,XML} ...]
Input sensor list
-out out_dir Output directory
--full Fill all default values
--check Check inputs
Finally, an output ``used_conf.json`` file will be created on the output directory. This file contains all the parameters used during execution and can be used as an input configuration file to re-run cars.

0 comments on commit 05189ea

Please sign in to comment.