Beispiel #1
0
    def test_web_propagate(self):
        """Test the web update propogate function"""

        # Posting some data at res0 to propagate
        p.args = (200, 300, 200, 300, 4, 5)
        image_data = np.ones([1, 1, 100, 100],
                             dtype=np.uint8) * random.randint(0, 255)
        response = postNPZ(p, image_data)

        # Check if the project is not proagated
        f = getURL("http://{}/ca/{}/{}/getPropagate/".format(
            SITE_HOST, p.token, ','.join(p.channels)))
        value = int(f.read())
        assert (value == PROPAGATED)

        # check that it cannot start propagating a channel which is already propagated
        assert (getURL("http://{}/ca/{}/{}/setPropagate/{}/".format(
            SITE_HOST, p.token, ','.join(p.channels),
            UNDER_PROPAGATION)) == 404)
        f = getURL("http://{}/ca/{}/{}/setPropagate/{}/".format(
            SITE_HOST, p.token, ','.join(p.channels), NOT_PROPAGATED))
        # can set to not propagated
        f = getURL("http://{}/ca/{}/{}/getPropagate/".format(
            SITE_HOST, p.token, ','.join(p.channels)))
        value = int(f.read())
        assert (value == NOT_PROPAGATED)
Beispiel #2
0
    def test_web_propagate(self):
        """Test the web update propogate function"""

        p.resolution = 0
        # Posting some data at res0 to propagate
        p.args = (200, 300, 200, 300, 4, 5)
        image_data = np.ones([1, 1, 100, 100],
                             dtype=np.uint8) * random.randint(0, 255)
        response = postNPZ(p, image_data)
        # check that it cannot post to a readonly channle
        assert (response.status_code == 404)

        # Check if the project is not proagated
        f = getURL("https://{}/sd/{}/{}/getPropagate/".format(
            SITE_HOST, p.token, ','.join(p.channels)))
        value = int(f.content)
        assert (value == NOT_PROPAGATED)

        # check that it cannot start propagating a readonly channel
        assert (getURL("https://{}/sd/{}/{}/setPropagate/{}/".format(
            SITE_HOST, p.token, ','.join(p.channels),
            UNDER_PROPAGATION)).status_code == 404)
        # check that it cannot mark a channel as propagated
        assert (getURL("https://{}/sd/{}/{}/setPropagate/{}/".format(
            SITE_HOST, p.token, ','.join(p.channels),
            PROPAGATED)).status_code == 404)
  def test_web_propagate(self):
    """Test the web update propogate function"""

    # Posting some data at res0 to propagate
    p.args = (200,300,200,300,4,5)
    image_data = np.ones( [1,1,100,100], dtype=np.uint8) * random.randint(0,255)
    response = postNPZ(p, image_data)

    # Check if the project is not proagated
    f = getURL("http://{}/ca/{}/{}/getPropagate/".format(SITE_HOST, p.token, ','.join(p.channels)))
    value = int(f.read())
    assert(value == NOT_PROPAGATED)

    # Start propagating
    f = getURL("http://{}/ca/{}/{}/setPropagate/{}/".format(SITE_HOST, p.token, ','.join(p.channels), UNDER_PROPAGATION))
    time.sleep(10)
    # Checking if the PROPGATED value is set correctly
    f = getURL("http://{}/ca/{}/{}/getPropagate/".format(SITE_HOST, p.token, ','.join(p.channels)))
    value = int(f.read())
    assert(value == PROPAGATED)
    
    # Checking at res1
    p.args = (100,150,100,150,4,5)
    url = "http://{}/ca/{}/{}/xy/{}/{},{}/{},{}/{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution+1, p.args[0], p.args[1], p.args[2], p.args[3], p.args[4])
    f = getURL(url)
    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data, image_data[0][0][:50,:50]) )
   
    # Checking at res5
    p.args = (7,9,7,9,4,5)
    url = "http://{}/ca/{}/{}/xy/{}/{},{}/{},{}/{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution+5, p.args[0], p.args[1], p.args[2], p.args[3], p.args[4])
    f = getURL(url)
    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data, image_data[0][0][:2,:2]) )
Beispiel #4
0
    def test_web_propagate(self):
        """Test the web update propogate function"""

        # Posting some data at res0 to propagate
        p.args = (200, 300, 200, 300, 32, 64)
        p.resolution = 0
        image_data = np.ones([1, 32, 100, 100],
                             dtype=np.uint32) * random.randint(255, 65535)
        response = postNPZ(p, image_data)

        voxarray = getNPZ(p)
        # check that the return matches
        assert (np.array_equal(voxarray, image_data))

        # Check if the project is not proagated
        f = getURL("https://{}/sd/{}/{}/getPropagate/".format(
            SITE_HOST, p.token, ','.join(p.channels)))
        value = int(f.content)
        assert (value == NOT_PROPAGATED)

        # Start propagating
        f = getURL("https://{}/sd/{}/{}/setPropagate/{}/".format(
            SITE_HOST, p.token, ','.join(p.channels), UNDER_PROPAGATION))

        # Checking if the PROPGATED value is set correctly
        for iter_value in range(1, 100, 1):
            time.sleep(1)
            f = getURL("https://{}/sd/{}/{}/getPropagate/".format(
                SITE_HOST, p.token, ','.join(p.channels)))
            value = int(f.content)
            if value == PROPAGATED:
                break
        assert (value == PROPAGATED)

        # Checking at res1
        p.args = (100, 150, 100, 150, 16, 32)
        p.resolution = 1
        voxarray = getNPZ(p)
        assert (np.array_equal(voxarray[0][0], image_data[0][0][:50, :50]))

        # Checking at res2
        p.args = (50, 75, 50, 75, 8, 16)
        p.resolution = 2
        voxarray = getNPZ(p)
        assert (np.array_equal(voxarray[0][0], image_data[0][0][:25, :25]))

        # Checking at res3
        p.args = (25, 37, 25, 37, 4, 8)
        p.resolution = 3
        voxarray = getNPZ(p)
        assert (np.array_equal(voxarray[0][0], image_data[0][0][:12, :12]))

        # Checking at res4
        p.args = (13, 19, 13, 19, 2, 4)
        p.resolution = 4
        voxarray = getNPZ(p)
        assert (np.array_equal(voxarray[0][0], image_data[0][0][:6, :6]))
Beispiel #5
0
  def test_reserve ( self ):
    """Reserve 1000 ids twice and make sure that the numbers work"""
  
    url =  "http://{}/ca/{}/{}/reserve/{}/".format( SITE_HOST, p.token, p.channels[0], 1000 )
    f = getURL ( url )
    (id1, size1) = json.loads(f.read())
    f = getURL ( url )
    (id2, size2) = json.loads(f.read())

    assert ( id2 - id1 == 1000 )
    assert ( size1 == size2 == 1000 )
Beispiel #6
0
    def test_reserve(self):
        """Reserve 1000 ids twice and make sure that the numbers work"""

        url = "http://{}/ca/{}/{}/reserve/{}/".format(SITE_HOST, p.token,
                                                      p.channels[0], 1000)
        f = getURL(url)
        (id1, size1) = json.loads(f.read())
        f = getURL(url)
        (id2, size2) = json.loads(f.read())

        assert (id2 - id1 == 1000)
        assert (size1 == size2 == 1000)
