Skip to content

Commit

Permalink
Remove get_meta function from Context
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx committed Aug 25, 2024
1 parent cb7e232 commit af14f72
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
12 changes: 5 additions & 7 deletions strax/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -1462,10 +1462,10 @@ def estimate_run_start_and_end(self, run_id, targets=None):
continue
self.log.debug(f"Try inferring start/stop from {t}")
try:
t0 = self.get_meta(run_id, t)["chunks"][0]["start"]
t0 = self.get_metadata(run_id, t)["chunks"][0]["start"]
t0 = (int(t0) // int(1e9)) * int(1e9)

t1 = self.get_meta(run_id, t)["chunks"][-1]["end"]
t1 = self.get_metadata(run_id, t)["chunks"][-1]["end"]
t1 = (int(t1) // int(1e9)) * int(1e9)
return t0, t1
except strax.DataNotAvailable:
Expand Down Expand Up @@ -2026,7 +2026,7 @@ def key_for(self, run_id, target, chunk_number=None):
lineage = plugins[target].lineage
return self.get_data_key(run_id, target, lineage)

def get_meta(self, run_id, target, chunk_number=None) -> dict:
def get_metadata(self, run_id, target, chunk_number=None) -> dict:
"""Return metadata for target for run_id, or raise DataNotAvailable if data is not yet
available.
Expand All @@ -2042,8 +2042,6 @@ def get_meta(self, run_id, target, chunk_number=None) -> dict:
self.log.debug(f"Frontend {sf} does not have {key}")
raise strax.DataNotAvailable(f"Can't load metadata, data for {key} not available")

get_metadata = get_meta

def compare_metadata(self, data1, data2, return_results=False):
"""Compare the metadata between two strax data.
Expand Down Expand Up @@ -2156,7 +2154,7 @@ def run_metadata(self, run_id, projection=None) -> dict:

def size_mb(self, run_id, target):
"""Return megabytes of memory required to hold data."""
md = self.get_meta(run_id, target)
md = self.get_metadata(run_id, target)
return sum([x["nbytes"] for x in md["chunks"]]) / 1e6

def run_defaults(self, run_id):
Expand Down Expand Up @@ -2407,7 +2405,7 @@ def merge_per_chunk_storage(
_chunk_number = {per_chunked_dependency: combined_chunk_numbers}
else:
# if no chunk numbers are given, use information from the dependency
chunks = self.get_meta(run_id, per_chunked_dependency)["chunks"]
chunks = self.get_metadata(run_id, per_chunked_dependency)["chunks"]
chunk_number_group = [[c["chunk_i"]] for c in chunks]
_chunk_number = None

Expand Down
2 changes: 1 addition & 1 deletion tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_accumulate():
)
channels_from_array = np.sum(context.get_array(run_id, "records")["channel"])
channels_accumulate = context.accumulate(run_id, "records", fields="channel")
n_chunks = len(context.get_meta(run_id, "records")["chunks"])
n_chunks = len(context.get_metadata(run_id, "records")["chunks"])
channels = channels_accumulate["channel"]
assert n_chunks == channels_accumulate["n_chunks"]
assert channels_from_array == channels
Expand Down
8 changes: 4 additions & 4 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_filestore(allow_multiprocess, max_workers, processor):
assert sorted(os.listdir(data_dirs[0])) == [f"{prefix}-000000", f"{prefix}-metadata.json"]

# Check metadata got written correctly.
metadata = mystrax.get_meta(run_id, "peaks")
metadata = mystrax.get_metadata(run_id, "peaks")
assert len(metadata)
assert "writing_ended" in metadata
assert "exception" not in metadata
Expand All @@ -115,7 +115,7 @@ def test_filestore(allow_multiprocess, max_workers, processor):
use_per_run_defaults=True,
register=[Records, Peaks],
)
metadata_2 = mystrax.get_meta(run_id, "peaks")
metadata_2 = mystrax.get_metadata(run_id, "peaks")
assert metadata == metadata_2


Expand Down Expand Up @@ -166,7 +166,7 @@ def test_fuzzy_matching():
assert st2.list_available("peaks") == [run_id]

# And we can actually load it
st2.get_meta(run_id, "peaks")
st2.get_metadata(run_id, "peaks")
st2.get_array(run_id, "peaks")

# Fuzzy for options also works
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_exception(allow_multiprocess, max_workers, processor):
# Check exception is recorded in metadata
# in both its original data type and dependents
for target in ("peaks", "records"):
assert "SomeCrash" in st.get_meta(run_id, target)["exception"]
assert "SomeCrash" in st.get_metadata(run_id, target)["exception"]

# Check corrupted data does not load
st.context_config["forbid_creation_of"] = ("peaks",)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_down_chunk_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def test_down_chunking(self):
st.make(run_id, "records")
st.make(run_id, "records_down_chunked")

chunks_records = st.get_meta(run_id, "records")["chunks"]
chunks_records_down_chunked = st.get_meta(run_id, "records_down_chunked")["chunks"]
chunks_records = st.get_metadata(run_id, "records")["chunks"]
chunks_records_down_chunked = st.get_metadata(run_id, "records_down_chunked")["chunks"]

_chunks_are_downsampled = len(chunks_records) * 2 == len(chunks_records_down_chunked)
assert _chunks_are_downsampled
Expand Down
4 changes: 2 additions & 2 deletions tests/test_superruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_create_and_load_superruns(self):
assert np.all(subrun_data == superrun_data)

# Load meta data and check if rechunking worked:
chunks = self.context.get_meta(self.superrun_name, "peaks")["chunks"]
chunks = self.context.get_metadata(self.superrun_name, "peaks")["chunks"]
assert len(chunks) == 1
chunk = chunks[0]
assert chunk["run_id"] == self.superrun_name
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_superrun_chunk_and_meta(self):
"""Superrun chunks and meta data should contain information about its constituent
subruns."""
self.context.make(self.superrun_name, "peaks")
meta = self.context.get_meta(self.superrun_name, "peaks")
meta = self.context.get_metadata(self.superrun_name, "peaks")

n_chunks = 0
superrun_chunk = None
Expand Down

0 comments on commit af14f72

Please sign in to comment.