Skip to content

Laser

pychilaslasers.laser

Define the Laser class for Chilas lasers.

This acts as the main interface for controlling the laser. Some properties and methods of the laser are accessible at all times, while others are only available in specific operation modes.

The modes of the laser are:

  • ManualMode: Allows manual control of the heater values.
  • SteadyMode: Can be used to tune the laser to specific wavelengths according to the calibration data.
  • SweepMode: Sweep mode is used for COMET lasers to enable the sweep functionality.

Changing the diode current or TEC temperature of the laser is available in all modes however this implies that the calibration of the laser is no longer valid and the laser may not achieve the desired wavelength.

Authors: RLK, AVR, SDU

pychilaslasers.Laser(com_port: str, calibration_file: str | Path | None = None)

Laser class for Chilas lasers.

Contains the main methods for communication with the laser, the logic for changing and accessing the laser modes, and the properties of the laser. Multiple overloaded methods are available to interact with the laser. Many of the methods are overloads of other methods that either provide different ways do the same operation for convenience.

Usage

Accessing functionality of a specific mode is done through the mode property such as laser.steady.method_name() or laser.sweep.method_name(). This will however only work if the laser is in the correct mode. If the laser is not in the correct mode, an exception will be raised. The current mode of the laser can be set using the mode property as well.

The laser can be turned on and off using the system_state property. The laser can also be triggered to pulse using the trigger_pulse() method. The laser can be set to prefix mode using the prefix_mode property. The prefix mode can be used to speed up communication with the laser by reducing the amount of data sent over the serial connection however this reduces the amount of information that is sent back from the laser.

Some laser components such as the TEC and Diode can be accessed in all modes using the tec and diode properties respectively. Other components are only available in manual mode.

Attributes:

  • tec (TEC) –

    The TEC component of the laser.

  • diode (Diode) –

    The Diode component of the laser.

  • mode (Mode) –

    The current mode of the laser.

  • system_state (bool) –

    The system state of the laser (on/off).

  • prefix_mode (bool) –

    Whether the laser is in prefix mode or not.

Opens the serial connection to the laser, initializes the laser components and variables, and sets the initial mode to manual.

Warning

During the initialization, the laser will turn on and communicate over the serial connection to gather necessary information about the laser and its components such as maximum values for parameters.

Parameters:

  • com_port (str) –

    The COM port to which the laser is connected. This should be a string such as "COM7". To see available COM you may use the pychilaslasers.utils.list_comports method from the utils module.

  • calibration_file (str | Path, default: None ) –

    The path to the calibration file that was provided for the laser.

Source code in src/pychilaslasers/laser.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def __init__(
    self, com_port: str, calibration_file: str | Path | None = None
) -> None:
    """Initialize the laser with the given COM port and calibration file.

    Opens the serial connection to the laser, initializes the laser components and
    variables, and sets the initial mode to manual.

    Warning:
        During the initialization, **the laser will turn on** and communicate over
        the serial connection to gather necessary information about the laser and
        its components such as maximum values for parameters.

    Args:
        com_port: The COM port to which the laser is connected. This should
            be a string such as "COM7". To see available COM you may use the
            `pychilaslasers.utils.list_comports` method from the `utils` module.
        calibration_file (str | Path):
            The path to the calibration file that was provided for the laser.

    """
    self._comm: Communication = Communication(com_port=com_port)

    # Laser identification. Library will not work with non-Chilas lasers.
    if "Chilas" not in (idn := self._comm.query("*IDN?")) and "LioniX" not in idn:
        logger.critical("Laser is not a Chilas device")
        import sys

        sys.exit(1)

    # Initialize laser components
    self.tec: TEC = TEC(self)
    self.diode: Diode = Diode(self)

    # Initialize modes
    self._manual_mode: ManualMode = ManualMode(self)

    self._model: str = "Unknown"
    self._steady_mode: SteadyMode | None = None
    self._sweep_mode: SweepMode | None = None

    if calibration_file is not None:
        calibration = read_calibration_file(file_path=calibration_file)
        self._model = calibration["model"]
        self._steady_mode = SteadyMode(self, calibration)
        self._sweep_mode = (
            SweepMode(self, calibration)
            if calibration["model"] == "COMET"
            else None
        )

    self._mode: Mode = self._manual_mode

    logger.debug(
        f"Initialized laser {self._model} on {com_port} with calibration file "
        f"{calibration_file}"
    )

Attributes

comm: Communication property

Communication object for the laser.

This property provides access to the communication object used to interact with the laser. It can be used to send commands and queries to the laser.

Returns:

system_state: bool property writable

System state of the laser.

The property of the laser that indicates whether the laser is on or off. This is a boolean property that can be set to True to turn on the laser or False to turn it off.

Returns:

  • bool

    The system state. Whether the laser is on (True) or off (False).

mode: LaserMode property writable

Gets the current mode of the laser.

Returns:

  • LaserMode

    The current mode of the laser. This can be one of the following: - LaserMode.MANUAL - LaserMode.STEADY - LaserMode.SWEEP