Beispiel #7
0
    def test_web_propagate(self):
        """Test the web update propogate function"""

        # Posting some data at res0 to propagate
        p.args = (200, 300, 200, 300, 32, 64, 9, 10)
        image_data = np.ones([1, 1, 32, 100, 100],
                             dtype=np.uint8) * random.randint(0, 255)
        if KV_ENGINE == REDIS:
            response = postNPZ(p, image_data, time=True, direct=True)
        else:
            response = postNPZ(p, image_data, time=True)

        # Check if the project is not proagated
        f = getURL("https://{}/sd/{}/{}/getPropagate/".format(
            SITE_HOST, p.token, ','.join(p.channels)))
        value = int(f.content)
        assert (value == NOT_PROPAGATED)

        # Start propagating
        f = getURL("https://{}/sd/{}/{}/setPropagate/{}/".format(
            SITE_HOST, p.token, ','.join(p.channels), UNDER_PROPAGATION))

        # Checking if the PROPGATED value is set correctly
        for iter_value in range(1, 500, 1):
            time.sleep(1)
            f = getURL("https://{}/sd/{}/{}/getPropagate/".format(
                SITE_HOST, p.token, ','.join(p.channels)))
            value = int(f.content)
            if value == PROPAGATED:
                break
        assert (value == PROPAGATED)

        # Checking at res1
        p.args = (100, 150, 100, 150, 16, 32, 9, 10)
        p.resolution = 1
        voxarray = getNPZ(p, time=True)
        assert (np.array_equal(voxarray[0][0][0],
                               image_data[0][0][0][:50, :50]))

        # Checking at res2
        p.args = (50, 75, 50, 75, 8, 16, 9, 10)
        p.resolution = 2
        voxarray = getNPZ(p, time=True)
        assert (np.array_equal(voxarray[0][0][0],
                               image_data[0][0][0][:25, :25]))

        # Checking at res3
        p.args = (25, 37, 25, 37, 4, 8, 9, 10)
        p.resolution = 3
        voxarray = getNPZ(p, time=True)
        assert (np.array_equal(voxarray[0][0][0],
                               image_data[0][0][0][:12, :12]))
  def test_web_propagate(self):
    """Test the web update propogate function"""
    
    # Posting some data at res0 to propagate
    p.args = (200,300,200,300,32,64)
    p.resolution=0
    image_data = np.ones( [1,32,100,100], dtype=np.uint32) * random.randint(255,65535)
    response = postNPZ(p, image_data)

    voxarray = getNPZ(p)
    # check that the return matches
    assert ( np.array_equal(voxarray,image_data) )

    # Check if the project is not proagated
    f = getURL("http://{}/ca/{}/{}/getPropagate/".format(SITE_HOST, p.token, ','.join(p.channels)))
    value = int(f.read())
    assert(value == NOT_PROPAGATED)

    # Start propagating
    f = getURL("http://{}/ca/{}/{}/setPropagate/{}/".format(SITE_HOST, p.token, ','.join(p.channels), UNDER_PROPAGATION))

    # Checking if the PROPGATED value is set correctly
    time.sleep(30)
    f = getURL("http://{}/ca/{}/{}/getPropagate/".format(SITE_HOST, p.token, ','.join(p.channels)))
    value = int(f.read())
    assert(value == PROPAGATED)

    # Checking at res1
    p.args = (100,150,100,150,16,32)
    p.resolution = 1
    voxarray = getNPZ(p)
    assert ( np.array_equal(voxarray[0][0], image_data[0][0][:50,:50]) )

    # Checking at res2
    p.args = (50,75,50,75,8,16)
    p.resolution = 2
    voxarray = getNPZ(p)
    assert ( np.array_equal(voxarray[0][0], image_data[0][0][:25,:25]) )
    
    # Checking at res3
    p.args = (25,37,25,37,4,8)
    p.resolution = 3
    voxarray = getNPZ(p)
    assert ( np.array_equal(voxarray[0][0], image_data[0][0][:12,:12]) )

    # Checking at res4
    p.args = (13,19,13,19,2,4)
    p.resolution = 4
    voxarray = getNPZ(p)
    assert ( np.array_equal(voxarray[0][0], image_data[0][0][:6,:6]) )
def getField(p, field):
    """Get the specified field"""

    url = "http://{}/ca/{}/{}/getField/{}/{}/".format(SITE_HOST, p.token,
                                                      p.channels[0], p.annoid,
                                                      field)
    return getURL(url)
Beispiel #10
0
  def test_complex_json(self):
    """Test the complex JSON project creation with only the required fields"""
    
    p.token = 'unittest2'
    # dataset format = (dataset_name, [ximagesz, yimagesz, zimagesz], [[xvoxel, yvoxel, zvoxel], [xoffset, yoffset, zoffset], timerange, scalinglevels, scaling)
    dataset = (p.dataset, [2000,2000,30], [1.0,1.0,5.0], [0,0,0], None, None, None)
    # project format = (project_name, token_name, public)
    project = (p.token, None, None)
    # channel format = { chan1 : (channel_name, datatype, channel_type, data_url, file_name, exceptions, resolution, windowrange, readonly), chan2: ...... }
    channels = { p.channels[1] : (p.channels[1], p.datatype, p.channel_type, 'sample_data_url', 'sample_filename', 'tif', None, None, None, None) }
    
    json_file = tempfile.NamedTemporaryFile(mode='w+b')
    json_file.write(createJson(dataset, project, channels))
    json_file.seek(0)

    # posting the JSON url and checking if it is successful
    response = json.loads(postURL("http://{}/ca/autoIngest/".format(SITE_HOST), json_file).read())
    assert('SUCCESS. The ingest process has now started.' == response)

    # fetching the JSON info
    f = getURL("http://{}/ca/{}/info/".format(SITE_HOST, p.token))

    # read the JSON file
    proj_info = json.loads(f.read())
    assert( proj_info['project']['name'] == p.token )
    assert( proj_info['dataset']['imagesize']['0'] == [2000,2000,30])
    assert( proj_info['dataset']['cube_dimension']['0'] == [128,128,16])
    assert( proj_info['dataset']['scalinglevels'] == 1)
    assert( proj_info['channels'][p.channels[1]]['resolution'] == 0)
    assert( proj_info['channels'][p.channels[1]]['datatype'] == p.datatype)
Beispiel #11
0
  def test_get_anno_by_loc(self):
    """Test the annotation (RAMON) JSON interface"""

    image_data = np.random.randint(0, high=255, size=[1, 10, 1024, 1024]).astype(np.uint32)
    response = postNPZ(p, image_data)

    assert( response.status_code == 200 )

    voxarray = getNPZ(p)
    # check that the return data matches
    assert( np.array_equal(voxarray, image_data) )

    # query for an ID at res0
    res = 0
    x = 50
    y = 50
    z = 5
    cutout = '{}/{}/{}/{}/'.format( res, x, y, z )
    url = 'https://{}/sd/{}/{}/id/{}'.format( SITE_HOST, p.token, p.channels[0], cutout )

    try:
      # Build a get request
      response = getURL(url)
    except Exception as e:
      print e

    assert( response.status_code == 200 )

    response_id = int(response.content)

    # the offset for this dataset is set to 1, hence z-1
    assert( response_id == image_data[0, z-1, y, x] )
