def test_request_tile_init_tileargs_time(self):
        """
        Test initialization of timesample arguments  with a single time
        :return:
        """
        url = '/' + version + '/tile/col1/exp1/channel1/xy/512/2/0/0/1/1/'

        # Create the request dict
        request_args = {
            "service": "tile",
            "collection_name": "col1",
            "experiment_name": "exp1",
            "channel_name": "channel1",
            "orientation": "xy",
            "tile_size": 512,
            "resolution": 2,
            "x_args": "0",
            "y_args": "0",
            "z_args": "1",
            "time_args": "1"
        }

        # Create the request
        request = self.rf.get(url)
        force_authenticate(request, user=self.user)
        drfrequest = Tile().initialize_request(request)
        drfrequest.version = version

        ret = BossRequest(drfrequest, request_args)
        time = ret.get_time()
        self.assertEqual(time, range(1, 2))
    def test_request_tile_invalid_orientation(self):
        """
        Test initialization of tile arguments for a invalid tile request. Unrecognized orientation
        :return:
        """
        url = '/' + version + '/tile/col1/exp1/channel1/xe/512/2/0/1/1/1/'

        # Create the request dict
        request_args = {
            "service": "tile",
            "collection_name": "col1",
            "experiment_name": "exp1",
            "channel_name": "channel1",
            "orientation": "xe",
            "tile_size": 512,
            "resolution": 2,
            "x_args": "0",
            "y_args": "0",
            "z_args": "1",
            "time_args": "1"
        }

        # Create the request
        request = self.rf.get(url)
        force_authenticate(request, user=self.user)
        drfrequest = Tile().initialize_request(request)
        drfrequest.version = version

        with self.assertRaises(BossError):
            BossRequest(drfrequest, request_args)
Exemple #3
0
    def test_request_tile_invalid_orientation(self):
        """
        Test initialization of tile arguments for a invalid tile request. Unrecognized orientation
        :return:
        """
        url = '/' + version + '/tile/col1/exp1/channel1/xe/512/2/0/1/1/1/'

        # Create the request dict
        request_args = {
            "service": "tile",
            "collection_name": "col1",
            "experiment_name": "exp1",
            "channel_name": "channel1",
            "orientation": "xe",
            "tile_size": 512,
            "resolution": 2,
            "x_args": "0",
            "y_args": "0",
            "z_args": "1",
            "time_args": "1"
        }

        # Create the request
        request = self.rf.get(url)
        force_authenticate(request, user=self.user)
        drfrequest = Tile().initialize_request(request)
        drfrequest.version = version

        with self.assertRaises(BossError):
            BossRequest(drfrequest, request_args)
Exemple #4
0
    def test_request_tile_init_tileargs_time(self):
        """
        Test initialization of timesample arguments  with a single time
        :return:
        """
        url = '/' + version + '/tile/col1/exp1/channel1/xy/512/2/0/0/1/1/'

        # Create the request dict
        request_args = {
            "service": "tile",
            "collection_name": "col1",
            "experiment_name": "exp1",
            "channel_name": "channel1",
            "orientation": "xy",
            "tile_size": 512,
            "resolution": 2,
            "x_args": "0",
            "y_args": "0",
            "z_args": "1",
            "time_args": "1"
        }

        # Create the request
        request = self.rf.get(url)
        force_authenticate(request, user=self.user)
        drfrequest = Tile().initialize_request(request)
        drfrequest.version = version

        ret = BossRequest(drfrequest, request_args)
        time = ret.get_time()
        self.assertEqual(time, range(1, 2))
Exemple #5
0
    def test_png_uint8_yz(self):
        """ Test a png yz slice"""
        # Post data to the database
        factory = APIRequestFactory()

        # Get an image file
        request = factory.get('/' + version +
                              '/tile/col1/exp1/channel1/yz/4/0/0/7/2/',
                              Accept='image/png')
        force_authenticate(request, user=self.user)
        # Make request
        response = Tile.as_view()(request,
                                  collection='col1',
                                  experiment='exp1',
                                  dataset='channel1',
                                  orientation='yz',
                                  tile_size='4',
                                  resolution='0',
                                  x_idx='0',
                                  y_idx='7',
                                  z_idx='2')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Check data is correct (this is pre-renderer)
        test_img = np.array(response.data, dtype="uint8")

        np.testing.assert_equal(test_img,
                                np.squeeze(self.test_data_8[8:12, 28:32, 0]))
