예제 #1
0
파일: test_snapshot.py 프로젝트: ijiraq/MOP
class SourceSnapshotTest(FileReadingTestCase):
    def setUp(self):
        test_file = "data/image_reading/realstest2.measure3.reals.astrom"
        astrom_data = AstromParser().parse(self.get_abs_path(test_file))

        self.reading = astrom_data.get_sources()[0].get_reading(0)
        self.original_observed_x = self.reading.x
        self.original_observed_y = self.reading.y

        self.offset_x = 10
        self.offset_y = 15
        coordinate_converter = CoordinateConverter(self.offset_x,
                                                   self.offset_y)

        self.undertest = SourceCutout(self.reading, Mock())

        self.mock_update_ra_dec = Mock()
        self.undertest._update_ra_dec = self.mock_update_ra_dec

    def assert_update_ra_dec_call_count_equals(self, expected_calls):
        assert_that(self.mock_update_ra_dec.call_count,
                    equal_to(expected_calls))

    def test_xy_coordinate_systems(self):
        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y))

        expected_pixel_x = self.original_observed_x - self.offset_x
        expected_pixel_y = self.original_observed_y - self.offset_y

        assert_that(self.undertest.pixel_x, equal_to(expected_pixel_x))
        assert_that(self.undertest.pixel_y, equal_to(expected_pixel_y))

        assert_that(
            self.undertest.observed_source_point,
            equal_to((self.original_observed_x, self.original_observed_y)))
        assert_that(self.undertest.pixel_source_point,
                    equal_to((expected_pixel_x, expected_pixel_y)))

    def test_xy_adjusted(self):
        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y))

        assert_that(self.undertest.is_adjusted(), equal_to(False))

        diff_x = 2.5
        diff_y = 3.5

        new_pixel_x = self.undertest.pixel_x + diff_x
        new_pixel_y = self.undertest.pixel_y + diff_y

        self.undertest.update_pixel_location((new_pixel_x, new_pixel_y))

        assert_that(self.undertest.pixel_x, equal_to(new_pixel_x))
        assert_that(self.undertest.pixel_y, equal_to(new_pixel_y))

        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x + diff_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y + diff_y))

        assert_that(self.undertest.is_adjusted(), equal_to(True))

    def test_update_xy_updates_ra_dec(self):
        self.assert_update_ra_dec_call_count_equals(0)

        self.undertest.update_pixel_location((665.0, 3215.0))

        _ = self.undertest.dec

        self.assert_update_ra_dec_call_count_equals(1)

    def test_ra_dec_updates_lazilly(self):
        self.assert_update_ra_dec_call_count_equals(0)

        self.undertest.update_pixel_location((665.0, 3215.0))

        self.assert_update_ra_dec_call_count_equals(0)

        self.undertest.update_pixel_location((665.0, 3218.0))

        self.assert_update_ra_dec_call_count_equals(0)

        _ = self.undertest.ra

        self.assert_update_ra_dec_call_count_equals(1)

        _ = self.undertest.dec

        self.assert_update_ra_dec_call_count_equals(1)

        self.undertest.update_pixel_location((667.2, 3216.6))

        self.assert_update_ra_dec_call_count_equals(1)

        _ = self.undertest.dec
        _ = self.undertest.ra

        self.assert_update_ra_dec_call_count_equals(2)

    def test_original_xy(self):
        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y))

        assert_that(self.undertest.original_observed_x,
                    equal_to(self.original_observed_x))
        assert_that(self.undertest.original_observed_y,
                    equal_to(self.original_observed_y))

        diff_x = 2.5
        diff_y = 3.5

        new_pixel_x = self.undertest.pixel_x + diff_x
        new_pixel_y = self.undertest.pixel_y + diff_y

        self.undertest.update_pixel_location((new_pixel_x, new_pixel_y))

        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x + diff_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y + diff_y))

        assert_that(self.undertest.original_observed_x,
                    equal_to(self.original_observed_x))
        assert_that(self.undertest.original_observed_y,
                    equal_to(self.original_observed_y))

    def test_reset_location(self):
        original_pixel_x, original_pixel_y = self.undertest.pixel_source_point

        diff_x = 2.5
        diff_y = 3.5
        new_pixel_x = self.undertest.pixel_x + diff_x
        new_pixel_y = self.undertest.pixel_y + diff_y

        self.undertest.update_pixel_location((new_pixel_x, new_pixel_y))

        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x + diff_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y + diff_y))

        assert_that(self.undertest.pixel_x, equal_to(new_pixel_x))
        assert_that(self.undertest.pixel_y, equal_to(new_pixel_y))

        self.undertest.reset_source_location()

        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y))

        assert_that(self.undertest.pixel_x, equal_to(original_pixel_x))
        assert_that(self.undertest.pixel_y, equal_to(original_pixel_y))

    def test_reset_location_is_adjusted_false(self):
        assert_that(self.undertest.is_adjusted(), equal_to(False))

        self.undertest.update_pixel_location((100, 100))

        assert_that(self.undertest.is_adjusted(), equal_to(True))

        self.undertest.reset_source_location()

        assert_that(self.undertest.is_adjusted(), equal_to(False))

    def test_reset_location_makes_data_stale(self):
        self.assert_update_ra_dec_call_count_equals(0)

        self.undertest.update_pixel_location((665.0, 3215.0))

        _ = self.undertest.ra

        self.assert_update_ra_dec_call_count_equals(1)

        self.undertest.reset_source_location()

        self.assert_update_ra_dec_call_count_equals(1)

        _ = self.undertest.ra

        self.assert_update_ra_dec_call_count_equals(2)