Beispiel #12
0
  def test_xy_incorrect (self):
    """Test the xy slice cutout with incorrect cutout arguments"""

    p.args = (11000,11100,4000,4100,200,201)

    url = "http://{}/ca/{}/{}/xy/{}/{},{}/{},{}/{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0], p.args[1], p.args[2], p.args[3], p.args[4])
    assert ( 404 == getURL (url) )
Beispiel #13
0
    def test_time_diff(self):
        """Post npz data with default channel"""

        p.args = (3000, 3100, 2000, 2100, 10, 11, 2, 3)
        image_data1 = np.ones([2, 1, 1, 100, 100],
                              dtype=np.uint8) * random.randint(0, 255)
        response = postNPZ(p, image_data1, time=True)
        assert (response.status_code == 200)
        voxarray = getNPZ(p, time=True)
        # check that the return matches
        assert (np.array_equal(voxarray, image_data1))

        p.args = (3000, 3100, 2000, 2100, 10, 11, 3, 4)
        image_data2 = np.ones([2, 1, 1, 100, 100],
                              dtype=np.uint8) * random.randint(0, 255)
        response = postNPZ(p, image_data2, time=True)
        assert (response.status_code == 200)
        voxarray = getNPZ(p, time=True)
        # check that the return matches
        assert (np.array_equal(voxarray, image_data2))

        p.args = (3000, 3100, 2000, 2100, 10, 11, 2, 4)
        url = "https://{}/sd/{}/{}/diff/{}/{},{}/{},{}/{},{}/{},{}/".format(
            SITE_HOST, p.token, p.channels[0], p.resolution, *p.args)
        f = getURL(url)
        voxarray = blosc.unpack_array(f.content)

        image_data = np.subtract(np.float32(image_data1),
                                 np.float32(image_data2))
        assert (np.array_equal(image_data[0, :], voxarray[0, :]))
Beispiel #14
0
    def test_public_tokens(self):
        """Test the function that shows the public tokens"""

        f = getURL("http://{}/ca/public_tokens/".format(SITE_HOST))

        # read the json data
        tokens = json.loads(f.read())
        assert (p.token in tokens)
Beispiel #15
0
  def test_xmlinfo (self):
    """Test the projinfo query"""

    f = getURL("http://{}/ca/{}/volume.vikingxml".format(SITE_HOST, p.token))

    xmlinfo = etree.XML(f.read())
    assert( xmlinfo.values()[2] == p.token )
    assert( xmlinfo.values()[3] == '1000' )
Beispiel #16
0
  def test_error_json(self):
    """ Request an annotation Id that doesn't exist """

    ann_annoid = str(13);
    # fetching the JSON info
    f = getURL("https://{}/sd/{}/{}/{}/json/".format(SITE_HOST, p.token, p.channels, ann_annoid))

    assert(f.status_code == 404)
Beispiel #17
0
  def test_error_json(self):
    """ Request an annotation Id that doesn't exist """

    ann_annoid = str(13);
    # fetching the JSON info
    f = getURL("http://{}/ca/{}/{}/{}/json/".format(SITE_HOST, p.token, p.channels, ann_annoid))
    
    assert(f == 404)
Beispiel #18
0
  def test_public_tokens (self):
    """Test the function that shows the public tokens"""

    f =  getURL("http://{}/ca/public_tokens/".format( SITE_HOST ))

    # read the json data
    tokens = json.loads ( f.read() )
    assert ( p.token in tokens )
Beispiel #19
0
    def test_xmlinfo(self):
        """Test the projinfo query"""

        f = getURL("http://{}/ca/{}/volume.vikingxml".format(
            SITE_HOST, p.token))

        xmlinfo = etree.XML(f.read())
        assert (xmlinfo.values()[2] == p.token)
        assert (xmlinfo.values()[3] == '1000')
Beispiel #20
0
    def test_xy_incorrect(self):
        """Test the xy slice cutout with incorrect cutout arguments"""

        p.args = (11000, 11100, 4000, 4100, 200, 201)

        url = "https://{}/sd/{}/{}/xy/{}/{},{}/{},{}/{}/".format(
            SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0],
            p.args[1], p.args[2], p.args[3], p.args[4])
        assert (404 == getURL(url).status_code)
Beispiel #21
0
  def test_info(self):
    """Test the info query"""

    f = getURL("http://{}/ca/{}/info/".format(SITE_HOST, p.token))
    
    # read the json data
    projinfo = json.loads ( f.read() )
    assert ( projinfo['project']['name'] == p.token )
    assert ( projinfo['channels'][p.channels[0]]['channel_type'] == 'annotation' )
    assert ( projinfo['dataset']['offset']['0'][2] == 1 )
  def test_web_propagate(self):
    """Test the web update propogate function"""

    # Posting some data at res0 to propagate
    p.args = (200,300,200,300,4,5)
    image_data = np.ones( [1,1,100,100], dtype=np.uint8) * random.randint(0,255)
    response = postNPZ(p, image_data)
    # check that it cannot post to a readonly channle
    assert(response.code == 404)

    # Check if the project is not proagated
    f = getURL("http://{}/ca/{}/{}/getPropagate/".format(SITE_HOST, p.token, ','.join(p.channels)))
    value = int(f.read())
    assert(value == NOT_PROPAGATED)
    
    # check that it cannot start propagating a readonly channel
    assert (getURL("http://{}/ca/{}/{}/setPropagate/{}/".format(SITE_HOST, p.token, ','.join(p.channels), UNDER_PROPAGATION)) == 404 )
    # check that it cannot mark a channel as propagated
    assert (getURL("http://{}/ca/{}/{}/setPropagate/{}/".format(SITE_HOST, p.token, ','.join(p.channels), PROPAGATED)) == 404 )
Beispiel #23
0
    def test_ErrorHandling(self):
        """Invalid graphtype and invalid token"""
        syn_segments = [[7, 3], [7, 12], [3, 9], [5, 12]]
        truthGraph = nx.Graph()
        truthGraph.add_edges_from(syn_segments)

        url = 'https://{}/ndgraph/{}/{}/{}/'.format(SITE_HOST, p.token,
                                                    p.channels[0], 'foograph')
        graphFile = getURL(url)
        with open(("/tmp/{}_{}.graphml").format(p.token, p.channels[0]),
                  "wb") as f:
            f.write(graphFile.content)
        outputGraph = nx.read_graphml(
            ("/tmp/{}_{}.graphml").format(p.token, p.channels[0]))
        assert (nx.is_isomorphic(outputGraph, truthGraph))
        """Invalid token"""
        url = 'https://{}/ndgraph/{}/{}/{}/{},{}/{},{}/{},{}/'.format(
            SITE_HOST, 'foo', p.channels[0], 'graphml', 0, 7, 0, 7, 0, 7)
        assert (getURL(url).status_code >= 500)
