Skip to content

Commit

Permalink
0.2.3 Update of CollectionProcessor
Browse files Browse the repository at this point in the history
 - processing_fn_use_block: bool, whether to pass 'block' argument to processing_fn
 - write_output_to_dst: bool, whether to write output of processing_fn to dst
  • Loading branch information
adeshkin committed Feb 20, 2024
1 parent 33d0b21 commit 31bb68e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.2.3:
=====
Update of CollectionProcessor:
- processing_fn_use_block: bool, whether to pass 'block' argument to processing_fn
- write_output_to_dst: bool, whether to write output of processing_fn to dst

0.2.2:
=====
Update of CollectionProcessor:
Expand Down
2 changes: 1 addition & 1 deletion aeronet/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = (0, 2, 2)
VERSION = (0, 2, 3)

__version__ = '.'.join(map(str, VERSION))
2 changes: 1 addition & 1 deletion aeronet_raster/aeronet_raster/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = (0, 2, 2)
VERSION = (0, 2, 3)

__version__ = '.'.join(map(str, VERSION))
26 changes: 19 additions & 7 deletions aeronet_raster/aeronet_raster/collectionprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@ def __init__(self,
verbose: bool = True,
bound_mode: str = 'drop',
padding: str = 'none',
nodata_mask_mode: bool = False):
nodata_mask_mode: bool = False,
processing_fn_use_block: bool = False,
write_output_to_dst: bool = True,
):
"""
Args:
input_channels: list of str, names of bands/channels
Expand All @@ -422,6 +425,8 @@ def __init__(self,
padding: str, 'none' or 'mirror', default 'none':
'none' - no padding, 'mirror' - mirror padding of nodata areas
nodata_mask_mode: bool, whether to fill by dst_nodata where nodata mask is True
processing_fn_use_block: bool, whether to pass 'block' argument to processing_fn
write_output_to_dst: bool, whether to write output of processing_fn to dst
Returns:
processed BandCollection
"""
Expand Down Expand Up @@ -460,7 +465,8 @@ def __init__(self,
self.padding = padding

self.nodata_mask_mode = nodata_mask_mode

self.processing_fn_use_block = processing_fn_use_block
self.write_output_to_dst = write_output_to_dst
self.n_workers = n_workers
self.verbose = verbose
self.lock = Lock()
Expand All @@ -470,12 +476,18 @@ def _threaded_processing(self, args):

def _processing(self, sample: np.ndarray, block: dict, dst: SampleCollectionWindowWriter):
if np.all(sample == self.src_nodata):
with self.lock:
dst.write_empty_block(**block)
if self.write_output_to_dst:
with self.lock:
dst.write_empty_block(**block)
else:
raster = self.processing_fn(sample)
with self.lock:
dst.write(raster, **block)
if self.processing_fn_use_block:
raster = self.processing_fn(sample, block)
else:
raster = self.processing_fn(sample)

if self.write_output_to_dst:
with self.lock:
dst.write(raster, **block)

def process(self, bc: BandCollection, output_directory: str) -> BandCollection:
self.src_nodata = self.src_nodata if bc.nodata is None else bc.nodata
Expand Down

0 comments on commit 31bb68e

Please sign in to comment.