Exemplo n.º 1
0
    def test_bias_frame_subtraction(self):
        bias_file = 'bias_image.fits'
        bias_func_x = lambda x: 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)
Exemplo n.º 2
0
 def setUp(self):
     "Set the physical pixels and columns to mask."
     self.template_file = 'template_frame.fits'
     ccd = sim_tools.CCD()
     ccd.writeto(self.template_file)
     self.mask_file = 'test_mask_file.fits'
     # These are physical pixel coordinates in the imaging section,
     # i.e., prescan pixels are not included in the x-coordinate.
     self.pixels = dict([(1, [(200, 1000), (500, 300), (140, 1499)]),
                         (2, [(342, 6), (50, 2), (403, 11), (420, 12)])])
     self.columns = dict([(1, (120, 212, 320, 432))])
Exemplo n.º 3
0
 def setUpClass(cls):
     cls.amp_geom = AmplifierGeometry()
     cls.bias_image = afwImage.ImageF(cls.amp_geom.full_segment)
     imarr = cls.bias_image.getArray()
     ny, nx = imarr.shape
     yvals = np.arange(0, ny, dtype=np.float)
     bias_func = BiasFunc(cls.bias_slope, cls.bias_intercept)
     for x in range(nx):
         imarr[:, x] += bias_func(yvals)
     ccd = sim_tools.CCD(exptime=cls.exptime, gain=cls.gain)
     for amp in ccd.segments:
         ccd.segments[amp].image += cls.bias_image
     ccd.writeto(cls.image_file)
Exemplo n.º 4
0
    def setUp(self):
        self.flat_file1 = 'brighter_fatter_test1.fits'
        self.flat_file2 = 'brighter_fatter_test2.fits'
        self.emin = 10
        self.exptime = 10
        self.gain = 5
        self.ccdtemp = -100
        self.maxLag = 1
        self.nSigmaClip = 3
        self.backgroundBinSize = 128
        self.bias_level, self.bias_sigma = 1e2, 4
        self.ccd1 = sim_tools.CCD(exptime=self.exptime,
                                  gain=self.gain,
                                  ccdtemp=self.ccdtemp)
        self.ccd1.add_bias(self.bias_level, self.bias_sigma)

        self.ccd1.writeto(self.flat_file1)
        self.ccd2 = sim_tools.CCD(exptime=self.exptime,
                                  gain=self.gain,
                                  ccdtemp=self.ccdtemp)
        self.ccd2.add_bias(self.bias_level, self.bias_sigma)

        self.ccd2.writeto(self.flat_file2)
Exemplo n.º 5
0
 def setUp(self):
     """
     Create a CCD frame FITS file with known imaging and overscan
     values.
     """
     self.fits_file = 'eper_parallel_test_frame.fits'
     ccd = sim_tools.CCD()
     for amp in ccd.segments:
         segment = ccd.segments[amp]
         segment.imarr[-1, :] = self.imaging_value
         overscan_region = segment.geometry.parallel_overscan
         overscan = segment.image.Factory(segment.image,
                                          overscan_region).getArray()
         overscan[0:self.overscans, :] = self.overscan_value
     ccd.writeto(self.fits_file)
Exemplo n.º 6
0
 def test_rolloff_mask(self):
     for amp_geom in self.amp_geoms:
         ccd = sim_tools.CCD(geometry=amp_geom)
         ccd.writeto(self.input_file, bitpix=16)
         rolloff_mask(self.input_file,
                      self.mask_file,
                      tmp_mask_image=self.image_file,
                      outer_edge_width=self.outer_edge_width,
                      bloom_stop_width=self.bloom_stop_width,
                      signal=self.signal,
                      cleanup=False)
         image = _FitsFile(self.image_file)
         mask = _FitsFile(self.mask_file)
         ymin = amp_geom.imaging.getMinY()
         ymax = amp_geom.imaging.getMaxY()
         for amp in imutils.allAmps(self.input_file):
             #
             # Unmasked region.
             #
             indx = np.where(image[amp] == 0)
             #
             # Verify expected sensor perimeter mask along vertical sides.
             #
             self.assertEqual(min(indx[0]), ymin + self.outer_edge_width)
             #
             # Verify that mask has zero bits set in unmasked region.
             #
             self.assertEqual(min(mask[amp][indx].flat), 0)
             self.assertEqual(max(mask[amp][indx].flat), 0)
             #
             # Check that mask area is subset of mask image area.
             #
             indx = np.where(mask[amp] != 0)
             self.assertTrue(min(image[amp][indx].flat) >= self.signal)
         # Check masked regions along sensor edges for amps 1, 8, 9, 16:
         if amp_geom.vendor == 'E2V':
             for amp in (1, 9):
                 self.assertGreaterEqual(image[amp][ymax, -1], self.signal)
             for amp in (8, 16):
                 self.assertGreaterEqual(image[amp][ymax, 0], self.signal)
         if amp_geom.vendor == 'ITL':
             for amp in (1, 16):
                 self.assertGreaterEqual(image[amp][ymax, -1], self.signal)
             for amp in (8, 9):
                 self.assertGreaterEqual(image[amp][ymax, 0], self.signal)
Exemplo n.º 7
0
def generate_crosstalk_frame(aggressor,
                             dn,
                             x,
                             y,
                             radius,
                             xtalk_frac=None,
                             nom_frac=0.1):
    if xtalk_frac is None:
        xtalk_frac = dict([(amp, nom_frac) for amp in imutils.allAmps])
    ccd = sim_tools.CCD()
    ccd.add_bias()
    ccd.add_dark_current()
    for amp in ccd.segments:
        if amp == aggressor:
            ccd.segments[amp].add_spot_image(dn, x, y, radius)
        else:
            ccd.segments[amp].add_spot_image(dn * xtalk_frac[amp], x, y,
                                             radius)
    return ccd
Exemplo n.º 8
0
 def setUp(self):
     self.dark_file = 'bright_columns_test.fits'
     self.emin = 10
     self.exptime = 10
     self.gain = 5
     self.ccdtemp = -100
     self.bias_level, self.bias_sigma = 1e2, 4
     self.dark_curr = 2e-3
     self.ccd = sim_tools.CCD(exptime=self.exptime,
                              gain=self.gain,
                              ccdtemp=self.ccdtemp)
     self.ccd.add_bias(self.bias_level, self.bias_sigma)
     self.ccd.add_dark_current(level=self.dark_curr)
     self.nsig = ((self.emin * self.exptime / self.gain) /
                  self.ccd.segments[self.ccd.segments.keys()[0]].sigma())
     self.ncols = 10
     self.columns = self.ccd.generate_bright_cols(self.ncols)
     self.ccd.add_bright_cols(self.columns, nsig=self.nsig)
     self.ccd.writeto(self.dark_file)
Exemplo n.º 9
0
 def setUp(self):
     self.sflat_file = 'dark_columns_test.fits'
     self.emin = 10
     self.exptime = 10
     self.gain = 5
     self.ccdtemp = -100
     self.bias_level = 1e2
     self.bias_sigma = 4
     self.dark_curr = 2e-3
     self.frac_level = 0.5
     self.ccd = sim_tools.CCD(exptime=self.exptime,
                              gain=self.gain,
                              ccdtemp=self.ccdtemp)
     self.ccd.add_bias(self.bias_level, self.bias_sigma)
     self.ccd.add_dark_current(level=self.dark_curr)
     # For an exptime of 10, this should give about 2e5 e- per pixel.
     self.ccd.expose_flat(1e4)
     self.ncols = 10
     self.columns = self.ccd.generate_bright_cols(self.ncols)
     self.ccd.set_dark_cols(self.columns, self.frac_level)
     self.ccd.writeto(self.sflat_file)
Exemplo n.º 10
0
 def setUp(self):
     self.sflat_file = 'dark_pixels_test.fits'
     self.emin = 10
     self.exptime = 10
     self.gain = 5
     self.ccdtemp = -100
     self.bias_level = 1e2
     self.bias_sigma = 4
     self.dark_curr = 2e-3
     self.frac_level = 0.5
     self.ccd = sim_tools.CCD(exptime=self.exptime,
                              gain=self.gain,
                              ccdtemp=self.ccdtemp)
     self.ccd.add_bias(self.bias_level, self.bias_sigma)
     self.ccd.add_dark_current(level=self.dark_curr)
     # For an exptime of 10, this should give about 2e5 e- per pixel.
     self.ccd.expose_flat(1e4)
     # Number of dark pixels per segment
     self.npix = 100
     # This just generates a mask of pixel locations for each amp.
     self.pixels = self.ccd.generate_bright_pix(self.npix)
     self.ccd.set_dark_pix(self.pixels, self.frac_level)
     self.ccd.writeto(self.sflat_file)