Beispiel #24
0
    def test_web_propagate(self):
        """Test the web update propogate function"""

        # Posting some data at res0 to propagate
        p.args = (200, 300, 200, 300, 4, 5)
        p.resolution = 0
        image_data = np.ones([1, 1, 100, 100],
                             dtype=np.uint32) * random.randint(255, 65535)
        response = postNPZ(p, image_data)

        voxarray = getNPZ(p)
        # check that the return matches
        assert (np.array_equal(voxarray, image_data))

        # Check if the project is not propagated
        f = getURL("http://{}/ca/{}/{}/getPropagate/".format(
            SITE_HOST, p.token, ','.join(p.channels)))
        value = int(f.read())
        assert (value == NOT_PROPAGATED)

        # Start propagating
        f = getURL("http://{}/ca/{}/{}/setPropagate/{}/".format(
            SITE_HOST, p.token, ','.join(p.channels), UNDER_PROPAGATION))

        # Checking if the PROPGATED value is set correctly
        time.sleep(30)
        f = getURL("http://{}/ca/{}/{}/getPropagate/".format(
            SITE_HOST, p.token, ','.join(p.channels)))
        value = int(f.read())
        assert (value == PROPAGATED)

        # Checking at res1
        p.args = (100, 150, 100, 150, 4, 5)
        p.resolution = 1
        voxarray = getNPZ(p)
        assert (np.array_equal(voxarray[0][0], image_data[0][0][:50, :50]))

        # Checking at res5
        p.args = (7, 9, 7, 9, 4, 5)
        p.resolution = 5
        voxarray = getNPZ(p)
        assert (np.array_equal(voxarray[0][0], image_data[0][0][:2, :2]))
Beispiel #25
0
    def test_web_propagate(self):
        """Test the web update propogate function"""

        # Posting some data at res0 to propagate
        p.args = (200, 300, 200, 300, 4, 5)
        image_data = np.ones([1, 1, 100, 100],
                             dtype=np.uint8) * random.randint(0, 255)
        response = postNPZ(p, image_data)

        # Check if the project is not proagated
        f = getURL("http://{}/ca/{}/{}/getPropagate/".format(
            SITE_HOST, p.token, ','.join(p.channels)))
        value = int(f.read())
        assert (value == NOT_PROPAGATED)

        # Start propagating
        f = getURL("http://{}/ca/{}/{}/setPropagate/{}/".format(
            SITE_HOST, p.token, ','.join(p.channels), UNDER_PROPAGATION))
        time.sleep(10)
        # Checking if the PROPGATED value is set correctly
        f = getURL("http://{}/ca/{}/{}/getPropagate/".format(
            SITE_HOST, p.token, ','.join(p.channels)))
        value = int(f.read())
        assert (value == PROPAGATED)

        # Checking at res1
        p.args = (100, 150, 100, 150, 4, 5)
        url = "http://{}/ca/{}/{}/xy/{}/{},{}/{},{}/{}/".format(
            SITE_HOST, p.token, p.channels[0], p.resolution + 1, p.args[0],
            p.args[1], p.args[2], p.args[3], p.args[4])
        f = getURL(url)
        slice_data = np.asarray(Image.open(StringIO(f.read())))
        assert (np.array_equal(slice_data, image_data[0][0][:50, :50]))

        # Checking at res5
        p.args = (7, 9, 7, 9, 4, 5)
        url = "http://{}/ca/{}/{}/xy/{}/{},{}/{},{}/{}/".format(
            SITE_HOST, p.token, p.channels[0], p.resolution + 5, p.args[0],
            p.args[1], p.args[2], p.args[3], p.args[4])
        f = getURL(url)
        slice_data = np.asarray(Image.open(StringIO(f.read())))
        assert (np.array_equal(slice_data, image_data[0][0][:2, :2]))
Beispiel #26
0
    def test_info(self):
        """Test the info query"""

        f = getURL("http://{}/ca/{}/info/".format(SITE_HOST, p.token))

        # read the json data
        projinfo = json.loads(f.read())
        assert (projinfo['project']['name'] == p.token)
        assert (projinfo['channels'][p.channels[0]]['channel_type'] ==
                'annotation')
        assert (projinfo['dataset']['offset']['0'][2] == 1)
Beispiel #27
0
def queryField (p, field, value):
  """Get the specified query to the value"""

  url =  "http://{}/ca/{}/{}/query/{}/{}/".format(SITE_HOST, p.token, p.channels[0], field, value)
  f = getURL(url)
  tmpfile = tempfile.NamedTemporaryFile ( )
  tmpfile.write ( f.read() )
  tmpfile.seek(0)
  h5f = h5py.File ( tmpfile.name, driver='core', backing_store=False )

  return h5f
Beispiel #28
0
  def test_xz (self):
    """Test the xz slice cutout"""

    p.args = (5000,5100,2000,2001,200,300)
    image_data = np.ones( [2,100,1,100], dtype=np.uint8 ) * random.randint(0,255)
    response = postNPZ(p, image_data)

    url = "http://{}/ca/{}/{}/xz/{}/{},{}/{}/{},{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0], p.args[1], p.args[2], p.args[4], p.args[5])
    f = getURL (url)

    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data, image_data[0][:75][:].reshape(75,100)) )
  def test_xy (self):
    """Test the xy slice cutout"""

    p.args = (3000,3100,4000,4100,200,201,10,12)
    time_data = np.ones( [2,2,1,100,100], dtype=np.uint8 ) * random.randint(0,255)
    response = postNPZ(p, time_data, time=True)

    url = "http://{}/ca/{}/{}/xy/{}/{},{}/{},{}/{}/{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0], p.args[1], p.args[2], p.args[3], p.args[4], p.args[6])
    f = getURL (url)

    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data, time_data[0][0][0]) )
