Skip to content

Commit

Permalink
added an attribute to LSCReader
Browse files Browse the repository at this point in the history
  • Loading branch information
RemDelaporteMathurin committed Dec 17, 2024
1 parent f4dc2c7 commit 6c971cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libra_toolbox/tritium/lsc_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@


class LSCFileReader:
quench_set: str

def __init__(
self,
file_path: str,
Expand All @@ -29,6 +31,7 @@ def __init__(
self.labels_column = labels_column
self.data = None
self.header_content = None
self.quench_set = None

def read_file(self):
"""
Expand All @@ -50,12 +53,14 @@ def read_file(self):
with open(self.file_path, "r") as file:
lines = file.readlines()
for i, line in enumerate(lines):
if line.startswith("Quench Set:"):
quench_set_line_idx = i + 1
if line.startswith("S#"):
start = i
break
header_lines.append(line)
self.header_content = "".join(header_lines)

self.quench_set = lines[quench_set_line_idx].strip()
# read the file with dataframe starting from the line with S#
self.data = pd.read_csv(self.file_path, skiprows=start)

Expand Down
10 changes: 10 additions & 0 deletions test/tritium/test_lsc_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ def test_lsc_reader_label_automated():

assert len(bq1_values) == 10
assert len(bq1_values_with_labels) == 10


def test_read_quench_set():
"""Tests reading the quench set from the LSC file"""
filename = Path(__file__).parent / "test_lsc_file_with_labels.csv"

csv_reader = LSCFileReader(filename, labels_column="SMPL_ID")
csv_reader.read_file()

assert csv_reader.quench_set == "Low Energy: 3H-UG"

0 comments on commit 6c971cf

Please sign in to comment.