From 55e01887922a69c78f5e94b2ac5c59f4796b04a6 Mon Sep 17 00:00:00 2001 From: Simon Birkholz Date: Mon, 21 Oct 2024 13:10:44 +0200 Subject: [PATCH 1/4] added option to capture_async to add mesu to internal queue --- cuvis/AcquisitionContext.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cuvis/AcquisitionContext.py b/cuvis/AcquisitionContext.py index 2118097..1f2379b 100644 --- a/cuvis/AcquisitionContext.py +++ b/cuvis/AcquisitionContext.py @@ -7,7 +7,7 @@ from .cuvis_aux import SDKException, SessionData from .cuvis_types import HardwareState, OperationMode -from typing import Coroutine, Callable, Awaitable, Union, Iterable +from typing import Coroutine, Callable, Awaitable, Union, Iterable, Optional from .doc import copydoc import cuvis.cuvis_types as internal @@ -193,12 +193,18 @@ def _set_integration_time_factor_async(self, idref: int, val: float) -> Async: return Async(cuvis_il.p_int_value(_pasync)) @copydoc(cuvis_il.cuvis_acq_cont_capture_async) - def capture(self) -> AsyncMesu: - _pasync = cuvis_il.new_p_int() - if cuvis_il.status_ok != cuvis_il.cuvis_acq_cont_capture_async( - self._handle, _pasync): - raise SDKException() - return AsyncMesu(cuvis_il.p_int_value(_pasync)) + def capture(self, to_interal=False) -> Optional[AsyncMesu]: + if not to_interal: + _pasync = cuvis_il.new_p_int() + if cuvis_il.status_ok != cuvis_il.cuvis_acq_cont_capture_async( + self._handle, _pasync): + raise SDKException() + return AsyncMesu(cuvis_il.p_int_value(_pasync)) + else: + if cuvis_il.status_ok != cuvis_il.cuvis_acq_cont_capture_async( + self._handle, 0): + raise SDKException() + return None @copydoc(cuvis_il.cuvis_acq_cont_capture) def capture_at(self, timeout_ms: int) -> Measurement: From 1d8ea0827a19cba722f45f453e258d3883af3f97 Mon Sep 17 00:00:00 2001 From: Simon Birkholz Date: Tue, 22 Oct 2024 10:29:16 +0200 Subject: [PATCH 2/4] added missing struct ViewerSettings --- cuvis/Calibration.py | 1 - cuvis/FileWriteSettings.py | 67 ++++++++++++++++++++++++++++++++++++++ cuvis/Viewer.py | 23 ++++++------- cuvis/__init__.py | 36 ++++++++++---------- setup.py | 6 ++-- 5 files changed, 99 insertions(+), 34 deletions(-) diff --git a/cuvis/Calibration.py b/cuvis/Calibration.py index efa2a31..981f4f3 100644 --- a/cuvis/Calibration.py +++ b/cuvis/Calibration.py @@ -39,7 +39,6 @@ def get_capabilities(self, operation_mode: OperationMode) -> Capabilities: @property def info(self) -> CalibrationInfo: - ret = cuvis_il.cuvis_calibration_info_t() if cuvis_il.status_ok != cuvis_il.cuvis_calib_get_info( self._handle, ret): diff --git a/cuvis/FileWriteSettings.py b/cuvis/FileWriteSettings.py index d8ed69a..015245b 100644 --- a/cuvis/FileWriteSettings.py +++ b/cuvis/FileWriteSettings.py @@ -228,3 +228,70 @@ def _get_internal(self): self.can_skip_supplementary_steps) wa.can_drop_results = int(self.can_drop_results) return wa + + +@dataclass(repr=False) +class ViewerSettings(): + userplugin: InitVar[str] = None + pan_scale: float = 0.0 + pan_sharpening_interpolation_type: PanSharpeningInterpolationType = PanSharpeningInterpolationType.Linear + pan_sharpening_algorithm: PanSharpeningAlgorithm = PanSharpeningAlgorithm.CubertMacroPixel + pre_pan_sharpen_cube: bool = False + complete: bool = False + blend_opacity: float = 0.0 + + def __post_init__(self, userplugin: str): + if userplugin is not None: + if '' in userplugin: + # Seems to be a valid plugin + self._userplugin = userplugin + return + if os.path.exists(userplugin): + # Seems to be a valid path to a file, read in + with open(userplugin) as f: + self._userplugin = "".join(f.readlines()) + else: + raise SDKException( + 'Error when validating plugin data. Please provide a valid plugin or a path to a plugin file') + + @property + def userplugin(self) -> str: + return self._userplugin + + @userplugin.setter + def userplugin(self, v: str) -> None: + self.__post_init__(v) + + def __repr__(self): + def short_str(s: str, l: int) -> str: + return (s[:l] + '...') if len(s) > l else s + + """Returns a string containing but shortens the userplugin field.""" + s = ', '.join(list(f'{field.name}={getattr(self, field.name)}' + for field in fields(self)) + [f'userplugin={short_str(self._userplugin, 15)}']) + return f'{type(self).__name__}({s})' + + def _get_internal(self): + vs = cuvis_il.cuvis_viewer_settings_t() + vs.userplugin = self.userplugin + vs.pan_scale = float(self.pan_scale) + vs.pan_interpolation_type = internal.__CuvisPanSharpeningInterpolationType__[ + self.pan_sharpening_interpolation_type] + vs.pan_algorithm = internal.__CuvisPanSharpeningAlgorithm__[ + self.pan_sharpening_algorithm] + vs.pre_pan_sharpen_cube = int(self.pre_pan_sharpen_cube) + vs.complete = int(self.complete) + vs.blend_opacity = float(self.blend_opacity) + return vs + + @classmethod + def _from_internal(cls, vs: cuvis_il.cuvis_viewer_settings_t): + return cls(userplugin=vs.userplugin, + pan_scale=float(vs.pan_scale), + pan_sharpening_interpolation_type=internal.__PanSharpeningInterpolationType__[ + vs.pan_interpolation_type], + pan_sharpening_algorithm=internal.__PanSharpeningAlgorithm__[ + vs.pan_algorithm], + pre_pan_sharpen_cube=bool(vs.pre_pan_sharpen_cube), + complete=bool(vs.complete), + blend_opacity=float(vs.blend_opacity)) diff --git a/cuvis/Viewer.py b/cuvis/Viewer.py index ed42f4e..f42a6e1 100644 --- a/cuvis/Viewer.py +++ b/cuvis/Viewer.py @@ -3,19 +3,20 @@ from .cuvis_aux import SDKException from .cuvis_types import CUVIS_imbuffer_format -from .FileWriteSettings import ViewExportSettings +from .FileWriteSettings import ViewerSettings from typing import Union, Dict + class Viewer(object): - def __init__(self, settings: Union[int,ViewExportSettings]): + def __init__(self, settings: Union[int, ViewerSettings]): self._handle = None if isinstance(settings, int): self._handle = settings - if isinstance(settings, ViewExportSettings): + if isinstance(settings, ViewerSettings): _ptr = cuvis_il.new_p_int() if cuvis_il.status_ok != cuvis_il.cuvis_viewer_create( - _ptr, settings._get_internal()[1]): + _ptr, settings._get_internal()): raise SDKException() self._handle = cuvis_il.p_int_value(_ptr) else: @@ -24,7 +25,7 @@ def __init__(self, settings: Union[int,ViewExportSettings]): type(settings))) pass - def _create_view_data(self,new_handle: int) -> Dict[str,ImageData]: + def _create_view_data(self, new_handle: int) -> Dict[str, ImageData]: _ptr = cuvis_il.new_p_int() if cuvis_il.status_ok != cuvis_il.cuvis_view_get_data_count( @@ -38,22 +39,22 @@ def _create_view_data(self,new_handle: int) -> Dict[str,ImageData]: for i in range(dataCount): view_data = cuvis_il.cuvis_view_data_t() if cuvis_il.status_ok != cuvis_il.cuvis_view_get_data( - new_handle, view_data): + new_handle, view_data): raise SDKException() - + if view_data.data.format == CUVIS_imbuffer_format["imbuffer_format_uint8"]: - view_data[view_data.id]= ImageData(img_buf=view_data.data, - dformat=view_data.data.format) + view_data[view_data.id] = ImageData(img_buf=view_data.data, + dformat=view_data.data.format) else: raise SDKException("Unsupported viewer bit depth!") # TODO when is a good point to release the view # cuvis_il.cuvis_view_free(_ptr) return view_array - def apply(self, mesu: Measurement) -> Dict[str,ImageData]: + def apply(self, mesu: Measurement) -> Dict[str, ImageData]: _ptr = cuvis_il.new_p_int() if cuvis_il.status_ok != cuvis_il.cuvis_viewer_apply(self._handle, - mesu._handle, _ptr): + mesu._handle, _ptr): raise SDKException() currentView = cuvis_il.p_int_value(_ptr) diff --git a/cuvis/__init__.py b/cuvis/__init__.py index fec9d66..bde3037 100644 --- a/cuvis/__init__.py +++ b/cuvis/__init__.py @@ -1,3 +1,19 @@ +from .cuvis_aux import SessionData, Capabilities, MeasurementFlags, SensorInfo, GPSData, CalibrationInfo +from .cuvis_types import OperationMode, HardwareState, ProcessingMode, PanSharpeningInterpolationType, \ + PanSharpeningAlgorithm, TiffCompressionMode, TiffFormat, ComponentType, ReferenceType, SessionItemType +from .Worker import Worker, WorkerResult +from .Viewer import Viewer +from .SessionFile import SessionFile +from .ProcessingContext import ProcessingContext +from .Measurement import Measurement +from .General import init, shutdown, version, set_log_level +from .FileWriteSettings import GeneralExportSettings, SaveArgs, \ + ProcessingArgs, \ + EnviExportSettings, TiffExportSettings, ViewExportSettings, \ + WorkerSettings, ViewerSettings +from .Export import CubeExporter, EnviExporter, TiffExporter, ViewExporter +from .Calibration import Calibration +from .AcquisitionContext import AcquisitionContext import os import platform import sys @@ -17,23 +33,5 @@ raise NotImplementedError('Invalid operating system detected!') # sys.exit(1) -from .AcquisitionContext import AcquisitionContext -from .Calibration import Calibration -from .Export import CubeExporter, EnviExporter, TiffExporter, ViewExporter -from .FileWriteSettings import GeneralExportSettings, SaveArgs, \ - ProcessingArgs, \ - EnviExportSettings, TiffExportSettings, ViewExportSettings, \ - WorkerSettings -from .General import init, shutdown, version, set_log_level -from .Measurement import Measurement -from .ProcessingContext import ProcessingContext -from .SessionFile import SessionFile -from .Viewer import Viewer -from .Worker import Worker, WorkerResult - -from .cuvis_types import OperationMode, HardwareState, ProcessingMode, PanSharpeningInterpolationType, \ - PanSharpeningAlgorithm, TiffCompressionMode, TiffFormat, ComponentType, ReferenceType, SessionItemType - -from .cuvis_aux import SessionData, Capabilities, MeasurementFlags, SensorInfo, GPSData, CalibrationInfo -del os, platform, sys \ No newline at end of file +del os, platform, sys diff --git a/setup.py b/setup.py index 73f64a1..b31891e 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ here = os.path.abspath(os.path.dirname(__file__)) NAME = 'cuvis' -VERSION = '3.3.0' +VERSION = '3.3.0.post1' DESCRIPTION = 'CUVIS Python SDK.' @@ -22,7 +22,7 @@ # Installation dependencies # Use with pip install . to install from source 'install': [ - 'cuvis-il == 3.3.0', + 'cuvis-il>=3.3.0,<=3.3.0.post999999', ], } @@ -67,7 +67,7 @@ def run(self): os.system('python setup.py sdist'.format(sys.executable)) self.status('Uploading the package to PyPI via Twine…') - os.system('twine upload -r testpypi dist/*') + os.system('twine upload dist/*') # self.status('Pushing git tags…') # os.system('git tag v{0}'.format(about['__version__'])) From 6746769db78f55d4f3a0081c0a7fde6c65fa6e73 Mon Sep 17 00:00:00 2001 From: Simon Birkholz Date: Tue, 22 Oct 2024 10:34:52 +0200 Subject: [PATCH 3/4] fix: missing argument in _create_view_data --- cuvis/Viewer.py | 6 +++--- setup.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cuvis/Viewer.py b/cuvis/Viewer.py index f42a6e1..0ea9f23 100644 --- a/cuvis/Viewer.py +++ b/cuvis/Viewer.py @@ -39,12 +39,12 @@ def _create_view_data(self, new_handle: int) -> Dict[str, ImageData]: for i in range(dataCount): view_data = cuvis_il.cuvis_view_data_t() if cuvis_il.status_ok != cuvis_il.cuvis_view_get_data( - new_handle, view_data): + new_handle, i, view_data): raise SDKException() if view_data.data.format == CUVIS_imbuffer_format["imbuffer_format_uint8"]: - view_data[view_data.id] = ImageData(img_buf=view_data.data, - dformat=view_data.data.format) + view_array[view_data.id] = ImageData(img_buf=view_data.data, + dformat=view_data.data.format) else: raise SDKException("Unsupported viewer bit depth!") # TODO when is a good point to release the view diff --git a/setup.py b/setup.py index b31891e..e12589f 100644 --- a/setup.py +++ b/setup.py @@ -67,7 +67,7 @@ def run(self): os.system('python setup.py sdist'.format(sys.executable)) self.status('Uploading the package to PyPI via Twine…') - os.system('twine upload dist/*') + os.system('twine upload -r testpypi dist/*') # self.status('Pushing git tags…') # os.system('git tag v{0}'.format(about['__version__'])) From 7cc546fc3c99e59add2360a53134de07bbcbf336 Mon Sep 17 00:00:00 2001 From: Simon Birkholz Date: Tue, 22 Oct 2024 13:32:01 +0200 Subject: [PATCH 4/4] fix: missing handle --- cuvis/Worker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cuvis/Worker.py b/cuvis/Worker.py index 4b30091..b822797 100644 --- a/cuvis/Worker.py +++ b/cuvis/Worker.py @@ -105,7 +105,7 @@ def ingest_session_file(self, session: SessionFile, frame_selection: str = 'all' @copydoc(cuvis_il.cuvis_worker_ingest_mesu) def ingest_mesu(self, mesu: Measurement) -> None: if cuvis_il.status_ok != cuvis_il.cuvis_worker_ingest_mesu( - self._handle, mesu): + self._handle, mesu._handle): raise SDKException() pass