steady: SteadyMode property

Getter function for the steady mode instance.

This property allows access to the steady mode instance of the laser in a convenient way such as laser.steady.method(). Steady mode uses calibration data to tune the laser to specific wavelengths with high precision. This mode is available for both COMET and ATLAS lasers and provides wavelength control based on the laser's calibration file.

Warning

This method will not change the mode of the laser, it will only return the steady mode instance if the laser is in that mode. To switch to steady mode, use laser.mode = LaserMode.STEADY or laser.set_mode("steady") first.

Returns:

  • SteadyMode

    The steady mode instance with access to wavelength control methods.

Raises:

  • ModeError

    If the laser is not in steady mode.

Example
>>> laser.mode = LaserMode.STEADY
>>> laser.steady.set_wavelength(1550.0)  # Set wavelength to 1550nm

sweep: SweepMode property

Getter function for the sweep mode instance.

This property allows access to the sweep mode instance of the laser in a convenient way such as laser.sweep.method(). Sweep mode is only available for COMET lasers and enables sweeping functionality for wavelength scanning applications. This mode uses calibration data to perform controlled wavelength sweeps across specified ranges.

Warning

This method will not change the mode of the laser, it will only return the sweep mode instance if the laser is in that mode. To switch to sweep mode, use laser.mode = LaserMode.SWEEP or laser.set_mode("sweep") first.

Returns:

  • SweepMode

    The sweep mode instance with access to sweep control methods.

Raises:

  • ModeError

    If the laser is not in sweep mode or sweep mode is not available.

Example
>>> laser.mode = LaserMode.SWEEP  # Only works for COMET lasers
>>> laser.sweep.start_wavelength_sweep(1550.0, 1560.0)  # Sweep from 1550nm to 1560nm

manual: ManualMode property

Getter function for the manual mode instance.

This property allows access to the manual mode instance of the laser in a convenient way such as laser.manual.method(). Manual mode is always available and is the default mode. In manual mode, you have direct control over individual laser components and can manually set heater values and other parameters.

Warning

This method will not change the mode of the laser, it will only return the manual mode instance if the laser is in that mode. To switch to manual mode, use laser.mode = LaserMode.MANUAL or laser.set_mode("manual") first.

Returns:

  • ManualMode

    The manual mode instance with access to manual control methods.

Raises:

  • ModeError

    If the laser is not in manual mode.

Example
>>> laser.mode = LaserMode.MANUAL
>>> laser.manual.set_heater_value(50.0)  # Set heater to 50%

model: str property

Return the model of the laser.

Returns:

  • str

    The model of the laser. May be "COMET" or "ATLAS"

calibrated: bool property

Check if the laser is calibrated.

Returns:

  • bool

    True if the laser has calibration data, False otherwise.

Functions

trigger_pulse() -> None

Instructs the laser to send a trigger pulse.

Source code in src/pychilaslasers/laser.py
143
144
145
146
def trigger_pulse(self) -> None:
    """Instructs the laser to send a trigger pulse."""
    self._comm.query(f"DRV:CYC:TRIG {int(True):d}")
    self._comm.query(f"DRV:CYC:TRIG {int(False):d}")

calibrate(calibration_file: str | Path) -> None

Calibrates the laser with the given calibration file.

Parameters:

  • calibration_file (str | Path) –

    The path to the calibration file to be used for calibrating the laser.

Source code in src/pychilaslasers/laser.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
def calibrate(self, calibration_file: str | Path) -> None:
    """Calibrates the laser with the given calibration file.

    Args:
        calibration_file (str | Path):
            The path to the calibration file to be used for calibrating the laser.

    """
    calibration = read_calibration_file(file_path=calibration_file)
    self._model = calibration["model"]
    self._steady_mode = SteadyMode(self, calibration)

    if self._model == "COMET":
        self._sweep_mode = SweepMode(self, calibration)
    params = calibration["steady"]["anti-hyst"]
    self._manual_mode.phase_section.set_hyst_params(params[0], params[1])

set_mode(mode: LaserMode | Mode | str) -> None

Set the mode of the laser.

This is an alias for the mode property setter.

Source code in src/pychilaslasers/laser.py
453
454
455
456
457
458
def set_mode(self, mode: LaserMode | Mode | str) -> None:
    """Set the mode of the laser.

    This is an alias for the `mode` property setter.
    """
    self.mode = mode

turn_on() -> None

Turn on the laser.

This is an alias for setting the system state to True.

Source code in src/pychilaslasers/laser.py
460
461
462
463
464
465
def turn_on(self) -> None:
    """Turn on the laser.

    This is an alias for setting the system state to True.
    """
    self.system_state = True

turn_off() -> None

Turn off the laser.

This is an alias for setting the system state to False.

Source code in src/pychilaslasers/laser.py
467
468
469
470
471
472
def turn_off(self) -> None:
    """Turn off the laser.

    This is an alias for setting the system state to False.
    """
    self.system_state = False