Skip to content

hal

plantimager.hal Link

AbstractCNC Link

AbstractCNC()

Abstract CNC class.

Source code in plantimager/hal.py
69
70
def __init__(self):
    pass

AbstractCamera Link

Bases: ABC

Abstract Camera class.

grab abstractmethod Link

grab(idx, metadata=None)

Grab data with an id and metadata.

Parameters:

Name Type Description Default
idx int

Id of the data DataItem to create.

required
metadata dict

Dictionary of metadata associated to the camera data.

None

Returns:

Type Description
DataItem

The image data.

Source code in plantimager/hal.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@abstractmethod
def grab(self, idx: int, metadata: dict = None):
    """Grab data with an id and metadata.

    Parameters
    ----------
    idx : int
        Id of the data `DataItem` to create.
    metadata : dict, optional
        Dictionary of metadata associated to the camera data.

    Returns
    -------
    plantimager.hal.DataItem
        The image data.
    """
    pass

AbstractGimbal Link

Bases: ABC

Abstract Gimbal class.

AbstractScanner Link

AbstractScanner()

An abstract scanner class.

Attributes:

Name Type Description
scan_count int

Incremental counter saving last picture index for the grab method. Modified by the inc_count method.

exact_pose bool

States whether the camera pose is exact or approximate.

ext str

Extension to use to write image data from the grab method.

Source code in plantimager/hal.py
165
166
167
168
169
def __init__(self):
    self.scan_count = 0
    self.exact_pose = False
    self.ext = 'jpg'
    super().__init__()

channels abstractmethod Link

channels()

Channel names associated to data from grab method.

See Also

plantimager.hal.AbstractCamera

Source code in plantimager/hal.py
203
204
205
206
207
208
209
210
211
@abstractmethod
def channels(self) -> List[str]:
    """Channel names associated to data from `grab` method.

    See Also
    --------
    plantimager.hal.AbstractCamera
    """
    pass

get_position abstractmethod Link

get_position()

Get the current position of the scanner.

Source code in plantimager/hal.py
171
172
173
174
@abstractmethod
def get_position(self) -> Pose:
    """Get the current position of the scanner."""
    pass

get_target_pose Link

get_target_pose(elt)

Get the target pose from a given path element (singleton).

Parameters:

Name Type Description Default
elt PathElement

The path element to reach.

required

Returns:

Type Description
Pose

The target pose to reach.

Notes

If a Pose attribute is missing from the given path element, we use the value from the previous pose.

Source code in plantimager/hal.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
def get_target_pose(self, elt):
    """Get the target pose from a given path element (singleton).

    Parameters
    ----------
    elt : plantimager.path.PathElement
        The path element to reach.

    Returns
    -------
    plantimager.path.Pose
        The target pose to reach.

    Notes
    -----
    If a ``Pose`` attribute is missing from the given path element, we use the value from the previous pose.
    """
    pos = self.get_position()
    target_pose = Pose()
    for attr in pos.attributes():
        if getattr(elt, attr) is None:
            setattr(target_pose, attr, getattr(pos, attr))
        else:
            setattr(target_pose, attr, getattr(elt, attr))
    return target_pose

grab abstractmethod Link

grab(idx, metadata)

Grab data with an id and metadata.

Parameters:

Name Type Description Default
idx int

Id of the data DataItem to create.

required
metadata dict

Dictionary of metadata associated to the camera data.

required

Returns:

Type Description
DataItem

The image data & metadata.

See Also

plantimager.hal.AbstractCamera

Source code in plantimager/hal.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
@abstractmethod
def grab(self, idx, metadata):
    """Grab data with an id and metadata.

    Parameters
    ----------
    idx : int
        Id of the data `DataItem` to create.
    metadata : dict, optional
        Dictionary of metadata associated to the camera data.

    Returns
    -------
    plantimager.hal.DataItem
        The image data & metadata.

    See Also
    --------
    plantimager.hal.AbstractCamera
    """
    pass

inc_count Link

inc_count()

Incremental counter used to return a picture index for the grab method.

Source code in plantimager/hal.py
213
214
215
216
217
def inc_count(self) -> int:
    """Incremental counter used to return a picture index for the ``grab`` method."""
    x = self.scan_count
    self.scan_count += 1
    return x

scan Link

scan(path, fileset)

Performs a scan, that is a series of movements and image acquisitions.

Parameters:

Name Type Description Default
path Path

The path to follows to acquire image.

required
fileset Fileset

The output fileset used to save the image.

required
Source code in plantimager/hal.py
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
def scan(self, path, fileset):
    """Performs a scan, that is a series of movements and image acquisitions.

    Parameters
    ----------
    path : plantimager.path.Path
        The path to follows to acquire image.
    fileset : plantdb.FSDB.Fileset
        The output fileset used to save the image.
    """
    for x in tqdm(path, unit='pose'):
        pose = self.get_target_pose(x)
        data_item = self.scan_at(pose, self.exact_pose)
        for c in self.channels():
            f = fileset.create_file(data_item.channels[c].format_id())
            data = data_item.channels[c].data
            if "float" in data.dtype.name:
                data = np.array(data * 255).astype("uint8")
            io.write_image(f, data, ext=self.ext)
            if data_item.metadata is not None:
                f.set_metadata(data_item.metadata)
            f.set_metadata("shot_id", "%06i" % data_item.idx)
            f.set_metadata("channel", c)
    return

scan_at Link

scan_at(pose, exact_pose=True, metadata=None)

Move to a given position and take a picture.

Parameters:

Name Type Description Default
pose Pose

The position of the camera to take the picture.

required
exact_pose bool

If True (default), save the given pose under a "pose" entry in metadata. Else, save it as an "approximate_pose" entry in metadata.

True
metadata dict

The dictionary of metadata to associate to this picture.

None

Returns:

Type Description
DataItem

The picture data & metadata.

Source code in plantimager/hal.py
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
def scan_at(self, pose, exact_pose=True, metadata=None):
    """Move to a given position and take a picture.

    Parameters
    ----------
    pose : plantimager.path.Pose
        The position of the camera to take the picture.
    exact_pose : bool, optional
        If ``True`` (default), save the given `pose` under a "pose" entry in metadata.
        Else, save it as an "approximate_pose" entry in metadata.
    metadata : dict, optional
        The dictionary of metadata to associate to this picture.

    Returns
    -------
    plantimager.hal.DataItem
        The picture data & metadata.
    """
    logger.debug(f"scanning at: {pose}")
    if metadata is None:
        metadata = {}
    if exact_pose:
        metadata = {**metadata, "pose": [pose.x, pose.y, pose.z, pose.pan, pose.tilt]}
    else:
        metadata = {**metadata, "approximate_pose": [pose.x, pose.y, pose.z, pose.pan, pose.tilt]}
    logger.debug(f"with metadata: {metadata}")
    self.set_position(pose)
    return self.grab(self.inc_count(), metadata=metadata)

set_position abstractmethod Link

set_position(pose)

Set the position of the scanner from a 5D Pose.

Source code in plantimager/hal.py
176
177
178
179
@abstractmethod
def set_position(self, pose: Pose) -> None:
    """Set the position of the scanner from a 5D Pose."""
    pass