Skip to content
Snippets Groups Projects
Commit 9432aaf2 authored by pswain's avatar pswain
Browse files

final docs for postprocessor

parent 81524254
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env jupyter
"""
Convenience decorators that extend commonly-used methods or functions.
Convenience decorators to extend commonly-used methods or functions.
"""
import typing as t
from functools import wraps
......@@ -9,14 +9,14 @@ from functools import wraps
def _first_arg_str_to_df(
fn: t.Callable,
):
"""Ensures Signal-like classes convert strings to datasets when calling them"""
"""Enable Signal-like classes to convert strings to data sets."""
@wraps(fn)
def format_input(*args, **kwargs):
cls = args[0]
data = args[1]
if isinstance(data, str):
# get data from h5 file
data = cls.get_raw(data)
# replace path in the undecorated function with data
return fn(cls, data, *args[2:], **kwargs)
return format_input
......@@ -42,7 +42,7 @@ class Signal(BridgeH5):
"Cy5",
"pHluorin405",
)
# Alan: why "equivalences"?
# Alan: why "equivalences"? this variable is unused.
equivalences = {
"m5m": ("extraction/GFP/max/max5px", "extraction/GFP/max/median")
}
......@@ -118,7 +118,13 @@ class Signal(BridgeH5):
@_first_arg_str_to_df
def retained(self, signal, cutoff=0.8):
"""Reduce a dataframe, or a list of dataframes, to a fraction of its former size, losing late time points."""
"""
Load data (via decorator) and reduce the resulting dataframe.
Load data for a signal or a list of signals and reduce the resulting
dataframes to a fraction of their original size, losing late time
points.
"""
if isinstance(signal, pd.DataFrame):
return self.get_retained(signal, cutoff)
elif isinstance(signal, list):
......@@ -144,6 +150,7 @@ class Signal(BridgeH5):
tile_mo_da["trap"],
tile_mo_da["mother_label"],
tile_mo_da["daughter_label"],
a
)
).T
return lineage
......@@ -161,7 +168,7 @@ class Signal(BridgeH5):
Parameters
----------
data : t.Union[str, pd.DataFrame]
DataFrame or url to one.
DataFrame or path to one.
merges : t.Union[np.ndarray, bool]
(optional) 2-D array with three columns: the tile id, the mother label, and the daughter id.
If True, fetch merges from file.
......@@ -215,7 +222,7 @@ class Signal(BridgeH5):
if not hasattr(self, "_available"):
self._available = []
with h5py.File(self.filename, "r") as f:
f.visititems(self.store_signal_url)
f.visititems(self.store_signal_path)
for sig in self._available:
print(sig)
......@@ -231,7 +238,7 @@ class Signal(BridgeH5):
if not hasattr(self, "_available"):
self._available = []
with h5py.File(self.filename, "r") as f:
f.visititems(self.store_signal_url)
f.visititems(self.store_signal_path)
except Exception as e:
print("Error visiting h5: {}".format(e))
return self._available
......@@ -344,7 +351,7 @@ class Signal(BridgeH5):
"""Get name of h5 file."""
return self.filename.stem
def store_signal_url(
def store_signal_path(
self,
fullname: str,
node: t.Union[h5py.Dataset, h5py.Group],
......
......@@ -83,6 +83,7 @@ class Chainer(Signal):
**kwargs,
):
"""Load data from an h5 file."""
1/0
if dataset in self.common_chains:
# get dataset for composite chains
data = self.common_chains[dataset](**kwargs)
......
......@@ -91,7 +91,8 @@ class Grouper(ABC):
**kwargs,
):
"""
Concatenate data for one signal from different h5 files, with one h5 file per position, into a dataframe.
Concatenate data for one signal from different h5 files, with
one h5 file per position, into a dataframe.
Parameters
----------
......@@ -387,7 +388,7 @@ def concat_signal_ind(
**kwargs,
) -> pd.DataFrame:
"""
Core function that retrieves an individual signal.
Retrieve an individual signal.
Applies filtering if requested and adjusts indices.
"""
......@@ -482,6 +483,7 @@ class MultiGrouper:
return self._sigtable
# Alan: function seems out of place
# seaborn is not in pyproject.toml
def sigtable_plot(self) -> None:
"""
Plot number of chains for all available experiments.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment