cars 1.0.0rc3__cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cars/__init__.py +74 -0
- cars/applications/__init__.py +40 -0
- cars/applications/application.py +117 -0
- cars/applications/application_constants.py +29 -0
- cars/applications/application_template.py +146 -0
- cars/applications/auxiliary_filling/__init__.py +29 -0
- cars/applications/auxiliary_filling/abstract_auxiliary_filling_app.py +105 -0
- cars/applications/auxiliary_filling/auxiliary_filling_algo.py +475 -0
- cars/applications/auxiliary_filling/auxiliary_filling_from_sensors_app.py +632 -0
- cars/applications/auxiliary_filling/auxiliary_filling_wrappers.py +90 -0
- cars/applications/dem_generation/__init__.py +30 -0
- cars/applications/dem_generation/abstract_dem_generation_app.py +116 -0
- cars/applications/dem_generation/bulldozer_config/base_config.yaml +46 -0
- cars/applications/dem_generation/bulldozer_dem_app.py +641 -0
- cars/applications/dem_generation/bulldozer_memory.py +55 -0
- cars/applications/dem_generation/dem_generation_algo.py +107 -0
- cars/applications/dem_generation/dem_generation_constants.py +32 -0
- cars/applications/dem_generation/dem_generation_wrappers.py +323 -0
- cars/applications/dense_match_filling/__init__.py +30 -0
- cars/applications/dense_match_filling/abstract_dense_match_filling_app.py +242 -0
- cars/applications/dense_match_filling/fill_disp_algo.py +113 -0
- cars/applications/dense_match_filling/fill_disp_constants.py +39 -0
- cars/applications/dense_match_filling/fill_disp_wrappers.py +83 -0
- cars/applications/dense_match_filling/zero_padding_app.py +302 -0
- cars/applications/dense_matching/__init__.py +30 -0
- cars/applications/dense_matching/abstract_dense_matching_app.py +261 -0
- cars/applications/dense_matching/census_mccnn_sgm_app.py +1461 -0
- cars/applications/dense_matching/cpp/__init__.py +0 -0
- cars/applications/dense_matching/cpp/dense_matching_cpp.cpython-313-x86_64-linux-gnu.so +0 -0
- cars/applications/dense_matching/cpp/dense_matching_cpp.py +94 -0
- cars/applications/dense_matching/cpp/includes/dense_matching.hpp +58 -0
- cars/applications/dense_matching/cpp/meson.build +9 -0
- cars/applications/dense_matching/cpp/src/bindings.cpp +13 -0
- cars/applications/dense_matching/cpp/src/dense_matching.cpp +207 -0
- cars/applications/dense_matching/dense_matching_algo.py +401 -0
- cars/applications/dense_matching/dense_matching_constants.py +89 -0
- cars/applications/dense_matching/dense_matching_wrappers.py +951 -0
- cars/applications/dense_matching/disparity_grid_algo.py +597 -0
- cars/applications/dense_matching/loaders/__init__.py +23 -0
- cars/applications/dense_matching/loaders/config_census_sgm_default.json +31 -0
- cars/applications/dense_matching/loaders/config_census_sgm_homogeneous.json +30 -0
- cars/applications/dense_matching/loaders/config_census_sgm_mountain_and_vegetation.json +30 -0
- cars/applications/dense_matching/loaders/config_census_sgm_shadow.json +30 -0
- cars/applications/dense_matching/loaders/config_census_sgm_sparse.json +36 -0
- cars/applications/dense_matching/loaders/config_census_sgm_urban.json +30 -0
- cars/applications/dense_matching/loaders/config_mapping.json +13 -0
- cars/applications/dense_matching/loaders/config_mccnn.json +28 -0
- cars/applications/dense_matching/loaders/global_land_cover_map.tif +0 -0
- cars/applications/dense_matching/loaders/pandora_loader.py +593 -0
- cars/applications/dsm_filling/__init__.py +32 -0
- cars/applications/dsm_filling/abstract_dsm_filling_app.py +101 -0
- cars/applications/dsm_filling/border_interpolation_app.py +278 -0
- cars/applications/dsm_filling/bulldozer_config/base_config.yaml +44 -0
- cars/applications/dsm_filling/bulldozer_filling_app.py +288 -0
- cars/applications/dsm_filling/exogenous_filling_app.py +341 -0
- cars/applications/dsm_merging/__init__.py +28 -0
- cars/applications/dsm_merging/abstract_dsm_merging_app.py +101 -0
- cars/applications/dsm_merging/weighted_fusion_app.py +639 -0
- cars/applications/grid_correction/__init__.py +30 -0
- cars/applications/grid_correction/abstract_grid_correction_app.py +103 -0
- cars/applications/grid_correction/grid_correction_app.py +557 -0
- cars/applications/grid_generation/__init__.py +30 -0
- cars/applications/grid_generation/abstract_grid_generation_app.py +142 -0
- cars/applications/grid_generation/epipolar_grid_generation_app.py +327 -0
- cars/applications/grid_generation/grid_generation_algo.py +388 -0
- cars/applications/grid_generation/grid_generation_constants.py +46 -0
- cars/applications/grid_generation/transform_grid.py +88 -0
- cars/applications/ground_truth_reprojection/__init__.py +30 -0
- cars/applications/ground_truth_reprojection/abstract_ground_truth_reprojection_app.py +137 -0
- cars/applications/ground_truth_reprojection/direct_localization_app.py +629 -0
- cars/applications/ground_truth_reprojection/ground_truth_reprojection_algo.py +275 -0
- cars/applications/point_cloud_outlier_removal/__init__.py +30 -0
- cars/applications/point_cloud_outlier_removal/abstract_outlier_removal_app.py +385 -0
- cars/applications/point_cloud_outlier_removal/outlier_removal_algo.py +392 -0
- cars/applications/point_cloud_outlier_removal/outlier_removal_constants.py +43 -0
- cars/applications/point_cloud_outlier_removal/small_components_app.py +522 -0
- cars/applications/point_cloud_outlier_removal/statistical_app.py +528 -0
- cars/applications/rasterization/__init__.py +30 -0
- cars/applications/rasterization/abstract_pc_rasterization_app.py +183 -0
- cars/applications/rasterization/rasterization_algo.py +534 -0
- cars/applications/rasterization/rasterization_constants.py +38 -0
- cars/applications/rasterization/rasterization_wrappers.py +639 -0
- cars/applications/rasterization/simple_gaussian_app.py +1152 -0
- cars/applications/resampling/__init__.py +28 -0
- cars/applications/resampling/abstract_resampling_app.py +187 -0
- cars/applications/resampling/bicubic_resampling_app.py +760 -0
- cars/applications/resampling/resampling_algo.py +590 -0
- cars/applications/resampling/resampling_constants.py +36 -0
- cars/applications/resampling/resampling_wrappers.py +309 -0
- cars/applications/sensors_subsampling/__init__.py +32 -0
- cars/applications/sensors_subsampling/abstract_subsampling_app.py +109 -0
- cars/applications/sensors_subsampling/rasterio_subsampling_app.py +420 -0
- cars/applications/sensors_subsampling/subsampling_algo.py +108 -0
- cars/applications/sparse_matching/__init__.py +30 -0
- cars/applications/sparse_matching/abstract_sparse_matching_app.py +599 -0
- cars/applications/sparse_matching/sift_app.py +724 -0
- cars/applications/sparse_matching/sparse_matching_algo.py +360 -0
- cars/applications/sparse_matching/sparse_matching_constants.py +66 -0
- cars/applications/sparse_matching/sparse_matching_wrappers.py +282 -0
- cars/applications/triangulation/__init__.py +32 -0
- cars/applications/triangulation/abstract_triangulation_app.py +227 -0
- cars/applications/triangulation/line_of_sight_intersection_app.py +1243 -0
- cars/applications/triangulation/pc_transform.py +552 -0
- cars/applications/triangulation/triangulation_algo.py +371 -0
- cars/applications/triangulation/triangulation_constants.py +38 -0
- cars/applications/triangulation/triangulation_wrappers.py +259 -0
- cars/bundleadjustment.py +750 -0
- cars/cars.py +179 -0
- cars/conf/__init__.py +23 -0
- cars/conf/geoid/egm96.grd +0 -0
- cars/conf/geoid/egm96.grd.hdr +15 -0
- cars/conf/input_parameters.py +156 -0
- cars/conf/mask_cst.py +35 -0
- cars/core/__init__.py +23 -0
- cars/core/cars_logging.py +402 -0
- cars/core/constants.py +191 -0
- cars/core/constants_disparity.py +50 -0
- cars/core/datasets.py +140 -0
- cars/core/geometry/__init__.py +27 -0
- cars/core/geometry/abstract_geometry.py +1130 -0
- cars/core/geometry/shareloc_geometry.py +604 -0
- cars/core/inputs.py +568 -0
- cars/core/outputs.py +176 -0
- cars/core/preprocessing.py +722 -0
- cars/core/projection.py +843 -0
- cars/core/roi_tools.py +215 -0
- cars/core/tiling.py +774 -0
- cars/core/utils.py +164 -0
- cars/data_structures/__init__.py +23 -0
- cars/data_structures/cars_dataset.py +1544 -0
- cars/data_structures/cars_dict.py +74 -0
- cars/data_structures/corresponding_tiles_tools.py +186 -0
- cars/data_structures/dataframe_converter.py +185 -0
- cars/data_structures/format_transformation.py +297 -0
- cars/devibrate.py +689 -0
- cars/extractroi.py +264 -0
- cars/orchestrator/__init__.py +23 -0
- cars/orchestrator/achievement_tracker.py +125 -0
- cars/orchestrator/cluster/__init__.py +37 -0
- cars/orchestrator/cluster/abstract_cluster.py +250 -0
- cars/orchestrator/cluster/abstract_dask_cluster.py +381 -0
- cars/orchestrator/cluster/dask_cluster_tools.py +103 -0
- cars/orchestrator/cluster/dask_config/README.md +94 -0
- cars/orchestrator/cluster/dask_config/dask.yaml +21 -0
- cars/orchestrator/cluster/dask_config/distributed.yaml +70 -0
- cars/orchestrator/cluster/dask_config/jobqueue.yaml +26 -0
- cars/orchestrator/cluster/dask_config/reference_confs/dask-schema.yaml +137 -0
- cars/orchestrator/cluster/dask_config/reference_confs/dask.yaml +26 -0
- cars/orchestrator/cluster/dask_config/reference_confs/distributed-schema.yaml +1009 -0
- cars/orchestrator/cluster/dask_config/reference_confs/distributed.yaml +273 -0
- cars/orchestrator/cluster/dask_config/reference_confs/jobqueue.yaml +212 -0
- cars/orchestrator/cluster/dask_jobqueue_utils.py +204 -0
- cars/orchestrator/cluster/local_dask_cluster.py +116 -0
- cars/orchestrator/cluster/log_wrapper.py +728 -0
- cars/orchestrator/cluster/mp_cluster/__init__.py +27 -0
- cars/orchestrator/cluster/mp_cluster/mp_factorizer.py +212 -0
- cars/orchestrator/cluster/mp_cluster/mp_objects.py +535 -0
- cars/orchestrator/cluster/mp_cluster/mp_tools.py +93 -0
- cars/orchestrator/cluster/mp_cluster/mp_wrapper.py +505 -0
- cars/orchestrator/cluster/mp_cluster/multiprocessing_cluster.py +986 -0
- cars/orchestrator/cluster/mp_cluster/multiprocessing_profiler.py +399 -0
- cars/orchestrator/cluster/pbs_dask_cluster.py +207 -0
- cars/orchestrator/cluster/sequential_cluster.py +139 -0
- cars/orchestrator/cluster/slurm_dask_cluster.py +234 -0
- cars/orchestrator/memory_tools.py +47 -0
- cars/orchestrator/orchestrator.py +755 -0
- cars/orchestrator/orchestrator_constants.py +29 -0
- cars/orchestrator/registry/__init__.py +23 -0
- cars/orchestrator/registry/abstract_registry.py +143 -0
- cars/orchestrator/registry/compute_registry.py +106 -0
- cars/orchestrator/registry/id_generator.py +116 -0
- cars/orchestrator/registry/replacer_registry.py +213 -0
- cars/orchestrator/registry/saver_registry.py +363 -0
- cars/orchestrator/registry/unseen_registry.py +118 -0
- cars/orchestrator/tiles_profiler.py +279 -0
- cars/pipelines/__init__.py +26 -0
- cars/pipelines/conf_resolution/conf_final_resolution.yaml +5 -0
- cars/pipelines/conf_resolution/conf_first_resolution.yaml +4 -0
- cars/pipelines/conf_resolution/conf_intermediate_resolution.yaml +2 -0
- cars/pipelines/default/__init__.py +26 -0
- cars/pipelines/default/default_pipeline.py +1095 -0
- cars/pipelines/filling/__init__.py +26 -0
- cars/pipelines/filling/filling.py +981 -0
- cars/pipelines/formatting/__init__.py +26 -0
- cars/pipelines/formatting/formatting.py +190 -0
- cars/pipelines/merging/__init__.py +26 -0
- cars/pipelines/merging/merging.py +439 -0
- cars/pipelines/parameters/__init__.py +0 -0
- cars/pipelines/parameters/advanced_parameters.py +256 -0
- cars/pipelines/parameters/advanced_parameters_constants.py +68 -0
- cars/pipelines/parameters/application_parameters.py +72 -0
- cars/pipelines/parameters/depth_map_inputs.py +0 -0
- cars/pipelines/parameters/dsm_inputs.py +349 -0
- cars/pipelines/parameters/dsm_inputs_constants.py +25 -0
- cars/pipelines/parameters/output_constants.py +52 -0
- cars/pipelines/parameters/output_parameters.py +435 -0
- cars/pipelines/parameters/sensor_inputs.py +859 -0
- cars/pipelines/parameters/sensor_inputs_constants.py +51 -0
- cars/pipelines/parameters/sensor_loaders/__init__.py +29 -0
- cars/pipelines/parameters/sensor_loaders/basic_classif_loader.py +86 -0
- cars/pipelines/parameters/sensor_loaders/basic_image_loader.py +98 -0
- cars/pipelines/parameters/sensor_loaders/pivot_classif_loader.py +90 -0
- cars/pipelines/parameters/sensor_loaders/pivot_image_loader.py +105 -0
- cars/pipelines/parameters/sensor_loaders/sensor_loader.py +93 -0
- cars/pipelines/parameters/sensor_loaders/sensor_loader_template.py +71 -0
- cars/pipelines/parameters/sensor_loaders/slurp_classif_loader.py +86 -0
- cars/pipelines/pipeline.py +119 -0
- cars/pipelines/pipeline_constants.py +38 -0
- cars/pipelines/pipeline_template.py +135 -0
- cars/pipelines/subsampling/__init__.py +26 -0
- cars/pipelines/subsampling/subsampling.py +358 -0
- cars/pipelines/surface_modeling/__init__.py +26 -0
- cars/pipelines/surface_modeling/surface_modeling.py +2098 -0
- cars/pipelines/tie_points/__init__.py +26 -0
- cars/pipelines/tie_points/tie_points.py +536 -0
- cars/starter.py +167 -0
- cars-1.0.0rc3.dist-info/METADATA +289 -0
- cars-1.0.0rc3.dist-info/RECORD +220 -0
- cars-1.0.0rc3.dist-info/WHEEL +6 -0
- cars-1.0.0rc3.dist-info/entry_points.txt +8 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# coding: utf8
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2020 Centre National d'Etudes Spatiales (CNES).
|
|
5
|
+
#
|
|
6
|
+
# This file is part of CARS
|
|
7
|
+
# (see https://github.com/CNES/cars).
|
|
8
|
+
#
|
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
# you may not use this file except in compliance with the License.
|
|
11
|
+
# You may obtain a copy of the License at
|
|
12
|
+
#
|
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
#
|
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
# See the License for the specific language governing permissions and
|
|
19
|
+
# limitations under the License.
|
|
20
|
+
#
|
|
21
|
+
"""
|
|
22
|
+
this module contains the dense_matching application class.
|
|
23
|
+
"""
|
|
24
|
+
import copy
|
|
25
|
+
import os
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
|
|
28
|
+
# Standard imports
|
|
29
|
+
from typing import Dict, Tuple
|
|
30
|
+
|
|
31
|
+
import rasterio
|
|
32
|
+
import xarray as xr
|
|
33
|
+
from affine import Affine
|
|
34
|
+
from json_checker import Checker
|
|
35
|
+
|
|
36
|
+
import cars.orchestrator.orchestrator as ocht
|
|
37
|
+
from cars.applications.resampling import (
|
|
38
|
+
resampling_wrappers,
|
|
39
|
+
)
|
|
40
|
+
from cars.applications.sensors_subsampling import (
|
|
41
|
+
abstract_subsampling_app as ssa,
|
|
42
|
+
)
|
|
43
|
+
from cars.applications.sensors_subsampling import (
|
|
44
|
+
subsampling_algo,
|
|
45
|
+
)
|
|
46
|
+
from cars.core import constants as cst
|
|
47
|
+
from cars.core import inputs, tiling
|
|
48
|
+
from cars.core.utils import safe_makedirs
|
|
49
|
+
from cars.data_structures import cars_dataset
|
|
50
|
+
from cars.pipelines.parameters import sensor_inputs_constants as sens_cst
|
|
51
|
+
|
|
52
|
+
# pylint: disable= C0302
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class RasterioSubsampling(ssa.SensorsSubsampling, short_name=["rasterio"]):
|
|
56
|
+
"""
|
|
57
|
+
SensorsSubsampling
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
def __init__(self, conf=None):
|
|
61
|
+
"""
|
|
62
|
+
Init function of SensorsSubsampling
|
|
63
|
+
|
|
64
|
+
:param conf: configuration for SensorsSubsampling
|
|
65
|
+
:return: an application_to_use object
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
super().__init__(conf=conf)
|
|
69
|
+
# check conf
|
|
70
|
+
self.used_method = self.used_config["method"]
|
|
71
|
+
|
|
72
|
+
self.tile_size = self.used_config["tile_size"]
|
|
73
|
+
|
|
74
|
+
self.interpolator_image = self.used_config["interpolator_image"]
|
|
75
|
+
self.interpolator_classif = self.used_config["interpolator_classif"]
|
|
76
|
+
self.interpolator_mask = self.used_config["interpolator_mask"]
|
|
77
|
+
|
|
78
|
+
# Init orchestrator
|
|
79
|
+
self.orchestrator = None
|
|
80
|
+
|
|
81
|
+
def check_conf(self, conf):
|
|
82
|
+
"""
|
|
83
|
+
Check configuration
|
|
84
|
+
|
|
85
|
+
:param conf: configuration to check
|
|
86
|
+
:type conf: dict
|
|
87
|
+
|
|
88
|
+
:return: overloaded configuration
|
|
89
|
+
:rtype: dict
|
|
90
|
+
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
# init conf
|
|
94
|
+
if conf is not None:
|
|
95
|
+
overloaded_conf = conf.copy()
|
|
96
|
+
else:
|
|
97
|
+
conf = {}
|
|
98
|
+
overloaded_conf = {}
|
|
99
|
+
|
|
100
|
+
# Overload conf
|
|
101
|
+
overloaded_conf["method"] = conf.get("method", "rasterio")
|
|
102
|
+
|
|
103
|
+
overloaded_conf["tile_size"] = conf.get("tile_size", 10000)
|
|
104
|
+
|
|
105
|
+
overloaded_conf["interpolator_image"] = conf.get(
|
|
106
|
+
"interpolator_image", "bilinear"
|
|
107
|
+
)
|
|
108
|
+
overloaded_conf["interpolator_classif"] = conf.get(
|
|
109
|
+
"interpolator_classif", "nearest"
|
|
110
|
+
)
|
|
111
|
+
overloaded_conf["interpolator_mask"] = conf.get(
|
|
112
|
+
"interpolator_mask", "nearest"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
subsampling_schema = {
|
|
116
|
+
"method": str,
|
|
117
|
+
"tile_size": int,
|
|
118
|
+
"interpolator_image": str,
|
|
119
|
+
"interpolator_mask": str,
|
|
120
|
+
"interpolator_classif": str,
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
# Check conf
|
|
124
|
+
checker = Checker(subsampling_schema)
|
|
125
|
+
checker.validate(overloaded_conf)
|
|
126
|
+
|
|
127
|
+
return overloaded_conf
|
|
128
|
+
|
|
129
|
+
def update_profile(self, img_path, scale_factor):
|
|
130
|
+
"""
|
|
131
|
+
Update rasterio profile
|
|
132
|
+
|
|
133
|
+
:param img_path: the image path
|
|
134
|
+
:type img_path: str
|
|
135
|
+
:param scale_factor: the scaling factor
|
|
136
|
+
:type scale_factor: float
|
|
137
|
+
"""
|
|
138
|
+
with rasterio.open(img_path) as src:
|
|
139
|
+
height = src.height
|
|
140
|
+
width = src.width
|
|
141
|
+
|
|
142
|
+
new_height = int(height * scale_factor)
|
|
143
|
+
new_width = int(width * scale_factor)
|
|
144
|
+
|
|
145
|
+
transform = src.transform
|
|
146
|
+
new_transform = transform * Affine.scale(
|
|
147
|
+
(width / new_width), (height / new_height)
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
profile = src.profile.copy()
|
|
151
|
+
profile.update(
|
|
152
|
+
{
|
|
153
|
+
"height": new_height,
|
|
154
|
+
"width": new_width,
|
|
155
|
+
"transform": new_transform,
|
|
156
|
+
"driver": "GTiff",
|
|
157
|
+
"compress": "lzw",
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
return profile, height, width
|
|
162
|
+
|
|
163
|
+
def get_paths_dictionary(self, sensor_dict):
|
|
164
|
+
"""
|
|
165
|
+
Get the paths dictionary
|
|
166
|
+
|
|
167
|
+
:param sensor_dict: the sensor dictionary (classification, image...)
|
|
168
|
+
:type sensor_dict: dict
|
|
169
|
+
"""
|
|
170
|
+
# get images, no data and classifs
|
|
171
|
+
image_dict = resampling_wrappers.get_paths_and_bands_from_image(
|
|
172
|
+
sensor_dict[sens_cst.INPUT_IMG],
|
|
173
|
+
None,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
image = next(iter(image_dict))
|
|
177
|
+
|
|
178
|
+
mask = sensor_dict.get(sens_cst.INPUT_MSK, None)
|
|
179
|
+
|
|
180
|
+
classif = sensor_dict.get(sens_cst.INPUT_CLASSIFICATION, None)
|
|
181
|
+
classif_path = None
|
|
182
|
+
if classif is not None:
|
|
183
|
+
classif = resampling_wrappers.get_path_and_values_from_classif(
|
|
184
|
+
classif
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
classif_path = next(iter(classif))
|
|
188
|
+
|
|
189
|
+
paths_dictionary = {"im": image, "mask": mask, "classif": classif_path}
|
|
190
|
+
|
|
191
|
+
for step, key in enumerate(list(image_dict.keys())[1:]):
|
|
192
|
+
paths_dictionary[f"texture_{step}"] = key
|
|
193
|
+
|
|
194
|
+
for key, path in paths_dictionary.items():
|
|
195
|
+
paths_dictionary[key] = {"path": path}
|
|
196
|
+
|
|
197
|
+
paths_dictionary[key]["nodata"] = None
|
|
198
|
+
paths_dictionary[key]["dtype"] = None
|
|
199
|
+
if path is not None:
|
|
200
|
+
paths_dictionary[key]["nodata"] = inputs.rasterio_get_nodata(
|
|
201
|
+
path
|
|
202
|
+
)
|
|
203
|
+
paths_dictionary[key]["dtype"] = inputs.rasterio_get_dtype(path)
|
|
204
|
+
|
|
205
|
+
return paths_dictionary
|
|
206
|
+
|
|
207
|
+
def run( # pylint: disable=too-many-positional-arguments
|
|
208
|
+
self,
|
|
209
|
+
id_image,
|
|
210
|
+
sensor_dict,
|
|
211
|
+
resolution,
|
|
212
|
+
out_directory,
|
|
213
|
+
orchestrator,
|
|
214
|
+
):
|
|
215
|
+
"""
|
|
216
|
+
Run subsampling using rasterio
|
|
217
|
+
|
|
218
|
+
:param id_image: the id of the image
|
|
219
|
+
:type id_image: str
|
|
220
|
+
:param sensor_dict: the sensor dictionnary (image, classification...)
|
|
221
|
+
:type sensor_dict: dict
|
|
222
|
+
:param resolution: the subsampling resolution
|
|
223
|
+
:type resolution: int
|
|
224
|
+
:param out_directory: the output directory
|
|
225
|
+
:type out_directory: str
|
|
226
|
+
:param orchestrator: orchestrator used
|
|
227
|
+
"""
|
|
228
|
+
|
|
229
|
+
# Default orchestrator
|
|
230
|
+
if orchestrator is None:
|
|
231
|
+
# Create default sequential orchestrator for current application
|
|
232
|
+
# be awere, no out_json will be shared between orchestrators
|
|
233
|
+
# No files saved
|
|
234
|
+
self.orchestrator = ocht.Orchestrator(
|
|
235
|
+
orchestrator_conf={"mode": "sequential"}
|
|
236
|
+
)
|
|
237
|
+
else:
|
|
238
|
+
self.orchestrator = orchestrator
|
|
239
|
+
|
|
240
|
+
# Create CarsDataset
|
|
241
|
+
# images
|
|
242
|
+
image_subsampled = cars_dataset.CarsDataset(
|
|
243
|
+
"arrays", name="subsampling_left_" + str(resolution)
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
# Define the scale factor
|
|
247
|
+
scale_factor = 1 / resolution
|
|
248
|
+
|
|
249
|
+
# put a multiple of the resolution for tiling to avoid artefacts
|
|
250
|
+
self.tile_size = int(self.tile_size * scale_factor) * resolution
|
|
251
|
+
|
|
252
|
+
# Define the path of each image
|
|
253
|
+
img_path = sensor_dict[sens_cst.INPUT_IMG]["bands"]["b0"]["path"]
|
|
254
|
+
|
|
255
|
+
# update profile of each image
|
|
256
|
+
new_profile, height, width = self.update_profile(img_path, scale_factor)
|
|
257
|
+
|
|
258
|
+
# Get saving infos in order to save tiles when they are computed
|
|
259
|
+
[
|
|
260
|
+
saving_info,
|
|
261
|
+
] = self.orchestrator.get_saving_infos([image_subsampled])
|
|
262
|
+
|
|
263
|
+
# Build paths dictionnary
|
|
264
|
+
paths_dictionary = self.get_paths_dictionary(sensor_dict)
|
|
265
|
+
|
|
266
|
+
# Define tiling grid
|
|
267
|
+
tiling_grid = tiling.generate_tiling_grid(
|
|
268
|
+
0,
|
|
269
|
+
0,
|
|
270
|
+
height,
|
|
271
|
+
width,
|
|
272
|
+
self.tile_size,
|
|
273
|
+
self.tile_size,
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
# Compute tiling grid
|
|
277
|
+
image_subsampled.tiling_grid = tiling_grid
|
|
278
|
+
|
|
279
|
+
# Save files
|
|
280
|
+
safe_makedirs(os.path.join(out_directory, id_image))
|
|
281
|
+
for key, val in paths_dictionary.items():
|
|
282
|
+
path = val["path"]
|
|
283
|
+
dtype_val = val["dtype"]
|
|
284
|
+
nodata_val = val["nodata"]
|
|
285
|
+
|
|
286
|
+
if key == "classif":
|
|
287
|
+
dtype = dtype_val
|
|
288
|
+
optional_data = True
|
|
289
|
+
nodata = nodata_val
|
|
290
|
+
else:
|
|
291
|
+
dtype = dtype_val
|
|
292
|
+
nodata = nodata_val
|
|
293
|
+
optional_data = False
|
|
294
|
+
|
|
295
|
+
if path is not None:
|
|
296
|
+
name_file = Path(path).stem
|
|
297
|
+
orchestrator.add_to_save_lists(
|
|
298
|
+
os.path.join(out_directory, id_image, name_file + ".tif"),
|
|
299
|
+
key,
|
|
300
|
+
image_subsampled,
|
|
301
|
+
dtype=dtype,
|
|
302
|
+
nodata=nodata,
|
|
303
|
+
optional_data=optional_data,
|
|
304
|
+
cars_ds_name="subsampling_"
|
|
305
|
+
+ key
|
|
306
|
+
+ "_res_"
|
|
307
|
+
+ str(resolution),
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
# Generate Image pair
|
|
311
|
+
for col in range(image_subsampled.shape[1]):
|
|
312
|
+
for row in range(image_subsampled.shape[0]):
|
|
313
|
+
|
|
314
|
+
# update saving infos for potential replacement
|
|
315
|
+
full_saving_info = ocht.update_saving_infos(
|
|
316
|
+
saving_info, row=row, col=col
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
window = image_subsampled.get_window_as_dict(row, col)
|
|
320
|
+
# Compute images
|
|
321
|
+
(
|
|
322
|
+
image_subsampled[row, col]
|
|
323
|
+
) = self.orchestrator.cluster.create_task(
|
|
324
|
+
generate_subsampled_images_wrapper, nout=1
|
|
325
|
+
)(
|
|
326
|
+
paths_dictionary,
|
|
327
|
+
new_profile,
|
|
328
|
+
scale_factor,
|
|
329
|
+
self.tile_size,
|
|
330
|
+
window=window,
|
|
331
|
+
saving_info=full_saving_info,
|
|
332
|
+
)
|
|
333
|
+
return image_subsampled
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
# pylint: disable=too-many-positional-arguments
|
|
337
|
+
def generate_subsampled_images_wrapper(
|
|
338
|
+
paths_dictionary,
|
|
339
|
+
profile,
|
|
340
|
+
scale_factor=1,
|
|
341
|
+
tile_size=10000,
|
|
342
|
+
window=None,
|
|
343
|
+
saving_info=None,
|
|
344
|
+
) -> Dict[str, Tuple[xr.Dataset, xr.Dataset]]:
|
|
345
|
+
"""
|
|
346
|
+
Subsampling wrapper
|
|
347
|
+
|
|
348
|
+
:param paths_dictionary: the paths dictionary
|
|
349
|
+
:type paths_dictionary: dict
|
|
350
|
+
:param profile: the new profile
|
|
351
|
+
:param scale_factor: the scaling_factor
|
|
352
|
+
:type scale_factor: float
|
|
353
|
+
:param tile_size: the tile size
|
|
354
|
+
:type tile_size: int
|
|
355
|
+
:param window: the current window
|
|
356
|
+
:type window: Window
|
|
357
|
+
:param saving_info: the saving information
|
|
358
|
+
"""
|
|
359
|
+
|
|
360
|
+
global_dataset = None
|
|
361
|
+
for key, val in paths_dictionary.items():
|
|
362
|
+
path = val["path"]
|
|
363
|
+
# Rectify images
|
|
364
|
+
if path is not None:
|
|
365
|
+
interpolator = "bilinear"
|
|
366
|
+
if key in ("classif", "mask"):
|
|
367
|
+
interpolator = "nearest"
|
|
368
|
+
|
|
369
|
+
dataset = subsampling_algo.resample_image(
|
|
370
|
+
path,
|
|
371
|
+
window,
|
|
372
|
+
tile_size,
|
|
373
|
+
key,
|
|
374
|
+
scale_factor=scale_factor,
|
|
375
|
+
interpolator=interpolator,
|
|
376
|
+
)
|
|
377
|
+
if key == "im":
|
|
378
|
+
global_dataset = copy.deepcopy(dataset)
|
|
379
|
+
|
|
380
|
+
if key == "classif":
|
|
381
|
+
global_dataset[key] = xr.DataArray(
|
|
382
|
+
dataset[cst.EPI_IMAGE].values,
|
|
383
|
+
dims=[cst.ROW, cst.COL],
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
if key == "mask":
|
|
387
|
+
global_dataset[key] = xr.DataArray(
|
|
388
|
+
dataset[cst.EPI_IMAGE].values,
|
|
389
|
+
dims=[cst.ROW, cst.COL],
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
if "texture" in key:
|
|
393
|
+
global_dataset.coords[cst.BAND_IM] = dataset.attrs[
|
|
394
|
+
cst.BAND_NAMES
|
|
395
|
+
]
|
|
396
|
+
global_dataset[key] = xr.DataArray(
|
|
397
|
+
dataset[cst.EPI_IMAGE].values,
|
|
398
|
+
dims=[cst.BAND_NAMES, cst.ROW, cst.COL],
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
window_out_left = {
|
|
402
|
+
"row_min": global_dataset.region[1],
|
|
403
|
+
"row_max": global_dataset.region[3],
|
|
404
|
+
"col_min": global_dataset.region[0],
|
|
405
|
+
"col_max": global_dataset.region[2],
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
# Add attributes info
|
|
409
|
+
attributes = {}
|
|
410
|
+
# fill datasets with saving info, window, profile, overlaps for correct
|
|
411
|
+
# saving
|
|
412
|
+
cars_dataset.fill_dataset(
|
|
413
|
+
global_dataset,
|
|
414
|
+
saving_info=saving_info,
|
|
415
|
+
window=window_out_left,
|
|
416
|
+
profile=profile,
|
|
417
|
+
attributes=attributes,
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
return global_dataset
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# coding: utf8
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2020 Centre National d'Etudes Spatiales (CNES).
|
|
5
|
+
#
|
|
6
|
+
# This file is part of CARS
|
|
7
|
+
# (see https://github.com/CNES/cars).
|
|
8
|
+
#
|
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
# you may not use this file except in compliance with the License.
|
|
11
|
+
# You may obtain a copy of the License at
|
|
12
|
+
#
|
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
#
|
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
# See the License for the specific language governing permissions and
|
|
19
|
+
# limitations under the License.
|
|
20
|
+
#
|
|
21
|
+
"""
|
|
22
|
+
Resampling module:
|
|
23
|
+
contains functions used for epipolar resampling
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
# Standard imports
|
|
27
|
+
import rasterio
|
|
28
|
+
from rasterio.enums import Resampling
|
|
29
|
+
from rasterio.windows import Window
|
|
30
|
+
|
|
31
|
+
from cars.core import datasets
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def resample_image( # pylint: disable=too-many-positional-arguments
|
|
35
|
+
image,
|
|
36
|
+
tile_window,
|
|
37
|
+
tile_size,
|
|
38
|
+
key,
|
|
39
|
+
scale_factor=1,
|
|
40
|
+
interpolator="bilinear",
|
|
41
|
+
):
|
|
42
|
+
"""
|
|
43
|
+
Resample the image
|
|
44
|
+
|
|
45
|
+
:param image: the image to resample
|
|
46
|
+
:type image: str
|
|
47
|
+
:param tile_window: the tile window
|
|
48
|
+
:type tile_window: Window
|
|
49
|
+
:param tile_size: the tile size
|
|
50
|
+
:type tile_size: int
|
|
51
|
+
:param key: the key in the path dictionary
|
|
52
|
+
:type key: str
|
|
53
|
+
:param scale_factor: the scaling factor
|
|
54
|
+
:type scale_factor: float
|
|
55
|
+
:param interpolator: the interpolator
|
|
56
|
+
:type interpolator: str
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
x = tile_window["col_min"]
|
|
60
|
+
y = tile_window["row_min"]
|
|
61
|
+
|
|
62
|
+
x_read = max(x, 0)
|
|
63
|
+
y_read = max(y, 0)
|
|
64
|
+
|
|
65
|
+
width = tile_window["col_max"]
|
|
66
|
+
height = tile_window["row_max"]
|
|
67
|
+
w = min(tile_size, width - x_read)
|
|
68
|
+
h = min(tile_size, height - y_read)
|
|
69
|
+
|
|
70
|
+
window_in = Window(x_read, y_read, w, h)
|
|
71
|
+
|
|
72
|
+
new_w = int(w * scale_factor)
|
|
73
|
+
new_h = int(h * scale_factor)
|
|
74
|
+
|
|
75
|
+
resampling_image = getattr(Resampling, interpolator)
|
|
76
|
+
|
|
77
|
+
band_coords = None
|
|
78
|
+
with rasterio.open(image) as src:
|
|
79
|
+
data_resampled = src.read(
|
|
80
|
+
out_shape=(src.count, new_h, new_w),
|
|
81
|
+
window=window_in,
|
|
82
|
+
resampling=resampling_image,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
description = list(src.descriptions)
|
|
86
|
+
|
|
87
|
+
if len(description) > 1:
|
|
88
|
+
band_coords = "band" + key
|
|
89
|
+
|
|
90
|
+
out_x = int(x * scale_factor)
|
|
91
|
+
out_y = int(y * scale_factor)
|
|
92
|
+
|
|
93
|
+
region = [
|
|
94
|
+
out_x,
|
|
95
|
+
out_y,
|
|
96
|
+
out_x + data_resampled.shape[2],
|
|
97
|
+
out_y + data_resampled.shape[1],
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
dataset = datasets.create_im_dataset(
|
|
101
|
+
data_resampled,
|
|
102
|
+
region,
|
|
103
|
+
[data_resampled.shape[1], data_resampled.shape[2]],
|
|
104
|
+
band_coords=band_coords,
|
|
105
|
+
descriptions=description,
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
return dataset
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# !/usr/bin/env python
|
|
2
|
+
# coding: utf8
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 2020 Centre National d'Etudes Spatiales (CNES).
|
|
5
|
+
#
|
|
6
|
+
# This file is part of CARS
|
|
7
|
+
# (see https://github.com/CNES/cars).
|
|
8
|
+
#
|
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
# you may not use this file except in compliance with the License.
|
|
11
|
+
# You may obtain a copy of the License at
|
|
12
|
+
#
|
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
#
|
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
# See the License for the specific language governing permissions and
|
|
19
|
+
# limitations under the License.
|
|
20
|
+
#
|
|
21
|
+
"""
|
|
22
|
+
CARS core matching module init file
|
|
23
|
+
"""
|
|
24
|
+
# flake8: noqa: F401
|
|
25
|
+
|
|
26
|
+
from cars.applications.sparse_matching.abstract_sparse_matching_app import (
|
|
27
|
+
SparseMatching,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
from . import sift_app
|