NNDy/scripts/sequences/TestSetup.py
castaneda be2a7831ea Upload files to "scripts/sequences"
Sequences used for testing MLOOP on the "test setup"
2025-03-21 14:04:46 +01:00

109 lines
2.9 KiB
Python

from labscript import *
import numpy as np
from labscript_utils import import_or_reload
import_or_reload('labscriptlib.NNDy_TestSetup.connection_table')
def wlm(shot_context,t, period = 10, buffer = 1e-3):
import lyse
import time
import pandas as pd
import sys
import h5py
import numpy as np
new_path = r'C:\Users\DyLab\labscript-suite\userlib\labscriptlib\NNDy_TestSetup\Sequences'
if new_path not in sys.path:
sys.path.append(new_path)
import wlmData
# Load the DLL
DLL_PATH = "C:\Windows\SysWOW64\wlmData.dll"
wlmData.LoadDLL(DLL_PATH)
#lyse recalls the hdf5 file, where it will save the measurements
#run = lyse.Run(shot_context.h5_file)
#run.set_group('wlm')
group_name = 'results/wlm'
print(f"Reading wavelength data for {period} seconds. Wait or Press Ctrl+C to stop.")
data = []
start_time = time.time()
#print(start_time)
try:
while True:
# Get the current timestamp
elapsed_time = time.time() - start_time
if elapsed_time > period:
print("Measurement completed!")
break
# Get the wavelength
channel = 4
#second argument is to be left to 0 - see wlm manual page 80
wavelength = wlmData.dll.GetWavelengthNum(channel,0.0)
frequency = wlmData.dll.GetFrequencyNum(channel,0.0)
# Log the data, with a list it's more efficient
data.append([elapsed_time, wavelength, frequency])
#print(f"Time: {elapsed_time}, Wavelength: {wavelength} nm, frequency: {frequency} THz")
# Wait for a short interval before the next reading
time.sleep(buffer)
except KeyboardInterrupt:
print("Measurement stopped.")
#data_df = pd.DataFrame(data, columns = ['timestamp [s]','wavelength [nm]', 'frequency [THz]'])
#the dataframe is saved as wlm_df
frametype = 'wlm_df'
#run.save_result(frametype, data)
with h5py.File(shot_context.h5_file, 'r+') as f:
group = f.require_group(group_name)
dset = group.create_dataset(
frametype, data=data
)
# Specify this dataset should be viewed as an image
dset.attrs['CLASS'] = np.bytes_('TABLE')
fr.add_function('stop',wlm, T_wlm, buffer_wlm)
start()
t0 = 0
t = t0 + wait_AWG
analogue_val = delta_freq * FM_halfrange_analogue / FM_FreqDev
AOM_Control.constant(t, 0)
t+=0.1
AOM_Control.constant(t, analogue_val)
t+=0.5
Camera.expose(t, name = 'camera_snap', frametype = 'image' #name of the frame to be saved in the hdf5 file
)
t+=0.1
CH3.go_high(t + 0.01)
CH3.go_low(t + 0.02)
CH3.go_high(t + 0.03)
CH3.go_low(t + 0.04)
t += 1.05
stop(t)