Skip to content

npxpy.nodes.aligners.FiberAligner

Bases: Node

Source code in npxpy/nodes/aligners.py
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
class FiberAligner(Node):
    def __init__(
        self,
        name: str = "Fiber aligner",
        fiber_radius: Union[float, int] = 63.5,
        center_stage: bool = True,
        action_upon_failure: str = "abort",
        illumination_name: str = "process_led_1",
        core_signal_lower_threshold: Union[float, int] = 0.05,
        core_signal_range: List[Union[float, int]] = [0.1, 0.9],
        detection_margin: Union[float, int] = 6.35,
    ):
        """
        Initialize the fiber aligner with specified parameters.

        Parameters:
            name (str): Name of the fiber aligner.
            fiber_radius (Union[float, int]): Radius of the fiber.
            center_stage (bool): Whether to center the stage.
            action_upon_failure (str): Action upon failure ('abort' or 'ignore').
            illumination_name (str): Name of the illumination source.
            core_signal_lower_threshold (Union[float, int]): Lower threshold for
                the core signal.
            core_signal_range (List[Union[float, int]]): Range for the core
                signal [min, max].
            detection_margin (Union[float, int]): Detection margin.
        """
        super().__init__(
            node_type="fiber_core_alignment",
            name=name,
        )

        # Use setters to handle attributes
        self.fiber_radius = fiber_radius
        self.center_stage = center_stage
        self.action_upon_failure = action_upon_failure
        self.illumination_name = illumination_name
        self.core_signal_lower_threshold = core_signal_lower_threshold
        self.core_signal_range = core_signal_range
        self.detection_margin = detection_margin

        # Default values using setters for consistency
        self.detect_light_direction = False
        self.z_scan_range = [10, 100]
        self.z_scan_range_sample_count = 1
        self.z_scan_range_scan_count = 1

    # Proper setters with validation
    @property
    def fiber_radius(self) -> Union[float, int]:
        return self._fiber_radius

    @fiber_radius.setter
    def fiber_radius(self, value: Union[float, int]):
        if not isinstance(value, (float, int)) or value <= 0:
            raise ValueError("fiber_radius must be a positive number.")
        self._fiber_radius = value

    @property
    def center_stage(self) -> bool:
        return self._center_stage

    @center_stage.setter
    def center_stage(self, value: bool):
        if not isinstance(value, bool):
            raise TypeError("center_stage must be a boolean.")
        self._center_stage = value

    @property
    def action_upon_failure(self) -> str:
        return self._action_upon_failure

    @action_upon_failure.setter
    def action_upon_failure(self, value: str):
        if value not in ["abort", "ignore"]:
            raise ValueError(
                "action_upon_failure must be 'abort' or 'ignore'."
            )
        self._action_upon_failure = value

    @property
    def illumination_name(self) -> str:
        return self._illumination_name

    @illumination_name.setter
    def illumination_name(self, value: str):
        if not isinstance(value, str):
            raise TypeError("illumination_name must be a string.")
        self._illumination_name = value

    @property
    def core_signal_lower_threshold(self) -> Union[float, int]:
        return self._core_signal_lower_threshold

    @core_signal_lower_threshold.setter
    def core_signal_lower_threshold(self, value: Union[float, int]):
        if not isinstance(value, (float, int)):
            raise TypeError(
                "core_signal_lower_threshold must be a float or an int."
            )
        self._core_signal_lower_threshold = value

    @property
    def core_signal_range(self) -> List[Union[float, int]]:
        return self._core_signal_range

    @core_signal_range.setter
    def core_signal_range(self, value: List[Union[float, int]]):
        if not isinstance(value, list) or len(value) != 2:
            raise ValueError(
                "core_signal_range must be a list of two elements."
            )
        if not all(isinstance(val, (float, int)) for val in value):
            raise TypeError(
                "All elements in core_signal_range must be numbers."
            )
        self._core_signal_range = value

    @property
    def detection_margin(self) -> Union[float, int]:
        return self._detection_margin

    @detection_margin.setter
    def detection_margin(self, value: Union[float, int]):
        if not isinstance(value, (float, int)) or value <= 0:
            raise ValueError("detection_margin must be a positive number.")
        self._detection_margin = value

    @property
    def z_scan_range(self) -> List[Union[float, int]]:
        return self._z_scan_range

    @z_scan_range.setter
    def z_scan_range(self, value: List[Union[float, int]]):
        if (
            not isinstance(value, list)
            or len(value) != 2
            or value[1] <= value[0]
        ):
            raise ValueError(
                "z_scan_range must be a list of two elements where the "
                "second element is greater than the first."
            )
        self._z_scan_range = value

    @property
    def z_scan_range_sample_count(self) -> int:
        return self._z_scan_range_sample_count

    @z_scan_range_sample_count.setter
    def z_scan_range_sample_count(self, value: int):
        if not isinstance(value, int) or value <= 0:
            raise ValueError(
                "z_scan_range_sample_count must be a positive integer."
            )
        self._z_scan_range_sample_count = value

    @property
    def z_scan_range_scan_count(self) -> int:
        return self._z_scan_range_scan_count

    @z_scan_range_scan_count.setter
    def z_scan_range_scan_count(self, value: int):
        if not isinstance(value, int) or value <= 0:
            raise ValueError(
                "z_scan_range_scan_count must be a positive integer."
            )
        self._z_scan_range_scan_count = value

    def measure_tilt(
        self,
        z_scan_range: List[Union[float, int]] = [10, 100],
        z_scan_range_sample_count: int = 3,
        z_scan_range_scan_count: int = 1,
    ):
        """
        Measures tilt by setting scan range parameters.

        Parameters:
            z_scan_range (List[Union[float, int]]): Range for the z-scan.
            z_scan_range_sample_count (int): Number of samples in the z-scan.
            z_scan_range_scan_count (int): Number of scans in the z-scan.

        Returns:
            self: The instance of the FiberAligner class.

        """
        self.z_scan_range = z_scan_range
        self.z_scan_range_sample_count = z_scan_range_sample_count
        self.z_scan_range_scan_count = z_scan_range_scan_count
        self.detect_light_direction = True

        return self

    def to_dict(self) -> Dict:
        """
        Converts the current state of the object into a dictionary.

        Returns:
            dict: Dictionary representation of the current state of the object.
        """
        node_dict = super().to_dict()
        # Add custom attributes not covered by super().__init__()
        node_dict.update(
            {
                "fiber_radius": self.fiber_radius,
                "center_stage": self.center_stage,
                "action_upon_failure": self.action_upon_failure,
                "illumination_name": self.illumination_name,
                "core_signal_lower_threshold": self.core_signal_lower_threshold,
                "core_signal_range": self.core_signal_range,
                "core_position_offset_tolerance": self.detection_margin,
                "detect_light_direction": self.detect_light_direction,
                "z_scan_range": self.z_scan_range,
                "z_scan_range_sample_count": self.z_scan_range_sample_count,
                "z_scan_range_scan_count": self.z_scan_range_scan_count,
            }
        )
        return node_dict