Beispiel #30
0
    def test_create_json(self):
        """Test the basic JSON project creation with only the required fields"""

        p.channels = ['CHAN1', 'CHAN2']
        # dataset format = (dataset_name, [ximagesz, yimagesz, zimagesz], [[xvoxel, yvoxel, zvoxel], [xoffset, yoffset, zoffset], timerange, scalinglevels, scaling)
        dataset = (p.dataset, [2000, 2000,
                               1000], [1.0, 1.0, 5.0], None, None, None, None)
        # project format = (project_name, token_name, public)
        project = (p.token, None, None)
        # channel format = { chan1 : (channel_name, datatype, channel_type, data_url, file_name, exceptions, resolution, windowrange, readonly), chan2: ...... }
        channels = {
            p.channels[0]:
            (p.channels[0], p.datatype, p.channel_type, 'sample_data_url',
             'sample_filename', 'tif', None, None, None, 0),
            p.channels[1]:
            (p.channels[1], p.datatype, p.channel_type, 'sample_data_url',
             'sample_filename', 'tif', None, None, None, 0),
        }

        json_file = tempfile.NamedTemporaryFile(mode='w+b')
        json_file.write(
            createJson(dataset, project, channels, channel_only=True))
        json_file.seek(0)

        # posting the JSON url and checking if it is successful
        response = json.loads(
            postURL(
                "http://{}/ca/{}/createChannel/".format(SITE_HOST, p.token),
                json_file).read())
        assert (
            'SUCCESS. The information in the channel was correct.' == response)

        # fetching the JSON info
        f = getURL("http://{}/ca/{}/info/".format(SITE_HOST, p.token))

        # read the JSON file
        proj_info = json.loads(f.read())
        assert (proj_info['project']['name'] == p.token)
        assert (proj_info['dataset']['imagesize']['0'] == [2000, 2000, 1000])
        assert (proj_info['dataset']['cube_dimension']['0'] == [128, 128, 16])
        assert (proj_info['dataset']['scalinglevels'] == 5)
        assert (proj_info['channels'][p.channels[0]]['resolution'] == 0)
        assert (proj_info['channels'][p.channels[0]]['channel_type'] ==
                p.channel_type)
        assert (proj_info['channels'][p.channels[1]]['datatype'] == p.datatype)

        # Testing if the it allows data to be posted to the created channels
        p.args = (1000, 1100, 500, 600, 200, 201)
        image_data = np.ones([2, 1, 100, 100],
                             dtype=np.uint8) * random.randint(0, 255)
        response = postNPZ(p, image_data)
        voxarray = getNPZ(p)
        assert (np.array_equal(image_data, voxarray))
  def test_yz (self):
    """Test the yz slice cutout"""

    p.args = (4000,4001,3000,3100,200,300,10,11)
    image_data = np.ones( [2,1,100,100,1], dtype=np.uint8 ) * random.randint(0,255)
    response = postNPZ(p, image_data, time=True)

    url = "http://{}/ca/{}/{}/yz/{}/{}/{},{}/{},{}/{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0], p.args[2], p.args[3], p.args[4], p.args[5], p.args[6])
    f = getURL (url)

    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data, image_data[0][0][:75][:].reshape(75,100)) )
Beispiel #32
0
def queryField(p, field, value):
    """Get the specified query to the value"""

    url = "http://{}/ca/{}/{}/query/{}/{}/".format(SITE_HOST, p.token,
                                                   p.channels[0], field, value)
    f = getURL(url)
    tmpfile = tempfile.NamedTemporaryFile()
    tmpfile.write(f.read())
    tmpfile.seek(0)
    h5f = h5py.File(tmpfile.name, driver='core', backing_store=False)

    return h5f
Beispiel #33
0
  def test_xy (self):
    """Test the xy slice cutout"""

    p.args = (3000,3100,4000,4100,200,201)
    image_data = np.ones( [2,1,100,100], dtype=np.uint8 ) * random.randint(0,255)
    response = postNPZ(p, image_data)

    url = "https://{}/sd/{}/{}/xy/{}/{},{}/{},{}/{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0], p.args[1], p.args[2], p.args[3], p.args[4])
    f = getURL (url)

    slice_data = np.asarray ( Image.open(StringIO(f.content)) )
    assert ( np.array_equal(slice_data,image_data[0][0]) )
Beispiel #34
0
  def test_get_jpeg (self):
    """Test the jpeg volume cutout"""

    p.args = (3000,3100,4000,4100,200,210)
    image_data = np.ones( [2,10,100,100], dtype=np.uint8 ) * random.randint(0,255)
    response = postNPZ(p, image_data)
    
    url = "http://{}/ca/{}/{}/jpeg/{}/{},{}/{},{}/{},{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0], p.args[1], p.args[2], p.args[3], p.args[4], p.args[5])
    data = getURL(url).read()
    posted_data = np.asarray( Image.open(cStringIO.StringIO(data)) )

    image_data = image_data[0,:,:,:].reshape(1000,100)
    assert ( np.array_equal(image_data,posted_data) )
Beispiel #35
0
  def test_yz (self):
    """Test the yz slice cutout"""

    p.args = (4000,4001,3000,3100,200,300)
    image_data = np.ones( [2,100,100,1], dtype=np.float32 ) * random.random()
    response = postNPZ(p, image_data)

    url = "http://{}/ca/{}/{}/yz/{}/{}/{},{}/{},{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0], p.args[2], p.args[3], p.args[4], p.args[5])
    f = getURL (url)

    image_data = np.uint8(image_data*256)
    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data[:,:,0], image_data[0][:75][:].reshape(75,100)) )
Beispiel #36
0
  def test_window_default(self):
    "Test the window functionality"

    p.args = (3000,3100,4000,4100,200,201)
    image_data = np.ones([2,1,100,100], dtype=np.uint16) * 2000
    response = postNPZ(p, image_data)

    url = "http://{}/ca/{}/{}/xy/{}/{},{}/{},{}/{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0], p.args[1], p.args[2], p.args[3], p.args[4])
    f = getURL (url)

    from windowcutout import windowCutout
    windowCutout(image_data, p.window)
    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data,image_data[0][0]) )
Beispiel #37
0
  def test_xy_tile(self):
    """Test a mcfc xy tile fetch"""

    p.args = (3072,3584,4096,4608,200,201)
    # have to use a constant here for memcache purposes
    image_data = np.ones([2,1,512,512], dtype=np.uint8) * 200
    response = postNPZ(p, image_data)
    
    voxarray = getNPZ(p)
    # check that the return matches
    assert ( np.array_equal(voxarray, image_data) )
    
    url = "http://{}/catmaid/mcfc/{}/{}/xy/{}/{}_{}_{}.png".format(SITE_HOST, p.token, ','.join(p.channels), p.args[4], p.args[2]/512, p.args[0]/512, p.resolution)
    f = getURL (url)
  def test_window_default(self):
    "Test the window functionality"

    p.args = (3000,3100,4000,4100,200,201,50,52)
    image_data = np.ones([2,2,1,100,100], dtype=np.uint16) * 2000
    response = postNPZ(p, image_data, time=True)

    url = "http://{}/ca/{}/{}/xy/{}/{},{}/{},{}/{}/{}".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0], p.args[1], p.args[2], p.args[3], p.args[4], p.args[6])
    f = getURL (url)

    from windowcutout import windowCutout
    windowCutout(image_data, p.window)
    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data,image_data[0][0][0]) )
Beispiel #39
0
  def test_projinfo (self):
    """Test the projinfo query"""

    f = getURL("http://{}/ca/{}/projinfo/".format(SITE_HOST, p.token))

    # read the hdf5 file
    tmpfile = tempfile.NamedTemporaryFile ()
    tmpfile.write(f.read())
    tmpfile.seek(0)
    h5f = h5py.File ( tmpfile.name, driver='core', backing_store=False )

    assert (str(h5f['CHANNELS'][p.channels[0]]['TYPE'].value[0]) == 'annotation')
    assert (str(h5f['PROJECT']['NAME'].value[0]) == p.token)
    assert (h5f['DATASET']['OFFSET']['0'][2] == 1)