Exemple #6
0
    def test_png_uint8_xy_x_offset(self):
        """ Test a png xy slice"""
        # Post data to the database
        factory = APIRequestFactory()

        # Get an image file
        request = factory.get('/' + version +
                              '/tile/col1/exp1/channel1/xy/512/0/1/1/3/',
                              Accept='image/png')
        force_authenticate(request, user=self.user)
        # Make request
        response = Tile.as_view()(request,
                                  collection='col1',
                                  experiment='exp1',
                                  dataset='channel1',
                                  orientation='xy',
                                  tile_size='512',
                                  resolution='0',
                                  x_idx='1',
                                  y_idx='1',
                                  z_idx='3')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Check data is correct (this is pre-renderer)
        test_img = np.array(response.data, dtype="uint8")

        np.testing.assert_equal(test_img, self.test_data_8[3, 512:1024,
                                                           512:1024])
    def test_no_cache_read(self):
        """Test no-cache option when reading an image"""
        factory = APIRequestFactory()

        # Get an image file
        request = factory.get(
            '/' + version +
            '/tile/col1/exp1/channel1/xy/512/0/0/0/5/?no-cache=true',
            Accept='image/png')
        force_authenticate(request, user=self.user)

        time.sleep(10)

        # Make request
        response = Tile.as_view()(request,
                                  collection='col1',
                                  experiment='exp1',
                                  channel='channel1',
                                  orientation='xy',
                                  tile_size='512',
                                  resolution='0',
                                  x_idx='0',
                                  y_idx='0',
                                  z_idx='5')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Check data is correct (this is pre-renderer)
        test_img = np.array(response.data, dtype="uint8")

        np.testing.assert_equal(test_img, self.test_data_8[5, 0:512, 0:512])
Exemple #8
0
    def test_full_token_tile_time_resolves(self):
        """
        Test to make sure the tiles URL with all datamodel params resolves
        :return:
        """
        view_tiles = resolve('/' + version + '/tile/col1/exp1/ds1/xy/512/2/0/1/1/3')
        self.assertEqual(view_tiles.func.__name__, Tile.as_view().__name__)

        view_tiles = resolve('/' + version + '/tile/col1/exp1/ds1/xz/512/2/0/1/1/3')
        self.assertEqual(view_tiles.func.__name__, Tile.as_view().__name__)

        view_tiles = resolve('/' + version + '/tile/col1/exp1/ds1/yz/512/2/0/1/1/3')
        self.assertEqual(view_tiles.func.__name__, Tile.as_view().__name__)

        view_tiles = resolve('/' + version + '/tile/col1/exp1/ds1/yz/512/2/0/1/1/3/')
        self.assertEqual(view_tiles.func.__name__, Tile.as_view().__name__)
    def test_request_tile_init_tileargs_channel(self):
        """
        Test initialization of tile arguments for a tile request for a channel
        :return:
        """
        url = '/' + version + '/tile/col1/exp1/channel1/xy/512/2/0/0/1'

        res = 2
        (x_start, x_stop) = (0, 512)
        (y_start, y_stop) = (0, 512)
        (z_start, z_stop) = (1, 2)

        # Create the request dict
        request_args = {
            "service": "tile",
            "collection_name": "col1",
            "experiment_name": "exp1",
            "channel_name": "channel1",
            "orientation": "xy",
            "tile_size": 512,
            "resolution": 2,
            "x_args": "0",
            "y_args": "0",
            "z_args": "1",
            "time_args": None
        }
        # Create the request
        request = self.rf.get(url)
        force_authenticate(request, user=self.user)
        drfrequest = Tile().initialize_request(request)
        drfrequest.version = version
        ret = BossRequest(drfrequest, request_args)

        self.assertEqual(ret.get_resolution(), res)
        self.assertEqual(ret.get_x_start(), x_start)
        self.assertEqual(ret.get_x_stop(), x_stop)
        self.assertEqual(ret.get_x_span(), x_stop - x_start)

        self.assertEqual(ret.get_y_start(), y_start)
        self.assertEqual(ret.get_y_stop(), y_stop)
        self.assertEqual(ret.get_y_span(), y_stop - y_start)

        self.assertEqual(ret.get_z_start(), z_start)
        self.assertEqual(ret.get_z_stop(), z_stop)
        self.assertEqual(ret.get_z_span(), z_stop - z_start)
