FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 3f26a0b4 authored by Argyris Z's avatar Argyris Z
Browse files

TV convert functions + more types

parent 5b977c20
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ from common.seg import (Tissue,
Vec3,
readDataT1,
readGeomT1,
readGeomIm,
readRess,
geneNms,
readDataT1Im)
......@@ -361,6 +362,37 @@ def mkSeriesIm0(dataDir: str,
return tss, linss
def mkSeriesGeomIm(dataDir: str,
fid: int = 1,
ft: Callable[[int], bool] = lambda x: True):
d = join(dataDir, "FM{fid}".format(fid=fid))
linDataLoc = join(dataDir, "FM{fid}/tracking_data".format(fid=str(fid)))
ressFn = join(dataDir, "FM{fid}/resolutions.txt".format(fid=str(fid)))
ress = readRess(ressFn.format(fid=str(fid)))
tpoints = [t for t in sorted(ress.keys()) if ft(t)]
lins = mkLinsSeries1(readLins1(linDataLoc))
tss = dict()
linss = dict()
for t in tpoints:
print(t)
tss[t] = readGeomIm(d, t)
for t1, t2 in zip(tpoints, tpoints[1:]):
print(t1, t2)
linss[(t1, t2)] = mergeLinss(list(map(lambda x: x[1],
between(lins, t1, t2))))
return tss, linss
def writeSeriesGeomTV(tss: Dict[int, Tissue], d: str):
for t, ts in tss.items():
seg.writeTV(ts, d, "{t}h".format(t=str(t)))
###################################
def invertMap(ln):
iLin = [list(zip(ds, repeat(m, len(ds)))) for m, ds in ln.items()]
......
......@@ -3,6 +3,8 @@ import ast # type: ignore
from tifffile import TiffFile # type: ignore
from copy import deepcopy # type: ignore
from typing import Tuple, Dict, TypeVar, Callable, List, Set, Iterator
from numpy import ndarray
from os.path import join
T = TypeVar('T')
......@@ -374,7 +376,7 @@ class Tissue():
ns=repr(nids))
return "\n".join([toTVNeighCell(cid, neighs)
for cid, neighs in self.neighs.items()])
for cid, neighs in self.neighs.items() if cid != 1])
def toTV(self) -> Tuple[str, str]:
return (self.toTVGeom(), self.toTVNeigh())
......@@ -500,7 +502,9 @@ def readImage(fseg: str):
return seg
def readImageRegionPoints(fseg, res=[1, 1, 1], d=2):
def readImageRegionPoints(fseg: str,
res: List[float] = [1, 1, 1],
d: int = 3) -> Dict[int, ndarray]:
from skimage.measure import regionprops # type: ignore
cell_regions = dict()
......@@ -509,8 +513,12 @@ def readImageRegionPoints(fseg, res=[1, 1, 1], d=2):
cellsSeg = regionprops(seg)
for cregion in cellsSeg:
cell_regions[cregion.label] = np.multiply(cregion.coords[:, :d],
res[:d])
cid = int(cregion.label)
if cid != 1:
coords = cregion.coords[:, [2, 1, 0]]
coords_: ndarray = np.multiply(coords,
res[:d])
cell_regions[cid] = coords_
return cell_regions
......@@ -519,15 +527,19 @@ def mergePoints(cell_regions, cids):
return np.vstack(tuple([cell_regions[cid] for cid in cids]))
def getCellRegions(fid=1, ft=lambda t: True, d=2):
segFn = "../data/FM{fid}/segmentation_tiffs/{t}h_segmented.tif"
ressFn = "../data/FM{fid}/resolutions.txt"
def getCellRegions(d: str,
fid: int = 1,
ft: Callable[[int], bool] = lambda t: True,
dim: int = 3) -> Dict[int, Dict[int, ndarray]]:
segFn = join(d, "FM{fid}/segmentation_tiffs/{t}h_segmented.tif")
ressFn = join(d, "FM{fid}/resolutions.txt")
ress = readRess(ressFn.format(fid=str(fid)))
tpoints = [t for t in sorted(ress.keys()) if ft(t)]
fsegs = dict([(t, segFn.format(fid=fid, t=str(t))) for t in tpoints])
return dict([(t, readImageRegionPoints(fn, res=ress[t], d=d))
return dict([(t, readImageRegionPoints(fn, res=ress[t], d=dim))
for t, fn in fsegs.items()])
......@@ -558,7 +570,7 @@ def writeOrg(fnGeom, fnNeigh, ts):
def writeTV(ts, d, lab):
from os.path import join
fnGeom = "{lab}_segmented_tvformat_volume_position.txt".format(lab=lab)
fnNeigh = "{lab}_segmented_tvformat_neighbors.txt".format(lab=lab)
......
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