예제 #2
0
class SourceSnapshotIntegrationTest(FileReadingTestCase):
    def path(self, relative):
        return self.get_abs_path("data/image_reading/%s" % relative)

    def setUp(self):
        test_file = self.path("realstest2.measure3.reals.astrom")
        astrom_data = AstromParser().parse(test_file)

        self.reading = astrom_data.get_sources()[0].get_reading(0)

        # Load the real image
        hdulist = fits.open(self.path("cutout-1616687p.fits"))

        with open(self.path("1616687p10.apcor")) as fh:
            apcor = ApcorData.from_string(fh.read())

        # NOTE: the test image
        # vos://cadc.nrc.ca~vospace/OSSOS/dbimages/1616687/1616687p.fits
        # has cutout: [11][1449:1199,1429:1179] and is inverted.
        #
        # Therefore the first reading at (772.13, 3334.70) in observed
        # coordinates is at
        # (NAX1 - max cutout x, NAX2 - max cutout y)
        #  = (2112 - 1449, 4644 - 1429) = (663, 3215)
        self.original_pixel_x = 663
        self.original_pixel_y = 3215

        self.original_observed_x = 772.13
        self.original_observed_y = 3334.70

        x_offset = self.original_observed_x - self.original_pixel_x
        y_offset = self.original_observed_y - self.original_pixel_y

        self.undertest = SourceCutout(self.reading, hdulist,
                                      CoordinateConverter(x_offset, y_offset),
                                      apcor=apcor)

        assert_that(self.undertest.observed_x, equal_to(self.original_observed_x))
        assert_that(self.undertest.observed_y, equal_to(self.original_observed_y))

        assert_that(self.undertest.pixel_x, equal_to(self.original_pixel_x))
        assert_that(self.undertest.pixel_y, equal_to(self.original_pixel_y))

    @patch("ossos.wcs.xy2sky")
    def test_update_ra_dec(self, mock_xy2sky):
        new_ra = 2000.0
        new_dec = -11.0
        mock_xy2sky.return_value = (new_ra, new_dec)

        diff_x = 5.5
        diff_y = 4.5
        new_pixel_x = self.original_pixel_x + diff_x
        new_pixel_y = self.original_pixel_y + diff_y

        self.undertest.update_pixel_location((new_pixel_x, new_pixel_y))

        assert_that(self.undertest.ra, equal_to(new_ra))
        assert_that(self.undertest.dec, equal_to(new_dec))

        # Check it was called with the correct values:
        #   x, y, crpix1, crpix2, crval1, crval2, cd, pv, nord

        # These values from FITS header:

        crpix1 = 6.779623933420000E+03
        crpix2 = -3.343209710100000E+03

        crval1 = 211.828420000
        crval2 = -11.8333100000

        # CD1_1, CD1_2, CD2_1, CD2_2
        cd = [[-5.156837193510000E-05, -3.588985558218000E-07],
              [-1.674871346376000E-07, 5.178515755263000E-05]]

        # PV1_0 - PV1_10, PV2_0 - PV2_10
        pv = [[-1.909806626877E-03, 1.00815723310, 1.983393486250E-03,
               0.00000000000, 4.623172227977E-05, -1.020423075276E-05,
               2.258600565396E-05, -2.354656733463E-02, -1.671912720931E-04,
               -2.339051960031E-02, -2.903290518437E-05],
              [-7.294883106769E-04, 1.00392029973, 1.983331686156E-03,
               0.00000000000, 3.022667872225E-05, 4.509364811534E-05,
               -5.385195875663E-06, -2.333221106141E-02, -1.789051786060E-04,
               -2.348803123711E-02, -2.465552723903E-05]]

        # NORDFIT
        nord = 3

        # NOTE: the x and y passed in must be the updated OBSERVED coordinates
        mock_xy2sky.assert_called_once_with(
            new_pixel_x, new_pixel_y,
            crpix1, crpix2, crval1, crval2,
            cd, pv, nord)

    @patch("ossos.daophot.phot_mag")
    def test_get_observed_magnitude(self, mock_phot_mag):
        self.undertest.get_observed_magnitude()

        # NOTE: the x and y passed in must be the PIXEL coordinates
        mock_phot_mag.assert_called_once_with(
            ANY,
            self.original_pixel_x,
            self.original_pixel_y,
            aperture=5.0,
            sky=21.0,
            swidth=5.0,
            apcor=0.23,
            maxcount=30000.0)
예제 #3
0
class SourceSnapshotTest(FileReadingTestCase):
    def setUp(self):
        test_file = "data/image_reading/realstest2.measure3.reals.astrom"
        astrom_data = AstromParser().parse(self.get_abs_path(test_file))

        self.reading = astrom_data.get_sources()[0].get_reading(0)
        self.original_observed_x = self.reading.x
        self.original_observed_y = self.reading.y

        self.offset_x = 10
        self.offset_y = 15
        coordinate_converter = CoordinateConverter(self.offset_x, self.offset_y)

        self.undertest = SourceCutout(self.reading, Mock(), coordinate_converter)

        self.mock_update_ra_dec = Mock()
        self.undertest._update_ra_dec = self.mock_update_ra_dec

    def assert_update_ra_dec_call_count_equals(self, expected_calls):
        assert_that(self.mock_update_ra_dec.call_count,
                    equal_to(expected_calls))

    def test_xy_coordinate_systems(self):
        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y))

        expected_pixel_x = self.original_observed_x - self.offset_x
        expected_pixel_y = self.original_observed_y - self.offset_y

        assert_that(self.undertest.pixel_x, equal_to(expected_pixel_x))
        assert_that(self.undertest.pixel_y, equal_to(expected_pixel_y))

        assert_that(self.undertest.observed_source_point,
                    equal_to((self.original_observed_x, self.original_observed_y)))
        assert_that(self.undertest.pixel_source_point,
                    equal_to((expected_pixel_x, expected_pixel_y)))

    def test_xy_adjusted(self):
        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y))

        assert_that(self.undertest.is_adjusted(), equal_to(False))

        diff_x = 2.5
        diff_y = 3.5

        new_pixel_x = self.undertest.pixel_x + diff_x
        new_pixel_y = self.undertest.pixel_y + diff_y

        self.undertest.update_pixel_location((new_pixel_x, new_pixel_y))

        assert_that(self.undertest.pixel_x, equal_to(new_pixel_x))
        assert_that(self.undertest.pixel_y, equal_to(new_pixel_y))

        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x + diff_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y + diff_y))

        assert_that(self.undertest.is_adjusted(), equal_to(True))

    def test_update_xy_updates_ra_dec(self):
        self.assert_update_ra_dec_call_count_equals(0)

        self.undertest.update_pixel_location((665.0, 3215.0))

        _ = self.undertest.dec

        self.assert_update_ra_dec_call_count_equals(1)

    def test_ra_dec_updates_lazilly(self):
        self.assert_update_ra_dec_call_count_equals(0)

        self.undertest.update_pixel_location((665.0, 3215.0))

        self.assert_update_ra_dec_call_count_equals(0)

        self.undertest.update_pixel_location((665.0, 3218.0))

        self.assert_update_ra_dec_call_count_equals(0)

        _ = self.undertest.ra

        self.assert_update_ra_dec_call_count_equals(1)

        _ = self.undertest.dec

        self.assert_update_ra_dec_call_count_equals(1)

        self.undertest.update_pixel_location((667.2, 3216.6))

        self.assert_update_ra_dec_call_count_equals(1)

        _ = self.undertest.dec
        _ = self.undertest.ra

        self.assert_update_ra_dec_call_count_equals(2)

    def test_original_xy(self):
        assert_that(self.undertest.observed_x, equal_to(self.original_observed_x))
        assert_that(self.undertest.observed_y, equal_to(self.original_observed_y))

        assert_that(self.undertest.original_observed_x,
                    equal_to(self.original_observed_x))
        assert_that(self.undertest.original_observed_y,
                    equal_to(self.original_observed_y))

        diff_x = 2.5
        diff_y = 3.5

        new_pixel_x = self.undertest.pixel_x + diff_x
        new_pixel_y = self.undertest.pixel_y + diff_y

        self.undertest.update_pixel_location((new_pixel_x, new_pixel_y))

        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x + diff_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y + diff_y))

        assert_that(self.undertest.original_observed_x,
                    equal_to(self.original_observed_x))
        assert_that(self.undertest.original_observed_y,
                    equal_to(self.original_observed_y))

    def test_reset_location(self):
        original_pixel_x, original_pixel_y = self.undertest.pixel_source_point

        diff_x = 2.5
        diff_y = 3.5
        new_pixel_x = self.undertest.pixel_x + diff_x
        new_pixel_y = self.undertest.pixel_y + diff_y

        self.undertest.update_pixel_location((new_pixel_x, new_pixel_y))

        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x + diff_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y + diff_y))

        assert_that(self.undertest.pixel_x, equal_to(new_pixel_x))
        assert_that(self.undertest.pixel_y, equal_to(new_pixel_y))

        self.undertest.reset_source_location()

        assert_that(self.undertest.observed_x,
                    equal_to(self.original_observed_x))
        assert_that(self.undertest.observed_y,
                    equal_to(self.original_observed_y))

        assert_that(self.undertest.pixel_x, equal_to(original_pixel_x))
        assert_that(self.undertest.pixel_y, equal_to(original_pixel_y))

    def test_reset_location_is_adjusted_false(self):
        assert_that(self.undertest.is_adjusted(), equal_to(False))

        self.undertest.update_pixel_location((100, 100))

        assert_that(self.undertest.is_adjusted(), equal_to(True))

        self.undertest.reset_source_location()

        assert_that(self.undertest.is_adjusted(), equal_to(False))

    def test_reset_location_makes_data_stale(self):
        self.assert_update_ra_dec_call_count_equals(0)

        self.undertest.update_pixel_location((665.0, 3215.0))

        _ = self.undertest.ra

        self.assert_update_ra_dec_call_count_equals(1)

        self.undertest.reset_source_location()

        self.assert_update_ra_dec_call_count_equals(1)

        _ = self.undertest.ra

        self.assert_update_ra_dec_call_count_equals(2)