__init__(name='Fiber aligner', fiber_radius=63.5, center_stage=True, action_upon_failure='abort', illumination_name='process_led_1', core_signal_lower_threshold=0.05, core_signal_range=[0.1, 0.9], detection_margin=6.35)

Initialize the fiber aligner with specified parameters.

Parameters:

Name Type Description Default
name str

Name of the fiber aligner.

'Fiber aligner'
fiber_radius Union[float, int]

Radius of the fiber.

63.5
center_stage bool

Whether to center the stage.

True
action_upon_failure str

Action upon failure ('abort' or 'ignore').

'abort'
illumination_name str

Name of the illumination source.

'process_led_1'
core_signal_lower_threshold Union[float, int]

Lower threshold for the core signal.

0.05
core_signal_range List[Union[float, int]]

Range for the core signal [min, max].

[0.1, 0.9]
detection_margin Union[float, int]

Detection margin.

6.35
Source code in npxpy/nodes/aligners.py
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
def __init__(
    self,
    name: str = "Fiber aligner",
    fiber_radius: Union[float, int] = 63.5,
    center_stage: bool = True,
    action_upon_failure: str = "abort",
    illumination_name: str = "process_led_1",
    core_signal_lower_threshold: Union[float, int] = 0.05,
    core_signal_range: List[Union[float, int]] = [0.1, 0.9],
    detection_margin: Union[float, int] = 6.35,
):
    """
    Initialize the fiber aligner with specified parameters.

    Parameters:
        name (str): Name of the fiber aligner.
        fiber_radius (Union[float, int]): Radius of the fiber.
        center_stage (bool): Whether to center the stage.
        action_upon_failure (str): Action upon failure ('abort' or 'ignore').
        illumination_name (str): Name of the illumination source.
        core_signal_lower_threshold (Union[float, int]): Lower threshold for
            the core signal.
        core_signal_range (List[Union[float, int]]): Range for the core
            signal [min, max].
        detection_margin (Union[float, int]): Detection margin.
    """
    super().__init__(
        node_type="fiber_core_alignment",
        name=name,
    )

    # Use setters to handle attributes
    self.fiber_radius = fiber_radius
    self.center_stage = center_stage
    self.action_upon_failure = action_upon_failure
    self.illumination_name = illumination_name
    self.core_signal_lower_threshold = core_signal_lower_threshold
    self.core_signal_range = core_signal_range
    self.detection_margin = detection_margin

    # Default values using setters for consistency
    self.detect_light_direction = False
    self.z_scan_range = [10, 100]
    self.z_scan_range_sample_count = 1
    self.z_scan_range_scan_count = 1

measure_tilt(z_scan_range=[10, 100], z_scan_range_sample_count=3, z_scan_range_scan_count=1)

Measures tilt by setting scan range parameters.

Parameters:

Name Type Description Default
z_scan_range List[Union[float, int]]

Range for the z-scan.

[10, 100]
z_scan_range_sample_count int

Number of samples in the z-scan.

3
z_scan_range_scan_count int

Number of scans in the z-scan.

1

Returns:

Name Type Description
self

The instance of the FiberAligner class.

Source code in npxpy/nodes/aligners.py
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
def measure_tilt(
    self,
    z_scan_range: List[Union[float, int]] = [10, 100],
    z_scan_range_sample_count: int = 3,
    z_scan_range_scan_count: int = 1,
):
    """
    Measures tilt by setting scan range parameters.

    Parameters:
        z_scan_range (List[Union[float, int]]): Range for the z-scan.
        z_scan_range_sample_count (int): Number of samples in the z-scan.
        z_scan_range_scan_count (int): Number of scans in the z-scan.

    Returns:
        self: The instance of the FiberAligner class.

    """
    self.z_scan_range = z_scan_range
    self.z_scan_range_sample_count = z_scan_range_sample_count
    self.z_scan_range_scan_count = z_scan_range_scan_count
    self.detect_light_direction = True

    return self

to_dict()

Converts the current state of the object into a dictionary.

Returns:

Name Type Description
dict Dict

Dictionary representation of the current state of the object.

Source code in npxpy/nodes/aligners.py
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
def to_dict(self) -> Dict:
    """
    Converts the current state of the object into a dictionary.

    Returns:
        dict: Dictionary representation of the current state of the object.
    """
    node_dict = super().to_dict()
    # Add custom attributes not covered by super().__init__()
    node_dict.update(
        {
            "fiber_radius": self.fiber_radius,
            "center_stage": self.center_stage,
            "action_upon_failure": self.action_upon_failure,
            "illumination_name": self.illumination_name,
            "core_signal_lower_threshold": self.core_signal_lower_threshold,
            "core_signal_range": self.core_signal_range,
            "core_position_offset_tolerance": self.detection_margin,
            "detect_light_direction": self.detect_light_direction,
            "z_scan_range": self.z_scan_range,
            "z_scan_range_sample_count": self.z_scan_range_sample_count,
            "z_scan_range_scan_count": self.z_scan_range_scan_count,
        }
    )
    return node_dict