Пример #1
0
    def __init__(self, slice_rows=None, slice_cols=None, vosclient=None):
        """
        Constructor.

        Args:
          resolver:
            Resolves source readings to the URI's from which they can be
            retrieved.
          slice_rows, slice_cols: int
            The number of rows and columns (pixels) to slice out around the
            source.  Leave as None to use default configuration values.
        """
        # If not provided, read defaults from application config file
        if slice_rows is None:
            slice_rows = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_ROWS")
        if slice_cols is None:
            slice_cols = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_COLS")

        self.slice_rows = slice_rows
        self.slice_cols = slice_cols

        if vosclient is None:
            self.vosclient = vos.Client(cadc_short_cut=True)
        else:
            self.vosclient = vosclient

        self.cutout_calculator = CutoutCalculator(slice_rows, slice_cols)
Пример #2
0
    def test_calc_cutout_boundary_y(self):
        self.calculator = CutoutCalculator(200, 200)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((400, 50), self.imgsize)
        assert_that(x0, equal_to(300))
        assert_that(x1, equal_to(500))
        assert_that(y0, equal_to(1))
        assert_that(y1, equal_to(201))
Пример #3
0
    def test_calc_cutout_internal_str_float(self):
        self.calculator = CutoutCalculator(100, 200)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((500.00, 600.00), self.imgsize)
        assert_that(x0, equal_to(400))
        assert_that(x1, equal_to(600))
        assert_that(y0, equal_to(550))
        assert_that(y1, equal_to(650))
Пример #4
0
    def test_calc_cutout_boundary_ymax_converter(self):
        self.imgsize = (200, 200)
        self.calculator = CutoutCalculator(100, 100)

        _, converter = self.calculator.calc_cutout((100, 175), self.imgsize)
        assert_that(converter.convert((100, 175)), equal_to((50, 75)))
        assert_that(converter.convert((50, 100)), equal_to((0, 0)))
        assert_that(converter.convert((150, 200)), equal_to((100, 100)))
Пример #5
0
    def test_calc_cutout_boundary_xmax(self):
        self.imgsize = (200, 200)
        self.calculator = CutoutCalculator(100, 100)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((175, 100), self.imgsize)
        assert_that(x0, equal_to(100))
        assert_that(x1, equal_to(200))
        assert_that(y0, equal_to(50))
        assert_that(y1, equal_to(150))
Пример #6
0
    def test_build_cutout_str_converter(self):
        self.calculator = CutoutCalculator(100, 200)

        _, converter = self.calculator.build_cutout_str(15, (500, 600), self.imgsize)
        assert_that(converter.convert((400, 550)), equal_to((0, 0)))
        assert_that(converter.convert((600, 550)), equal_to((200, 0)))
        assert_that(converter.convert((400, 650)), equal_to((0, 100)))
        assert_that(converter.convert((600, 650)), equal_to((200, 100)))
        assert_that(converter.convert((500, 600)), equal_to((100, 50)))
Пример #7
0
    def test_calc_cutout_inverted(self):
        self.calculator = CutoutCalculator(20, 20)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((20, 20), (200, 200),
                                                          inverted=True)
        assert_that(x0, equal_to(190))
        assert_that(x1, equal_to(170))
        assert_that(y0, equal_to(190))
        assert_that(y1, equal_to(170))
Пример #8
0
    def test_calc_cutout_inverted_converter(self):
        self.calculator = CutoutCalculator(20, 20)

        _, converter = self.calculator.calc_cutout((20, 20), (200, 200),
                                                   inverted=True)
        assert_that(converter.convert((10, 10)), equal_to((0, 0)))
        assert_that(converter.convert((30, 10)), equal_to((20, 0)))
        assert_that(converter.convert((10, 30)), equal_to((0, 20)))
        assert_that(converter.convert((30, 30)), equal_to((20, 20)))
        assert_that(converter.convert((20, 20)), equal_to((10, 10)))
Пример #9
0
    def __init__(self, slice_rows=None, slice_cols=None, vosclient=None):
        """
        Constructor.

        Args:
          resolver:
            Resolves source readings to the URI's from which they can be
            retrieved.
          slice_rows, slice_cols: int
            The number of rows and columns (pixels) to slice out around the
            source.  Leave as None to use default configuration values.
        """
        # If not provided, read defaults from application config file
        if slice_rows is None:
            slice_rows = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_ROWS")
        if slice_cols is None:
            slice_cols = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_COLS")

        self.slice_rows = slice_rows
        self.slice_cols = slice_cols

        if vosclient is None:
            self.vosclient = vos.Client(cadc_short_cut=True)
        else:
            self.vosclient = vosclient

        self.cutout_calculator = CutoutCalculator(slice_rows, slice_cols)
