Beispiel #1
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 #2
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 #3
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]) )
Beispiel #5
0
    def setup_class(self):
        """Create the unittest database"""
        makeunitdb.createTestDB(p.token,
                                p.channels,
                                channel_type=IMAGE,
                                channel_datatype=UINT8,
                                public=True,
                                ximagesize=1024,
                                yimagesize=1024,
                                zimagesize=20,
                                xvoxelres=1.0,
                                yvoxelres=1.0,
                                zvoxelres=10.0,
                                readonly=0)

        # modify params args to match new data size
        p.args = (0, 1024, 0, 1024, 1, 21)

        # post some sample image data
        self.image_data = np.random.randint(0,
                                            high=255,
                                            size=[1, 20, 1024,
                                                  1024]).astype(np.uint8)
        response = postNPZ(p, self.image_data)

        assert (response.code == 200)

        voxarray = getNPZ(p)
        # check that the return data matches
        assert (np.array_equal(voxarray, self.image_data))
Beispiel #6
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 #7
0
  def test_post_blosc (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 = postBlosc(p, image_data)
    posted_data = getNPZ(p)

    assert ( np.array_equal(image_data,posted_data) )
Beispiel #8
0
  def test_genhistogram (self):
    """Test generating an 8bit histogram"""

    image_data = np.random.randint(0, high=255, size=[1, 10, 1024, 1024]).astype(np.uint8)
    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) )

    # generate the histogram
    url = 'https://{}/stats/{}/{}/genhist/'.format( SITE_HOST, p.token, p.channels[0] )
    try:
      # Build a get request
      response = getURL(url)
    except Exception as e:
      print e

    assert( response.status_code == 200 )

    jsonresponse = json.loads(response.content)

    # make sure the celery job started
    celerystatus = celery_app.AsyncResult(jsonresponse['jobid'])

    # wait for histogram generation to finish (either 10 mins or failure)
    # note: actual generation time should be more like 0.2 seconds, but there may be other jobs in the queue
    count = 0
    while celerystatus.state != 'SUCCESS':
      time.sleep(1)
      celerystatus = celery_app.AsyncResult(jsonresponse['jobid'])
      assert( celerystatus.state != 'FAILURE' )
      assert( count != 60 )
      count += 1

    # now get the histogram
    url = 'https://{}/stats/{}/{}/hist/'.format( SITE_HOST, p.token, p.channels[0] )
    try:
      # Build a get request
      response = getURL(url)
    except Exception as e:
      print e

    assert( response.status_code == 200 )

    jsonresponse = json.loads(response.content)

    # now see if the two histograms are equivalent
    testhist = np.histogram(image_data[image_data > 0], bins=256, range=(0,256))

    # check to see that the bins are equal
    assert( np.array_equal( jsonresponse['bins'], testhist[1] ) )

    # check to see that the counts are equal
    assert( np.array_equal( jsonresponse['hist'], testhist[0] ) )
Beispiel #9
0
  def test_npz_default_channel (self):
    """Post npz data with default channel"""

    image_data = np.ones ( [1,10,100,100], dtype=np.uint8 ) * random.randint(0,255)
    p.channels = None
    response = postNPZ(p, image_data)
    assert (response.code == 200)
    voxarray = getNPZ(p)
    # check that the return matches
    assert ( np.array_equal(voxarray,image_data) )
    def test_post_blosc(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 = postBlosc(p, image_data)
        posted_data = getNPZ(p)

        assert (np.array_equal(image_data, posted_data))
Beispiel #11
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 #12
0
    def test_npz_default_channel(self):
        """Post npz data with default channel"""

        image_data = np.ones([1, 10, 100, 100],
                             dtype=np.uint8) * random.randint(0, 255)
        p.channels = None
        response = postNPZ(p, image_data)
        assert (response.code == 200)
        voxarray = getNPZ(p)
        # check that the return matches
        assert (np.array_equal(voxarray, image_data))
Beispiel #13
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_npz (self):
    """Post npz data to correct region with correct datatype"""

    p.args = (3000,3100,4000,4100,500,510,20,24)
    # upload some image data
    image_data = np.ones ( [2,4,10,100,100], dtype=np.uint8 ) * random.randint(0,255)
    
    response = postNPZ(p, image_data, time=True)
    # Checking for successful post
    assert( response.code == 200 )
    voxarray = getNPZ(p, time=True)
    # check that the return matches
    assert ( np.array_equal(voxarray,image_data) )
Beispiel #15
0
  def test_npz (self):
    """Post npz data to correct region with correct datatype"""

    p.args = (3000,3100,4000,4100,500,510)
    # upload some image data
    image_data = np.ones ( [2,10,100,100], dtype=np.float32 ) * random.random()
    
    response = postNPZ(p, image_data)
    # Checking for successful post
    assert( response.code == 200 )
    voxarray = getNPZ(p)
    # check that the return matches
    assert ( np.array_equal(voxarray,image_data) )
Beispiel #16
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)
Beispiel #17
0
    def test_npz(self):
        """Post npz data to correct region with correct datatype"""

        p.args = (3000, 3100, 4000, 4100, 500, 510)
        # upload some image data
        time_data = np.ones([2, 10, 100, 100],
                            dtype=np.float32) * random.random()

        response = postNPZ(p, time_data)
        # Checking for successful post
        assert (response.status_code == 200)
        voxarray = getNPZ(p)
        # check that the return matches
        assert (np.array_equal(voxarray, time_data))
Beispiel #18
0
    def test_direct_neariso_npz(self):
        """Post npz data to correct region with correct datatype"""

        p.resolution = 2
        p.args = (1000, 1100, 500, 600, 100, 110, 10, 14)
        # upload some image data
        image_data = np.ones([2, 4, 10, 100, 100],
                             dtype=np.uint8) * random.randint(0, 255)

        response = postNPZ(p, image_data, time=True, neariso=True, direct=True)
        # Checking for successful post
        assert (response.status_code == 200)
        voxarray = getNPZ(p, time=True, neariso=True)
        # check that the return matches
        assert (np.array_equal(voxarray, image_data))
Beispiel #19
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)
Beispiel #20
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 #21
0
  def setup_class(self):
    """Create the unittest database"""
    makeunitdb.createTestDB(p.token, p.channels, channel_type=IMAGE, channel_datatype=UINT8, public=True, ximagesize=1024, yimagesize=1024, zimagesize=20, xvoxelres=1.0, yvoxelres=1.0, zvoxelres=10.0, readonly=0)

    # modify params args to match new data size
    p.args = (0,1024,0,1024,1,21)

    # post some sample image data
    self.image_data = np.random.randint(0, high=255, size=[1, 20, 1024, 1024]).astype(np.uint8)
    response = postNPZ(p, self.image_data)

    assert( response.code == 200 )

    voxarray = getNPZ(p)
    # check that the return data matches
    assert( np.array_equal(voxarray, self.image_data) )
Beispiel #22
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]) )
  def test_xy_tile(self):
    """Test a simple xy tile fetch"""
   
    p.args = (3072,3584,4096,4608,200,201,50,52)
    # have to use a constant here for memcache purposes
    image_data = np.ones([2,2,1,512,512], dtype=np.uint8) * 130
    response = postNPZ(p, image_data, time=True)
    
    voxarray = getNPZ(p, time=True)
    # check that the return matches
    assert ( np.array_equal(voxarray, image_data) )
    
    url = "http://{}/catmaid/{}/{}/xy/{}/{}/{}_{}_{}.png".format(SITE_HOST, p.token, p.channels[0], p.args[6], p.args[4], p.args[2]/512, p.args[0]/512, p.resolution)
    f = getURL (url)

    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data, image_data[0][0][0]) )
Beispiel #24
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,:]) )
  def test_yz_tile (self):
    """Test a simple yz slice fetch"""

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

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

    scale_range = 512*p.voxel[2]/p.voxel[1]
    slice_data = np.asarray ( Image.open(StringIO(f.read())) )
    assert ( np.array_equal(slice_data[:scale_range,:], image_data[0,0,:scale_range,:,0]) )
Beispiel #26
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 #27
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 #28
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 = "https://{}/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.content)))
        assert (np.array_equal(slice_data, image_data[0][0]))
Beispiel #29
0
  def test_genhistogram (self):
    """Test generating an 8bit histogram"""

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

    assert( response.code == 200 )

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

    # generate the histogram 
    url = 'http://{}/stats/{}/{}/genhist/'.format( SITE_HOST, p.token, p.channels[0] )
    try:
      # Build a get request
      req = urllib2.Request(url)
      response = urllib2.urlopen(req)
    except urllib2.HTTPError,e:
      return e
Beispiel #30
0
    def test_xz_tile(self):
        """Test a simple xz slice fetch"""

        p.args = (3072, 3584, 4096, 4097, 1, 513, 80, 82)
        # have to use a constant here for memcache purposes
        image_data = np.ones([2, 2, 512, 1, 512], dtype=np.uint8) * 130
        response = postNPZ(p, image_data, time=True)

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

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

        scale_range = int(512 * p.voxel[2] / p.voxel[0])
        slice_data = np.asarray(Image.open(StringIO(f.content)))
        assert (np.array_equal(slice_data[:scale_range, :],
                               image_data[0, 0, :scale_range, 0, :]))
Beispiel #31
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 #32
0
    def test_genhistogram(self):
        """Test generating an 8bit histogram"""

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

        assert (response.code == 200)

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

        # generate the histogram
        url = 'http://{}/stats/{}/{}/genhist/'.format(SITE_HOST, p.token,
                                                      p.channels[0])
        try:
            # Build a get request
            req = urllib2.Request(url)
            response = urllib2.urlopen(req)
        except urllib2.HTTPError, e:
            return e
Beispiel #33
0
    def test_genhistogram(self):
        """Test generating an 8bit histogram"""

        image_data = np.random.randint(0, high=255,
                                       size=[1, 10, 1024,
                                             1024]).astype(np.uint8)
        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))

        # generate the histogram
        url = 'https://{}/stats/{}/{}/genhist/'.format(SITE_HOST, p.token,
                                                       p.channels[0])
        try:
            # Build a get request
            response = getURL(url)
        except Exception as e:
            print e

        assert (response.status_code == 200)

        jsonresponse = json.loads(response.content)

        # make sure the celery job started
        celerystatus = celery_app.AsyncResult(jsonresponse['jobid'])

        # wait for histogram generation to finish (either 10 mins or failure)
        # note: actual generation time should be more like 0.2 seconds, but there may be other jobs in the queue
        count = 0
        while celerystatus.state != 'SUCCESS':
            time.sleep(1)
            celerystatus = celery_app.AsyncResult(jsonresponse['jobid'])
            assert (celerystatus.state != 'FAILURE')
            assert (count != 60)
            count += 1

        # now get the histogram
        url = 'https://{}/stats/{}/{}/hist/'.format(SITE_HOST, p.token,
                                                    p.channels[0])
        try:
            # Build a get request
            response = getURL(url)
        except Exception as e:
            print e

        assert (response.status_code == 200)

        jsonresponse = json.loads(response.content)

        # now see if the two histograms are equivalent
        testhist = np.histogram(image_data[image_data > 0],
                                bins=256,
                                range=(0, 256))

        # check to see that the bins are equal
        assert (np.array_equal(jsonresponse['bins'], testhist[1]))

        # check to see that the counts are equal
        assert (np.array_equal(jsonresponse['hist'], testhist[0]))
Beispiel #34
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, 6, 7)
        image_data = np.ones([1, 1, 1, 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))
        for iter_value in range(1, 500, 1):
            time.sleep(1)
            # Checking if the PROPGATED value is set correctly
            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, 4, 5, 6, 7)
        url = "https://{}/sd/{}/{}/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], p.args[6])
        f = getURL(url)
        slice_data = np.asarray(Image.open(StringIO(f.content)))
        assert (np.array_equal(slice_data, image_data[0][0][0][:50, :50]))

        # Checking at res5
        p.args = (7, 9, 7, 9, 4, 5, 6, 7)
        url = "https://{}/sd/{}/{}/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], p.args[6])
        f = getURL(url)
        slice_data = np.asarray(Image.open(StringIO(f.content)))
        assert (np.array_equal(slice_data, image_data[0][0][0][:2, :2]))

        # checking at res5 for neariso data
        # extract data from res4 slice 4
        p.args = (14, 18, 14, 18, 4, 5, 6, 7)
        url = "https://{}/sd/{}/{}/xy/{}/{},{}/{},{}/{}/{}/".format(
            SITE_HOST, p.token, p.channels[0], p.resolution + 4, p.args[0],
            p.args[1], p.args[2], p.args[3], p.args[4], p.args[6])
        f = getURL(url)
        slice_data_1 = np.asarray(Image.open(StringIO(f.content)))
        # extract data from res4 slice 5
        url = "https://{}/sd/{}/{}/xy/{}/{},{}/{},{}/{}/{}/".format(
            SITE_HOST, p.token, p.channels[0], p.resolution + 4, p.args[0],
            p.args[1], p.args[2], p.args[3], p.args[4] + 1, p.args[6])
        f = getURL(url)
        slice_data_2 = np.asarray(Image.open(StringIO(f.content)))
        # generate isotropic slice from this
        new_slicedata = isotropicBuild_ctype(slice_data_1, slice_data_2)
        p.args = (7, 9, 7, 9, 2, 3, 6, 7)
        data = getNPZ(p, neariso=True)
        url = "https://{}/sd/{}/{}/xy/{}/{},{}/{},{}/{}/{}/neariso/".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], p.args[6])
        f = getURL(url)
        slice_data = np.asarray(Image.open(StringIO(f.content)))
        assert (np.array_equal(slice_data, new_slicedata[:2, :2]))