class TestDownload(unittest.TestCase):

    def setUp(self):
        self.oo = OCP()

    def test_get_cutout_type(self):
        # kasthuri11/image/xy/3/1000,1100/1000,1100/1000/
        numpy_download = self.oo.get_cutout('kasthuri11', 'image',
                                            1000, 1100,
                                            1000, 1100,
                                            1000, 1001,
                                            resolution=3)

        self.assertEqual(type(numpy_download), numpy.ndarray)

    def test_get_cutout(self):
        # kasthuri11/image/xy/3/1000,1100/1000,1100/1000/
        numpy_download = self.oo.get_cutout('kasthuri11', 'image',
                                            1000, 1100,
                                            1000, 1100,
                                            1000, 1001,
                                            resolution=3)

        # We know this pixel is 132
        self.assertEqual(numpy_download[0][0][0], 132)

    def test_get_volume_type(self):
        # kasthuri11/image/xy/3/1000,1100/1000,1100/1000/
        ramon_download = self.oo.get_volume('kasthuri11', 'image',
                                            1000, 1100,
                                            1000, 1100,
                                            1000, 1001,
                                            resolution=3)

        self.assertEqual(type(ramon_download), ndio.ramon.RAMONVolume)

    def test_get_volume(self):
        # kasthuri11/image/xy/3/1000,1100/1000,1100/1000/
        ramon_download = self.oo.get_volume('kasthuri11', 'image',
                                            1000, 1100,
                                            1000, 1100,
                                            1000, 1001,
                                            resolution=3)

        self.assertEqual(ramon_download.xyz_offset[0], 1000)
        self.assertEqual(ramon_download.resolution, 3)
        self.assertEqual(ramon_download.cutout[0][0][0], 132)

    def test_get_image_type(self):
        # kasthuri11/image/xy/3/1000,1100/1000,1100/1000/
        image_download = self.oo.get_image('kasthuri11', 'image',
                                           1000, 1100,
                                           1000, 1100,
                                           1000,
                                           resolution=3)

        self.assertEqual(type(image_download), numpy.ndarray)
        self.assertEqual(image_download.shape, (100, 100))
def getRaw(x1,x2,y1,y2,z1,z2):
	"""
	Retrieve mitochondria image volume from neurodata given x,y,z parameters
	
	Arguments:
		x1/y1/z1: starting value for cut
		x2/y2/z2: ending cut value
	
	Returns: 
		3D Numpy Array of images (each image is in a 2D numpy array)
	"""
	oo = OCP()
	return oo.get_cutout('kasthuri11cc', 'image', x1, x2, y1, y2, z1, z2, resolution = 3)
def getTruth(db = False):
    # Careful of hardcoded filepath    
    if db == False:
        vol = np.array([])
        data = ndio.convert.png.import_png_collection('newdata/mito_anno_*')
        for img in data:
            vol = np.dstack([vol, img]) if vol.size else img
        return vol
    else:
		boundaries = getConfig()
		oo = OCP()
		#added +12 because first 10 images in stack aren't even annotated
		return oo.get_cutout('kasthuri2015_ramon_v1', 'mitochondria', 694 + boundaries[0], 694 + boundaries[1], 1750 + boundaries[2], 1750 + boundaries[3], 1004, 1154, resolution = 3)
class TestRAMONSegment(unittest.TestCase):

    def setUp(self):
        self.oo = OCP()
        self.ramon_segment = self.oo.get_ramon('kasthuri2015_ramon_v1',
                                               'neurons', 3, 3)
        self.default_ramon_segment = ndio.ramon.RAMONSynapse()

    def test_metadata(self):
        self.assertEqual(str(self.ramon_segment.id), '3')
class TestDownload(unittest.TestCase):

    def setUp(self):
        self.oo = OCP()

    def test_export_import_png(self):
        # kasthuri11/image/xy/3/1000,1100/1000,1100/1000/
        image_download = self.oo.get_image('kasthuri11', 'image',
                                           1000, 1100,
                                           1000, 1100,
                                           1000,
                                           resolution=3)

        # if returns string, successful export
        self.assertEqual(
                ndpng.export_png("tests/trash/download.png", image_download),
                "tests/trash/download.png")

        # now confirm import works too
        self.assertEqual(ndpng.import_png("tests/trash/download.png")[0][0],
                         image_download[0][0])
        self.assertEqual(ndpng.import_png("tests/trash/download.png")[10][10],
                         image_download[10][10])

    def test_export_import_tiff(self):
        # kasthuri11/image/xy/3/1000,1100/1000,1100/1000/
        image_download = self.oo.get_image('kasthuri11', 'image',
                                           1000, 1100,
                                           1000, 1100,
                                           1000,
                                           resolution=3)

        # if returns string, successful export
        self.assertEqual(
                ndtiff.export_tiff("tests/trash/download-1.tiff", image_download),
                "tests/trash/download-1.tiff")

        # now confirm import works too
        self.assertEqual(ndtiff.import_tiff("tests/trash/download-1.tiff")[0][0],
                         image_download[0][0])
        self.assertEqual(ndtiff.import_tiff("tests/trash/download-1.tiff")[10][10],
                         image_download[10][10])
