diff --git a/axidence/plugin.py b/axidence/plugin.py index 0dd61d4..19f4000 100644 --- a/axidence/plugin.py +++ b/axidence/plugin.py @@ -6,28 +6,9 @@ import straxen from straxen import units - export, __all__ = strax.exporter() -@export -class ExhaustPlugin(Plugin): - """Plugin that exhausts all chunks when fetching data.""" - - def _fetch_chunk(self, d, iters, check_end_not_before=None): - while super()._fetch_chunk(d, iters, check_end_not_before=check_end_not_before): - pass - return False - - def do_compute(self, chunk_i=None, **kwargs): - if chunk_i != 0: - raise RuntimeError( - f"{self.__class__.__name__} is an ExhaustPlugin. " - "It should read all chunks together can process them together." - ) - return super().do_compute(chunk_i=chunk_i, **kwargs) - - @export class RunMetaPlugin(Plugin): """Plugin that provides run metadata.""" diff --git a/axidence/plugins/meta/run_meta.py b/axidence/plugins/meta/run_meta.py index ee7d374..c0f08cc 100644 --- a/axidence/plugins/meta/run_meta.py +++ b/axidence/plugins/meta/run_meta.py @@ -1,7 +1,6 @@ import numpy as np import strax - -from ...plugin import ExhaustPlugin +from strax import ExhaustPlugin class RunMeta(ExhaustPlugin): diff --git a/axidence/plugins/pairing/peaks_paired.py b/axidence/plugins/pairing/peaks_paired.py index fbda08b..f4d8fa8 100644 --- a/axidence/plugins/pairing/peaks_paired.py +++ b/axidence/plugins/pairing/peaks_paired.py @@ -2,7 +2,7 @@ from immutabledict import immutabledict import numpy as np import strax -from strax import Plugin, DownChunkingPlugin +from strax import Plugin, ExhaustPlugin, DownChunkingPlugin import straxen from straxen import units from straxen import PeakProximity @@ -11,7 +11,6 @@ from ...utils import copy_dtype from ...samplers import SAMPLERS from ...dtypes import peak_positions_dtype -from ...plugin import ExhaustPlugin class PeaksPaired(ExhaustPlugin, DownChunkingPlugin): diff --git a/axidence/plugins/salting/event_building.py b/axidence/plugins/salting/event_building.py index 1f6cb5a..b90f0a9 100644 --- a/axidence/plugins/salting/event_building.py +++ b/axidence/plugins/salting/event_building.py @@ -2,11 +2,11 @@ from typing import Tuple import numpy as np import strax +from strax import ExhaustPlugin import straxen from straxen import Events, EventBasics from ...utils import needed_dtype, merge_salted_real -from ...plugin import ExhaustPlugin class EventsSalted(Events, ExhaustPlugin): diff --git a/axidence/plugins/salting/events_salting.py b/axidence/plugins/salting/events_salting.py index 4fc8123..7e7ddca 100644 --- a/axidence/plugins/salting/events_salting.py +++ b/axidence/plugins/salting/events_salting.py @@ -1,12 +1,11 @@ import numpy as np import strax -from strax import DownChunkingPlugin +from strax import ExhaustPlugin, DownChunkingPlugin import straxen from straxen import units, EventBasics, EventPositions from ...utils import copy_dtype from ...samplers import SAMPLERS -from ...plugin import ExhaustPlugin class EventsSalting(ExhaustPlugin, DownChunkingPlugin, EventPositions, EventBasics): diff --git a/pyproject.toml b/pyproject.toml index a4617ef..82252fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ repository = "https://github.com/dachengx/axidence" documentation = "https://readthedocs.org/projects/axidence/" [tool.poetry.dependencies] -strax = ">=1.6.2" +strax = ">=1.6.3" straxen = ">=2.2.1" GOFevaluation = ">=0.1.4" diff --git a/tests/test_exhaust_plugin.py b/tests/test_exhaust_plugin.py deleted file mode 100644 index fb7acc2..0000000 --- a/tests/test_exhaust_plugin.py +++ /dev/null @@ -1,77 +0,0 @@ -from typing import Tuple -import numpy as np -import strax -import straxen -from strax import Plugin -from axidence.plugin import ExhaustPlugin - - -class ToExhaust(Plugin): - depends_on: Tuple = tuple() - provides = "to_exhaust" - - dtype = strax.time_fields - - n_chunks = straxen.URLConfig(default=10) - n_items = straxen.URLConfig(default=10) - - source_done = False - - def compute(self, chunk_i): - data = np.empty(self.n_items, dtype=self.dtype) - data["time"] = np.arange(self.n_items) + chunk_i * self.n_items - data["endtime"] = data["time"] - - if chunk_i == self.n_chunks - 1: - self.source_done = True - - return self.chunk( - data=data, - start=int(data[0]["time"]), - end=int(strax.endtime(data[-1])) + 1, # to make sure that data is continuous - ) - - def source_finished(self): - return self.source_done - - def is_ready(self, chunk_i): - if "ready" not in self.__dict__: - self.ready = False - self.ready ^= True # Flip - return self.ready - - -class Exhausted(ExhaustPlugin): - depends_on = "to_exhaust" - provides = "exhausted" - - dtype = strax.time_fields - - n_chunks = straxen.URLConfig(default=10) - n_items = straxen.URLConfig(default=10) - - def compute(self, to_exhaust): - return to_exhaust - - def _fetch_chunk(self, d, iters, check_end_not_before=None): - flag = self.input_buffer[d] is None # only check if we have not read anything yet - super()._fetch_chunk(d, iters, check_end_not_before=check_end_not_before) - if flag and (len(self.input_buffer[d]) != self.n_chunks * self.n_items): - raise RuntimeError("Exhausted plugin did not read all chunks!") - return False - - -def test_exhaust_plugin(): - """Test the ExhaustPlugin, about whether it can really exhaust the data or - not.""" - st = strax.Context(storage=[]) - st.register((ToExhaust, Exhausted)) - st.storage = [ - strax.DataDirectory( - "./strax_data", - provide_run_metadata=True, - ) - ] - run_id = "000000" - st.make(run_id, "to_exhaust") - st.get_array(run_id, "exhausted")