Beispiel #40
0
    def test_checkType(self):
        """Test the export to different data types"""
        syn_segments = [[7, 3], [7, 12], [3, 9], [5, 12]]
        truthGraph = nx.Graph()
        truthGraph.add_edges_from(syn_segments)

        url = 'https://{}/ndgraph/{}/{}/{}/'.format(SITE_HOST, p.token,
                                                    p.channels[0], 'adjlist')
        graphFile = getURL(url)
        with open(("/tmp/{}_{}.adjlist").format(p.token, p.channels[0]),
                  "wb") as f:
            f.write(graphFile.content)
        outputGraph = nx.read_adjlist(
            ("/tmp/{}_{}.adjlist").format(p.token, p.channels[0]))
        assert (nx.is_isomorphic(outputGraph, truthGraph))
Beispiel #41
0
    def test_checkTotal(self):
        """Test the original/non-specific dataset"""
        syn_segments = [[7, 3], [7, 12], [3, 9], [5, 12]]
        truthGraph = nx.Graph()
        truthGraph.add_edges_from(syn_segments)

        url = 'https://{}/ndgraph/{}/{}/'.format(SITE_HOST, p.token,
                                                 p.channels[0])
        graphFile = getURL(url)
        with open(("/tmp/{}_{}.graphml").format(p.token, p.channels[0]),
                  "wb") as f:
            f.write(graphFile.content)
        outputGraph = nx.read_graphml(
            ("/tmp/{}_{}.graphml").format(p.token, p.channels[0]))
        assert (nx.is_isomorphic(outputGraph, truthGraph))
Beispiel #42
0
    def test_projinfo(self):
        """Test the projinfo query"""

        f = getURL("http://{}/ca/{}/projinfo/".format(SITE_HOST, p.token))

        # read the hdf5 file
        tmpfile = tempfile.NamedTemporaryFile()
        tmpfile.write(f.read())
        tmpfile.seek(0)
        h5f = h5py.File(tmpfile.name, driver='core', backing_store=False)

        assert (str(
            h5f['CHANNELS'][p.channels[0]]['TYPE'].value[0]) == 'annotation')
        assert (str(h5f['PROJECT']['NAME'].value[0]) == p.token)
        assert (h5f['DATASET']['OFFSET']['0'][2] == 1)
Beispiel #43
0
  def test_window_args(self):
    "Test the window functionality"

    p.args = (3000,3100,4000,4100,200,201)
    p.window = [0,1500]
    image_data = np.ones([2,1,100,100], dtype=np.uint16) * 2000
    response = postNPZ(p, image_data)

    url = "https://{}/sd/{}/{}/xy/{}/{},{}/{},{}/{}/window/{},{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0], p.args[1], p.args[2], p.args[3], p.args[4], *p.window)
    f = getURL (url)

    from ndlib.windowcutout import windowCutout
    image_data = windowCutout(image_data, p.window).astype(np.uint8)
    slice_data = np.asarray ( Image.open(StringIO(f.content)) )
    assert ( np.array_equal(slice_data,image_data[0][0]) )
Beispiel #44
0
  def test_xz (self):
    """Test the xz slice cutout"""

    p.args = (5000,5100,2000,2001,200,300,10,12)
    time_data = np.ones( [2,2,100,1,100], dtype=np.float32 ) * random.random()
    response = postNPZ(p, time_data, time=True)

    url = "https://{}/sd/{}/{}/xz/{}/{},{}/{}/{},{}/{}/".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0], p.args[1], p.args[2], p.args[4], p.args[5], p.args[6])
    f = getURL (url)

    from ndlib.windowcutout import windowCutout
    time_data = windowCutout(time_data, p.window).astype(np.uint8)
    # time_data = np.uint8(time_data*256)
    slice_data = np.asarray ( Image.open(StringIO(f.content)) )
    assert ( np.array_equal(slice_data, time_data[0][0][:75][:].reshape(75,100)) )
Beispiel #45
0
    def test_basic_json(self):
        """Test the basic JSON project creation with only the required fields"""

        # dataset format = (dataset_name, [ximagesz, yimagesz, zimagesz], [[xvoxel, yvoxel, zvoxel], [xoffset, yoffset, zoffset], timerange, scalinglevels, scaling)
        dataset = (p.dataset, [2000, 2000, 30], [1.0, 1.0,
                                                 5.0], None, None, None, None)
        # project format = (project_name, token_name, public)
        project = (p.token, None, None)
        # channel format = { chan1 : (channel_name, datatype, channel_type, data_url, file_name, exceptions, resolution, windowrange, readonly), chan2: ...... }
        channels = {
            p.channels[0]: (p.channels[0], p.datatype, p.channel_type,
                            'http://127.0.0.1/data/sample_dir/', 'SLICE',
                            'tif', None, None, None, None)
        }
        metadata = {
            'Author': 'Will',
            'Animal': 'Mouse',
            'Date_Collected': '10/2/2015'
        }

        json_file = tempfile.NamedTemporaryFile(mode='w+b')
        json_file.write(
            createJson(dataset, project, channels, metadata=metadata))
        json_file.seek(0)

        # posting the JSON url and checking if it is successful
        response = json.loads(
            postURL("http://{}/ca/createProject/".format(SITE_HOST),
                    json_file).read())
        assert ('SUCCESS' == response)

        # fetching the JSON info
        f = getURL("http://{}/ca/{}/info/".format(SITE_HOST, p.token))

        # read the JSON file
        proj_info = json.loads(f.read())
        assert (proj_info['project']['name'] == p.token)
        assert (proj_info['dataset']['imagesize']['0'] == [2000, 2000, 30])
        assert (proj_info['dataset']['cube_dimension']['0'] == [128, 128, 16])
        assert (proj_info['dataset']['scalinglevels'] == 1)
        assert (proj_info['channels'][p.channels[0]]['resolution'] == 0)
        assert (proj_info['channels'][p.channels[0]]['datatype'] == p.datatype)
        try:
            assert (proj_info['metadata'][0]['Author'] == 'Will')
        except KeyError:
            print "LIMS System not working"
        except AssertionError:
            print "LIMS System not working"
Beispiel #46
0
    def test_xy_tile(self):
        """Test a mcfc xy tile fetch"""

        p.args = (3072, 3584, 4096, 4608, 200, 201)
        # have to use a constant here for memcache purposes
        image_data = np.ones([2, 1, 512, 512], dtype=np.uint8) * 200
        response = postNPZ(p, image_data)

        voxarray = getNPZ(p)
        # check that the return matches
        assert (np.array_equal(voxarray, image_data))

        url = "http://{}/catmaid/mcfc/{}/{}/xy/{}/{}_{}_{}.png".format(
            SITE_HOST, p.token, ','.join(p.channels), p.args[4],
            p.args[2] / 512, p.args[0] / 512, p.resolution)
        f = getURL(url)
    def test_xy(self):
        """Test the xy slice cutout"""

        p.args = (3000, 3100, 4000, 4100, 200, 201)
        image_data = np.ones([2, 1, 100, 100],
                             dtype=np.float32) * random.random()
        response = postNPZ(p, image_data)

        url = "http://{}/ca/{}/{}/xy/{}/{},{}/{},{}/{}/".format(
            SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0],
            p.args[1], p.args[2], p.args[3], p.args[4])
        f = getURL(url)

        image_data = np.uint8(image_data * 256)
        slice_data = np.asarray(Image.open(StringIO(f.read())))
        assert (np.array_equal(slice_data[:, :, 0], image_data[0][0]))
