From 0f3748152a7100ad472c1e7c6a899bf21ded1992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <amuoz@ed.ac.uk> Date: Thu, 13 Jan 2022 18:13:28 +0000 Subject: [PATCH] rm group and update deps --- aliby/grouper.py | 175 ----------------------------------------------- poetry.lock | 20 +++--- pyproject.toml | 10 +-- 3 files changed, 17 insertions(+), 188 deletions(-) delete mode 100644 aliby/grouper.py diff --git a/aliby/grouper.py b/aliby/grouper.py deleted file mode 100644 index 33180641..00000000 --- a/aliby/grouper.py +++ /dev/null @@ -1,175 +0,0 @@ -#!/usr/bin/env python3 - -from abc import ABC, abstractmethod, abstractproperty -from pathlib import Path -from pathos.multiprocessing import Pool - -import h5py -import numpy as np -import pandas as pd - -from agora.io.signal import Signal - - -class Grouper(ABC): - """ - Base grouper class - """ - - files = [] - - def __init__(self, dir): - self.files = list(Path(dir).glob("*.h5")) - self.load_signals() - - def load_signals(self): - self.signals = {f.name[:-3]: Signal(f) for f in self.files} - - @property - def fsignal(self): - return list(self.signals.values())[0] - - @property - def siglist(self): - return self.fsignal.datasets - - @abstractproperty - def group_names(): - pass - - def concat_signal(self, path, reduce_cols=None, axis=0, pool=8): - group_names = self.group_names - sitems = self.signals.items() - if pool: - with Pool(pool) as p: - signals = p.map( - lambda x: concat_signal_ind(path, group_names, x[0], x[1]), - sitems, - ) - else: - signals = [ - concat_signal_ind(path, group_names, name, signal) - for name, signal in sitems - ] - - signals = [s for s in signals if s is not None] - sorted = pd.concat(signals, axis=axis).sort_index() - if reduce_cols: - sorted = sorted.apply(np.nanmean, axis=1) - spath = path.split("/") - sorted.name = "_".join([spath[1], spath[-1]]) - - return sorted - - @property - def ntraps(self): - for pos, s in self.signals.items(): - with h5py.File(s.filename, "r") as f: - print(pos, f["/trap_info/trap_locations"].shape[0]) - - def traplocs(self): - d = {} - for pos, s in self.signals.items(): - with h5py.File(s.filename, "r") as f: - d[pos] = f["/trap_info/trap_locations"][()] - return d - - -class MetaGrouper(Grouper): - """Group positions using metadata's 'group' number""" - - pass - - -class NameGrouper(Grouper): - """ - Group a set of positions using a subsection of the name - """ - - def __init__(self, dir, by=None): - super().__init__(dir=dir) - - if by is None: - by = (0, -4) - self.by = by - - @property - def group_names(self): - if not hasattr(self, "_group_names"): - self._group_names = {} - for name in self.signals.keys(): - self._group_names[name] = name[self.by[0] : self.by[1]] - - return self._group_names - - def aggregate_multisignals(self, paths=None, **kwargs): - - aggregated = pd.concat( - [ - self.concat_signal(path, reduce_cols=np.nanmean, **kwargs) - for path in paths - ], - axis=1, - ) - # ph = pd.Series( - # [ - # self.ph_from_group(x[list(aggregated.index.names).index("group")]) - # for x in aggregated.index - # ], - # index=aggregated.index, - # name="media_pH", - # ) - # self.aggregated = pd.concat((aggregated, ph), axis=1) - - return aggregated - - -class phGrouper(NameGrouper): - """ - Grouper for pH calibration experiments where all surveyed media pH values - are within a single experiment. - """ - - def __init__(self, dir, by=(3, 7)): - super().__init__(dir=dir, by=by) - - def get_ph(self): - self.ph = {gn: self.ph_from_group(gn) for gn in self.group_names} - - @staticmethod - def ph_from_group(group_name): - if group_name.startswith("ph_"): - group_name = group_name[3:] - - return float(group_name.replace("_", ".")) - - def aggregate_multisignals(self, paths): - - aggregated = pd.concat( - [self.concat_signal(path, reduce_cols=np.nanmean) for path in paths], axis=1 - ) - ph = pd.Series( - [ - self.ph_from_group(x[list(aggregated.index.names).index("group")]) - for x in aggregated.index - ], - index=aggregated.index, - name="media_pH", - ) - aggregated = pd.concat((aggregated, ph), axis=1) - - return aggregated - - -def concat_signal_ind(path, group_names, group, signal): - print("Looking at ", group) - # try: - combined = signal[path] - combined["position"] = group - combined["group"] = group_names[group] - combined.set_index(["group", "position"], inplace=True, append=True) - combined.index = combined.index.swaplevel(-2, 0).swaplevel(-1, 1) - - return combined - # except: - # return None diff --git a/poetry.lock b/poetry.lock index f93587a0..882b485b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -78,13 +78,16 @@ python-versions = "*" [[package]] name = "aliby-agora" -version = "0.2.3" +version = "0.2.8" description = "A gathering of shared utilities for the Swain Lab image processing pipeline." category = "main" optional = false python-versions = ">=3.7.1,<3.11" [package.dependencies] +h5py = "2.10" +pandas = ">=1.3.5,<2.0.0" +py-find-1st = ">=1.1.5,<2.0.0" PyYAML = ">=6.0,<7.0" [[package]] @@ -110,20 +113,21 @@ xgboost = "1.4.2" [[package]] name = "aliby-post" -version = "0.1.1" +version = "0.1.2" description = "Post-processing tools for aliby pipeline." category = "main" optional = false python-versions = ">=3.7.1,<3.11" [package.dependencies] -aliby-agora = ">=0.2.0" +aliby-agora = ">=0.2.7,<0.3.0" catch22 = ">=0.2.0,<0.3.0" leidenalg = ">=0.8.8,<0.9.0" more-itertools = ">=8.12.0,<9.0.0" numpy = ">=1.17.3" omni-gaussian = "*" pandas = ">=1.3.5,<2.0.0" +pathos = ">=0.2.8,<0.3.0" PyYAML = ">=6.0,<7.0" scipy = ">=1.4.1" @@ -1913,7 +1917,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = ">=3.7.1,<3.11" -content-hash = "e1e7066cb95566d8b8151a3dc7fc74d2dce27c535c55e6acdb708ce6a6b55c19" +content-hash = "2df95f3e88418a2193aa261bbe8823aea1e3830add76236b5e38e1b98ec740d4" [metadata.files] absl-py = [ @@ -2011,16 +2015,16 @@ alabaster = [ {file = "alabaster-0.7.12.tar.gz", hash = "sha256:a661d72d58e6ea8a57f7a86e37d86716863ee5e92788398526d58b26a4e4dc02"}, ] aliby-agora = [ - {file = "aliby-agora-0.2.3.tar.gz", hash = "sha256:a3a56a773243c04fb4dffb54301d77ff7869e98047d6ba9261cbe4864f715744"}, - {file = "aliby_agora-0.2.3-py3-none-any.whl", hash = "sha256:003f5b52dfa5513ea02497701c11dd50014496c264de75f474534358df89416b"}, + {file = "aliby-agora-0.2.8.tar.gz", hash = "sha256:e340e917ff62c7694e174ceb2d0c32f1c8335b501be7af0dc7145058ebd1d5a1"}, + {file = "aliby_agora-0.2.8-py3-none-any.whl", hash = "sha256:4e02b79d76db6941c55a25f2d0936bc80039f3b63b9bfd94facc07dafd32f363"}, ] aliby-baby = [ {file = "aliby-baby-0.1.2.tar.gz", hash = "sha256:564a12b44fc7e4889fb70d5a82e39e7fb01f37eeb60669c684bd18677160de93"}, {file = "aliby_baby-0.1.2-py3-none-any.whl", hash = "sha256:f8f11b82db89a74ad8cc48059370af889f246a83d4cbc45ce75d9475a15605f7"}, ] aliby-post = [ - {file = "aliby-post-0.1.1.tar.gz", hash = "sha256:426510854767402adc06ed62b7867866dcad054838432ffe26ebb91861c85828"}, - {file = "aliby_post-0.1.1-py3-none-any.whl", hash = "sha256:6bd666a37b83ee750c9837ce08a8541d16290811fadcf020378b6122f3b1f8bd"}, + {file = "aliby-post-0.1.2.tar.gz", hash = "sha256:73940768cd3bc77908525ec7700c6712f520cb768e505019db644ee391feafc5"}, + {file = "aliby_post-0.1.2-py3-none-any.whl", hash = "sha256:ed01d4f96ebd24a0832d8f27de4dc38d649609d47507ffa760ff57b255e4fde4"}, ] appdirs = [ {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, diff --git a/pyproject.toml b/pyproject.toml index b46e1308..114dfd28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "aliby" -version = "0.1.7" +version = "0.1.8" description = "" authors = ["Alan Munoz <alan.munoz@ed.ac.uk>"] packages = [ @@ -28,10 +28,10 @@ imageio = "2.8.0" omero-py = ">=5.6.2" zeroc-ice = "3.6.5" tensorflow = ">=1.15,<=2.3" -aliby-agora = ">=0.2.0" -aliby-baby = "*" -omni-gaussian = "*" -aliby-post = "^0.1.1" +aliby-agora = "^0.2.4" +aliby-baby = "^0.1.2" +omni-gaussian = "^0.1.1" +aliby-post = "^0.1.2" [tool.poetry.dev-dependencies] -- GitLab