XChroma.app module#

class XChroma.app.MainWindow(*args: Any, **kwargs: Any)[source]#

Bases: QMainWindow

clear_avg()[source]#

Clear the averaged data stored in the data_spectro class

Return type:

None.

clear_plot()[source]#

Clear plots, and init them back

Return type:

None.

clear_static()[source]#

Clear the static data stored in the data_spectro class

Return type:

None.

clear_temp()[source]#

Clear the temporal averaged data stored in the data_spectro class

Return type:

None.

closeEvent(event)[source]#

Handles the event when the main window is closed.

This method is called when the main window is closed. It performs cleanup tasks before the application exits:

  • If an Arduino is connected, it sends a command to the Arduino to signal the termination of communication.

  • Closes the serial connection with the Arduino to safely disconnect.

Additionally, it could optionally save data to a CSV file, though this functionality is currently commented out.

Parameters:

event (QCloseEvent) – The close event triggered when the user attempts to close the window.

Return type:

None.

connect_arduino()[source]#

Initializes and connects to the Arduino controller.

Return type:

None.

connect_ocean()[source]#

Connects to an Ocean Optics spectrometer and initializes it.

This function detects connected spectrometer devices, establishes a connection to the first available device, and initializes its integration time. If no spectrometer is found, it generates synthetic data for display.

Return type:

None.

init_plots()[source]#

Initializes the PyQtGraph plots for displaying spectrometer data.

Return type:

None.

mousePressEvent(event)[source]#

XChroma logo links to documentation

reset_sequence()[source]#

Stops and resets the sequence execution.

If a sequence thread is running, it sends a stop request to ensure the sequence is properly terminated before resetting.

Return type:

None

reset_servo()[source]#

Reset the state of all Servo’s and the checkbox status.

Return type:

None.

sequence_finished()[source]#

Handles actions to perform when a sequence is finished.

  • Resets the button text and icon to indicate that the sequence has stopped.

Return type:

None

set_roi()[source]#

Set the Region Of Interest, also update it if units are changed

Return type:

None.

set_static()[source]#

Sets the static intensity data in the data_spectro class.

This function updates the static attribute in the data_spectro class based on the current checkbox selection:

  • If the “Avg” checkbox is checked, the static data is set to the average intensity data (avg_i).

  • If the “Avg” checkbox is not checked, the static data is set to the raw intensity data (intensities).

The static value is used for baseline correction and further data analysis.

Return type:

None.

set_zero()[source]#

Sets the baseline (zero) intensity data in the data_spectro class.

This function updates the zero attribute in data_spectro based on the current checkbox selection:

  • If the “Avg” checkbox is checked, the baseline is set to the average intensity data.

  • If the “Avg” checkbox is not checked, the baseline is set to the raw intensity data.

Return type:

None.

toggle_sequence()[source]#

Starts, pauses, or resumes the sequence execution.

  • If a sequence thread is running:

    • Toggles between pausing and resuming.

    • Updates the button text and icon accordingly.

  • If no sequence is running:

    • Creates a new SequenceWorker thread to handle the sequence.

    • Connects thread signals for progress updates and completion handling.

    • Starts the thread and updates the button to indicate a running sequence.

Return type:

None

toggle_servo1()[source]#

Toggles the state of Servo 1 based on the checkbox status.

Return type:

None.

toggle_servo2()[source]#

Toggles the state of Servo 2 based on the checkbox status.

Return type:

None.

toggle_servo3()[source]#

Toggles the state of Servo 3 based on the checkbox status.

Return type:

None.

up_delay(value)[source]#

Sets the time interval between two acquisitions. This affects both the display refresh rate and the minimum time between two redundant saves.

This function is triggered when the value of delay_doubleSpinBox changes.

Parameters:

value (int) – timer interval.

Return type:

None.

up_inttime(value)[source]#

Sets the integration time for the spectrometer.

This function is triggered when the value of integrationtime_spinBox changes.

Parameters:

value (int or float) – Integration time in milliseconds.

Return type:

None

update_axis_units()[source]#

Updates the x-axis label based on the selected unit.

This function checks the current selection of units_comboBox and updates the x-axis labels of multiple plots accordingly. Depending on the selected unit, the x-axis could be labeled with:

  • Wavelength (nm): For normal people.

  • Energy (eV): For energy enthusiasts.

  • Frequency (THz): Who use this ?

Return type:

None.

update_plots()[source]#

Updates all plots with the latest data.

This function checks whether a device is connected:

  • If a device is found, it fetches the latest intensity data from the spectrometer.

  • If no device is found, it uses synthetic data for the plots.

After updating the intensity data, the function:

  • Updates the moving average of the intensity data based on the value from the avgspinBox.

  • Updates all four plots (uplot_1, uplot_2, uplot_3, and uplot_4) with the latest data.

Return type:

None.

update_progress_bar(progress)[source]#

Updates the progress bar based on the received progress value.

Parameters:

progress (int) – The current progress value (typically between 0 and 100).

Return type:

None

update_selected_sequence(sequence_name)[source]#

Update the input fields when the user selects a sequence.

uplot_1()[source]#

Updates the first plot with spectrometer data.

This function updates Plot 1 based on the current settings:

  • If the “Static” checkbox is checked, the static data is plotted with a custom color.

  • If the “Avg” checkbox is checked, the average intensity data is plotted, adjusted for static values, with a yellow line.

  • If neither checkbox is selected, the static plot is cleared, and only the raw intensity data is shown.

What is displayed:

  • Raw Data: A plot of the intensity values against the wavelength (scaled data) with a gray line.

  • Static Data: If enabled, a plot of the static values against the wavelength with a purple line.

  • Average Data: If enabled, a plot of the average intensity values with the static data subtracted, displayed in yellow.

Return type:

None.

uplot_2()[source]#

Updates the second plot with absorbance data.

This function updates Plot 2 (For the Spetral Tab) based on the current settings:

  • If the “Static” checkbox is checked, the static data is considered when calculating absorbance.

  • If the “Avg” checkbox is checked, the average intensity is used for absorbance calculation.

  • If the “Avg” checkbox is not checked, the raw intensity is used instead.

The absorbance is calculated directly with the compute_absorbance method of the Dataclass

What is displayed:

  • Absorbance Data: A plot of absorbance values.

Return type:

None.

uplot_3()[source]#

Updates the second plot with absorbance data.

This function updates Plot 3 (For the Temporal Tab) based on the current settings:

  • If the “Static” checkbox is checked, the static data is considered when calculating absorbance.

  • If the “Avg” checkbox is checked, the average intensity is used for absorbance calculation.

  • If the “Avg” checkbox is not checked, the raw intensity is used instead.

The absorbance is calculated directly with the compute_absorbance method of the Dataclass

What is displayed:

  • Absorbance Data: A plot of absorbance values.

Return type:

None.

uplot_4()[source]#

Updates the Plot 4 with temporal absorbance data.

This function updates Plot 4 based on the current settings:

  • If the “Static” checkbox is checked, the static data is considered when calculating temporal absorbance.

  • If the “Avg” checkbox is checked, the average intensity is used for the absorbance calculation.

  • If the “Avg” checkbox is not checked, the raw intensity is used instead.

The absorbance is calculated over a selected region, and the time series data is plotted accordingly.

What is displayed:

  • Temporal Absorbance Data: A plot of temporal absorbance over the selected wavelength region. The x-axis represents time (relative to the start time), and the y-axis represents the absorbance values.

Return type:

None.