Beispiel #48
0
    def test_xy_neariso_zoom_in(self):
        """Test the xy slice cutout"""

        p.resolution = 3
        p.args = (1000, 1100, 500, 600, 10, 11, 10, 12)
        time_data = np.ones([2, 2, 1, 100, 100],
                            dtype=np.uint8) * random.randint(0, 255)
        response = postNPZ(p, time_data, time=True, neariso=True, direct=False)
        assert (response.status_code == 200)

        p.resolution = 0
        p.args = (8000, 8800, 4000, 4800, 30, 31, 10, 12)
        url = "https://{}/sd/{}/{}/xy/{}/{},{}/{},{}/{}/{}/".format(
            SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0],
            p.args[1], p.args[2], p.args[3], p.args[4], p.args[6])
        response = getURL(url)
Beispiel #49
0
    def test_window_default(self):
        "Test the window functionality"

        p.args = (3000, 3100, 4000, 4100, 200, 201)
        image_data = np.ones([2, 1, 100, 100], dtype=np.uint16) * 2000
        response = postNPZ(p, image_data)

        url = "https://{}/sd/{}/{}/xy/{}/{},{}/{},{}/{}/".format(
            SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0],
            p.args[1], p.args[2], p.args[3], p.args[4])
        f = getURL(url)

        from ndlib.windowcutout import windowCutout
        image_data = windowCutout(image_data, p.window).astype(np.uint8)
        slice_data = np.asarray(Image.open(StringIO(f.content)))
        assert (np.array_equal(slice_data, image_data[0][0]))
Beispiel #50
0
    def test_checkCutout(self):
        """Test the cutout arguement of graphgen"""

        syn_segments = [[7, 3], [7, 4], [5, 4]]
        truthGraph = nx.Graph()
        truthGraph.add_edges_from(syn_segments)

        url = 'https://{}/ndgraph/{}/{}/{}/{},{}/{},{}/{},{}/'.format(
            SITE_HOST, p.token, p.channels[0], 'graphml', 0, 7, 0, 8, 1, 4)
        graphFile = getURL(url)
        with open(("/tmp/{}_{}.graphml").format(p.token, p.channels[0]),
                  "wb") as f:
            f.write(graphFile.content)
        outputGraph = nx.read_graphml(
            ("/tmp/{}_{}.graphml").format(p.token, p.channels[0]))
        assert (nx.is_isomorphic(outputGraph, truthGraph))
Beispiel #51
0
  def test_xy_default_channel (self):
    """Test the xy slice cutout"""

    p.args = (3000,3100,4000,4100,200,201)
    image_data = np.ones( [1,1,100,100], dtype=np.uint8 ) * random.randint(0,255)
    response = postNPZ(p, image_data)
    assert (response.code == 200)
    voxarray = getNPZ(p)
    # check that the return matches
    assert ( np.array_equal(voxarray,image_data) )

    url = "http://{}/ca/{}/xy/{}/{},{}/{},{}/{}/".format(SITE_HOST, p.token, p.resolution, p.args[0], p.args[1], p.args[2], p.args[3], p.args[4])
    f = getURL (url)

    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data,image_data[0][0]) )
Beispiel #52
0
 def test_xy_tile(self):
   """Test a simple xy tile fetch"""
  
   p.args = (1536,2048,4096,4608,200,201)
   # have to use a constant here for memcache purposes
   image_data = np.ones([2,1,512,512], dtype=np.uint8) * 130
   response = postNPZ(p, image_data)
   
   voxarray = getNPZ(p)
   # check that the return matches
   assert ( np.array_equal(voxarray, image_data) )
   
   url = "http://{}/catmaid/viking/{}/volume/{}/{}/X{}_Y{}_Z{}.png".format(SITE_HOST, p.token, p.channels[0], p.resolution, p.args[0]/512, p.args[2]/512, p.args[4])
   f = getURL (url)
   
   slice_data = np.asarray ( Image.open(StringIO(f.read())) )
   assert ( np.array_equal(slice_data, image_data[0][0]) )
Beispiel #53
0
  def test_ErrorHandling(self):
    """Invalid graphtype"""
    syn_segments = [[7, 3], [7, 12], [3, 9], [5, 12]]
    truthGraph = nx.Graph()
    truthGraph.add_edges_from(syn_segments)

    url = 'http://{}/ocpgraph/{}/{}/{}/'.format(
        SITE_HOST, p.token, p.channels[0], 'foograph')
    graphFile = urllib2.urlopen(url)

    outputGraph = nx.read_graphml(("/tmp/{}_{}.graphml").format(p.token, p.channels[0]))
    #os.remove(("/tmp/{}_{}.graphml").format(p.token, p.channels[0]))
    assert(nx.is_isomorphic(outputGraph, truthGraph))

    """Invalid token"""
    url = 'http://{}/ocpgraph/{}/{}/{}/{}/{}/{}/{}/{}/{}/'.format(
        SITE_HOST, 'foo', p.channels[0], 'graphml', 0, 7, 0, 7, 0, 7)
    assert (getURL(url) == 500)
Beispiel #54
0
  def test_xz_tile (self):
    """Test a simple xz slice fetch"""

    p.args = (3072,3584,4096,4097,1,513)
    # have to use a constant here for memcache purposes
    image_data = np.ones([2,512,1,512], dtype=np.uint8) * 130
    response = postNPZ(p, image_data)
    
    voxarray = getNPZ(p)
    # check that the return matches
    assert ( np.array_equal(voxarray, image_data) )

    url = "http://{}/catmaid/{}/{}/xz/{}/{}_{}_{}.png".format(SITE_HOST, p.token, p.channels[0], p.args[4]/512, p.args[2], p.args[0]/512, p.resolution)
    f = getURL (url)

    scale_range = 512*p.voxel[2]/p.voxel[0]
    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data[:scale_range,:], image_data[0,:scale_range,0,:]) )
Beispiel #55
0
  def test_yz_tile (self):
    """Test a simple yz slice fetch"""

    p.args = (8072,8073,4096,4608,1,513)
    # have to use a constant here for memcache purposes
    image_data = np.ones([2,512,512,1], dtype=np.uint8) * 130
    response = postNPZ(p, image_data)

    voxarray = getNPZ(p)
    # check that the return matches
    assert ( np.array_equal(voxarray, image_data) )

    # yz/x/z_y_res
    url = "https://{}/catmaid/{}/{}/yz/{}/{}_{}_{}.png".format(SITE_HOST, p.token, p.channels[0], p.args[0], p.args[4]/512, p.args[2]/512, p.resolution)
    f = getURL (url)
    
    scale_range = int(512*p.voxel[2]/p.voxel[1])
    slice_data = np.asarray ( Image.open(StringIO(f.content)) )
    assert ( np.array_equal(slice_data[:scale_range,:], image_data[0,:scale_range,:,0] ))
