From 6f21c34889776cc19342649a07ca8fc1667b4583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <amuoz@ed.ac.uk> Date: Wed, 16 Jun 2021 18:34:31 +0100 Subject: [PATCH] add base and signal Former-commit-id: 828ea0f0c3348532c794417d6714d279576a3291 --- core/io/base.py | 9 +++++++++ core/io/signal.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 core/io/base.py create mode 100644 core/io/signal.py diff --git a/core/io/base.py b/core/io/base.py new file mode 100644 index 00000000..a757a96e --- /dev/null +++ b/core/io/base.py @@ -0,0 +1,9 @@ +import h5py + + +class BridgeH5: + def __init__(self, file): + self._hdf = h5py.File(file, "r") + + def close(self): + self._hdf.close() diff --git a/core/io/signal.py b/core/io/signal.py new file mode 100644 index 00000000..5f3e8c6d --- /dev/null +++ b/core/io/signal.py @@ -0,0 +1,35 @@ +from postprocessor.core.io.base import BridgeH5 + + +class Signal(BridgeH5): + """ + Class that fetches data from the hdf5 storage for post-processing + """ + + def __init__(self, file): + super().__init__(file) + + def __getitem__(self, dataset): + dset = self._hdf[dataset][()] + attrs = self._hdf[dataset].attrs + first_dataset = "/" + dataset.split("/")[0] + "/" + timepoints = self._hdf[first_dataset].attrs["processed_timepoints"] + + if "cell_label" in self._hdf[dataset].attrs: + ids = pd.MultiIndex.from_tuples( + zip(attrs["trap"], attrs["cell_label"]), names=["trap", "cell_label"] + ) + else: + ids = pd.Index(attrs["trap"], names=["trap"]) + + return pd.DataFrame(dset, index=ids, columns=timepoints) + + @staticmethod + def _if_ext_or_post(name): + if name.startswith("extraction") or name.startswith("postprocessing"): + if len(name.split("/")) > 3: + return name + + @property + def datasets(self): + return signals._hdf.visit(self._if_ext_or_post) -- GitLab