def fits_to_png(inpath, outpath, coords=''): import numpy as np import img_scale import pylab import pyfits fn = inpath sig_fract = 5.0 percent_fract = 0.01 hdulist = pyfits.open(fn) img_header = hdulist[0].header img_data_raw = hdulist[0].data hdulist.close() width=img_data_raw.shape[0] height=img_data_raw.shape[1] img_data_raw = np.array(img_data_raw, dtype=float) sky, num_iter = img_scale.sky_mean_sig_clip(img_data_raw, sig_fract, percent_fract, max_iter=10) img_data = img_data_raw - sky min_val = 10.0 new_img = img_scale.log(img_data, scale_min = min_val) pylab.imshow(new_img, interpolation='nearest', origin='lower',cmap=pylab.cm.gray) if coords != '': for coord in coords: circle=pylab.Circle((coord['x'],coord['y']),radius=10) circle.set_edgecolor( 'red' ) circle.set_facecolor( 'none' ) # "none" not None circle.set_alpha( 0 ) pylab.gca().add_artist(circle) pylab.text(coord['x']+15, coord['y']-20, coord['id'], color='red') pylab.axis('off') pylab.savefig(outpath) pylab.clf()
def doScaling(self, img, rgb): for j in range(3): smin, it = img_scale.sky_mean_sig_clip(rgb[j], self.SKY_SIGMA, self.SKY_CONVERGENCE) pxmax = max(rgb[j].flatten()) smax = int(self.wb[j] * (self.SCALE_RANGE / self.opt['scaling'] + smin)) # smax = int((self.SCALE_RANGE + smin) / self.wb[j]) if self.SCALE_METHOD == self.scaleMethods[0]: img[:, :, j] = img_scale.linear(rgb[j], scale_min=smin, scale_max=smax) elif self.SCALE_METHOD == self.scaleMethods[1]: img[:, :, j] = img_scale.sqrt(rgb[j], scale_min=smin, scale_max=smax) elif self.SCALE_METHOD == self.scaleMethods[2]: img[:, :, j] = img_scale.log(rgb[j], scale_min=smin, scale_max=smax) elif self.SCALE_METHOD == self.scaleMethods[3]: img[:, :, j] = img_scale.asinh(rgb[j], scale_min=smin, scale_max=smax)
def plot_image(): rotated = np.flip(np.rot90(stamp, 2), 1) plt.imshow(img_scale.log(rotated, scale_min=5, scale_max=10000), cmap='Greys', interpolation='none')
stamp = data[round(gal.y - dy):round(gal.y + dy), round(gal.x - dx):round(gal.x + dx)] ax = fig.add_subplot(1, len(filters) + 1, 1 + f) #ax = fig.add_subplot(1,4, 1+f) plt.axis('off') plot_image() plt.title(fil) if f == 0: image_b = np.flip(np.rot90(stamp, 2), 1) if f == 1: image_g = np.flip(np.rot90(stamp, 2), 1) if f == 2: image_r = np.flip(np.rot90(stamp, 2), 1) alldata.append(stamp) bx = fig.add_subplot(1, len(filters) + 1, 4) #bx = fig.add_subplot(1, 4, 4) img = np.zeros([120, 120, 3]) img[:, :, 0] = img_scale.log(image_r, scale_min=5, scale_max=10000) img[:, :, 1] = img_scale.log(image_g, scale_min=5, scale_max=10000) img[:, :, 2] = img_scale.log(image_b, scale_min=5, scale_max=10000) plt.imshow(img) plt.axis('off') plt.title('color') pdf.savefig(dpi=1000) plt.close() os.system('open %s &' % 'ad_poster.pdf')
min_val = 0.0 print "... min. and max. value : ", numpy.min(img_data), numpy.max(img_data) ''' new_img = img_scale.sqrt(img_data, scale_min = min_val) pylab.imshow(new_img, interpolation='nearest', origin='lower', cmap=pylab.cm.hot) pylab.axis('off') pylab.savefig(image) pylab.clf() new_img = img_scale.power(img_data, power_index=3.0, scale_min = min_val) pylab.imshow(new_img, interpolation='nearest', origin='lower', cmap=pylab.cm.hot) pylab.axis('off') pylab.savefig(image) pylab.clf() ''' new_img = img_scale.log(img_data, scale_min=min_val) pylab.imshow(new_img, interpolation='nearest', origin='lower', cmap=pylab.cm.hot) pylab.axis('off') pylab.savefig(image) pylab.clf() sys.exit() new_img = img_scale.linear(img_data, scale_min=min_val) pylab.imshow(new_img, interpolation='nearest', origin='lower', cmap=pylab.cm.hot)
print "sky = ", sky, "(", num_iter, ")" img_data = img_data_raw - sky min_val = 0.0 print "... min. and max. value : ", numpy.min(img_data), numpy.max(img_data) new_img = img_scale.sqrt(img_data, scale_min=min_val) pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot) pylab.axis("off") pylab.savefig("sqrt.png") pylab.clf() new_img = img_scale.power(img_data, power_index=3.0, scale_min=min_val) pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot) pylab.axis("off") pylab.savefig("power.png") pylab.clf() new_img = img_scale.log(img_data, scale_min=min_val) pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot) pylab.axis("off") pylab.savefig("log.png") pylab.clf() new_img = img_scale.linear(img_data, scale_min=min_val) pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot) pylab.axis("off") pylab.savefig("linear.png") pylab.clf() new_img = img_scale.asinh(img_data, scale_min=min_val, non_linear=0.01) pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot) pylab.axis("off") pylab.savefig("asinh_beta_01.png") pylab.clf() new_img = img_scale.asinh(img_data, scale_min=min_val, non_linear=0.5)
def create_images_png(filename, outfilename='Default'): """Creates the original, clean, and mask images in single a PNG. Useful for checking how well LACosmic worked. You may want to adjust the size of the "cut" images so to capture your source star. Parameters: filename : string Name of the original FITS image, including the path. outfilename : string, optional Name of the outfile PNG. Returns: nothing Outputs: PNG file. ``<file rootname>.png`` by default. Shows both full frame images and "cut" images of the source. """ pylab.ioff() # create page for plots page_width = 21.59 / 2 page_height = 27.94 / 2 fig = pylab.figure(figsize=(page_width, page_height)) file_clean = (filename.split('.fits')[0] + '.clean.fits') file_mask = (filename.split('.fits')[0] + '.mask.fits') scmax = 7000 # scale_max for raw and clean scmin = 3 # scale_min for raw and clean # Plot the original image pylab.subplot(3, 2, 1, aspect='equal') # 311 image_orig = fits.open(filename) image_orig_ext = image_orig[1].data image_orig_scaled = img_scale.log(image_orig_ext, \ scale_min=scmin, \ scale_max=scmax) plt_orig = pylab.imshow(image_orig_scaled, aspect='equal') pylab.title('Original (SCI)') # Plot cut of original image pylab.subplot(3, 2, 2, aspect='equal') image_orig_cut = img_scale.log(image_orig_ext[175:275,175:275], \ scale_min=scmin, \ scale_max=scmax) plt_orig_cut = pylab.imshow(image_orig_cut, aspect='equal') pylab.title('Original (SCI)') image_orig.close() # Plot the mask image pylab.subplot(3, 2, 3) #312 image_mask = fits.open(file_mask) image_mask_ext = image_mask[0].data plt_orig = pylab.imshow(image_mask_ext, aspect='equal', vmin=-2, vmax=1) #-2, -5 pylab.title('Mask') # Plot cut of the mask image pylab.subplot(3, 2, 4) plt_mask_cut = pylab.imshow(image_mask_ext[175:275,175:275], \ aspect='equal', vmin=-2, vmax=1) pylab.title('Mask') image_mask.close() # Plot the LACosmic-cleaned image pylab.subplot(3, 2, 5) #313 image_clean = fits.open(file_clean) image_clean_ext = image_clean[0].data image_clean_scaled = img_scale.log(image_clean_ext, \ scale_min=scmin, \ scale_max=scmax) plt_clean = pylab.imshow(image_clean_scaled, aspect='equal') pylab.title('Clean') #Plot cut of the LACosmic-cleaned image pylab.subplot(3, 2, 6) image_clean_cut = img_scale.log(image_clean_ext[175:275,175:275], \ scale_min=scmin, scale_max=scmax) plt_clean_cut = pylab.imshow(image_clean_cut, aspect='equal') pylab.title('Clean') image_clean.close() if outfilename == 'Default': pylab.savefig(filename.split('.fits')[0] + '.png') else: pylab.savefig(outfilename) pylab.close() pylab.ion()
def create_diagnostic_png(filename, outfilename='Default'): pylab.ioff() # create page for plots page_width = 21.59 / 2 page_height = 27.94 / 2 fig = pylab.figure(figsize=(page_width, page_height)) file_clean = (filename.split('.fits')[0] + '.clean.fits') file_mask = (filename.split('.fits')[0] + '.mask.fits') scmax = 7000 # scale_max for raw and clean scmin = 3 # scale_min for raw and clean # Plot the original image pylab.subplot(3, 2, 1, aspect='equal') # 311 image_orig = pyfits.open(filename) image_orig_ext = image_orig[1].data image_orig_scaled = img_scale.log(image_orig_ext, \ scale_min=scmin, \ scale_max=scmax) plt_orig = pylab.imshow(image_orig_scaled, aspect='equal') pylab.title('Original (SCI)') # Plot cut of original image pylab.subplot(3, 2, 2, aspect='equal') image_orig_cut = img_scale.log(image_orig_ext[175:275,175:275], \ scale_min=scmin, \ scale_max=scmax) plt_orig_cut = pylab.imshow(image_orig_cut, aspect='equal') pylab.title('Original (SCI)') image_orig.close() # Plot the mask image pylab.subplot(3, 2, 3) #312 image_mask = pyfits.open(file_mask) image_mask_ext = image_mask[0].data plt_orig = pylab.imshow(image_mask_ext, aspect='equal', vmin=-2, vmax=1) #-2, -5 pylab.title('Mask') # Plot cut of the mask image pylab.subplot(3, 2, 4) plt_mask_cut = pylab.imshow(image_mask_ext[175:275,175:275], \ aspect='equal', vmin=-2, vmax=1) pylab.title('Mask') image_mask.close() # Plot the LACosmic-cleaned image pylab.subplot(3, 2, 5) #313 image_clean = pyfits.open(file_clean) image_clean_ext = image_clean[0].data image_clean_scaled = img_scale.log(image_clean_ext, \ scale_min=scmin, \ scale_max=scmax) plt_clean = pylab.imshow(image_clean_scaled, aspect='equal') pylab.title('Clean') #Plot cut of the LACosmic-cleaned image pylab.subplot(3, 2, 6) image_clean_cut = img_scale.log(image_clean_ext[175:275,175:275], \ scale_min=scmin, scale_max=scmax) plt_clean_cut = pylab.imshow(image_clean_cut, aspect='equal') pylab.title('Clean') image_clean.close() if outfilename == 'Default': pylab.savefig(filename.split('.fits')[0] + '.png') else: pylab.savefig(outfilename) pylab.close() pylab.ion()