Skip to content

Commit

Permalink
Adding TMI (#46)
Browse files Browse the repository at this point in the history
* using tmi

* pinned tmi to v0.0.1
  • Loading branch information
srivarra authored Nov 16, 2022
1 parent 5645497 commit 66e9647
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 324 deletions.
6 changes: 3 additions & 3 deletions mibi_bin_tools/bin_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import skimage.io as io
import xarray as xr

from mibi_bin_tools import io_utils, type_utils, _extract_bin
from tmi.image_utils import save_image
from mibi_bin_tools import type_utils, _extract_bin
from tmi import io_utils, image_utils


def _mass2tof(masses_arr: np.ndarray, mass_offset: float, mass_gain: float,
Expand Down Expand Up @@ -102,7 +102,7 @@ def _write_out(img_data: np.ndarray, out_dir: str, fov_name: str, targets: List[
# if not replace (i=1), only save intensity images for specified targets
if i == 0 or (target in list(intensities)):
fname = os.path.join(out_dir_i, f"{target}{suffix}.tiff")
save_image(fname=fname, data=img_data[i, :, :, j].astype(save_dtype))
image_utils.save_image(fname=fname, data=img_data[i, :, :, j].astype(save_dtype))


def _find_bin_files(data_dir: str,
Expand Down
167 changes: 0 additions & 167 deletions mibi_bin_tools/io_utils.py

This file was deleted.

12 changes: 6 additions & 6 deletions mibi_bin_tools/panel_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Union, List
import pandas as pd

from mibi_bin_tools.type_utils import make_iterable
from tmi import misc_utils


def make_panel(mass: Union[float, List[float]],
Expand All @@ -25,9 +25,9 @@ def make_panel(mass: Union[float, List[float]],
single mass panel as pandas dataframe
"""

mass = make_iterable(mass)
mass = misc_utils.make_iterable(mass)
if target_name is not None:
target_name = make_iterable(target_name)
target_name = misc_utils.make_iterable(target_name)
if len(mass) != len(target_name):
raise ValueError(
'`mass` and `target_name` did not contain the same number of elements. '
Expand All @@ -38,16 +38,16 @@ def make_panel(mass: Union[float, List[float]],

# check for range lists
for r in (low_range, high_range):
if make_iterable(r) == r:
if misc_utils.make_iterable(r) == r:
if len(r) != len(mass):
raise ValueError(
'`mass` and a range argument did not contain the same number of elements. '
'If only one integration range is required, `low_range` and `high_range` can '
'be set to float values, e.g `low_range=0.3`'
)

low_range = make_iterable(low_range)
high_range = make_iterable(high_range)
low_range = misc_utils.make_iterable(low_range)
high_range = misc_utils.make_iterable(high_range)

if len(low_range) != len(mass):
low_range = low_range * len(mass)
Expand Down
19 changes: 2 additions & 17 deletions mibi_bin_tools/type_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Union, Iterable
from tmi import misc_utils


def any_true(a: Union[bool, Iterable[bool]]) -> bool:
Expand All @@ -12,20 +13,4 @@ def any_true(a: Union[bool, Iterable[bool]]) -> bool:
bool:
whether any true values where found
"""
return any(make_iterable(a))


def make_iterable(a: Union[type, Iterable[type]], ignore_str=True) -> Iterable[type]:
""" Convert noniterable type to singelton in list
Args:
a (T | Iterable[T]):
value or iterable of type T
ignore_str (bool):
whether to ignore the iterability of the str type
Returns:
List[T]:
a as singleton in list, or a if a was already iterable.
"""
return a if hasattr(a, '__iter__') and not (isinstance(a, str) and ignore_str) else [a]
return any(misc_utils.make_iterable(a))
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ matplotlib==3.4.3
numpy>=1.21.6,<2
pandas>=1.3.5,<2
scikit-image>=0.19.3,<0.20
tmi @ git+https://github.com/angelolab/tmi.git
tmi @ git+https://github.com/angelolab/tmi.git@v0.0.1
xarray>=2022.6.0,<2023
3 changes: 2 additions & 1 deletion tests/bin_files_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import numpy as np
import pandas as pd

from mibi_bin_tools import bin_files, io_utils, type_utils, _extract_bin
from mibi_bin_tools import bin_files, type_utils, _extract_bin
from tmi import io_utils

THIS_DIR = Path(__file__).parent

Expand Down
Loading

0 comments on commit 66e9647

Please sign in to comment.