-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Manifests.jl
117 lines (102 loc) · 3.66 KB
/
Manifests.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
module Manifests
include("DBFs.jl"); using .DBFs;
include("PointArrays.jl"); using .PointArrays;
# using JLD2
using BigArrays
using BigArrays.BinDicts
using ..RealNeuralNetworks.NodeNets
#import ..RealNeuralNetworks.NodeNets.DBFs
#import ..RealNeuralNetworks.NodeNets.PointArrays
using OffsetArrays
using JSON
import Distributed: pmap
const MIP_LEVEL = 4
export Manifest
struct Manifest
# the bigarray for cutout of segmentation
ba ::AbstractBigArray
# the id of object
obj_id ::Integer
# the unit range list for cutout
rangeList ::Vector
end
"""
Parameters:
dir
"""
function Manifest( manifestDirPath::AbstractString, manifestKey::AbstractString, bigArrayPath::AbstractString )
ba = BigArray( BinDict( bigArrayPath ) )
h = BinDict( manifestDirPath)
str = String(h[manifestKey])
d = JSON.parse(str; dicttype=Dict{Symbol, Any})
Manifest( d, ba )
end
"""
example: {"fragments": ["770048087:0:2968-3480_1776-2288_16912-17424"]}
"""
function Manifest( h::Dict{Symbol, Any}, ba::AbstractBigArray )
Manifest( h[:fragments], ba )
end
"""
example: ["770048087:0:2968-3480_1776-2288_16912-17424"]
"""
function Manifest( ranges::Vector, ba::BigArray{D,T,N,C} ) where {D,T,N,C}
obj_id = Meta.parse( split(ranges[1], ":")[1] )
obj_id = convert(T, obj_id)
ranges = map(x-> split(x,":")[end], ranges)
rangeList = map( BigArrays.Indexes.string2unit_range, ranges )
@show rangeList
Manifest( ba, obj_id, rangeList )
end
function Base.length(self::Manifest) length(get_range_list(self)) end
function get_range_list(self::Manifest) self.rangeList end
"""
the voxel offset in the neuroglancer precomputed info file
"""
function get_voxel_offset(self::Manifest)
voxel_offset = self.ba.kvStore.configDict[:offset]
#real voxel offset should based on the highest resolution 5x5x45
# we are using mip level 4 with (80x80x45 nm) now
# voxel_offset = map((x,y)->UInt32(x*y), voxel_offset, (2^MIP_LEVEL, 2^MIP_LEVEL,1))
voxel_offset = Vector{UInt32}(voxel_offset)
@show voxel_offset
return (voxel_offset...,)
end
"""
iterate the chunks containing the neuron with specified cellId
build point cloud and dbf when iterating the chunks
"""
function trace(self::Manifest, cellId)
println("extract point clouds and distance from boundary fields ...")
@time pointCloudDBFList = pmap( identity, self );
pointClouds = map( x->x[1], pointCloudDBFList )
pointCloud = vcat(pointClouds ...)
dbfs = map(x->x[2], pointCloudDBFList)
dbf = vcat(dbfs ...)
# save temporal variables for debug
# @save "/tmp/$(cellId).jld" pointClouds, pointCloud, dbf
println("skeletonization from global point cloud and dbf using RealNeuralNetworks algorithm...")
@time nodeNet = NodeNet(pointCloud; dbf=dbf)
return nodeNet
end
function Base.iterate(self::Manifest, state=1)
if state > length( self.rangeList )
# finish iteration
return nothing
end
println("manifest index: $state in $(length(self.rangeList))")
# example: [2456:2968, 1776:2288, 16400:16912]
ranges = self.rangeList[state]
offset = (map(x-> UInt32(x.start-1), ranges)...,)
seg = self.ba[ranges...] |> parent
bin_im = DBFs.create_binary_image( seg; obj_id = self.obj_id )
@assert any(bin_im)
point_cloud = PointArrays.from_binary_image( bin_im )
# distance from boundary field
dbf = DBFs.compute_DBF(point_cloud, bin_im)
PointArrays.add_offset!(point_cloud, offset)
# no need to use voxel_offset since the file name encoded the global coordinate
# PointArrays.add_offset!(point_cloud, get_voxel_offset(self))
return (point_cloud, dbf), state+1
end
end # module