Exemple #1
0
    def test_request_tile_invalid_orientation(self):
        """
        Test initialization of tile arguments for a invalid tile request. The x-args are outside the coordinate
        frame
        :return:
        """
        url = '/' + version + '/image/col1/exp1/channel1/xe/0/0:6/0:6/1/'

        # Create the request dict
        request_args = {
            "service": "image",
            "collection_name": "col1",
            "experiment_name": "exp1",
            "channel_name": "channel1",
            "orientation": "xe",
            "resolution": 0,
            "x_args": "0:5",
            "y_args": "0:6",
            "z_args": "1",
            "time_args": None
        }

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

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

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

        # Create the request
        request = self.rf.get(url)
        force_authenticate(request, user=self.user)
        drfrequest = CutoutTile().initialize_request(request)
        drfrequest.version = version
        ret = BossRequest(drfrequest, request_args)
        time = ret.get_time()
        self.assertEqual(time, range(1, 2))
Exemple #3
0
    def test_full_token_image_time_resolves(self):
        """
        Test to make sure the tiles URL with all datamodel params resolves
        :return:
        """
        view_tiles = resolve('/' + version + '/image/col1/exp1/ds1/xy/2/0:5/0:6/1/1')
        self.assertEqual(view_tiles.func.__name__, CutoutTile.as_view().__name__)

        view_tiles = resolve('/' + version + '/image/col1/exp1/ds1/xz/2/0:5/1/1:6/2')
        self.assertEqual(view_tiles.func.__name__, CutoutTile.as_view().__name__)

        view_tiles = resolve('/' + version + '/image/col1/exp1/ds1/yz/2/5/1:6/1:6/3/')
        self.assertEqual(view_tiles.func.__name__, CutoutTile.as_view().__name__)
Exemple #4
0
    def test_png_uint8_xz(self):
        """ Test a png xz slice"""
        # Post data to the database
        factory = APIRequestFactory()

        # Get an image file
        request = factory.get('/' + version +
                              '/image/col1/exp1/channel1/xz/0/0:128/2/0:16/',
                              Accept='image/png')
        force_authenticate(request, user=self.user)
        # Make request
        response = CutoutTile.as_view()(request,
                                        collection='col1',
                                        experiment='exp1',
                                        dataset='channel1',
                                        orientation='xz',
                                        resolution='0',
                                        x_args='0:128',
                                        y_args='2',
                                        z_args='0:16')
        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[0:16, 2, 0:128]))
    def test_no_cache_read(self):
        """Test no-cache option when reading an image"""
        factory = APIRequestFactory()

        # Get an image file
        request = factory.get(
            '/' + version +
            '/image/col1/exp1/channel1/xy/0/400:700/300:800/3/?no-cache=true',
            Accept='image/png')
        force_authenticate(request, user=self.user)

        time.sleep(10)

        # Make request
        response = CutoutTile.as_view()(request,
                                        collection='col1',
                                        experiment='exp1',
                                        channel='channel1',
                                        orientation='xy',
                                        resolution='0',
                                        x_args='400:700',
                                        y_args='300:800',
                                        z_args='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, 300:800,
                                                           400:700])
Exemple #6
0
    def test_request_tile_init_tileargs_channel(self):
        """
        Test initialization of tile arguments for a tile request
        :return:
        """
        url = '/' + version + '/image/col1/exp1/channel1/xy/2/0:5/0:6/1/'

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

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

        # Create the request
        request = self.rf.get(url)
        force_authenticate(request, user=self.user)
        drfrequest = CutoutTile().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 #7
0
    def test_request_tile_init_channel(self):
        """
        Test initialization of tile requests for the datamodel
        :return:
        """
        url = '/' + version + '/image/col1/exp1/channel1/xy/2/0:5/0:6/1/'
        col = 'col1'
        exp = 'exp1'
        channel = 'channel1'
        boss_key = 'col1&exp1&channel1'

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

        # Create the request
        request = self.rf.get(url)
        force_authenticate(request, user=self.user)
        drfrequest = CutoutTile().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 #8
0
    def test_png_uint8_xz(self):
        """ Test a png xz slice"""
        # Post data to the database
        factory = APIRequestFactory()

        # Get an image file
        request = factory.get('/' + version + '/image/col1/exp1/channel1/xz/0/0:128/2/0:16/',
                              Accept='image/png')
        force_authenticate(request, user=self.user)
        # Make request
        response = CutoutTile.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
                                        orientation='xz', resolution='0', x_args='0:128', y_args='2', z_args='0:16')
        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[0:16, 2, 0:128]))
    def test_no_cache_read(self):
        """Test no-cache option when reading an image"""
        factory = APIRequestFactory()

        # Get an image file
        request = factory.get('/' + version + '/image/col1/exp1/channel1/xy/0/400:700/300:800/3/?no-cache=true',
                              Accept='image/png')
        force_authenticate(request, user=self.user)

        time.sleep(10)

        # Make request
        response = CutoutTile.as_view()(request, collection='col1', experiment='exp1', channel='channel1',
                                        orientation='xy', resolution='0', x_args='400:700', y_args='300:800',
                                        z_args='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, 300:800, 400:700])