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
10 changes: 10 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pathlib import Path
from hatchling.metadata.plugin.interface import MetadataHookInterface
from pymodaq_utils.resources.hatch_build_plugins import update_metadata_from_toml

here = Path(__file__).absolute().parent


class PluginInfoTomlHook(MetadataHookInterface):
def update(self, metadata: dict) -> None:
update_metadata_from_toml(metadata, here)
24 changes: 0 additions & 24 deletions plugin_info.toml

This file was deleted.

61 changes: 61 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[features] # defines the plugin features contained into this plugin
instruments = true # true if plugin contains instrument classes (else false, notice the lowercase for toml files)
extensions = false # true if plugins contains dashboard extensions
models = false # true if plugins contains pid models
h5exporters = false # true if plugin contains custom h5 file exporters
scanners = false # true if plugin contains custom scan layout (daq_scan extensions)

[urls]
package-url = 'https://github.com/PyMoDAQ/pymodaq_plugins_raspberry'

[project]
name = "pymodaq_plugins_raspberry"
description = 'Set of instrument plugins to use with a raspberry'
dependencies = [
"pymodaq>=5.0.0",
'picamera2',
]

authors = [
{name = "Weber Sébastien", email = "sebastien.weber@cnrs.fr"},
]
maintainers = [
{name = "Weber Sébastien", email = "sebastien.weber@cnrs.fr"},
]

# nottodo: leave everything below as is!

dynamic = ["version", "urls", "entry-points"]
readme = "README.rst"
license = { file="LICENSE" }
requires-python = ">=3.8"

classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Human Machine Interfaces",
"Topic :: Scientific/Engineering :: Visualization",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: User Interfaces",
]

[build-system]
requires = [
"hatchling>=1.9.0",
"hatch-vcs", "toml",
"pymodaq_utils>=0.0.6",
]
build-backend = "hatchling.build"

[tool.hatch.metadata.hooks.custom]

[tool.hatch.version]
source = "vcs"

75 changes: 0 additions & 75 deletions setup.py

This file was deleted.

11 changes: 7 additions & 4 deletions src/pymodaq_plugins_raspberry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from pathlib import Path
from pymodaq.utils.logger import set_logger # to be imported by other modules.

from .utils import Config
from pymodaq_utils.utils import get_version, PackageNotFoundError
from pymodaq_utils.logger import set_logger, get_module_name

config = Config()
try:
__version__ = get_version(__package__)
except PackageNotFoundError:
__version__ = '0.0.0dev'

with open(str(Path(__file__).parent.joinpath('resources/VERSION')), 'r') as fvers:
__version__ = fvers.read().strip()
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import numpy as np
from qtpy import QtWidgets

from pymodaq.utils.daq_utils import ThreadCommand
from pymodaq.utils.data import DataFromPlugins, Axis, DataToExport
from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main
from pymodaq.utils.parameter import Parameter
from pymodaq_utils.logger import set_logger, get_module_name

logger = set_logger(get_module_name(__file__))

from picamera2 import Picamera2

Expand All @@ -23,14 +27,15 @@ class DAQ_2DViewer_PiCamera(DAQ_Viewer_base):
"""

hardware_averaging = True
live_mode_available = True
live_mode_available = False

params = comon_parameters + [
{'title': 'Zoom:', 'name': 'zoom', 'type': 'slide', 'value': 1.0, 'min': 0., 'max': 1., 'subtype': 'linear'},
{'title': 'Brightness:', 'name': 'brightness', 'type': 'slide', 'value': 50, 'min': 0, 'max': 100,
'subtype': 'linear', 'int': True},
{'title': 'Contrast:', 'name': 'contrast', 'type': 'slide', 'value': 0, 'min': -100, 'max': 100,
'subtype': 'linear', 'int': True},
{'title': 'Resolution:', 'name': 'resolution', 'type': 'list', 'value': 'low', 'limits': ['low', 'high']},
#{'title': 'Zoom:', 'name': 'zoom', 'type': 'slide', 'value': 1.0, 'min': 0., 'max': 1., 'subtype': 'linear'},
#{'title': 'Brightness:', 'name': 'brightness', 'type': 'slide', 'value': 50, 'min': 0, 'max': 100,
# 'subtype': 'linear', 'int': True},
#{'title': 'Contrast:', 'name': 'contrast', 'type': 'slide', 'value': 0, 'min': -100, 'max': 100,
# 'subtype': 'linear', 'int': True},
]

def ini_attributes(self):
Expand All @@ -55,8 +60,11 @@ def commit_settings(self, param: Parameter):
A given parameter (within detector_settings) whose value has been changed by the user
"""
# TODO for your custom plugin
if param.name() == "a_parameter_you've_added_in_self.params":
self.controller.your_method_to_apply_this_param_change()
if param.name() == "resolution":
if param.value() == 'low':
self.controller.switch_mode(self.low_res_config)
else:
self.controller.switch_mode(self.high_res_config)
#elif ...

