# apply metric either a cell function or otherwise
result=self._all_funs[metric](mask_set,trap)
ifcell_fun:
# store results for each cell separately
forlbl,valinzip(lbl_set,result):
results.append(val)
idx.append((trap_id,lbl))
else:
# background (trap) function
results.append(result)
idx.append(trap_id)
return (tuple(results),tuple(idx))
res_idx=(tuple(results),tuple(idx))
returnres_idx
defextract_funs(
self,
...
...
@@ -406,7 +408,7 @@ class Extractor(ProcessABC):
masks=None,
labels=None,
**kwargs,
)->t.Dict[str,t.Dict[str,pd.Series]]:
)->t.Dict[str,t.Dict[str,t.Dict[str,tuple]]]:
"""
Core extraction method for an individual time-point.
...
...
@@ -420,17 +422,25 @@ class Extractor(ProcessABC):
For example: {'general': {'None': ['area', 'volume', 'eccentricity']}}
tile_size : int
Size of the tile to be extracted.
masks : np.ndarray
A 3d boolean numpy array with dimensions (ncells, tile_size,
masks : list of arrays
A list of masks per trap with each mask having dimensions (ncells, tile_size,
tile_size).
labels : t.List[t.List[int]]
List of lists of ints indicating the ids of masks.
labels : dict
A dictionary with trap_ids as keys and cell_labels as values.
**kwargs : keyword arguments
Passed to extractor.reduce_extract.
Returns
-------
dict
d: dict
Dictionary of the results with three levels of dictionaries.
The first level has channels as keys.
The second level has reduction metrics as keys.
The third level has cell or background metrics as keys and a two-tuple as values.
The first tuple is the result of applying the metrics to a particular cell or trap; the second tuple is either (trap_id, cell_label) for a metric applied to a cell or a trap_id for a metric applied to a trap.
An example is d["GFP"]["np_max"]["mean"][0], which gives a tuple of the calculated mean GFP fluorescence for all cells.
"""
iftreeisNone:
# use default
...
...
@@ -465,26 +475,27 @@ class Extractor(ProcessABC):
Nested dictionary indicating channels, reduction functions and
metrics to be used.
For example: {'general': {'None': ['area', 'volume', 'eccentricity']}}
tps: list of int (optional)
Time points to include.
save: boolean (optional)
If True, save results to h5 file.
kwargs: keyword arguments (optional)
Passed to extract_tp.
Returns
-------
d: dict
A dict of the extracted data with a concatenated string of channel, reduction metric, and cell metric as keys and pd.Series of the extracted data as values.
Converts a nested extraction dict into a dict of pd.Series
Parameters
----------
nest: dict of dicts
Contains the nested results of extraction.
to: str (optional)
Specifies the format of the output, either pd.Series (default) or a list
tp: int
Timepoint used to name the pd.Series
Returns
-------
d: dict
A dict with a concatenated string of channel, reduction metric, and cell metric as keys and either a pd.Series or a list of the corresponding extracted data as values.