Skip to content
Snippets Groups Projects
Commit 3e5f041e authored by pswain's avatar pswain
Browse files

feature(imageviewer): dded sample_traps_with_cells

parent e51a5fcd
No related branches found
No related tags found
No related merge requests found
......@@ -14,12 +14,13 @@ server_info = {
h5file = f"{aliby_output}{omero_name}/{position}.h5"
iv = ImageViewer.remote(h5file, server_info, 2104)
tpt_end = 10
no_cells = 4
# for information only
iv.print_traps_with_cells(tpt_end)
# use Napari to view cells
# python -m pip install "napari[all]" --upgrade
iv.view(
trap_ids=[4, 8, 13],
trap_ids=iv.sample_traps_with_cells(tpt_end=tpt_end, no_cells=no_cells),
tpt_end=tpt_end,
channels_to_skip=["cy5"],
no_vertical_tiles=1,
......
from pathlib import Path
import h5py
import napari
try:
import napari
except ModuleNotFoundError:
print(
"Napari cannot be imported.\nRun",
' python -m pip install "napari[all]"',
)
import numpy as np
from agora.io.cells import Cells
from aliby.io.image import dispatch_image
......@@ -62,7 +69,7 @@ class ImageViewer:
iv.cells = Cells.from_source(iv.h5file_path)
return iv
def print_traps_with_cells(self, tpt_end, tpt_start=0):
def get_all_traps_with_cells(self, tpt_end, tpt_start=0, display=True):
"""List traps with cells."""
cells = self.cells
tpts = range(tpt_start, tpt_end)
......@@ -72,9 +79,23 @@ class ImageViewer:
if tpt in cells.nonempty_tp_in_trap(trap_id):
traps_with_cells.append(trap_id)
break
print(f"Traps with cells {traps_with_cells}")
if display:
print(f"Traps with cells {traps_with_cells}")
return traps_with_cells
def sample_traps_with_cells(self, no_cells, tpt_end, tpt_start=0):
"""Sample some traps that have cells."""
traps_with_cells = self.get_all_traps_with_cells(
tpt_end, tpt_start, display=False
)
rng = np.random.default_rng()
samples = rng.integers(
low=0,
high=len(traps_with_cells),
size=np.min([no_cells, len(traps_with_cells)]),
)
return samples
def get_tiles(self, trap_id, tps, channels_to_skip=None, cell_only=True):
"""Get dict of tiles with channel indices as keys."""
tiles_dict = {}
......
......@@ -496,7 +496,7 @@ def plot2Dhist(
--------
Load data:
>>> from wela.dataloader import dataloader
>>> from wela.plotting import plothist
>>> from wela.plotting import plot2Dhist
>>> dl = dataloader()
>>> dl.load("1334_2023_03_28_pyrTo2Gal_01glc_00", use_tsv=True)
>>> dlc = dataloader()
......@@ -507,8 +507,8 @@ def plot2Dhist(
>>> tc, dc = dlc.get_time_series("median_GFP")
Plot both data sets using axes with the same range:
>>> bins = plothist(t, dc, title="2% Gal", figsize=(4, 3))[0]
>>> plothist(t, d, title="2% Gal and 0.1% Glu", bins=bins, figsize=(4, 3))
>>> bins = plot2Dhist(t, dc, title="2% Gal", figsize=(4, 3))[0]
>>> plot2Dhist(t, d, title="2% Gal and 0.1% Glu", bins=bins, figsize=(4, 3))
"""
if x.ndim == 1:
# make into a 2D array
......
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