Ejemplo n.º 1
0
def test_interpolate_radius_extreme_cases():
    res = mm.interpolate_radius(1., 1., 0.2)
    assert res == 1.
    res = mm.interpolate_radius(0., 2., 0.3)
    assert res == 2. * 0.3
    res = mm.interpolate_radius(3., 0., 0.15)
    assert res == 3. * (1. - 0.15)
Ejemplo n.º 2
0
def test_interpolate_radius_extreme_cases():
    res = mm.interpolate_radius(1., 1., 0.2)
    nt.assert_equal(res, 1.)
    res = mm.interpolate_radius(0., 2., 0.3)
    nt.assert_equal(res, 2. * 0.3)
    res = mm.interpolate_radius(3., 0., 0.15)
    nt.assert_equal(res, 3. * (1. - 0.15))
Ejemplo n.º 3
0
def cross_section_at_fraction(segment, fraction):
    ''' Computes the point p along the line segment that connects the
    two ends of a segment p1p2 where |p1p| = fraction * |p1p2| along
    with the respective radius.
    Args:
        fraction: float between 0. and 1.

    Returns: tuple
        The 3D coordinates of the aforementioned point,
        Its respective radius
    '''
    return (mm.linear_interpolate(segment[0].value, segment[1].value, fraction),
            mm.interpolate_radius(segment[0].value[COLS.R], segment[1].value[COLS.R], fraction))
Ejemplo n.º 4
0
def test_interpolate_radius_r2_g_r1():
    res = mm.interpolate_radius(1., 2., 0.2)
    assert res == 1.2
Ejemplo n.º 5
0
def test_interpolate_radius_r1_g_r2():
    res = mm.interpolate_radius(2., 1., 0.1)
    assert res == 1.9
Ejemplo n.º 6
0
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''Get sections and segments by ID'''

import neurom as nm
from neurom import morphmath as mm
from neurom.core.dataformat import COLS


def get_segment(neuron, section_id, segment_id):
    '''Get a segment given a section and segment id

    Returns:
        array of two [x, y, z, r] points defining segment
    '''
    sec = neuron.sections[section_id]
    return sec.points[segment_id:segment_id + 2][:, COLS.XYZR]


if __name__ == '__main__':

    nrn = nm.load_neuron('test_data/h5/v1/Neuron.h5')

    seg = get_segment(nrn, 3, 2)
    print('Segment:\n', seg)
    print('Mid-point (x, y, z):\n', mm.linear_interpolate(seg[0], seg[1], 0.5))
    print('Mid-point R:\n',
          mm.interpolate_radius(seg[0][COLS.R], seg[1][COLS.R], 0.5))
Ejemplo n.º 7
0
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""Get sections and segments by ID."""

import neurom as nm
from neurom import morphmath as mm
from neurom.core.dataformat import COLS


def get_segment(neuron, section_id, segment_id):
    """Get a segment given a section and segment id

    Returns:
        array of two [x, y, z, r] points defining segment
    """
    sec = neuron.sections[section_id]
    return sec.points[segment_id:segment_id + 2][:, COLS.XYZR]


if __name__ == '__main__':

    nrn = nm.load_neuron('tests/data/h5/v1/Neuron.h5')

    seg = get_segment(nrn, 3, 2)
    print('Segment:\n', seg)
    print('Mid-point (x, y, z):\n', mm.linear_interpolate(seg[0], seg[1], 0.5))
    print('Mid-point R:\n', mm.interpolate_radius(seg[0][COLS.R], seg[1][COLS.R], 0.5))
Ejemplo n.º 8
0
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'''Get sections and segments by ID'''

import neurom as nm
from neurom import morphmath as mm
from neurom.core.dataformat import COLS


def get_segment(neuron, section_id, segment_id):
    '''Get a segment given a section and segment id

    Returns:
        array of two [x, y, z, r] points defining segment
    '''
    sec = neuron.sections[section_id]
    return sec.points[segment_id:segment_id + 2][:, 0:4]


if __name__ == '__main__':

    nrn = nm.load_neuron('test_data/h5/v1/Neuron.h5')

    seg = get_segment(nrn, 3, 2)
    print 'Segment:\n', seg
    print 'Mid-point (x, y, z):\n', mm.linear_interpolate(seg[0], seg[1], 0.5)
    print 'Mid-point R:\n', mm.interpolate_radius(seg[0][COLS.R], seg[1][COLS.R], 0.5)
Ejemplo n.º 9
0
def test_interpolate_radius_r2_g_r1():
    res = mm.interpolate_radius(1., 2., 0.2)
    nt.assert_equal(res, 1.2)
Ejemplo n.º 10
0
def test_interpolate_radius_r1_g_r2():
    res = mm.interpolate_radius(2.,1.,0.1)
    nt.assert_equal(res, 1.9)