diff --git a/src/dspeed/build_dsp.py b/src/dspeed/build_dsp.py index 3347a70..612ca34 100644 --- a/src/dspeed/build_dsp.py +++ b/src/dspeed/build_dsp.py @@ -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( @@ -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: diff --git a/src/dspeed/processing_chain.py b/src/dspeed/processing_chain.py index 1995d6e..563d5fb 100644 --- a/src/dspeed/processing_chain.py +++ b/src/dspeed/processing_chain.py @@ -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})" diff --git a/src/dspeed/vis/waveform_browser.py b/src/dspeed/vis/waveform_browser.py index 0bfa3ab..3486076 100644 --- a/src/dspeed/vis/waveform_browser.py +++ b/src/dspeed/vis/waveform_browser.py @@ -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 @@ -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: diff --git a/tests/conftest.py b/tests/conftest.py index 71dc0a8..8d56c6a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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, @@ -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, diff --git a/tests/processors/test_histogram.py b/tests/processors/test_histogram.py index 3462806..fd69c6b 100644 --- a/tests/processors/test_histogram.py +++ b/tests/processors/test_histogram.py @@ -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])): diff --git a/tests/test_build_dsp.py b/tests/test_build_dsp.py index 9fc3bec..0ae2897 100644 --- a/tests/test_build_dsp.py +++ b/tests/test_build_dsp.py @@ -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 @@ -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 diff --git a/tests/test_list_parsing.py b/tests/test_list_parsing.py index 9039de5..573ab50 100644 --- a/tests/test_list_parsing.py +++ b/tests/test_list_parsing.py @@ -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])) diff --git a/tests/test_numpy_constants_parsing.py b/tests/test_numpy_constants_parsing.py index c80f33b..97a3c97 100644 --- a/tests/test_numpy_constants_parsing.py +++ b/tests/test_numpy_constants_parsing.py @@ -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 @@ -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()