API
 
Loading...
Searching...
No Matches
__init__.py
Go to the documentation of this file.
1import sys
2import logging
3from enum import Enum
4import time
5import numpy as np
6
7import xconf
8
9from magaox.indi.device import XDevice, BaseConfig
10from magaox.camera import XCam
11from magaox.deformable_mirror import XDeformableMirror, XFourierMirror, XPokeMirror
12from magaox.constants import StateCodes
13
14from purepyindi2 import device, properties, constants
15from purepyindi2.messages import DefNumber, DefSwitch, DefLight, DefText
16
17from hcipy import make_circular_aperture
18
19def measure_center_position(image, threshold=1, mask_diameter=20):
20 center_mask = make_circular_aperture(mask_diameter)(image.grid)
21 mask = center_mask * ((image / np.nanstd(image)) < threshold)
22
23 if np.sum(mask) > 0:
24 xc = np.sum(mask * image.grid.x) / np.sum(mask)
25 yc = np.sum(mask * image.grid.y) / np.sum(mask)
26 return np.array([xc, yc])
27 else:
28 return np.array([0.0, 0.0])
29
30@xconf.config
32 """
33 """
34 shmim : str = xconf.field(help="Name of the camera device (specifically, the associated shmim, if different)")
35 dark_shmim : str = xconf.field(help="Name of the dark frame shmim associated with this camera device")
36
37@xconf.config
38class efcControlConfig(BaseConfig):
39 """Automatic coronagraph alignment assistant
40 """
41 camera : CameraConfig = xconf.field(help="Camera to use")
42 sleep_interval_sec : float = xconf.field(default=0.25, help="Sleep interval between loop() calls")
43
44class States(Enum):
45 IDLE = 0
46
47class efcControl(XDevice):
48 config : efcControlConfig
49
50 def setup(self):
51 self.log.debug(f"I was configured! See? {self.config=}")
52 fsm = properties.TextVector(name='fsm')
53 fsm.add_element(DefText(name='state', _value=StateCodes.INITIALIZED.name))
54 self.add_property(fsm)
55
56 self.log.info("Found camera: {:s}".format(self.config.camera.shmim))
57 self.camera = XCam(self.config.camera.shmim, use_hcipy=True)
58 self._state = States.IDLE
59
60 self.properties['fsm']['state'] = StateCodes.READY.name
61 self.update_property(self.properties['fsm'])
62
63 def loop(self):
64 pass
65 # Basic EFC loop
66 # Acquire sequence of images
67 # Need to trigger based on start of exposure?
68 # Send DM command
69 # Get
efcControlConfig config
Definition __init__.py:48
measure_center_position(image, threshold=1, mask_diameter=20)
Definition __init__.py:19