Skip to content

Commit

Permalink
Update TerascanLogic.save_dage()
Browse files Browse the repository at this point in the history
I added a function written by ChatGPT. I have not tested it yet.
  • Loading branch information
lange50 committed Apr 29, 2025
1 parent 80d5c68 commit 747b624
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions src/qudi/logic/terascan_logic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import os
import re
import numpy as np
import time
from PySide2 import QtCore
Expand Down Expand Up @@ -324,22 +326,43 @@ def clear_data(self):
self._curr_wavelength = 0.0
self._time_since_last_wl_change = time.perf_counter()


# TODO: Clean this up. I don't like the logic.

@QtCore.Slot()
def save_data(self) -> None:
ds = TextDataStorage(
root_dir=self.save_dir, # Use the configurable save directory
column_formats='.15e'
)
array = np.column_stack((
"""
Save self.valid_wavelength_data and self.valid_counts_data to a new
8-digit, zero-padded .dat file in self.save_dir, e.g. '00000001.dat'.
"""
# 1) Make sure directory exists
os.makedirs(self.save_dir, exist_ok=True)

# 2) Find existing files of form '########.dat'
existing = []
for fn in os.listdir(self.save_dir):
if re.fullmatch(r'\d{8}\.dat', fn):
existing.append(int(fn[:8]))
# 3) Determine next index
next_idx = max(existing) + 1 if existing else 1
filename = f"{next_idx:08d}.dat"

# 4) Stack wavelength and counts into an N×2 array
data = np.vstack([
self.valid_wavelength_data,
self.valid_counts_data,
self.ttl_data,
self.wavelength_data,
self.counts_data,
))
ds.save_data(array)
self.valid_counts_data
]).T # shape (N, 2)

# 5) Instantiate storage and save
storage = TextDataStorage(
root_dir=self.save_dir,
comments='# ',
delimiter='\t',
file_extension='.dat',
column_formats=('.8f', '.15e'),
include_global_metadata=False
)
# save_data returns (file_path, timestamp, (rows, columns))
storage.save_data(data, filename=filename)



def __update_data(self):
Expand Down

0 comments on commit 747b624

Please sign in to comment.