Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for change to lh5.read #89

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dspeed/build_dsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def build_dsp(
# Main processing loop
lh5_it = lh5.LH5Iterator(f_raw, tb, buffer_len=buffer_len)
proc_chain = None
for lh5_in, start_row, n_rows in lh5_it:
for lh5_in, start_row in lh5_it:
# Initialize
if proc_chain is None:
proc_chain, lh5_it.field_mask, tb_out = build_processing_chain(
Expand All @@ -184,7 +184,7 @@ def build_dsp(
unit=" rows",
)

n_rows = min(tot_n_rows - start_row, n_rows)
n_rows = min(tot_n_rows - start_row, len(lh5_in))
try:
proc_chain.execute(0, n_rows)
except DSPFatal as e:
Expand Down
11 changes: 8 additions & 3 deletions src/dspeed/processing_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1859,9 +1859,14 @@ def read(self, start: int, end: int) -> None:
)

def write(self, start: int, end: int) -> None:
np.copyto(
self.raw_buf[start:end, ...], self.raw_var[0 : end - start, ...], "unsafe"
)
if self.var.is_const:
np.copyto(self.raw_buf[start:end, ...], self.raw_var, "unsafe")
else:
np.copyto(
self.raw_buf[start:end, ...],
self.raw_var[0 : end - start, ...],
"unsafe",
)

def __str__(self) -> str:
return f"{self.var} linked to lgdo.ArrayOfEqualSizedArrays(shape={self.io_array.nda.shape}, dtype={self.io_array.nda.dtype}, attrs={self.io_array.attrs})"
Expand Down
6 changes: 3 additions & 3 deletions src/dspeed/vis/waveform_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def __init__(
)

# Get the input buffer and read the first chunk
self.lh5_in, _ = self.lh5_it.read(0)
self.lh5_in = self.lh5_it.read(0)

self.aux_vals = aux_values
# Apply entry selection to aux_vals if needed
Expand Down Expand Up @@ -379,11 +379,11 @@ def find_entry(

# Get our current position in the I/O buffers; update if needed
i_tb = entry - self.lh5_it.current_entry
if not (self.lh5_it.n_rows > i_tb >= 0):
if not (len(self.lh5_out) > i_tb >= 0):
self.lh5_it.read(entry)

# Check if entry is out of range
if self.lh5_it.n_rows == 0:
if len(self.lh5_out) == 0:
if safe:
raise IndexError
else:
Expand Down
8 changes: 3 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np
import pytest
from legendtestdata import LegendTestData
from lgdo.lh5 import LH5Store
from lgdo.lh5 import read

import dspeed.processors # noqa: F401

Expand Down Expand Up @@ -41,8 +41,7 @@ def lgnd_test_data():

@pytest.fixture(scope="session")
def geds_raw_tbl(lgnd_test_data):
store = LH5Store()
obj, _ = store.read(
obj = read(
"/geds/raw",
lgnd_test_data.get_path("lh5/LDQTA_r117_20200110T105115Z_cal_geds_raw.lh5"),
n_rows=10,
Expand All @@ -52,8 +51,7 @@ def geds_raw_tbl(lgnd_test_data):

@pytest.fixture(scope="session")
def spms_raw_tbl(lgnd_test_data):
store = LH5Store()
obj, _ = store.read(
obj = read(
"/ch0/raw",
lgnd_test_data.get_path("lh5/L200-comm-20211130-phy-spms.lh5"),
n_rows=10,
Expand Down
7 changes: 3 additions & 4 deletions tests/processors/test_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ def test_histogram_fixed_width(lgnd_test_data, tmptestdir):
)
assert os.path.exists(dsp_file)

st = lh5.LH5Store()
df = st.read("geds/dsp/", dsp_file, field_mask=["hist_weights", "hist_borders"])[
0
].view_as("pd")
df = lh5.read_as(
"geds/dsp/", dsp_file, "pd", field_mask=["hist_weights", "hist_borders"]
)

assert len(df["hist_weights"][0]) + 1 == len(df["hist_borders"][0])
for i in range(2, len(df["hist_borders"][0])):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_build_dsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import lgdo
import pytest
from lgdo.lh5 import LH5Store, ls
from lgdo.lh5 import ls, read

from dspeed import build_dsp

Expand Down Expand Up @@ -83,7 +83,6 @@ def test_build_dsp_spms_channelwise(dsp_test_file_spm):
"ch0/dsp/trigger_pos",
]

store = LH5Store()
lh5_obj, n_rows = store.read("/ch0/dsp/energies", dsp_test_file_spm)
lh5_obj = read("/ch0/dsp/energies", dsp_test_file_spm)
assert isinstance(lh5_obj, lgdo.VectorOfVectors)
assert len(lh5_obj) == 5
5 changes: 1 addition & 4 deletions tests/test_list_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ def test_list_parsing(lgnd_test_data, tmptestdir):
)
assert os.path.exists(dsp_file)

st = lh5.LH5Store()
df = st.read("geds/dsp/", dsp_file, n_rows=5, field_mask=["wf_out"])[0].view_as(
"pd"
)
df = lh5.read_as("geds/dsp/", dsp_file, "pd", n_rows=5, field_mask=["wf_out"])

assert np.all(df["wf_out"][:] == np.array([7, 9, 11, 13, 15]))
14 changes: 6 additions & 8 deletions tests/test_numpy_constants_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ def test_build_dsp(lgnd_test_data, tmptestdir):

def test_numpy_math_constants_dsp(tmptestdir):
dsp_file = f"{tmptestdir}/LDQTA_r117_20200110T105115Z_cal_geds__numpy_test_dsp.lh5"
st = lh5.LH5Store()
df = st.read(
"geds/dsp/", dsp_file, field_mask=["timestamp", "calc1", "calc2", "calc3"]
)[0].view_as("pd")
df = lh5.read_as(
"geds/dsp/", dsp_file, "pd", field_mask=["timestamp", "calc1", "calc2", "calc3"]
)

a1 = df["timestamp"] - df["timestamp"] - np.pi * df["timestamp"]
a2 = df["timestamp"] - df["timestamp"] - np.pi
Expand All @@ -44,10 +43,9 @@ def test_numpy_math_constants_dsp(tmptestdir):

def test_numpy_infinity_and_nan_dsp(tmptestdir):
dsp_file = f"{tmptestdir}/LDQTA_r117_20200110T105115Z_cal_geds__numpy_test_dsp.lh5"
st = lh5.LH5Store()
df = st.read("geds/dsp/", dsp_file, field_mask=["calc4", "calc5", "calc6"])[
0
].view_as("pd")
df = lh5.read_as(
"geds/dsp/", dsp_file, "pd", field_mask=["calc4", "calc5", "calc6"]
)

assert (np.isnan(df["calc4"])).all()
assert (np.isneginf(df["calc5"])).all()
Expand Down
Loading