21"""Simulation of a full setup based on a given image file.
41_logger = logging.getLogger(__name__)
45 """Simulated camera that returns subregions of image based on stage
48 Instead of using this class directly, consider using the
49 :func:`simulated_setup_from_image` function which will generate
50 all the required simulated devices
for a given image file.
53 image: the image
from which regions will be cropped based on
54 the stage
and filter wheel positions.
55 stage: stage to read coordinates
from. Must have an
"x",
57 filterwheel: filter wheel to read position.
74 if not all([name
in stage.axes.keys()
for name
in [
"x",
"y",
"z"]]):
76 "stage for StageAwareCamera requires x, y, and z axis"
80 "image has %d channels but filterwheel has %d positions"
93 lambda pxsz: setattr(self,
"_pixel_size", pxsz),
95 values=(0.0, float(
"inf")),
98 def _fetch_data(self) -> typing.Optional[np.ndarray]:
104 _logger.info(
"Creating image")
115 subsection = self.
_image[y : y + height, x : x + width, channel]
119 blur = abs((self.
_stage.position[
"z"]) / 10.0)
120 image = scipy.ndimage.gaussian_filter(subsection, blur)
126 return np.fliplr(np.flipud(image))
129def simulated_setup_from_image(
130 filepath: str, **kwargs
132 """Create simulated devices given an image file.
134 To use with the `device-server`::
137 device(simulated_setup_from_image,
'localhost', 8000,
138 conf={
'filepath': path_to_image_file}),
141 PIL.Image.MAX_IMAGE_PIXELS = None
142 image = np.array(PIL.Image.open(filepath))
143 if len(image.shape) < 3:
144 raise ValueError(
"not an RGB image")
158 "filterwheel": filterwheel,
None add_setting(self, name, dtype, get_func, set_func, values, typing.Optional[typing.Callable[[], bool]] readonly=None)
None __init__(self, np.ndarray image, microscope.abc.Stage stage, microscope.abc.FilterWheel filterwheel, **kwargs)