def ini_detector(self, controller=None):
Expand All @@ -74,37 +82,29 @@ def ini_detector(self, controller=None):
initialized: bool
False if initialization failed otherwise True
"""
self.ini_detector_init(old_controller=controller,
new_controller=PiCamera2())

# config = self.controller.create_preview_configuration()
# self.controller.configure(config)
self.capture_config = self.controller.create_still_configuration()

print(self.controller.camera_controls)
print(self.controller.camera_properties)
print(self.controller.capture_metadata())
self.controller.start(show_preview=True)

# self.controller.resolution = (self.width, self.height)
# # self.camera.resolution = (1648, 928)
# self.controller.framerate = 32 # nombres d'images par secondes
#
# self.controller.rotation = 180
#
# self.camera.zoom = (0, 0, 1, 1)
#
# # Produit un tableau tridimensionnel RGB à partir d'une capture RGB
# # self.rawCapture = PiRGBArray(self.camera, size=(self.width, self.height))
# self.rawCapture = PiRGBArray(self.camera, size=(self.width, self.height))
if self.is_master:
self.controller = Picamera2()
else:
self.controller = controller

self.low_res_config = self.controller.create_preview_configuration()
self.high_res_config = self.controller.create_still_configuration()

self.controller.configure(self.low_res_config)


logger.info(self.controller.camera_controls)
logger.info(self.controller.camera_properties)
#print(self.controller.capture_metadata())
self.controller.start()

info = "Whatever info you want to log"
initialized = True
return info, initialized

def close(self):
"""Terminate the communication protocol"""
if self.controller is not None:
if self.controller is not None and self.is_master:
self.controller.close()

def grab_data(self, Naverage=1, **kwargs):
Expand All @@ -125,33 +125,34 @@ def grab_data(self, Naverage=1, **kwargs):
self.live = kwargs['live']
else:
self.live = False
logger.debug(f'live: {self.live}')
if 'wait_time' in kwargs:
self.wait_time = kwargs['wait_time']


logger.debug(self.wait_time)

self.grab(Naverage)

def grab(self, Naverage):
for ind in range(Naverage):
if self.live:
array = self.controller.capture_array("main")
else:
array = self.controller.switch_mode_and_capture_array(self.capture_config, "main")
array = self.controller.capture_array("main")
logger.debug(f'array shape: {array.shape}')
if len(array.shape) == 2:
arrays = [array]
elif len(array.shape) == 3:
arrays = [array[..., ind] for ind in range(array.shape[2])]
arrays = [array[..., ind] for ind in range(3)] #alpha is with the last index equal to 4, we may skip it!
else:
arrays = [array[..., ind, 0] for ind in range(array.shape[2])] # TODO: check this with alpha
raise ValueError(f'The array shape is {array.shape} and is not handled')
if ind == 0:
dwa_camera = DataFromPlugins('PiCamera', data=arrays)
else:
dwa_camera = dwa_camera.average(DataFromPlugins('PiCamera', data=arrays),
weight= ind+1)
if self.live:
self.dte_signal_temp.emit(DataToExport('myplugin', data=[dwa_camera]))
else:
self.dte_signal.emit(DataToExport('myplugin', data=[dwa_camera]))
self.dte_signal.emit(DataToExport('myplugin', data=[dwa_camera]))


def stop(self):
"""Stop the current grab hardware wise if necessary"""
self.live = False
return ''


Expand Down
1 change: 0 additions & 1 deletion src/pymodaq_plugins_raspberry/resources/VERSION

This file was deleted.

2 changes: 1 addition & 1 deletion src/pymodaq_plugins_raspberry/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
from pathlib import Path

from pymodaq.utils.config import BaseConfig, USER
from pymodaq_utils.config import BaseConfig, USER


class Config(BaseConfig):
Expand Down
Loading