Exemple #10
0
    def test_request_tile_init_tileargs_channel(self):
        """
        Test initialization of tile arguments for a tile request for a channel
        :return:
        """
        url = '/' + version + '/tile/col1/exp1/channel1/xy/512/2/0/0/1'

        res = 2
        (x_start, x_stop) = (0, 512)
        (y_start, y_stop) = (0, 512)
        (z_start, z_stop) = (1, 2)

        # Create the request dict
        request_args = {
            "service": "tile",
            "collection_name": "col1",
            "experiment_name": "exp1",
            "channel_name": "channel1",
            "orientation": "xy",
            "tile_size": 512,
            "resolution": 2,
            "x_args": "0",
            "y_args": "0",
            "z_args": "1",
            "time_args": None
        }
        # Create the request
        request = self.rf.get(url)
        force_authenticate(request, user=self.user)
        drfrequest = Tile().initialize_request(request)
        drfrequest.version = version
        ret = BossRequest(drfrequest, request_args)

        self.assertEqual(ret.get_resolution(), res)
        self.assertEqual(ret.get_x_start(), x_start)
        self.assertEqual(ret.get_x_stop(), x_stop)
        self.assertEqual(ret.get_x_span(), x_stop - x_start)

        self.assertEqual(ret.get_y_start(), y_start)
        self.assertEqual(ret.get_y_stop(), y_stop)
        self.assertEqual(ret.get_y_span(), y_stop - y_start)

        self.assertEqual(ret.get_z_start(), z_start)
        self.assertEqual(ret.get_z_stop(), z_stop)
        self.assertEqual(ret.get_z_span(), z_stop - z_start)
    def test_request_tile_init_channel(self):
        """
        Test initialization of tile requests for the datamodel with a channel
        :return:
        """
        url = '/' + version + '/tile/col1/exp1/channel1/xy/512/2/0/0/1'
        col = 'col1'
        exp = 'exp1'
        channel = 'channel1'
        boss_key = 'col1&exp1&channel1'

        # Create the request dict
        request_args = {
            "service": "tile",
            "collection_name": col,
            "experiment_name": exp,
            "channel_name": channel,
            "orientation": "xy",
            "tile_size": 512,
            "resolution": 2,
            "x_args": "0",
            "y_args": "0",
            "z_args": "1",
            "time_args": None
        }

        # Create the request
        request = self.rf.get(url)
        force_authenticate(request, user=self.user)
        drfrequest = Tile().initialize_request(request)
        drfrequest.version = version

        ret = BossRequest(drfrequest, request_args)
        self.assertEqual(ret.get_collection(), col)
        self.assertEqual(ret.get_experiment(), exp)
        self.assertEqual(ret.get_channel(), channel)
        self.assertEqual(ret.get_boss_key(), boss_key)
Exemple #12
0
    def test_request_tile_init_channel(self):
        """
        Test initialization of tile requests for the datamodel with a channel
        :return:
        """
        url = '/' + version + '/tile/col1/exp1/channel1/xy/512/2/0/0/1'
        col = 'col1'
        exp = 'exp1'
        channel = 'channel1'
        boss_key = 'col1&exp1&channel1'

        # Create the request dict
        request_args = {
            "service": "tile",
            "collection_name": col,
            "experiment_name": exp,
            "channel_name": channel,
            "orientation": "xy",
            "tile_size": 512,
            "resolution": 2,
            "x_args": "0",
            "y_args": "0",
            "z_args": "1",
            "time_args": None
        }

        # Create the request
        request = self.rf.get(url)
        force_authenticate(request, user=self.user)
        drfrequest = Tile().initialize_request(request)
        drfrequest.version = version

        ret = BossRequest(drfrequest, request_args)
        self.assertEqual(ret.get_collection(), col)
        self.assertEqual(ret.get_experiment(), exp)
        self.assertEqual(ret.get_channel(), channel)
        self.assertEqual(ret.get_boss_key(), boss_key)
Exemple #13
0
    def test_png_uint8_yz(self):
        """ Test a png yz slice"""
        # Post data to the database
        factory = APIRequestFactory()

        # Get an image file
        request = factory.get('/' + version + '/tile/col1/exp1/channel1/yz/4/0/0/7/2/',
                              Accept='image/png')
        force_authenticate(request, user=self.user)
        # Make request
        response = Tile.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
                                  orientation='yz', tile_size='4', resolution='0',
                                  x_idx='0', y_idx='7', z_idx='2')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Check data is correct (this is pre-renderer)
        test_img = np.array(response.data, dtype="uint8")

        np.testing.assert_equal(test_img, np.squeeze(self.test_data_8[8:12, 28:32, 0]))
Exemple #14
0
    def test_png_uint8_xy_x_offset(self):
        """ Test a png xy slice"""
        # Post data to the database
        factory = APIRequestFactory()

        # Get an image file
        request = factory.get('/' + version + '/tile/col1/exp1/channel1/xy/512/0/1/1/3/',
                              Accept='image/png')
        force_authenticate(request, user=self.user)
        # Make request
        response = Tile.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
                                  orientation='xy', tile_size='512', resolution='0',
                                  x_idx='1', y_idx='1', z_idx='3')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Check data is correct (this is pre-renderer)
        test_img = np.array(response.data, dtype="uint8")

        np.testing.assert_equal(test_img, self.test_data_8[3, 512:1024, 512:1024])
    def test_no_cache_read(self):
        """Test no-cache option when reading an image"""
        factory = APIRequestFactory()

        # Get an image file
        request = factory.get('/' + version + '/tile/col1/exp1/channel1/xy/512/0/0/0/5/?no-cache=true',
                              Accept='image/png')
        force_authenticate(request, user=self.user)

        time.sleep(10)

        # Make request
        response = Tile.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
                                  orientation='xy', tile_size='512', resolution='0',
                                  x_idx='0', y_idx='0', z_idx='5')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Check data is correct (this is pre-renderer)
        test_img = np.array(response.data, dtype="uint8")

        np.testing.assert_equal(test_img, self.test_data_8[5, 0:512, 0:512])