Analysis Tools

This section contains various tools for analyzing laser measurements and data processing.

Optical Spectrum Analysis

The OSA (Optical Spectrum Analyzer) module provides functionality for loading, processing, and visualizing data from Optical Spectrum Analyzers. It includes tools for:

  • Loading OSA data from single files or directories

  • Processing wavelength and power measurements

  • Plotting optical spectra with customizable parameters

  • Handling metadata from OSA measurements

Key Methods

  • load_osa_data(file_path): Loads OSA data from a single file, extracting wavelength and power measurements and metadata. Returns wavelengths (nm), power (dBm), and metadata.

  • process_osa_directory(directory_path): Processes all OSA data files in a directory, handling errors gracefully. Returns a list of processed data tuples.

  • plot_osa_spectrum(wavelengths, power, title=None, ylim=None, save_path=None): Creates standardized plots of optical spectrum data with proper labeling and optional customization.

  • process_and_plot_osa_data(data_path, plot=True, save_plots=False, output_dir=None): High-level function that combines loading, processing, and plotting functionality for both single files and directories.

Complete API Reference

Noise Analysis

The RIN (Relative Intensity Noise) module provides comprehensive tools for analyzing Relative Intensity Noise in optical systems. Key features include:

  • Calibration of optical-to-electrical conversion

  • Processing of RIN measurements from ESA (Electrical Spectrum Analyzer) data

  • Calculation of single RIN values and statistical analysis

  • Visualization of RIN spectra with background comparison

  • Conversion utilities between linear and dB scales

Key Methods

Calibration and Conversion

  • calibrate_conversion(power_uW, voltage_mV): Performs linear fit to determine conversion factor between optical power and electrical voltage measurements.

  • convert_optical_to_electrical(power, conversion_factor, impedance=50.0, ret_V=False): Converts optical power to electrical power (dBm) or voltage (V) using calibration factor.

Data Processing

  • process_intensity_data(path, conversion_factor, power=None): Processes intensity data from a single file, applying RBW correction and conversion.

  • calculate_single_RIN(xs, ys, start_idx=10): Calculates single RIN value from frequency and RIN data.

  • get_RIN_data(directory, conversion_factor, background_identifier, background_power, plot=True, start_idx=None): Processes and gets RIN data from a directory, including background subtraction.

Utility Functions

  • ratio_to_db(feedback_power, output_power, min_power=0.000003): Converts power ratio to dB.

  • linear_to_dB(datapoint_linear): Converts linear power to dB.

  • dB_to_linear(power): Converts dB to linear power.

Visualization

  • plot_RIN_data(xs_list, ys_list, rbw, background_idx=None): Creates standardized plots of RIN data with proper formatting and optional background comparison.

Complete API Reference

Frequency Stability Analysis

The Beatnote Drift module provides tools for analyzing and visualizing beatnote drift measurements in optical systems. Key features include:

  • Loading and parsing beatnote measurement data

  • Processing time-dependent frequency and power measurements

  • Statistical analysis of frequency drift (mean, standard deviation, peak-to-peak)

  • Visualization of drift and power data with customizable units

  • Support for various data formats and conversion factors

Key Methods

Data Loading and Processing

  • load_beatnote_data(filepath): Loads beatnote data from a file, extracting timestamps, frequencies, and power measurements.

  • process_beatnote_data(timestamps, frequencies, powers, freq_conversion=1e-9, power_conversion=20/1000): Processes raw beatnote data with unit conversions and organizes into a dictionary format.

Analysis

  • analyze_beatnote_drift(freq_drift): Calculates statistical measures of frequency drift, including mean, standard deviation, and peak-to-peak values.

Visualization

  • plot_beatnote_data(processed_data, freq_ylim=None, power_ylim=None, title=None, save_path=None): Creates a figure with two subplots showing frequency drift and power measurements over time.

Complete API Reference

Linewidth Analysis

Module containing mathematical functions for fitting laser measurement data.

This module provides various mathematical functions used for fitting and analyzing laser measurement data, including Gaussian and Lorentzian functions, time delay calculations, and power spectral density (PSD) functions.

u_shaped_lib.fit_functions.gauss_log(x, a, b)[source]

Gaussian function in logarithmic scale (base e).

Parameters:
Returns:

Gaussian function values in log scale

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.lor_log(x, a, df)[source]

Lorentzian function in logarithmic scale (base 10).

Parameters:
Returns:

Lorentzian function values in log scale

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.del_o(del_f)[source]

Transform frequency to angular frequency.

Parameters:

del_f (float) – Frequency in Hz

Returns:

Angular frequency in rad/s

Return type:

float

u_shaped_lib.fit_functions.time_delay(fiber_length)[source]

Calculate time delay in an optical fiber.

Parameters:

fiber_length (float) – Length of the fiber in meters

Returns:

Time delay in seconds

Return type:

float

u_shaped_lib.fit_functions.Lorentzian_dB(omega, A, del_f, freq_center)[source]

Lorentzian function in dB scale.

Parameters:
  • omega (numpy.ndarray) – Angular frequencies

  • A (float) – Amplitude parameter

  • del_f (float) – Linewidth parameter

  • freq_center (float) – Center frequency

