-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for the file formats
- Loading branch information
Showing
9 changed files
with
392 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
from collections import namedtuple | ||
from docutils.parsers.rst import Directive, directives | ||
from docutils import nodes | ||
|
||
|
||
class bbp_table_value(nodes.Element): | ||
pass | ||
|
||
|
||
class BBPTableValue(Directive): | ||
has_content = True | ||
required_arguments = 1 | ||
optional_arguments = 0 | ||
final_argument_whitespace = True | ||
option_spec = {'type': directives.unchanged, | ||
'value': directives.unchanged, | ||
'comment': directives.unchanged | ||
} | ||
|
||
def run(self): | ||
resultnode = bbp_table_value() | ||
self.options['field'] = self.arguments[0] | ||
resultnode.options = self.options | ||
return [resultnode] | ||
|
||
|
||
BBPTableSectionInfo = namedtuple('BBPTableSectionInfo', | ||
'name, description, docname, targetid') | ||
|
||
|
||
class bbp_table_section(nodes.General, nodes.Element): | ||
pass | ||
|
||
|
||
class BBPTableSection(Directive): | ||
has_content = True | ||
required_arguments = 1 | ||
optional_arguments = 0 | ||
final_argument_whitespace = True | ||
option_spec = {'description': directives.unchanged, | ||
} | ||
|
||
def _make_table(self, rows): | ||
def create_table_row(row_cells): | ||
row = nodes.row() | ||
for cell in row_cells: | ||
row += nodes.entry('', nodes.paragraph(text=cell)) | ||
return row | ||
|
||
header = ('Field', 'Value Type', 'Suggested Value', 'Comments' ) | ||
colwidths = (1, 1, 2, 3) | ||
|
||
assert len(header) == len(colwidths) | ||
tgroup = nodes.tgroup(cols=len(header)) | ||
for c in colwidths: | ||
tgroup += nodes.colspec(colwidth=c) | ||
tgroup += nodes.thead('', create_table_row(header)) | ||
tbody = nodes.tbody() | ||
tgroup += tbody | ||
for row in rows: | ||
tbody += create_table_row((row.options['field'], | ||
row.options['type'], | ||
row.options['value'], | ||
row.options['comment'])) | ||
|
||
table = nodes.table('', tgroup) | ||
return table | ||
|
||
def run(self): | ||
env = self.state.document.settings.env | ||
if not hasattr(env, 'all_bbp_table_sections'): | ||
env.all_bbp_table_sections = [] | ||
|
||
name = self.arguments[0] | ||
description = self.options['description'] | ||
targetid = "bbp_tablesection-%d" % env.new_serialno('bbp_table_section') | ||
|
||
node = nodes.Element() | ||
self.state.nested_parse(self.content, self.content_offset, node) | ||
|
||
section_info = BBPTableSectionInfo(name, description, env.docname, targetid) | ||
env.all_bbp_table_sections.append(section_info) | ||
|
||
children = [] | ||
for child in node: | ||
if isinstance(child, bbp_table_value): | ||
children.append(child) | ||
|
||
resultnode = nodes.section(ids=[targetid]) | ||
resultnode += [nodes.title(text=name), | ||
nodes.paragraph(text=description), | ||
self._make_table(children), | ||
nodes.line() | ||
] | ||
|
||
return [resultnode] | ||
|
||
|
||
class bbp_table_section_index(nodes.Element): | ||
pass | ||
|
||
|
||
class BBPTableSectionIndex(Directive): | ||
'''create a place-holder for an index''' | ||
|
||
def run(self): | ||
return [bbp_table_section_index('')] | ||
|
||
|
||
def process_bbp_table_section_index(app, doctree, fromdocname): | ||
env = app.builder.env | ||
|
||
for node in doctree.traverse(bbp_table_section_index): | ||
references = [] | ||
for section in env.all_bbp_table_sections: | ||
ref = nodes.reference(section.name, section.name) | ||
ref['refdocname'] = section.docname | ||
ref['refuri'] = app.builder.get_relative_uri( | ||
fromdocname, section.docname) + '#' + section.targetid | ||
|
||
para = nodes.paragraph('', '', ref) | ||
item = nodes.list_item('', para, nodes.paragraph(text=section.description)) | ||
references.append(item) | ||
|
||
content = nodes.bullet_list('', *references) | ||
node.replace_self(content) | ||
|
||
|
||
def setup(app): | ||
app.add_node(bbp_table_section_index) | ||
app.add_directive('bbp_table_section_index', BBPTableSectionIndex) | ||
|
||
app.add_node(bbp_table_section) | ||
app.add_directive('bbp_table_section', BBPTableSection) | ||
app.add_config_value('bbp_table_section', {}, 'env') | ||
|
||
app.add_node(bbp_table_value) | ||
app.add_directive('bbp_table_value', BBPTableValue) | ||
|
||
app.connect('doctree-resolved', process_bbp_table_section_index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
NRRD File Formats | ||
================= | ||
|
||
.. toctree:: | ||
:hidden: | ||
|
||
mask | ||
orientation | ||
scalar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ Contents | |
aibs | ||
atlas | ||
extras | ||
formats | ||
api | ||
changelog | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
Mask Image for Region of Interest (ROI) | ||
======================================= | ||
|
||
.. _mask_roi: | ||
|
||
For validating the circuits we would need to specify "regions of interest" for a given atlas (for example, pick a sphere within a layer to measure cell density). A mask image is generated for given specific shape and stored in NRRD format with the following metadata. | ||
|
||
.. bbp_table_section:: Specification | ||
:description: | ||
The meta data stored in the NRRD file should follow the specification below: | ||
|
||
.. bbp_table_value:: dimension | ||
:type: integer | ||
:value: 3 | ||
:comment: dimension of the image is always 3 for volumetric data | ||
|
||
.. bbp_table_value:: encoding | ||
:type: string | ||
:value: gzip | ||
:comment: use 'gzip' for compressing the data | ||
|
||
.. bbp_table_value:: endian | ||
:type: string | ||
:value: little | ||
:comment: use 'little' for x86 machines | ||
|
||
.. bbp_table_value:: kinds | ||
:type: list of string | ||
:value: ['domain', 'domain', 'domain'] | ||
:comment: use 'domain' to indicate that the axis is image axis | ||
|
||
.. bbp_table_value:: sizes | ||
:type: list of integer | ||
:value: [{size_x}, {size_y}, {size_z}] | ||
:comment: the size of the volume in x, y, z dimension | ||
|
||
.. bbp_table_value:: space directions | ||
:type: 3d matrix | ||
:value: | ||
:comment: A 3D matrix indicating the orientation of the image data, with the value indicating the spacing of the voxel | ||
|
||
.. bbp_table_value:: space origin | ||
:type: list of float | ||
:value: [{origin_x}, {origin_y}, {origin_z}] | ||
:comment: physical coordinates of the image origin | ||
|
||
.. bbp_table_value:: space | ||
:type: string | ||
:value: {x_orientation}-{y_orientation}-{z_orientation} | ||
:comment: the orientation of the image data, should be consistent with the space direction | ||
|
||
.. bbp_table_value:: type | ||
:type: string | ||
:value: uchar | ||
:comment: the type of the values stored in the voxels is unsigned char | ||
|
||
Example: | ||
|
||
:: | ||
|
||
{ | ||
u'space origin': ['-46.540000915527344', '-152.15999984741211', '-152'], | ||
u'space directions': [['16', '0', '0'], ['0', '16', '0'], ['0', '0', '16']], | ||
u'sizes': [308, 495, 464], | ||
u'space': 'left-posterior-superior', | ||
u'encoding': 'gzip', | ||
u'endian': 'little', | ||
u'kinds': ['domain', 'domain', 'domain'], | ||
u'type': 'unsigned char', | ||
u'dimension': 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Orientation Field File Format | ||
============================= | ||
|
||
|
||
The orientation field indicates the orientation of the morphology at each voxel position in the form of quaternion. The coefficients of the quaternion is encoded in the order of (w, x, y, z).Therefore, each voxel stores a 4d vector of float number in the NRRD file. | ||
|
||
.. bbp_table_section:: Specification | ||
:description: | ||
The meta data stored in the NRRD file should follow the specification below: | ||
|
||
.. bbp_table_value:: dimension | ||
:type: integer | ||
:value: 4 | ||
:comment: dimension of the image is 4, with the 4th dimension indicating the quaternion 4d vector | ||
|
||
.. bbp_table_value:: encoding | ||
:type: string | ||
:value: gzip | ||
:comment: use 'gzip' for compressing the data | ||
|
||
.. bbp_table_value:: endian | ||
:type: string | ||
:value: little | ||
:comment: use 'little' for x86 machines | ||
|
||
.. bbp_table_value:: kinds | ||
:type: list of string | ||
:value: ['quaternion', 'domain', 'domain', 'domain'] | ||
:comment: use 'quaternion' to indicate the type of the first data dimension, use 'domain' to indicate the other dimensions are image axis | ||
|
||
.. bbp_table_value:: sizes | ||
:type: list of integer | ||
:value: [4, {size_x}, {size_y}, {size_z}] | ||
:comment: the 1st element is the size of quaternion vector which is 4, together with the size of the voxels in x, y, z dimension | ||
|
||
.. bbp_table_value:: space directions | ||
:type: 3d matrix | ||
:value: [u'none', {3d matrix}] | ||
:comment: 'none' indicate the first dimension does not represent the image space. the second part is a 3D matrix indicating the orientation of the image data, with the value indicating the spacing of the voxel | ||
|
||
.. bbp_table_value:: space origin | ||
:type: list of float | ||
:value: [{origin_x}, {origin_y}, {origin_z}] | ||
:comment: physical coordinates of the image origin | ||
|
||
.. bbp_table_value:: space | ||
:type: string | ||
:value: {x_orientation}-{y_orientation}-{z_orientation} | ||
:comment: the orientation of the image data, should be consistent with the space direction | ||
|
||
.. bbp_table_value:: type | ||
:type: string | ||
:value: float (default) or int8 (optional) | ||
:comment: the default type of the values stored in the voxels is float. alternatively, the type of the values stored in the voxels can be signed 1-byte integer to minimize the file size | ||
|
||
Example: | ||
|
||
:: | ||
|
||
{ | ||
u'space origin': ['-46.540000915527344', '-152.15999984741211', '-152'], | ||
u'space directions': [u'none', ['16', '0', '0'], ['0', '16', '0'], ['0', '0', '16']], | ||
u'sizes': [4, 308, 495, 464], | ||
u'space': 'left-posterior-superior', | ||
u'encoding': 'gzip', | ||
u'endian': 'little', | ||
u'kinds': ['quaternion', 'domain', 'domain', 'domain'], | ||
u'type': 'int8', | ||
u'dimension': 4 | ||
} |
Oops, something went wrong.