-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sakharov
committed
Apr 8, 2024
1 parent
2579ee3
commit 3f74efa
Showing
5 changed files
with
315 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
aeronet_raster/aeronet_raster/dataadapters/numpyadapter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from .abstractadapter import AbstractReader, AbstractWriter | ||
from .boundsafemixin import BoundSafeReaderMixin, BoundSafeWriterMixin | ||
|
||
|
||
class NumpyReader(BoundSafeReaderMixin, AbstractReader): | ||
"""Works with numpy arrays. Useful for testing""" | ||
def __init__(self, data, padding_mode='constant', **kwargs): | ||
super().__init__(padding_mode, **kwargs) | ||
self._data = data | ||
|
||
@property | ||
def ndim(self): | ||
return self._data.ndim | ||
|
||
@property | ||
def shape(self): | ||
return self._data.shape | ||
|
||
def __len__(self): | ||
return self.shape[0] | ||
|
||
def fetch(self, item): | ||
if isinstance(item, list): | ||
item = tuple(item) | ||
return self._data[item] | ||
|
||
|
||
class NumpyWriter(BoundSafeWriterMixin, NumpyReader): | ||
"""Works with numpy arrays. Useful for testing""" | ||
def write(self, item, data): | ||
if isinstance(item, list): | ||
item = tuple(item) | ||
self._data[item] = data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.