25
25
26
26
from __future__ import annotations
27
27
28
- import logging
29
28
import warnings
30
29
from typing import List , Union , Tuple , cast , Dict
31
- import sys
32
30
33
31
import numpy as np
34
32
import rasterio
@@ -87,8 +85,7 @@ def get_window(roi: Dict, width: int, height: int) -> Window:
87
85
88
86
# check roi outside
89
87
if col_off > width or row_off > height or (col_off + roi_width ) < 0 or (row_off + roi_height ) < 0 :
90
- logging .error ("Roi specified is outside the image" )
91
- sys .exit (1 )
88
+ raise ValueError ("Roi specified is outside the image" )
92
89
93
90
# overlap roi and image
94
91
# right side
@@ -144,7 +141,7 @@ def add_disparity(
144
141
145
142
def add_classif (dataset : xr .Dataset , classif : Union [str , None ], window : Window ) -> xr .Dataset :
146
143
"""
147
- Add classification informations and image to datasaet
144
+ Add classification information and image to dataset
148
145
149
146
:param dataset: xarray dataset without classification
150
147
:type dataset: xr.Dataset
@@ -169,7 +166,7 @@ def add_classif(dataset: xr.Dataset, classif: Union[str, None], window: Window)
169
166
170
167
def add_segm (dataset : xr .Dataset , segm : Union [str , None ], window : Window ) -> xr .Dataset :
171
168
"""
172
- Add Segmentation informations and image to datasaet
169
+ Add Segmentation information and image to dataset
173
170
174
171
:param dataset: xarray dataset without segmentation
175
172
:type dataset: xr.Dataset
@@ -191,9 +188,9 @@ def add_segm(dataset: xr.Dataset, segm: Union[str, None], window: Window) -> xr.
191
188
192
189
def add_no_data (dataset : xr .Dataset , no_data : Union [int , float ], no_data_pixels : np .ndarray ) -> xr .Dataset :
193
190
"""
194
- Add no data informations to datasaet
191
+ Add no data information to dataset
195
192
196
- :param dataset: xarray dataset without no_data informations
193
+ :param dataset: xarray dataset without no_data information
197
194
:type dataset: xr.Dataset
198
195
:param no_data: value
199
196
:type no_data: int or float
@@ -216,7 +213,7 @@ def add_mask(
216
213
dataset : xr .Dataset , mask : Union [str , None ], no_data_pixels : np .ndarray , width : int , height : int , window : Window
217
214
) -> xr .Dataset :
218
215
"""
219
- Add mask informations and image to datasaet
216
+ Add mask information and image to dataset
220
217
221
218
:param dataset: xarray dataset without mask
222
219
:type dataset: xr.Dataset
@@ -228,6 +225,8 @@ def add_mask(
228
225
:type width: int
229
226
:param height: nb rows
230
227
:type height: int
228
+ :param window: information about window
229
+ :type window: rasterio.window
231
230
:return: dataset : updated dataset
232
231
:rtype: xr.Dataset
233
232
"""
@@ -273,7 +272,7 @@ def create_dataset_from_inputs(input_config: dict, roi: dict = None) -> xr.Datas
273
272
274
273
:param input_config: configuration used to create dataset.
275
274
:type input_config: dict
276
- :param roi: dictionnary with a roi
275
+ :param roi: dictionary with a roi
277
276
278
277
"col": {"first": <value - int>, "last": <value - int>},
279
278
"row": {"first": <value - int>, "last": <value - int>},
@@ -497,9 +496,9 @@ def interpolate_nodata_sgm(img: np.ndarray, valid: np.ndarray) -> Tuple[np.ndarr
497
496
IEEE Transactions on pattern analysis and machine intelligence, 2007, vol. 30, no 2, p. 328-341.
498
497
499
498
:param img: input image
500
- :type img: 2D np.array (row, col)
499
+ :type img: 2D np.ndarray (row, col)
501
500
:param valid: validity mask
502
- :type valid: 2D np.array (row, col)
501
+ :type valid: 2D np.ndarray (row, col)
503
502
:return: the interpolate input image, with the validity mask update :
504
503
505
504
- If out & PANDORA_MSK_PIXEL_FILLED_NODATA != 0 : Invalid pixel : filled nodata pixel
@@ -540,11 +539,10 @@ def masks_pyramid(msk: np.ndarray, scale_factor: int, num_scales: int) -> List[n
540
539
:return: a List that contains the different scaled masks
541
540
:rtype: List of np.ndarray
542
541
"""
543
- msk_pyramid = []
542
+ msk_pyramid = [msk ]
544
543
# Add the full resolution mask
545
- msk_pyramid .append (msk )
546
544
tmp_msk = msk
547
- for scale in range (num_scales - 1 ): # pylint: disable=unused-variable
545
+ for _ in range (num_scales - 1 ):
548
546
# Decimate in the two axis
549
547
tmp_msk = tmp_msk [::scale_factor , ::scale_factor ]
550
548
msk_pyramid .append (tmp_msk )
@@ -657,7 +655,7 @@ def check_inside_image(img: xr.Dataset, row: int, col: int) -> bool:
657
655
:type row: int
658
656
:param col: column coordinates
659
657
:type col: int
660
- :return: a boolean
658
+ :return: True if the coordinates row,col are inside the image
661
659
:rtype: boolean
662
660
"""
663
661
ny_ , nx_ = img .dims ["row" ], img .dims ["col" ]
@@ -691,7 +689,7 @@ def census_transform(image: xr.Dataset, window_size: int, band: str = None) -> x
691
689
692
690
# Create a sliding window of using as_strided function : this function create a new a view (by manipulating data
693
691
# pointer) of the image array with a different shape. The new view pointing to the same memory block as
694
- # image so it does not consume any additional memory.
692
+ # image, so it does not consume any additional memory.
695
693
str_row , str_col = selected_band .strides
696
694
shape_windows = (
697
695
ny_ - (window_size - 1 ),
@@ -780,22 +778,22 @@ def find_valid_neighbors(dirs: np.ndarray, disp: np.ndarray, valid: np.ndarray,
780
778
Find valid neighbors along directions
781
779
782
780
:param dirs: directions
783
- :type dirs: 2D np.array (row, col)
781
+ :type dirs: 2D np.ndarray (row, col)
784
782
:param disp: disparity map
785
- :type disp: 2D np.array (row, col)
783
+ :type disp: 2D np.ndarray (row, col)
786
784
:param valid: validity mask
787
- :type valid: 2D np.array (row, col)
785
+ :type valid: 2D np.ndarray (row, col)
788
786
:param row: row current value
789
787
:type row: int
790
788
:param col: col current value
791
789
:type col: int
792
790
:return: valid neighbors
793
- :rtype: 2D np.array
791
+ :rtype: 2D np.ndarray
794
792
"""
795
793
ncol , nrow = disp .shape
796
794
# Maximum path length
797
795
max_path_length = max (nrow , ncol )
798
- # For each directions
796
+ # For each direction
799
797
valid_neighbors = np .zeros (8 , dtype = np .float32 )
800
798
for direction in range (8 ):
801
799
# Find the first valid pixel in the current path
@@ -843,8 +841,7 @@ def compute_mean_patch(img: xr.Dataset, row: int, col: int, win_size: int) -> np
843
841
dtype = np .float32 ,
844
842
)
845
843
846
- logging .error ("The window is outside the image" )
847
- raise IndexError
844
+ raise IndexError ("The window is outside the image" )
848
845
849
846
850
847
def compute_std_raster (img : xr .Dataset , win_size : int , band : str = None ) -> np .ndarray :
@@ -903,7 +900,7 @@ def read_disp(disparity: tuple[int, int] | list[int] | str) -> tuple[int, int] |
903
900
904
901
if not isinstance (disparity , str ):
905
902
# cast because of mypy when we give list as input while it expects a tuple as output
906
- # not sure it is the best solution
903
+ # not sure if it is the best solution
907
904
return cast (Tuple [int , int ], tuple (disparity ))
908
905
909
906
raster_disparity = rasterio_open (disparity )
0 commit comments