Пример #1
0
    def test_01_nonlinearity_task(self):
        """Run the NonlinearityTask"""
        task = NonlinearityTask()
        sensorid = 'RTM-022'
        task.run(sensorid,
                 _detrespfile,
                 outputfile=self.fits_file,
                 plotfile=None)

        nlc = NonlinearityCorrection.create_from_fits_file(self.fits_file)

        ccd_1 = MaskedCCD(_flat_frame, bias_frame=_bias_frame)
        ccd_2 = MaskedCCD(_flat_frame,
                          bias_frame=_bias_frame,
                          linearity_correction=nlc)

        img_1 = ccd_1.unbiased_and_trimmed_image(1)
        img_2 = ccd_2.unbiased_and_trimmed_image(1)

        mean_1 = afwMath.makeStatistics(img_1, afwMath.MEAN,
                                        ccd_1.stat_ctrl).getValue()
        mean_2 = afwMath.makeStatistics(img_2, afwMath.MEAN,
                                        ccd_2.stat_ctrl).getValue()

        self.assertAlmostEqual(mean_1, 40.724625956352185)
        self.assertAlmostEqual(mean_2, 40.724101151614555)
Пример #2
0
 def test_find_pixel_defects(self):
     ccd1 = MaskedCCD(self.flat_file1)
     ccd2 = MaskedCCD(self.flat_file2)
     for amp in ccd1:
         xcorr, xcorr_err = crossCorrelate(
             ccd1.unbiased_and_trimmed_image(amp),
             ccd2.unbiased_and_trimmed_image(amp), self.maxLag,
             self.nSigmaClip, self.backgroundBinSize)
         self.assertTrue(1 > xcorr[0][1] and 1 > xcorr[1][0])
Пример #3
0
    def test_bias_frame_subtraction(self):
        bias_file = 'bias_image.fits'

        def bias_func_x(x):
            return 100 * (np.sin(x / 509. * 2. * np.pi) + 1)

        bias_func_y = BiasFunc(self.bias_slope, self.bias_intercept)
        bias_ccd = sim_tools.CCD(exptime=self.exptime, gain=self.gain)
        for amp in bias_ccd.segments:
            imarr = bias_ccd.segments[amp].image.getArray()
            yvals = np.arange(0, imarr.shape[0], dtype=np.float)
            for x in range(imarr.shape[1]):
                imarr[:, x] += bias_func_x(x) + bias_func_y(yvals)
        bias_ccd.writeto(bias_file)

        image_file = 'image_file.fits'
        signal_level = 1000.
        image_ccd = sim_tools.CCD(exptime=self.exptime, gain=self.gain)
        for amp in image_ccd.segments:
            imarr = image_ccd.segments[amp].image.getArray()
            yvals = np.arange(0, imarr.shape[0], dtype=np.float)
            for x in range(imarr.shape[1]):
                imarr[:, x] +=\
                    bias_func_x(x) + bias_func_y(yvals)
            imaging_section = image_ccd.segments[amp].image.Factory(
                image_ccd.segments[amp].image, self.amp_geom.imaging)
            imaging_section += signal_level
        image_ccd.writeto(image_file)

        ccd = MaskedCCD(image_file, bias_frame=bias_file)
        for amp in ccd:
            image = ccd.unbiased_and_trimmed_image(amp)
            self.assertAlmostEqual(
                max(np.abs(image.getImage().getArray().ravel())) /
                signal_level, 1, 6)

        ccd = MaskedCCD(image_file)
        for amp in ccd:
            image = ccd.unbiased_and_trimmed_image(amp)
            self.assertTrue(
                max(np.abs(image.getImage().getArray().ravel())) /
                signal_level > 1.01)

        os.remove(bias_file)
        os.remove(image_file)
Пример #4
0
 def test_unbias_and_trim(self):
     ccd = MaskedCCD(self.image_file)
     for amp in ccd:
         #
         # Test of corresponding MaskedCCD method.
         #
         image = ccd.unbiased_and_trimmed_image(amp)
         imarr = image.getImage().getArray()
         self.assertTrue(max(np.abs(imarr.flat)) < 1e-6)
Пример #5
0
    def test_linearity_correction(self):
        """Linearity correction test."""
        def linearity_correction(amp, flux):
            """Set the correction to be the amp number times the flux."""
            return amp * flux

        np.random.seed(1000)
        ccd = MaskedCCD(self.image_file)
        ccd_corr = MaskedCCD(self.image_file,
                             linearity_correction=linearity_correction)
        for amp in ccd:
            # Check that the ratio of the corrected to uncorrected
            # flux is (almost) equal to the amp number.
            ratio = np.median(
                ccd_corr.unbiased_and_trimmed_image(
                    amp).getImage().array) / np.median(
                        ccd.unbiased_and_trimmed_image(amp).getImage().array)
            self.assertAlmostEqual(amp, ratio, places=5)
Пример #6
0
 def test_unbias_and_trim(self):
     ccd = MaskedCCD(self.image_file)
     for amp in ccd:
         image = imutils.unbias_and_trim(ccd[amp],
                                         self.amp_geom.serial_overscan,
                                         self.amp_geom.imaging)
         imarr = image.getImage().getArray()
         self.assertTrue(max(np.abs(imarr.flat)) < 1e-6)
         #
         # Test of corresponding MaskedCCD method.
         #
         image = ccd.unbiased_and_trimmed_image(amp)
         imarr = image.getImage().getArray()
         self.assertTrue(max(np.abs(imarr.flat)) < 1e-6)
Пример #7
0
 def test_unbias_and_trim(self):
     ccd = MaskedCCD(self.image_file)
     overscan = makeAmplifierGeometry(self.image_file)
     for amp in ccd:
         for method in ['mean', 'row', 'func', 'spline']:
             image = imutils.unbias_and_trim(ccd[amp],
                                             overscan.serial_overscan,
                                             bias_method=method,
                                             **self.kwargs)
             imarr = image.getImage().getArray()
             if method == 'mean':
                 self.assertTrue(max(np.abs(imarr.flat)) < 2)
             else:
                 self.assertTrue(max(np.abs(imarr.flat)) < 1e-6)
                 #
                 # Test of corresponding MaskedCCD method.
                 #
                 image = ccd.unbiased_and_trimmed_image(
                     amp, overscan.serial_overscan, **self.kwargs)
                 imarr = image.getImage().getArray()
                 self.assertTrue(max(np.abs(imarr.flat)) < 1e-6)