Beispiel #56
0
  def test_single_channel_json(self):
    """Test the basic JSON project creation with only the required fields"""
    
    ocp_dict = { 'channels' : (p.channels[1],) }

    json_file = tempfile.NamedTemporaryFile(mode='w+b')
    json_file.write(json.dumps(ocp_dict, sort_keys=True, indent=4))
    json_file.seek(0)

    # posting the JSON url and checking if it is successful
    response = json.loads(postURL("http://{}/ca/{}/deleteChannel/".format(SITE_HOST, p.token), json_file).read())
    assert('SUCCESS' == response)

    # fetching the JSON info
    f = getURL("http://{}/ca/{}/info/".format(SITE_HOST, p.token))

    # read the JSON file
    proj_info = json.loads(f.read())
    assert( proj_info['project']['name'] == p.token )
    assert( proj_info['channels'][p.channels[0]]['resolution'] == 0)
Beispiel #57
0
  def test_create_json(self):
    """Test the basic JSON project creation with only the required fields"""
    
    p.channels = ['CHAN1', 'CHAN2'] 
    # dataset format = (dataset_name, [ximagesz, yimagesz, zimagesz], [[xvoxel, yvoxel, zvoxel], [xoffset, yoffset, zoffset], timerange, scalinglevels, scaling)
    dataset = (p.dataset, [2000,2000,1000], [1.0,1.0,5.0], None, None, None, None)
    # project format = (project_name, token_name, public)
    project = (p.token, None, None)
    # channel format = { chan1 : (channel_name, datatype, channel_type, data_url, file_name, exceptions, resolution, windowrange, readonly), chan2: ...... }
    channels = { p.channels[0] : (p.channels[0], p.datatype, p.channel_type, 'sample_data_url', 'sample_filename', 'tif', None, None, None, 0), p.channels[1] : (p.channels[1], p.datatype, p.channel_type, 'sample_data_url', 'sample_filename', 'tif', None, None, None, 0),  }

    json_file = tempfile.NamedTemporaryFile(mode='w+b')
    json_file.write(createJson(dataset, project, channels, channel_only=True))
    json_file.seek(0)

    # posting the JSON url and checking if it is successful
    response = json.loads(postURL("http://{}/ca/{}/createChannel/".format(SITE_HOST, p.token), json_file).read())
    assert('SUCCESS. The information in the channel was correct.' == response)

    # fetching the JSON info
    f = getURL("http://{}/ca/{}/info/".format(SITE_HOST, p.token))

    # read the JSON file
    proj_info = json.loads(f.read())
    assert( proj_info['project']['name'] == p.token )
    assert( proj_info['dataset']['imagesize']['0'] == [2000,2000,1000])
    assert( proj_info['dataset']['cube_dimension']['0'] == [128,128,16])
    assert( proj_info['dataset']['scalinglevels'] == 5)
    assert( proj_info['channels'][p.channels[0]]['resolution'] == 0)
    assert( proj_info['channels'][p.channels[0]]['channel_type'] == p.channel_type)
    assert( proj_info['channels'][p.channels[1]]['datatype'] == p.datatype)
    
    # Testing if the it allows data to be posted to the created channels
    p.args = (1000,1100,500,600,200,201)
    image_data = np.ones( [2,1,100,100], dtype=np.uint8 ) * random.randint(0,255)
    response = postNPZ(p, image_data)
    voxarray = getNPZ(p)
    assert( np.array_equal(image_data, voxarray) )
Beispiel #58
0
  def test_bigint_json(self):
    """Test the annotation (RAMON) JSON interface with a large ID"""

    # create hdf5 file and post it
    tmpfile = tempfile.NamedTemporaryFile()
    h5fh = h5py.File( tmpfile.name )

    ann_status = random.randint(0,4)
    ann_confidence = random.random()
    ann_author = 'unittest_author'
    ann_annoid = 10025

    # create annotation id namespace
    idgrp = h5fh.create_group ( str(ann_annoid) )

    # annotation type
    idgrp.create_dataset ( "ANNOTATION_TYPE", (1,), np.uint32, data=1 )
    mdgrp = idgrp.create_group( "METADATA" )

    # set annotation metadata
    mdgrp.create_dataset ( "STATUS", (1,), np.uint32, data=ann_status )
    mdgrp.create_dataset ( "CONFIDENCE", (1,), np.float, data=ann_confidence )
    mdgrp.create_dataset ( "AUTHOR", (1,), dtype=h5py.special_dtype(vlen=str), data=ann_author )

    h5fh.flush()
    tmpfile.seek(0)

    p.annoid = putAnnotation(p, tmpfile)

    # fetching the JSON info
    f = getURL("https://{}/ca/{}/{}/{}/json/".format(SITE_HOST, p.token, p.channels[0], ann_annoid))

    # read the JSON file
    ann_info = json.loads(f.content)
    assert( ann_info.keys()[0] == str(ann_annoid) )
    assert( str(ann_info[str(ann_annoid)]['ann_status']) == str(ann_status) )
    assert( str(ann_info[str(ann_annoid)]['ann_confidence'])[:5] == str(ann_confidence)[:5] )
    assert( ann_info[str(ann_annoid)]['ann_author'] == str(ann_author) )
Beispiel #59
0
  def test_basic_json(self):
    """Test the basic JSON project creation with only the required fields"""
    
    # dataset format = (dataset_name, [ximagesz, yimagesz, zimagesz], [[xvoxel, yvoxel, zvoxel], [xoffset, yoffset, zoffset], timerange, scalinglevels, scaling)
    dataset = (p.dataset, [2000,2000,30], [1.0,1.0,5.0], None, None, None, None)
    # project format = (project_name, token_name, public)
    project = (p.token, None, None)
    # channel format = { chan1 : (channel_name, datatype, channel_type, data_url, file_name, exceptions, resolution, windowrange, readonly), chan2: ...... }
    channels = { p.channels[0] : (p.channels[0], p.datatype, p.channel_type, 'http://127.0.0.1/data/sample_dir/', 'SLICE', 'tif', None, None, None, None) }
    metadata = { 'Author': 'Will', 'Animal':'Mouse', 'Date_Collected':'10/2/2015' }

    json_file = tempfile.NamedTemporaryFile(mode='w+b')
    json_file.write(createJson(dataset, project, channels, metadata=metadata))
    json_file.seek(0)

    # posting the JSON url and checking if it is successful
    response = json.loads(postURL("http://{}/ca/autoIngest/".format(SITE_HOST), json_file).read())
    assert('SUCCESS. The ingest process has now started.' == response)

    # fetching the JSON info
    f = getURL("http://{}/ca/{}/info/".format(SITE_HOST, p.token))

    # read the JSON file
    proj_info = json.loads(f.read())
    assert( proj_info['project']['name'] == p.token )
    assert( proj_info['dataset']['imagesize']['0'] == [2000,2000,30])
    assert( proj_info['dataset']['cube_dimension']['0'] == [128,128,16])
    assert( proj_info['dataset']['scalinglevels'] == 1)
    assert( proj_info['channels'][p.channels[0]]['resolution'] == 0)
    assert( proj_info['channels'][p.channels[0]]['datatype'] == p.datatype)
    try:
      assert( proj_info['metadata'][0]['Author'] == 'Will')
    except KeyError:
      print "LIMS System not working"
    except AssertionError:
      print "LIMS System not working"