def setUp(self): """ Set up each test with a new PostageStampMaker object using the test FITS file, coordinates of the image center, and a postage stamp size of 10 arcsec. """ self.expfile = os.path.join(os.environ['TWINKLES_DIR'], 'tests', 'small_CoaddTempExp.fits.gz') self.stamp_maker = PostageStampMaker(self.expfile) center_coord = self.stamp_maker.center_coord(self.stamp_maker.exposure) self.ra = center_coord.getLongitude().asDegrees() self.dec = center_coord.getLatitude().asDegrees() self.size = 10
class PostageStampTestCase(unittest.TestCase): "TestCase class for PostageStampMaker module." def setUp(self): """ Set up each test with a new PostageStampMaker object using the test FITS file, coordinates of the image center, and a postage stamp size of 10 arcsec. """ self.expfile = os.path.join(os.environ['TWINKLES_DIR'], 'tests', 'small_CoaddTempExp.fits.gz') self.stamp_maker = PostageStampMaker(self.expfile) center_coord = self.stamp_maker.center_coord(self.stamp_maker.exposure) self.ra = center_coord.getLongitude().asDegrees() self.dec = center_coord.getLatitude().asDegrees() self.size = 10 def test_bbox_generation(self): "Test the make bounding box function." bbox = self.stamp_maker.makeBBox(self.ra, self.dec, self.size) self.assertEqual((bbox.getWidth(), bbox.getHeight()), (30, 30)) def test_stamp_size(self): "Test that the postage stamp has the expected size." my_exposure = self.stamp_maker.create(self.ra, self.dec, self.size) my_imarr = my_exposure.getMaskedImage().getImage().getArray() self.assertEqual(my_imarr.shape, (30, 30)) def test_stamp_central_pixel_value(self): """ Test that the center pixel of both the postage stamp and original image have the same value. """ my_exposure = self.stamp_maker.create(self.ra, self.dec, self.size) my_imarr = my_exposure.getMaskedImage().getImage().getArray() ref_exposure = self.stamp_maker.exposure ref_imarr = ref_exposure.getMaskedImage().getImage().getArray() self.assertEqual( my_imarr[int(my_imarr.shape[0] / 2)][int(my_imarr.shape[1] / 2)], ref_imarr[int(ref_imarr.shape[0] / 2)][int(ref_imarr.shape[1] / 2)]) def test_stamp_centers_match(self): """ Test that coordinates of the centers of the postage stamp and the original image are the same. """ my_exposure = self.stamp_maker.create(self.ra, self.dec, self.size) self.assertEqual( self.stamp_maker.center_coord(my_exposure), self.stamp_maker.center_coord(self.stamp_maker.exposure)) def test_create_array_of_stamps(self): """ Test that creates a sequence of stamps from the Exposure object given a sequence of (ra, dec, size) tuples and tests that the centers of the stamps are at the expected locations. """ pix_scale = self.stamp_maker.exposure.getWcs().pixelScale().asDegrees() npix = 10 stamp_specs = [(self.ra, self.dec - npix * pix_scale, self.size), (self.ra, self.dec, self.size), (self.ra, self.dec + npix * pix_scale, self.size)] my_stamps = self.stamp_maker.create_stamps(stamp_specs) self.assertEqual(len(my_stamps), len(stamp_specs)) for i, stamp in enumerate(my_stamps): coord = self.stamp_maker.center_coord(stamp) self.assertAlmostEqual(coord.getLongitude().asDegrees(), stamp_specs[i][0]) self.assertAlmostEqual(coord.getLatitude().asDegrees(), stamp_specs[i][1]) def test_create_sequence_function(self): """ For a given (ra, dec, size), test the create_postage_stamps function which returns a sequence of stamps for that sky region, extracted from a sequence of input Exposure FITS files. """ fits_files = [self.expfile] * 3 my_stamps = create_postage_stamps(self.ra, self.dec, self.size, fits_files) self.assertEqual(len(my_stamps), len(fits_files)) for stamp in my_stamps: self.assertTrue(isinstance(stamp, afwImage.ExposureF))
class PostageStampTestCase(unittest.TestCase): "TestCase class for PostageStampMaker module." def setUp(self): """ Set up each test with a new PostageStampMaker object using the test FITS file, coordinates of the image center, and a postage stamp size of 10 arcsec. """ self.expfile = os.path.join(os.environ['TWINKLES_DIR'], 'tests', 'small_CoaddTempExp.fits.gz') self.stamp_maker = PostageStampMaker(self.expfile) center_coord = self.stamp_maker.center_coord(self.stamp_maker.exposure) self.ra = center_coord.getLongitude().asDegrees() self.dec = center_coord.getLatitude().asDegrees() self.size = 10 def test_bbox_generation(self): "Test the make bounding box function." bbox = self.stamp_maker.makeBBox(self.ra, self.dec, self.size) self.assertEqual((bbox.getWidth(), bbox.getHeight()), (30, 30)) def test_stamp_size(self): "Test that the postage stamp has the expected size." my_exposure = self.stamp_maker.create(self.ra, self.dec, self.size) my_imarr = my_exposure.getMaskedImage().getImage().getArray() self.assertEqual(my_imarr.shape, (30, 30)) def test_stamp_central_pixel_value(self): """ Test that the center pixel of both the postage stamp and original image have the same value. """ my_exposure = self.stamp_maker.create(self.ra, self.dec, self.size) my_imarr = my_exposure.getMaskedImage().getImage().getArray() ref_exposure = self.stamp_maker.exposure ref_imarr = ref_exposure.getMaskedImage().getImage().getArray() self.assertEqual(my_imarr[my_imarr.shape[0]/2][my_imarr.shape[1]/2], ref_imarr[ref_imarr.shape[0]/2][ref_imarr.shape[1]/2]) def test_stamp_centers_match(self): """ Test that coordinates of the centers of the postage stamp and the original image are the same. """ my_exposure = self.stamp_maker.create(self.ra, self.dec, self.size) self.assertEqual(self.stamp_maker.center_coord(my_exposure), self.stamp_maker.center_coord(self.stamp_maker.exposure)) def test_create_array_of_stamps(self): """ Test that creates a sequence of stamps from the Exposure object given a sequence of (ra, dec, size) tuples and tests that the centers of the stamps are at the expected locations. """ pix_scale = self.stamp_maker.exposure.getWcs().pixelScale().asDegrees() npix = 10 stamp_specs = [(self.ra, self.dec - npix*pix_scale, self.size), (self.ra, self.dec, self.size), (self.ra, self.dec + npix*pix_scale, self.size)] my_stamps = self.stamp_maker.create_stamps(stamp_specs) self.assertEqual(len(my_stamps), len(stamp_specs)) for i, stamp in enumerate(my_stamps): coord = self.stamp_maker.center_coord(stamp) self.assertAlmostEqual(coord.getLongitude().asDegrees(), stamp_specs[i][0]) self.assertAlmostEqual(coord.getLatitude().asDegrees(), stamp_specs[i][1]) def test_create_sequence_function(self): """ For a given (ra, dec, size), test the create_postage_stamps function which returns a sequence of stamps for that sky region, extracted from a sequence of input Exposure FITS files. """ fits_files = [self.expfile]*3 my_stamps = create_postage_stamps(self.ra, self.dec, self.size, fits_files) self.assertEqual(len(my_stamps), len(fits_files)) for stamp in my_stamps: self.assertTrue(isinstance(stamp, afwImage.ExposureF))
%(ra_min)12.8f < psRa and psRa < %(ra_max)12.8f and %(dec_min)12.8f < psDecl and psDecl < %(dec_max)12.8f''' \ % locals() #query = """select objectId, psRa, psDecl from Object # where objectId=%(objectId)i or parentObjectId=%(objectId)i""" \ # % locals() objects = jc_desc.apply(query, lambda curs : [x for x in curs]) ids, ras, decs = zip(*objects) print query print "found", len(ids), "objects" plt.rcParams['figure.figsize'] = (15, 10) subplots = (231, 232, 233, 234, 235, 236) fig = None for subplot, band in zip(subplots, 'ugrizy'): coadd = PostageStampMaker(os.path.join('output_401', 'deepCoadd', band, '0/0,0.fits')) stamp = coadd.create(ra, dec, 2.*size_arcsec) outfile = 'stamp_%i.fits' % objectId stamp.writeFits(outfile) fits_obj = fits.open(outfile) fig, axes, norm = render_fits_image(fits_obj[1], title=outfile, subplot=subplot, fig=fig) axes.scatter(ras, decs, transform=axes.get_transform('icrs'), color='red', alpha=0.8) axes.scatter([ra], [dec], transform=axes.get_transform('icrs'), color='green') axes.set_title('%(objectId)i, %(band)s band coadd' % locals())
jc_desc = LsstDatabaseTable(**db_info) # Find all of the visits for the specified band. visits = jc_desc.apply('''select visitId from CcdVisit where filterName='%(band)s' order by visitId''' % locals(), lambda curs : [x[0] for x in curs]) # Find the coordinates of the object. ra, dec = jc_desc.apply('''select psRA, psDecl from Object where objectId=%(objectId)i''' % locals(), lambda curs : tuple([x for x in curs][0])) # Create the coadd postage stamp to get the normalization for the # individual stamp images. coadd = PostageStampMaker(os.path.join(level2_repo, 'deepCoadd', band, '0/0,0.fits')) stamp = coadd.create(ra, dec, size) hdu = convert_image_to_hdu(stamp) norm = image_norm(hdu.data*scaling_factor) fig, axes, norm = render_fits_image(hdu) plt.savefig('coadd_%(objectId)i.png' % locals()) plt.close(fig) # Generate the png files for each visit. for visit in visits: print("working on", visit) sys.stdout.flush() maker = PostageStampMaker(os.path.join(level2_repo, 'deepCoadd', band, '0/0,0tempExp', 'v%i-fu.fits' % visit))