def plot_image_solved(self): """ Superimpose found stars on the lid CCD image for each area of interest. If coordinates were found, it also shows the stars from the astrometry.net results. """ plt.ioff() fig = plt.figure() ax = plt.gca() lid_image = fits.open(self.filename)[0].data if type(lid_image) is not np.ndarray: raise AttributeError([self.filename, ' must be a fit file']) plt.imshow(lid_image, cmap='gray') for sky_image, rect in zip(self.sky_images, self.crop_rectangles): if sky_image.sources_pixel is not None: for i in range(min(sky_image.sources_pixel.shape[1], 30)): pixel_x = sky_image.sources_pixel[0, i] + rect.left pixel_y = sky_image.sources_pixel[1, i] + rect.bottom circle = Circle((pixel_x, pixel_y), radius=9, fill=False, color='r') ax.add_artist(circle) if sky_image.stars_pixel is not None: for i in range(sky_image.stars_pixel.shape[1]): pixel_x = sky_image.stars_pixel[0, i] + rect.left pixel_y = sky_image.stars_pixel[1, i] + rect.bottom circle = Circle((pixel_x, pixel_y), radius=11, fill=False, color='g') ax.add_artist(circle) rect = Rectangle((rect.left, rect.bottom), width=rect.width(), height=rect.height(), fill=False, color='k', linestyle='dashdot') ax.add_artist(rect) plt.grid(None) plt.axis('off') ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) output_filename = self.filename.replace('.fits', '-solved.png') plt.savefig(output_filename, bbox_inches='tight', pad_inches=0) plt.close(fig) print(output_filename, 'saved.')
def plot_image_treated(self): """ Superimpose stars and gamma sources on the lid CCD image. Internet access is needed for the Vizier requests. """ plt.ioff() fig = plt.figure() ax = plt.gca() lid_image = fits.open(self.filename)[0].data if type(lid_image) is not np.ndarray: raise AttributeError([self.filename, ' must be a fit file']) plt.imshow(lid_image, cmap='gray') image_treated = np.zeros(self.image_shape) vizier_blue = Vizier(columns=['all'], column_filters={"Bjmag": "<12"}, row_limit=-1, catalog=['I/271/out']) vizier_red = Vizier(columns=['all'], column_filters={"Rmag": "<12"}, row_limit=-1, catalog=['I/271/out']) vizier_green = Vizier(columns=['all'], column_filters={"Vmag": "<12"}, row_limit=-1, catalog=['VI/135/out']) vizier_gamma = Vizier(columns=['all'], row_limit=-1, catalog=['J/ApJS/197/34']) for (sky_image, rect) in zip(self.sky_images, self.crop_rectangles): image_treated[rect.bottom:rect.top, rect.left:rect.right] = np.log(1 + sky_image.image_stars) crop_origin = np.array([rect.left, rect.bottom]) if sky_image.sources_pixel is not None: for i in range(min(sky_image.sources_pixel.shape[1], 30)): pixel_x = sky_image.sources_pixel[0, i] + rect.left pixel_y = sky_image.sources_pixel[1, i] + rect.bottom circle = Circle((pixel_x, pixel_y), radius=20, fill=False, color='w') ax.add_artist(circle) if sky_image.wcs is not None: self.center_px = np.array( (self.image_shape[1], self.image_shape[0])).reshape(1, 2) / 2 self.center_ra_dec = sky_image.wcs.wcs_pix2world( self.center_px - crop_origin, 1)[0] print('image center (ra, dec):', self.center_ra_dec) center_coordinate = SkyCoord( ra=self.center_ra_dec[0] * u.degree, dec=self.center_ra_dec[1] * u.degree, frame='icrs') result_blue = vizier_blue.query_region(center_coordinate, radius=Angle(5, "deg"), catalog=['I/271/out' ])[0] blue_stars_ra_dec = np.array( (result_blue['RA_ICRS_'], result_blue['DE_ICRS_'])).transpose() # .reshape((-1,2)) blue_stars_mag = result_blue['Bjmag'] blue_stars_px = sky_image.wcs.wcs_world2pix( blue_stars_ra_dec, 1) for star_px, star_mag in zip(blue_stars_px, blue_stars_mag): if -5 < star_mag <= 12: radius = 18 - star_mag else: radius = 5 circle = Circle( (star_px[0] + rect.left, star_px[1] + rect.right), radius=radius, fill=False, color='b') ax.add_artist(circle) result_red = vizier_red.query_region(center_coordinate, radius=Angle(5, "deg"), catalog=['I/271/out'])[0] red_stars_ra_dec = np.array( (result_red['RA_ICRS_'], result_red['DE_ICRS_'])).transpose() # .reshape((-1,2)) red_stars_mag = result_red['Rmag'] red_stars_px = sky_image.wcs.wcs_world2pix(red_stars_ra_dec, 1) for star_px, star_mag in zip(red_stars_px, red_stars_mag): if -5 < star_mag <= 12: radius = 18 - star_mag else: radius = 5 circle = Circle( (star_px[0] + rect.left, star_px[1] + rect.right), radius=radius, fill=False, color='r') ax.add_artist(circle) result_green = vizier_green.query_region( center_coordinate, radius=Angle(5, "deg"), catalog=['I/271/out'])[0] green_stars_ra_dec = np.array( (result_green['RA_ICRS_'], result_green['DE_ICRS_'])).transpose() # .reshape((-1,2)) green_stars_mag = result_blue['Vmag'] green_stars_px = sky_image.wcs.wcs_world2pix( green_stars_ra_dec, 1) for star_px, star_mag in zip(green_stars_px, green_stars_mag): if -5 < star_mag <= 12: radius = 18 - star_mag else: radius = 5 circle = Circle( (star_px[0] + rect.left, star_px[1] + rect.right), radius=radius, fill=False, color='g') ax.add_artist(circle) result_gamma = vizier_gamma.query_region( center_coordinate, radius=Angle(5, "deg"), catalog=['J/ApJS/197/34'])[0] gamma_stars_ra_dec = np.array( (result_gamma['RAJ2000'], result_gamma['DEJ2000'])).transpose() # .reshape((-1,2)) gamma_stars_name = result_gamma['Name'] gamma_stars_px = sky_image.wcs.wcs_world2pix( gamma_stars_ra_dec, 1) for star_px, gamma_star_name in zip(gamma_stars_px, gamma_stars_name): circle = Circle( (star_px[0] + rect.left, star_px[1] + rect.bottom), radius=20, fill=False, color='Y') ax.add_artist(circle) ax.text(star_px[0] + rect.left, star_px[1] + rect.bottom, gamma_star_name, color='Y') crab_nebula_px = sky_image.wcs.wcs_world2pix( 83.640187, 22.044295, 1) circle = Circle((crab_nebula_px[0] + rect.left, crab_nebula_px[1] + rect.bottom), radius=20, fill=False, color='Y') ax.add_artist(circle) ax.text(crab_nebula_px[0] + rect.left, crab_nebula_px[1] + rect.right, 'Crab Pulsar', color='Y') rect = Rectangle(crop_origin, width=rect.width(), height=rect.height(), fill=False, color='y', linestyle='dashdot') ax.add_artist(rect) # plt.imshow(image_treated, cmap='gray') plt.plot(0, 0, 'w+') plt.grid(None) plt.axis('off') ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) output_filename = self.filename.replace('.fits', '-treated.png') plt.savefig(output_filename, bbox_inches='tight', pad_inches=0) plt.close(fig) print(output_filename, 'saved.')