Пример #10
0
class ImageSliceDownloader(object):
    """
    Downloads a slice of an image relevant to examining a (potential) source.
    """

    def __init__(self, slice_rows=None, slice_cols=None, vosclient=None):
        """
        Constructor.

        Args:
          resolver:
            Resolves source readings to the URI's from which they can be
            retrieved.
          slice_rows, slice_cols: int
            The number of rows and columns (pixels) to slice out around the
            source.  Leave as None to use default configuration values.
        """
        # If not provided, read defaults from application config file
        if slice_rows is None:
            slice_rows = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_ROWS")
        if slice_cols is None:
            slice_cols = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_COLS")

        self.slice_rows = slice_rows
        self.slice_cols = slice_cols

        if vosclient is None:
            self.vosclient = vos.Client(cadc_short_cut=True)
        else:
            self.vosclient = vosclient

        self.cutout_calculator = CutoutCalculator(slice_rows, slice_cols)

    def _download_fits_file(self, downloadable_item):
        cutout_str, converter = self.cutout_calculator.build_cutout_str(
            downloadable_item.get_extension(),
            downloadable_item.get_focal_point(),
            downloadable_item.get_full_image_size(),
            inverted=downloadable_item.is_inverted())

        vofile = self.vosclient.open(downloadable_item.get_image_uri(),
                                     view="cutout", cutout=cutout_str)

        return vofile.read(), converter

    def _download_apcor_file(self, downloadable_item):
        vofile = self.vosclient.open(downloadable_item.get_apcor_uri(),
                                     view="data")
        return vofile.read()

    def download(self, downloadable_item):
        """
        Retrieves a remote image.

        Args:
          downloadable_item: DownloadableItem
            Specification for the item to be downloaded.

        Returns:
          fitsimage: ossos.gui.image.DownloadedFitsImage
            The downloaded image, either in-memory or on disk as specified.
        """
        fits_str, converter = self._download_fits_file(downloadable_item)

        if downloadable_item.needs_apcor:
            apcor_str = self._download_apcor_file(downloadable_item)
        else:
            apcor_str = None

        return DownloadedFitsImage(fits_str, converter, apcor_str,
                                   in_memory=downloadable_item.in_memory)

    def refresh_vos_client(self):
        """
        If we have gotten a new certfile we have to create a new Client
        object before it will get used.
        """
        self.vosclient = vos.Client(cadc_short_cut=True)
Пример #11
0
    def test_calc_cutout_boundary_x_converter(self):
        self.calculator = CutoutCalculator(200, 200)

        _, converter = self.calculator.build_cutout_str(15, (400, 50), self.imgsize)
        assert_that(converter.convert((400, 51)), equal_to((100, 50)))
        assert_that(converter.convert((300, 1)), equal_to((0, 0)))
