Commit b47f2bb5 authored by Philipp Schubert's avatar Philipp Schubert
Browse files

added `syn_ssv` attribute to SuperSegmentationObjects, `init_sso_from_kzip` is...

added `syn_ssv` attribute to SuperSegmentationObjects, `init_sso_from_kzip` is now aware of `syn_ssv`, pkl files are now loaded with disabled gc, updated docs
parent 75cb200c
......@@ -29,7 +29,7 @@ For SyConn v1, please refer to the old [documentation](https://structuralneurobi
The Team
--------
The Synaptic connectivity inference toolkit is developed at the Max-Planck-Institute of Neurobiology in Martinsried by
The Synaptic connectivity inference toolkit is currently developed at the Max-Planck-Institute of Neurobiology in Martinsried by
Philipp Schubert, Maria Kawula, Carl Constantin v. Wedemeyer, Atul Mohite, Gaurav Kumar and Joergen Kornfeld.
......@@ -39,7 +39,8 @@ We are especially grateful for the support by Winfried Denk who enabled this wor
and his group at the MPCDF for cluster support and deepmind for providing egl extension code to handle multi-gpu rendering on the same machine.
The original code snippet (under the Apache License 2.0) used for our project can be found
[here](https://github.com/deepmind/dm_control/blob/30069ac11b60ee71acbd9159547d0bc334d63281/dm_control/_render/pyopengl/egl_ext.py).
Thanks to Julia Kuhl (see http://somedonkey.com/ for more beautiful work) for designing and creating the logo!
Thanks to Julia Kuhl (see http://somedonkey.com/ for more beautiful work) for designing and creating the logo and to
Rangoli Saxena, Mariana Shumliakivska and Josef Mark for code contributions.
Publications
......
......@@ -12,7 +12,7 @@ It consists of two steps: (1) Finding and extracting contact sites between super
because an oversegmentation is necessary in these cases.
## Prerequisites
* Knossos- and SegmentationDataset of the super voxel segmentation
* Knossos- and SegmentationDataset of the supervoxel segmentation
* SuperSegmentationDataset containg the cell reconstructions (SV-agglomeration/RAG)
* KnossosDataset of symmetric, asymmetric and SJ predictions (WIP)
......
......@@ -80,21 +80,23 @@ The basic data structures and initialization procedures are explained in the fol
* SyConn operates with a pre-defined [working directory and config files](config.md)
* Super voxels (and cellular organelles) are stored in the SegmentationObject data class ([SO](segmentation_datasets.md)), which are
organized in [SegmentationDatasets](segmentation_datasets.md).
* Supervoxels (and cellular organelles) are organized as `SegmentationObject` which are
handled by the `SegmentationDatasets`. For a more detailed description see [here](segmentation_datasets.md)).
* SyConn principally supports different [backends](backend.md) for data storage, the current default is a simple shared filesystem
* SyConn principally supports different [backends](backend.md) for data storage. The current default is a simple shared filesystem
(such as lustre, Google Cloud Filestore or AWS Elastic File System).
* Agglomerated super voxels (SVs) are implemented as SuperSegmentationObjects ([SSO](super_segmentation_objects.md)). The collection
* Agglomerated supervoxels (SVs) are implemented as SuperSegmentationObjects ([SSO](super_segmentation_objects.md)). The collection
of super-SVs are usually defined in a region adjacency graph (RAG) which is used to initialize the SuperSegmentationDataset
([SSD](super_segmentation_datasets.md)).
* [Skeletons](skeletons.md) of (super) super voxels, usually computed from variants of the TEASAR algorithm (https://ieeexplore.ieee.org/document/883951).
* [Skeletons](skeletons.md) of (super-) supervoxels, usually computed from variants of the TEASAR algorithm (https://ieeexplore.ieee.org/document/883951)
- currently a fall-back to a sampling procedure is in use.
* [Mesh](meshes.md) generation and representation of SOs
* [Mesh](meshes.md) generation and representation of supervoxels
* Multi-view representation of SSOs (see docs for [glia](glia_removal.md) and [neuron](neuron_analysis.md) analysis and [article](https://www.nature.com/articles/s41467-019-10836-3) in Nature Communications)
* Multi-view representation of neurpn reconstructions for [glia](glia_removal.md) and
[neuron](neuron_analysis.md) analysis (published in [Nature Communications](https://www.nature.com/articles/s41467-019-10836-3))
## Flowchart of SyConn
......@@ -117,13 +119,11 @@ compartments (e.g. axons and spines) and to perform morphology based cell type c
## SyConn KNOSSOS viewer
The following packages have to be available for the system's python2 interpreter
The following packages have to be available in the system's python2 interpreter
(will differ from the conda environment):
- numpy
- lz4
- requests
In order to inspect the resulting data via the SyConnViewer KNOSSOS-plugin follow these steps:
......
......@@ -2,7 +2,7 @@
All scripts used for the analysis of the neuron segmentation are located in `SyConn/scripts/multiviews_glia/`.
## Prerequisites
* Knossos- and SegmentationDataset of the super voxel segmentation
* Knossos- and SegmentationDataset of the supervoxel segmentation
* Initial RAG/SV-mapping
## Steps
......
......@@ -5,7 +5,7 @@ All scripts used for the analysis of the neuron segmentation are located in `SyC
* Cell type prediction: `celltype_prediction.py`
## Prerequisites
* Knossos- and SegmentationDataset of the super voxel segmentation
* Knossos- and SegmentationDataset of the supervoxel segmentation
* SegmentationDatasets for all cellular organelles (currently mitochondria, vesicle clouds and synaptic junctions)
* \[Optional\] [Glia removal](glia_removal.md)
* The RAG/SV-mapping in form of a SSD, see [SuperSegmentationDatasets](super_segmentation_datasets.md)
......
......@@ -4,8 +4,8 @@ The relevant code for the object mapping is in `syconn.proc.sd_proc` and `syconn
## Prerequisites
* SegmentationDatasets of cellular organelles (see [object mapping](object_mapping.md) and [SegmentationDataset](segmentation_dataset.md))
* Segmentation- and KnossosDataset of super voxel segmentation (i.e. 64 bit Knossos cubes).
* [SSD](super_segmentation_datasets.md) of cellular super voxels for the aggregation to SSVs.
* Segmentation- and KnossosDataset of supervoxel segmentation (i.e. 64 bit Knossos cubes).
* [SSD](super_segmentation_datasets.md) of cellular supervoxels for the aggregation to SSVs.
## Mapping objects to supervoxels
Objects are mapped to supervoxels with
......
......@@ -8,13 +8,13 @@ It is accompanied by helper functions in `super_segmentation_helper.py` for basi
The first initializing of an SSD usually happens after [glia removal](glia_removal.md).
## Prerequisites
* Knossos- and SegmentationDataset of the super voxel segmentation
* Knossos- and SegmentationDataset of the supervoxel segmentation
* Initial RAG/SV-agglomeration
## Initialization
In order to create a SuperSegmentationDataset from scratch one has to provide
the agglomerated super voxel (SSV) defined as a dict (coming soon!; AGG_SOURCE; keys: SSV IDs and values: list of SVs) or stored as a
the agglomerated supervoxel (SSV) defined as a dict (coming soon!; AGG_SOURCE; keys: SSV IDs and values: list of SVs) or stored as a
KNOSSOS mergelist (text file; variable holding the path string: AGG_SOURCE) and pass it
to the constructor (kwarg: 'sv_mapping'). The `version` kwarg is used to distinguish between different SSV datasets, e.g. if one
is interested in separating the initial RAG into neuron and glia segmentation one could use `version='glia'` and `version='neuron'`.
......
......@@ -5,7 +5,7 @@ Each `SuperSegmentationObject` owns cellular objects (see section 'Mapping of ce
interface for analysis and visualization methods (e.g. cellular compartment, spine, cell type classification),
which will be described in more detail under 'Classification procedures' and 'Visualization'.
In order to aggregate the mapping information of the cellular objects from SSO's super voxels, see [here](object_mapping.md).
In order to aggregate the mapping information of the cellular objects from SSO's supervoxels, see [here](object_mapping.md).
## Visualization
_in progress_
......
......@@ -20,6 +20,7 @@ except ImportError:
from knossos_utils.skeleton import SkeletonAnnotation, SkeletonNode
from knossos_utils import KnossosDataset
import re
import gc
import signal
import networkx as nx
import contextlib
......@@ -520,6 +521,7 @@ def write_obj2pkl(path, objects):
destianation
"""
# with DelayedInterrupt([signal.SIGTERM, signal.SIGINT]):
gc.disable()
if isinstance(path, str):
with open(path, 'wb') as output:
pkl.dump(objects, output, -1)
......@@ -528,6 +530,7 @@ def write_obj2pkl(path, objects):
"'objects' (python object).")
with open(objects, 'wb') as output:
pkl.dump(path, output, -1)
gc.enable()
def load_pkl2obj(path):
......@@ -541,13 +544,15 @@ def load_pkl2obj(path):
Returns
-------
"""
gc.disable()
try:
with open(path, 'rb') as inp:
objects = pkl.load(inp)
except UnicodeDecodeError: # python3 compatibility
except UnicodeDecodeError: # python3 compatibility
with open(path, 'rb') as inp:
objects = pkl.loads(inp.read(), encoding='bytes')
objects = convert_keys_byte2str(objects)
gc.enable()
return objects
......
......@@ -64,7 +64,7 @@ def init_sso_from_kzip(path, load_as_tmp=True, sso_id=None):
sso._view_caching = True
# meshes
for obj_type in global_params.existing_cell_organelles + ["sv"]:
for obj_type in global_params.existing_cell_organelles + ["sv", "syn_ssv"]:
ply_name = "{}.ply".format(obj_type)
if ply_name in files:
sso._meshes[obj_type] = read_mesh_from_zip(path, ply_name)
......
......@@ -385,6 +385,10 @@ class SuperSegmentationObject(object):
def mi_mesh(self):
return self.load_mesh("mi")
@property
def syn_ssv_mesh(self):
return self.load_mesh("syn_ssv")
def label_dict(self, data_type='vertex'):
if data_type == 'vertex':
if data_type in self._label_dict:
......@@ -1594,7 +1598,7 @@ class SuperSegmentationObject(object):
# dendrite, axon, soma, bouton, terminal, background, unpredicted
cols = np.array([[0.6, 0.6, 0.6, 1], [0.9, 0.2, 0.2, 1],
[0.1, 0.1, 0.1, 1], [0.05, 0.6, 0.6, 1],
[0.6, 0.05, 0.05, 1], [0.9, 0.9, 0.9, 1],
[0.8, 0.8, 0.1, 1], [0.9, 0.9, 0.9, 1],
[0.1, 0.1, 0.9, 1]])
cols = (cols * 255).astype(np.uint8)
else:
......@@ -1836,6 +1840,11 @@ class SuperSegmentationObject(object):
elif obj_type == "mi":
mesh = self.mi_mesh
# color = np.array([0, 153, 255, 255])
elif obj_type == "syn_ssv":
mesh = self.syn_ssv_mesh
# also store it as 'sj' s.t. `init_sso_from_kzip` can use it for rendering.
# TODO: add option to rendering code which enables rendering of arbitrary cell organelles
obj_type = 'sj'
else:
mesh = self._meshes[obj_type]
if ext_color is not None:
......@@ -1860,7 +1869,7 @@ class SuperSegmentationObject(object):
write_mesh2kzip(dest_path, mesh[0], mesh[1], mesh[2], color,
ply_fname=obj_type + ".ply")
def meshes2kzip(self, dest_path=None, sv_color=None):
def meshes2kzip(self, dest_path=None, sv_color=None, synssv_instead_sj=False):
"""
Writes SV, mito, vesicle cloud and synaptic junction meshes to k.zip
......@@ -1870,6 +1879,7 @@ class SuperSegmentationObject(object):
sv_color : np.array
array with RGBA values or None to use default values
(see 'mesh2kzip')
synssv_instead_sj : bool
Returns
-------
......@@ -1879,6 +1889,8 @@ class SuperSegmentationObject(object):
dest_path = self.skeleton_kzip_path
for ot in ["sj", "vc", "mi",
"sv"]: # determins rendering order in KNOSSOS
if ot == "sj" and synssv_instead_sj:
ot = 'syn_ssv'
self.mesh2kzip(obj_type=ot, dest_path=dest_path, ext_color=sv_color if
ot == "sv" else None)
......@@ -1901,7 +1913,8 @@ class SuperSegmentationObject(object):
mesh2obj_file(dest_path, self.mesh, center=center, color=color,
scale=scale)
def export2kzip(self, dest_path, attr_keys=(), rag=None, sv_color=None):
def export2kzip(self, dest_path, attr_keys=(), rag=None, sv_color=None,
synssv_instead_sj=False):
"""
Writes the sso to a KNOSSOS loadable kzip.
Color is specified as rgba, 0 to 255.
......@@ -1919,6 +1932,7 @@ class SuperSegmentationObject(object):
rag : nx.Graph
SV graph of SSV with uint nodes
sv_color : 4-tuple of int
synssv_instead_sj : bool
"""
# # The next two calls are probably deprecated
# self.save_skeleton_to_kzip(dest_path=dest_path)
......@@ -1959,7 +1973,8 @@ class SuperSegmentationObject(object):
'working_dir': self.working_dir})
# write all data
data2kzip(dest_path, tmp_dest_p, target_fnames)
self.meshes2kzip(dest_path=dest_path, sv_color=sv_color)
self.meshes2kzip(dest_path=dest_path, sv_color=sv_color,
synssv_instead_sj=synssv_instead_sj)
self.mergelist2kzip(dest_path=dest_path)
def write_svmeshes2kzip(self, dest_path=None):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment