Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions cuvis/AcquisitionContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion cuvis/Calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
67 changes: 67 additions & 0 deletions cuvis/FileWriteSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<userplugin xmlns="http://cubert-gmbh.de/user/plugin/userplugin.xsd">' 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))
23 changes: 12 additions & 11 deletions cuvis/Viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand All @@ -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, 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
# 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)

Expand Down
2 changes: 1 addition & 1 deletion cuvis/Worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 17 additions & 19 deletions cuvis/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
del os, platform, sys
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'

Expand All @@ -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',
],
}

Expand Down