Пример #12
0
class CutoutCalculatorTest(unittest.TestCase):
    def setUp(self):
        self.imgsize = (2000, 2000)

    def test_calc_cutout_internal(self):
        self.calculator = CutoutCalculator(100, 200)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((500, 600), self.imgsize)
        assert_that(x0, equal_to(400))
        assert_that(x1, equal_to(600))
        assert_that(y0, equal_to(550))
        assert_that(y1, equal_to(650))

    def test_calc_cutout_internal_str(self):
        self.calculator = CutoutCalculator(100, 200)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((500, 600), self.imgsize)
        assert_that(x0, equal_to(400))
        assert_that(x1, equal_to(600))
        assert_that(y0, equal_to(550))
        assert_that(y1, equal_to(650))

    def test_calc_cutout_internal_str_float(self):
        self.calculator = CutoutCalculator(100, 200)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((500.00, 600.00), self.imgsize)
        assert_that(x0, equal_to(400))
        assert_that(x1, equal_to(600))
        assert_that(y0, equal_to(550))
        assert_that(y1, equal_to(650))

    def test_build_cutout_str(self):
        self.calculator = CutoutCalculator(100, 200)

        cutout_str, _ = self.calculator.build_cutout_str(15, (500, 600), self.imgsize)
        assert_that(cutout_str, equal_to("[15][400:600,550:650]"))

    def test_calc_cutout_internal_converter(self):
        self.calculator = CutoutCalculator(100, 200)

        _, converter = self.calculator.calc_cutout((500, 600), self.imgsize)
        assert_that(converter.convert((400, 550)), equal_to((0, 0)))
        assert_that(converter.convert((600, 550)), equal_to((200, 0)))
        assert_that(converter.convert((400, 650)), equal_to((0, 100)))
        assert_that(converter.convert((600, 650)), equal_to((200, 100)))
        assert_that(converter.convert((500, 600)), equal_to((100, 50)))

    def test_build_cutout_str_converter(self):
        self.calculator = CutoutCalculator(100, 200)

        _, converter = self.calculator.build_cutout_str(15, (500, 600), self.imgsize)
        assert_that(converter.convert((400, 550)), equal_to((0, 0)))
        assert_that(converter.convert((600, 550)), equal_to((200, 0)))
        assert_that(converter.convert((400, 650)), equal_to((0, 100)))
        assert_that(converter.convert((600, 650)), equal_to((200, 100)))
        assert_that(converter.convert((500, 600)), equal_to((100, 50)))

    def test_calc_cutout_boundary_x(self):
        self.calculator = CutoutCalculator(200, 200)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((50, 400), self.imgsize)
        assert_that(x0, equal_to(1))
        assert_that(x1, equal_to(201))
        assert_that(y0, equal_to(300))
        assert_that(y1, equal_to(500))

    def test_calc_cutout_boundary_y(self):
        self.calculator = CutoutCalculator(200, 200)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((400, 50), self.imgsize)
        assert_that(x0, equal_to(300))
        assert_that(x1, equal_to(500))
        assert_that(y0, equal_to(1))
        assert_that(y1, equal_to(201))

    def test_calc_cutout_boundary_x_converter(self):
        self.calculator = CutoutCalculator(200, 200)

        _, converter = self.calculator.build_cutout_str(15, (50, 400), self.imgsize)
        assert_that(converter.convert((51, 400)), equal_to((50, 100)))
        assert_that(converter.convert((1, 300)), equal_to((0, 0)))

    def test_calc_cutout_boundary_x_converter(self):
        self.calculator = CutoutCalculator(200, 200)

        _, converter = self.calculator.build_cutout_str(15, (400, 50), self.imgsize)
        assert_that(converter.convert((400, 51)), equal_to((100, 50)))
        assert_that(converter.convert((300, 1)), equal_to((0, 0)))

    def test_calc_cutout_boundary_xmax(self):
        self.imgsize = (200, 200)
        self.calculator = CutoutCalculator(100, 100)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((175, 100), self.imgsize)
        assert_that(x0, equal_to(100))
        assert_that(x1, equal_to(200))
        assert_that(y0, equal_to(50))
        assert_that(y1, equal_to(150))

    def test_calc_cutout_boundary_ymax(self):
        self.imgsize = (200, 200)
        self.calculator = CutoutCalculator(100, 100)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((100, 175), self.imgsize)
        assert_that(x0, equal_to(50))
        assert_that(x1, equal_to(150))
        assert_that(y0, equal_to(100))
        assert_that(y1, equal_to(200))

    def test_calc_cutout_boundary_xmax_converter(self):
        self.imgsize = (200, 200)
        self.calculator = CutoutCalculator(100, 100)

        _, converter = self.calculator.calc_cutout((175, 100), self.imgsize)
        assert_that(converter.convert((175, 100)), equal_to((75, 50)))
        assert_that(converter.convert((100, 50)), equal_to((0, 0)))
        assert_that(converter.convert((200, 150)), equal_to((100, 100)))

    def test_calc_cutout_boundary_ymax_converter(self):
        self.imgsize = (200, 200)
        self.calculator = CutoutCalculator(100, 100)

        _, converter = self.calculator.calc_cutout((100, 175), self.imgsize)
        assert_that(converter.convert((100, 175)), equal_to((50, 75)))
        assert_that(converter.convert((50, 100)), equal_to((0, 0)))
        assert_that(converter.convert((150, 200)), equal_to((100, 100)))

    def test_calc_cutout_inverted(self):
        self.calculator = CutoutCalculator(20, 20)

        (x0, x1, y0, y1), _ = self.calculator.calc_cutout((20, 20), (200, 200),
                                                          inverted=True)
        assert_that(x0, equal_to(190))
        assert_that(x1, equal_to(170))
        assert_that(y0, equal_to(190))
        assert_that(y1, equal_to(170))

    def test_calc_cutout_inverted_converter(self):
        self.calculator = CutoutCalculator(20, 20)

        _, converter = self.calculator.calc_cutout((20, 20), (200, 200),
                                                   inverted=True)
        assert_that(converter.convert((10, 10)), equal_to((0, 0)))
        assert_that(converter.convert((30, 10)), equal_to((20, 0)))
        assert_that(converter.convert((10, 30)), equal_to((0, 20)))
        assert_that(converter.convert((30, 30)), equal_to((20, 20)))
        assert_that(converter.convert((20, 20)), equal_to((10, 10)))

    def test_build_cutout_str_inverted(self):
        self.calculator = CutoutCalculator(20, 20)

        cutout_str, _ = self.calculator.build_cutout_str("10", (20, 20), (200, 200),
                                                         inverted=True)
        assert_that(cutout_str, equal_to("[10][190:170,190:170]"))
