Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakharov committed May 2, 2024
1 parent 03577f2 commit c27e0db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 8 additions & 0 deletions aeronet_raster/aeronet_raster/dataadapters/boundsafemixin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import numpy as np


Expand All @@ -21,6 +23,8 @@ def __getitem__(self, item):
elif isinstance(coords, slice): # coords = (min:max:step)
pads.append((max(-coords.start, 0), max(coords.stop - self.shape[axis], 0)))
safe_coords.append(slice(coords.start + pads[-1][0], coords.stop - pads[-1][1], coords.step))
if safe_coords[-1].start >= safe_coords[-1].stop:
logging.warning(f'Probably incorrect slice {safe_coords[-1]}')
else:
raise ValueError(f'Can not parse coords={coords} at axis={axis}')

Expand All @@ -39,6 +43,10 @@ def __setitem__(self, item, data):
elif isinstance(coords, slice): # coords = (min:max:step)
crops.append((max(-coords.start, 0), max(coords.stop - self.shape[axis], 0)))
safe_coords.append(slice(coords.start + crops[-1][0], coords.stop - crops[-1][1], coords.step))
if safe_coords[-1].start >= safe_coords[-1].stop:
logging.warning(f'Probably incorrect slice {safe_coords[-1]}')
else:
raise ValueError(f'Can not parse coords={coords} at axis={axis}')

self.write(safe_coords,
data[tuple(slice(crops[i][0], data.shape[i]-crops[i][1], 1) for i in range(data.ndim))])
Expand Down
10 changes: 5 additions & 5 deletions aeronet_raster/aeronet_raster/dataprocessor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
from .utils.samplers.gridsampler import GridSampler, make_grid, get_safe_shape
from .dataadapters.abstractadapter import AbstractAdapter
from .dataadapters.imageadapter import ImageAdapter
from typing import Sequence, Callable, Union, Final, Tuple, Optional
import numpy as np

Expand Down Expand Up @@ -58,6 +57,7 @@ def process(src: ArrayLike,
dst_coords[i] + dst_sample_size[i],
1) for i in range(len(dst_coords)))] = readen + res


def get_blend_mask(shape: Sequence[int], margin: Sequence[int]) -> np.ndarray:
"""
Returns alpha-blend float mask with values within [0..1] and linear fades on each side
Expand Down Expand Up @@ -125,11 +125,11 @@ def build_sampler(shape: np.ndarray, sample_size: np.ndarray, margin: np.ndarray
return GridSampler(make_grid([(grid_start[i], grid_end[i]) for i in range(len(shape))], stride))


def process_image(src: ImageAdapter,
def process_image(src: AbstractAdapter,
src_sample_size: Union[int, Sequence[int]],
src_margin: Union[int, Sequence[int]],
processor: Callable,
dst: ImageAdapter,
dst: AbstractAdapter,
dst_sample_size: Union[int, Sequence[int], None] = None,
dst_margin: Union[int, Sequence[int], None] = None,
mode: str = 'crop',
Expand Down Expand Up @@ -157,8 +157,8 @@ def add_ch_ndim(size, n_ch):
else:
raise ValueError(f'Expecting size to be int or Sequence[int, int], got {size}')

dst_margin = add_ch_ndim(dst_margin or src_margin, 0)
dst_sample_size = add_ch_ndim(dst_sample_size or src_sample_size, dst.shape[0])
dst_margin = add_ch_ndim(dst_margin if dst_margin is not None else src_margin, 0)
dst_sample_size = add_ch_ndim(dst_sample_size if dst_sample_size is not None else src_sample_size, dst.shape[0])

src_sample_size = add_ch_ndim(src_sample_size, src.shape[0])
src_margin = add_ch_ndim(src_margin, 0)
Expand Down

0 comments on commit c27e0db

Please sign in to comment.