### ndio membrane segmentation imports
import ndio
import ndio.remote.OCP as OCP
import ndio.remote.OCPMeta as NDLIMS
import ndio.convert.tiff as ndtiff
###

### Create OCP / OCPMeta objects
oo = OCP()
nn = NDLIMS()
###

# Get all tokens
tokens = oo.get_public_tokens()

# Membrane group image and annotation tokens for membrane image in datamap
image_token = 'kasthuri11cc'
annotation_token = 'cv_kasthuri11_membrane_2014'

# Get channel ROI for token
channel_ROI = nn.get_metadata('cv_kasthuri11_membrane_2014')['channels']

# Get membrane ROI coordinates
membrane_group_ROI = channel_ROI['image']['rois']['ac4']

# Sets membrane query in Python
membrane_query = {
    'token': 'cv_kasthuri11_membrane_2014',
    'channel': 'image',
    'x_start': membrane_group_ROI['x'][0],
    'x_stop': membrane_group_ROI['x'][1],
### ndio membrane segmentation imports
import ndio
print "ndio version: %s" % (ndio.version)

import ndio.remote.OCP as OCP
oo = OCP()

import ndio.remote.OCPMeta as NDLIMS
nn = NDLIMS()
###

### Watershed segmentation imports
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage as ndi

from skimage.morphology import watershed
from skimage.feature import peak_local_max
from skimage.morphology import closing
from skimage.morphology import binary_dilation
from skimage.morphology import binary_erosion
from skimage.filters.rank import threshold
from skimage.exposure import rescale_intensity
from skimage.filters import threshold_otsu
###

print "Done importing packages"

#########
# ndio demo for membrane segmentation
#########
 def setUp(self):
     self.oo = OCP()
 def setUp(self):
     self.oo = OCP()
     self.ramon_segment = self.oo.get_ramon('kasthuri2015_ramon_v1',
                                            'neurons', 3, 3)
     self.default_ramon_segment = ndio.ramon.RAMONSynapse()
### ndio membrane segmentation imports
import ndio
import ndio.remote.OCP as OCP
import ndio.remote.OCPMeta as NDLIMS
import numpy as np

### Create OCP / OCPMeta objects
oo = OCP()
nn = NDLIMS()
###

print "Done importing packages"

image_token = "kasthuri11cc"
annotation_token = "kasthuri2015_ramon_v"
segmentation_token = "ac3ac4"

# Get channel ROI for token
channel_ROI = nn.get_metadata(segmentation_token)["channels"]

# Get membrane ROI coordinates
membrane_group_ROI = channel_ROI["ac4_neuron_truth"]["rois"]["ac4"]

# Sets membrane query in Python
membrane_query = {
    "token": "ac3ac4",
    "channel": "ac4_neuron_truth",
    "x_start": membrane_group_ROI["x"][0],
    "x_stop": membrane_group_ROI["x"][1],
    "y_start": membrane_group_ROI["y"][0],
    "y_stop": membrane_group_ROI["y"][1],
Example #11
0
### ndio membrane segmentation imports
import ndio
import ndio.remote.OCP as OCP
import ndio.remote.OCPMeta as NDLIMS
import numpy as np

### Create OCP / OCPMeta objects
oo = OCP()
nn = NDLIMS()
###

print "Done importing packages"

image_token = 'kasthuri11cc'
annotation_token = 'kasthuri2015_ramon_v'
segmentation_token = 'ac3ac4'

# Get channel ROI for token
channel_ROI = nn.get_metadata(segmentation_token)['channels']

# Get membrane ROI coordinates
membrane_group_ROI = channel_ROI['ac4_neuron_truth']['rois']['ac4']

# Sets membrane query in Python
membrane_query = {
    'token': 'ac3ac4',
    'channel': 'ac4_neuron_truth',
    'x_start': membrane_group_ROI['x'][0],
    'x_stop': membrane_group_ROI['x'][1],
    'y_start': membrane_group_ROI['y'][0],
    'y_stop': membrane_group_ROI['y'][1],