Пример #13
0
    def test_build_cutout_str(self):
        self.calculator = CutoutCalculator(100, 200)

        cutout_str, _ = self.calculator.build_cutout_str(15, (500, 600), self.imgsize)
        assert_that(cutout_str, equal_to("[15][400:600,550:650]"))
Пример #14
0
    def test_build_cutout_str_inverted(self):
        self.calculator = CutoutCalculator(20, 20)

        cutout_str, _ = self.calculator.build_cutout_str("10", (20, 20), (200, 200),
                                                         inverted=True)
        assert_that(cutout_str, equal_to("[10][190:170,190:170]"))
Пример #15
0
class ImageSliceDownloader(object):
    """
    Downloads a slice of an image relevant to examining a (potential) source.
    """
    def __init__(self, slice_rows=None, slice_cols=None, vosclient=None):
        """
        Constructor.

        Args:
          resolver:
            Resolves source readings to the URI's from which they can be
            retrieved.
          slice_rows, slice_cols: int
            The number of rows and columns (pixels) to slice out around the
            source.  Leave as None to use default configuration values.
        """
        # If not provided, read defaults from application config file
        if slice_rows is None:
            slice_rows = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_ROWS")
        if slice_cols is None:
            slice_cols = config.read("IMG_RETRIEVAL.DEFAULT_SLICE_COLS")

        self.slice_rows = slice_rows
        self.slice_cols = slice_cols

        if vosclient is None:
            self.vosclient = vos.Client(cadc_short_cut=True)
        else:
            self.vosclient = vosclient

        self.cutout_calculator = CutoutCalculator(slice_rows, slice_cols)

    def _download_fits_file(self, downloadable_item):
        cutout_str, converter = self.cutout_calculator.build_cutout_str(
            downloadable_item.get_extension(),
            downloadable_item.get_focal_point(),
            downloadable_item.get_full_image_size(),
            inverted=downloadable_item.is_inverted())

        vofile = self.vosclient.open(downloadable_item.get_image_uri(),
                                     view="cutout",
                                     cutout=cutout_str)

        return vofile.read(), converter

    def _download_apcor_file(self, downloadable_item):
        vofile = self.vosclient.open(downloadable_item.get_apcor_uri(),
                                     view="data")
        return vofile.read()

    def download(self, downloadable_item):
        """
        Retrieves a remote image.

        Args:
          downloadable_item: DownloadableItem
            Specification for the item to be downloaded.

        Returns:
          fitsimage: ossos.gui.image.DownloadedFitsImage
            The downloaded image, either in-memory or on disk as specified.
        """
        fits_str, converter = self._download_fits_file(downloadable_item)

        if downloadable_item.needs_apcor:
            apcor_str = self._download_apcor_file(downloadable_item)
        else:
            apcor_str = None

        return DownloadedFitsImage(fits_str,
                                   converter,
                                   apcor_str,
                                   in_memory=downloadable_item.in_memory)

    def refresh_vos_client(self):
        """
        If we have gotten a new certfile we have to create a new Client
        object before it will get used.
        """
        self.vosclient = vos.Client(cadc_short_cut=True)