예제 #1
0
def test_crop_data():
    ones = np.ones((201, 201))
    assert ones.sum() == 40401.

    cropped01 = img_utils.crop_data(
        ones, verbose=False)  # False to exercise coverage.
    assert cropped01.sum() == 40000.

    cropped02 = img_utils.crop_data(ones, verbose=True, box_width=10)
    assert cropped02.sum() == 100.

    cropped03 = img_utils.crop_data(ones,
                                    verbose=True,
                                    box_width=6,
                                    center=(50, 50))
    assert cropped03.sum() == 36.

    # Test the Cutout2D object
    cropped04 = img_utils.crop_data(ones,
                                    verbose=True,
                                    box_width=20,
                                    center=(50, 50),
                                    data_only=False)
    assert isinstance(cropped04, Cutout2D)
    assert cropped04.position_original == (50, 50)

    # Box is 20 pixels wide so center is at 10,10
    assert cropped04.position_cutout == (10, 10)
예제 #2
0
def test_crop_data():
    ones = np.ones((201, 201))
    assert ones.sum() == 40401.

    cropped01 = img_utils.crop_data(ones, verbose=True)
    assert cropped01.sum() == 40000.

    cropped02 = img_utils.crop_data(ones, verbose=True, box_width=10)
    assert cropped02.sum() == 100.

    cropped03 = img_utils.crop_data(ones,
                                    verbose=True,
                                    box_width=6,
                                    center=(50, 50))
    assert cropped03.sum() == 36.
예제 #3
0
파일: camera.py 프로젝트: ASTROGBAE/POCS
    def get_cutout(self,
                   seconds,
                   file_path,
                   cutout_size,
                   keep_file=False,
                   *args,
                   **kwargs):
        """
        Takes an image and returns a thumbnail cutout.

        Takes an image, grabs the data, deletes the FITS file and
        returns a cutout from the centre of the image.

        Args:
            seconds (astropy.units.Quantity): exposure time, Quantity or numeric type in seconds.
            file_path (str): path to (temporarily) save the image file to.
            cutout_size (int): size of the square region of the centre of the image to return.
            keep_file (bool, optional): if True the image file will be deleted, if False it will
                be kept.
            *args, **kwargs: passed to the `take_exposure` method
        """
        kwargs['blocking'] = True
        self.take_exposure(seconds, filename=file_path, *args, **kwargs)
        if self.exposure_error is not None:
            raise error.PanError(self.exposure_error)
        image = fits.getdata(file_path)
        if not keep_file:
            os.unlink(file_path)

        # Make sure cutout is not bigger than image.
        actual_size = min(cutout_size, *image.shape)
        if actual_size != cutout_size:  # noqa
            self.logger.warning(
                f'Requested cutout size is larger than image, using {actual_size}'
            )

        return img_utils.crop_data(image, box_width=cutout_size)