Returns:

Lorentzian function values in dB scale

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.Lor_dB(x, a, df)[source]

Alternative Lorentzian function in dB scale.

Parameters:
Returns:

Lorentzian function values in dB scale

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.PSD_real_laser_dB(omega, A, del_f, freq_center, a1)[source]

Real part of laser power spectral density in dB scale.

Parameters:
  • omega (numpy.ndarray) – Angular frequencies

  • A (float) – Amplitude parameter

  • del_f (float) – Linewidth parameter

  • freq_center (float) – Center frequency

  • a1 (float) – Gaussian width parameter

Returns:

PSD values in dB scale

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.zeta_func(f, del_f, t_d)[source]

Zeta function for laser linewidth calculations.

Parameters:
Returns:

Zeta function values

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.zeta_zero(del_f, t_d)[source]

Zero-frequency value of zeta function.

Parameters:
  • del_f (float) – Linewidth parameter

  • t_d (float) – Time delay

Returns:

Zero-frequency zeta value

Return type:

float

u_shaped_lib.fit_functions.f_minus(f, freq_shift)[source]

Frequency shift function.

Parameters:
Returns:

Shifted frequencies

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.q_func(A_1, A_2)[source]

Q-function for amplitude ratio calculations.

Parameters:
  • A_1 (float) – First amplitude

  • A_2 (float) – Second amplitude

Returns:

Q-function value

Return type:

float

u_shaped_lib.fit_functions.dirac_delta(x, limit)[source]

Approximate Dirac delta function.

Parameters:
Returns:

Approximate delta function values

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.DSH_ideal_PSD(f, freq_shift, del_f, t_d, limit)[source]

Ideal power spectral density for delayed self-heterodyne measurements.

Parameters:
  • f (numpy.ndarray) – Frequencies

  • freq_shift (float) – Frequency shift

  • del_f (float) – Linewidth parameter

  • t_d (float) – Time delay

  • limit (float) – Delta function limit

Returns:

PSD values

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.Gaussian_dB(x, A, freq_center, var)[source]

Gaussian function in dB scale.

Parameters:
  • x (numpy.ndarray) – Input values

  • A (float) – Amplitude parameter

  • freq_center (float) – Center frequency

  • var (float) – Variance parameter

Returns:

Gaussian function values in dB scale

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.Gauss_dB(x, a, b)[source]

Simplified Gaussian function in dB scale.

Parameters:
Returns:

Gaussian function values in dB scale

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.zeta_fit(freq, linewidth, offset, length)[source]

Zeta function for fitting laser linewidth data.

Parameters:
  • freq (numpy.ndarray) – Frequencies

  • linewidth (float) – Linewidth parameter

  • offset (float) – Offset parameter

  • length (float) – Fiber length

Returns:

Fitted zeta function values

Return type:

numpy.ndarray

u_shaped_lib.fit_functions.R_squared(data, fitfunc_evaluated)[source]

Calculate R-squared value for fit quality assessment.

Parameters:
Returns:

R-squared value

Return type:

float

Module for analyzing laser linewidth measurements.

This module provides a class for loading, processing and analyzing laser linewidth measurements, including frequency noise (FN) and relative intensity noise (RIN) data.

class u_shaped_lib.lwa_lib.LWA(path, header_lines=13)[source]

Bases: object

Class for analyzing laser linewidth measurements.

This class provides methods to load and process laser linewidth data from various measurement files, including frequency noise (FN) and relative intensity noise (RIN) measurements.

Variables:
  • path (str) – Path to the measurement file

  • header_lines (int) – Number of header lines in the file

  • type (str) – Type of measurement (‘PSD’, ‘RIN’, or ‘Power’)

  • freqs (numpy.ndarray) – Array of frequency values

  • powers (numpy.ndarray) – Array of power values

  • df (float) – Frequency step size

__init__(path, header_lines=13)[source]

Initialize LWA object.

Parameters:
  • path (str) – Path to the measurement file

  • header_lines (int, optional) – Number of header lines in the file, by default 13

get_header()[source]

Extract header information from the measurement file.

Returns:

List of header lines split into components

Return type:

list

get_type()[source]

Determine the type of measurement from the header.

Returns:

Type of measurement (‘PSD’, ‘RIN’, or ‘Power’)

Return type:

str

get_linewidth()[source]

Extract linewidth value from the header.

Returns:

Linewidth value in Hz

Return type:

float

fit_linewidth(lower=1e6, upper=10e6)[source]

Fit linewidth using data in specified frequency range.

Parameters:
  • lower (float, optional) – Lower frequency bound for fitting, by default 1e6

  • upper (float, optional) – Upper frequency bound for fitting, by default 10e6

Returns:

Fitted linewidth value in Hz

Return type:

float

plot(scale='log', factor=1, label='', title='')[source]

Plot the measurement data.

Parameters:
  • scale (str, optional) – Scale type (‘log’ or ‘lin’), by default ‘log’

  • factor (float, optional) – Scaling factor for the power values, by default 1

  • label (str, optional) – Plot label, by default ‘’

  • title (str, optional) – Plot title, by default ‘’