-
Notifications
You must be signed in to change notification settings - Fork 0
/
Power_Variation
75 lines (60 loc) · 2.23 KB
/
Power_Variation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 19 16:39:18 2023
@author: batman
"""
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import find_peaks
# Load an example laser pulse data
data = np.loadtxt('laser_pulse.txt') # replace with the path to your data file
# Define the wavelength range of the laser pulse (in nanometers)
wavelength_range = np.linspace(780, 820, data.shape[0])
# Plot the raw laser pulse data
plt.figure()
plt.plot(wavelength_range, data)
plt.xlabel('Wavelength (nm)')
plt.ylabel('Power (W)')
plt.title('Raw laser pulse data')
# Smooth the laser pulse data with a Gaussian filter
sigma = 5 # adjust this parameter to control the amount of smoothing
smoothed_data = ndimage.gaussian_filter1d(data, sigma)
# Plot the smoothed laser pulse data
plt.figure()
plt.plot(wavelength_range, smoothed_data)
plt.xlabel('Wavelength (nm)')
plt.ylabel('Power (W)')
plt.title('Smoothed laser pulse data')
# Find the peaks in the laser pulse spectrum
peaks, _ = find_peaks(smoothed_data, prominence=0.1)
# Plot the laser pulse spectrum with the identified peaks
plt.figure()
plt.plot(wavelength_range, smoothed_data)
plt.plot(wavelength_range[peaks], smoothed_data[peaks], 'x')
plt.xlabel('Wavelength (nm)')
plt.ylabel('Power (W)')
plt.title('Laser pulse spectrum')
# Calculate the peak wavelength and power at each optic
peak_wavelengths = []
peak_powers = []
for i, focal_length in enumerate(focal_lengths):
# Select the laser pulse data for this optic
optic_data = data[:, i]
# Smooth the laser pulse data with a Gaussian filter
smoothed_data = ndimage.gaussian_filter1d(optic_data, sigma)
# Find the peak in the laser pulse spectrum
peak, _ = find_peaks(smoothed_data, prominence=0.1)
# Calculate the peak wavelength and power
peak_wavelength = wavelength_range[peak[0]]
peak_power = smoothed_data[peak[0]]
# Store the peak wavelength and power for this optic
peak_wavelengths.append(peak_wavelength)
peak_powers.append(peak_power)
# Plot the peak power vs. wavelength for each optic
plt.figure()
plt.plot(peak_wavelengths, peak_powers, 'o-')
plt.xlabel('Wavelength (nm)')
plt.ylabel('Peak power (W)')
plt.title('Peak power vs. wavelength')
plt.show()