Example #1
0
    def test_error_radius_value(self):
        # Demonstrate that we calculate the expected value for the error
        # radius
        self.p.values['xbar'] = Uncertain(1025, 1)
        self.p.values['ybar'] = Uncertain(1025, 1)
        d_ncp = Detection(self.p, self.ncp_image)

        # cdelt gives the per-pixel increment along the axis in degrees
        # Detection.error_radius is in arcsec
        expected_error_radius = math.sqrt(
            (self.p.values['xbar'].error * self.ncp_image.wcs.cdelt[0] *
             3600)**2 + (self.p.values['ybar'].error *
                         self.ncp_image.wcs.cdelt[1] * 3600)**2)

        self.assertAlmostEqual(d_ncp.error_radius, expected_error_radius, 6)
Example #2
0
def get_paramset():
    paramset = ParamSet()
    paramset.sig = 1
    paramset.values = {
        'peak': Uncertain(10, 0),
        'flux': Uncertain(10, 0),
        'semimajor': Uncertain(10, 1),
        'semiminor': Uncertain(10, 1),
        'theta': Uncertain(0, 1),
        'semimaj_deconv': Uncertain(10, 1),
        'semimin_deconv': Uncertain(10, 1),
        'theta_deconv': Uncertain(10, 1),
        'xbar': Uncertain(10, 1),
        'ybar': Uncertain(10, 1)
    }
    return paramset
Example #3
0
 def test_castable_to_floating_point(self):
     """
     float(Uncertain(int(x))) should not raise.
     """
     x = Uncertain(int(0), int(0))
     self.assertFalse(isinstance(x.value, float))
     self.assertFalse(isinstance(x.error, float))
     float(x)
Example #4
0
    def testErrorBoxOverlapsEdge(self):
        """
        Error box overflows image

        Sometimes when fitting at a fixed position, we get extremely large
        uncertainty values.  These create an error box on position which
        extends outside the image, causing errors when we try to calculate the
        RA / Dec uncertainties.  This test ensures we handle this case
        gracefully.
        """
        img = self.image

        fake_params = tkp.sourcefinder.extract.ParamSet()
        fake_params.values.update({
            'peak': Uncertain(0.0, 0.5),
            'flux': Uncertain(0.0, 0.5),
            'xbar': Uncertain(5.5, 10000.5),  # Danger Will Robinson
            'ybar': Uncertain(5.5, 3),
            'semimajor': Uncertain(4, 200),
            'semiminor': Uncertain(4, 2),
            'theta': Uncertain(30, 10),
        })
        fake_params.sig = 0
        det = tkp.sourcefinder.extract.Detection(fake_params, img)
        #Raises runtime error prior to bugfix for issue #3294
        det._physical_coordinates()
        self.assertEqual(det.ra.error, float('inf'))
        self.assertEqual(det.dec.error, float('inf'))
Example #5
0
    def test_ra_error_scaling(self):
        # Demonstrate that RA errors scale with declination.
        # See HipChat discussion of 2013-08-28.
        # Values of all parameters are dummies except for the pixel position.
        # First, construct a source at the NCP
        self.p.values['xbar'] = Uncertain(1025, 1)
        self.p.values['ybar'] = Uncertain(1025, 1)
        d_ncp = Detection(self.p, self.ncp_image)

        # Then construct a source somewhere away from the NCP
        self.p.values['xbar'] = Uncertain(125, 1)
        self.p.values['ybar'] = Uncertain(125, 1)
        d_not_ncp = Detection(self.p, self.ncp_image)

        # One source is at higher declination
        self.assertGreater(d_ncp.dec.value, d_not_ncp.dec.value)

        # The RA error at higher declination must be greater
        self.assertGreater(d_ncp.ra.error, d_not_ncp.ra.error)
Example #6
0
    def testPositions(self):
        # The pixel position x, y of the source should be the same as the
        # position of the maximum in the generated result map.
        x_pos = 40
        y_pos = 60

        empty_data = numpy.zeros((100, 100))
        SrcMeasurement = namedtuple(
            "SrcMeasurement", ['peak', 'x', 'y', 'smaj', 'smin', 'theta'])
        src_measurement = SrcMeasurement(peak=Uncertain(10),
                                         x=Uncertain(x_pos),
                                         y=Uncertain(y_pos),
                                         smaj=Uncertain(10),
                                         smin=Uncertain(10),
                                         theta=Uncertain(0))
        gaussian_map, residual_map = generate_result_maps(
            empty_data, [src_measurement])
        gaussian_max_x = numpy.where(gaussian_map == gaussian_map.max())[0][0]
        gaussian_max_y = numpy.where(gaussian_map == gaussian_map.max())[1][0]

        self.assertEqual(gaussian_max_x, x_pos)
        self.assertEqual(gaussian_max_y, y_pos)
Example #7
0
 def test_error_radius_with_dec(self):
     self.p.values['xbar'] = Uncertain(1025, 1)
     self.p.values['ybar'] = Uncertain(1025, 1)
     d_ncp = Detection(self.p, self.ncp_image)
     d_equator = Detection(self.p, self.equator_image)
     self.assertEqual(d_ncp.error_radius, d_equator.error_radius)