def press(button): if button == "Quit": app.stop() else: in1 = app.getEntry("Objects_blue") in2 = app.getEntry("Objects_green") in3 = app.getEntry("Objects_red") in4 = app.getEntry("Dark") in5 = app.getEntry("Bias") in6 = app.getEntry("Flat_blue") in7 = app.getEntry("Flat_green") in8 = app.getEntry("Flat_red") b, g, r = calib4.calibration(in1, in2, in3, in4, in5, in6, in7, in8) hot_b, fixed_b = remove_deadhot.find_outlier_pixels(b / 65536.0 * 255.0) hot_g, fixed_g = remove_deadhot.find_outlier_pixels(g / 65536.0 * 255.0) hot_r, fixed_r = remove_deadhot.find_outlier_pixels(r / 65536.0 * 255.0) newb, newg, newr = alignment5.alignment(fixed_b, fixed_g, fixed_r) biasfiles = [line.rstrip('\n') for line in open(in1)] cat = get_pkg_data_filename(biasfiles[0]) hdu = fits.open(cat)[0] wcs = WCS(hdu.header) n1 = int(hdu.header['NAXIS1']) n2 = int(hdu.header['NAXIS2']) bmin, bmax = newb.mean() - 2.0 * newb.std(), newb.mean( ) + 5 * newb.std() gmin, gmax = newg.mean() - 2.0 * newg.std(), newg.mean( ) + 5 * newg.std() rmin, rmax = newr.mean() - 2.0 * newr.std(), newr.mean( ) + 5 * newr.std() img = zeros((n1, n2, 3)) img[:, :, 0] = img_scale.linear(newr, scale_min=rmin, scale_max=rmax) img[:, :, 1] = img_scale.linear(0.9 * newg, scale_min=gmin, scale_max=gmax) img[:, :, 2] = img_scale.linear(newb, scale_min=bmin, scale_max=bmax) fig = pylab.figure() pylab.clf() fig.add_subplot(111, projection=wcs) plt.imshow(img, cmap=plt.cm.viridis) plt.xlabel('RA') plt.ylabel('DEC') fig.set_size_inches(10, 10, forward=True) plt.savefig('img') plt.close()
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)
input7, input8) hot_b, fixed_b = remove_deadhot.find_outlier_pixels(b / 65536.0 * 255.0) hot_g, fixed_g = remove_deadhot.find_outlier_pixels(g / 65536.0 * 255.0) hot_r, fixed_r = remove_deadhot.find_outlier_pixels(r / 65536.0 * 255.0) newb, newg, newr = alignment5.alignment(fixed_b, fixed_g, fixed_r) biasfiles = [line.rstrip('\n') for line in open(input1)] cat = get_pkg_data_filename(biasfiles[0]) hdu = fits.open(cat)[0] wcs = WCS(hdu.header) n1 = int(hdu.header['NAXIS1']) n2 = int(hdu.header['NAXIS2']) bmin, bmax = newb.mean() - 2.0 * newb.std(), newb.mean() + 10 * newb.std() gmin, gmax = newg.mean() - 2.0 * newg.std(), newg.mean() + 10 * newg.std() rmin, rmax = newr.mean() - 2.0 * newr.std(), newr.mean() + 10 * newr.std() img = zeros((n1, n2, 3)) img[:, :, 2] = img_scale.linear(newb, scale_min=bmin, scale_max=bmax) img[:, :, 1] = img_scale.linear(0.9 * newg, scale_min=gmin, scale_max=gmax) img[:, :, 0] = img_scale.linear(newr, scale_min=rmin, scale_max=rmax) fig = pylab.figure() pylab.clf() fig.add_subplot(111, projection=wcs) pylab.xlabel('RA') pylab.ylabel('DEC') pylab.imshow(img, cmap=plt.cm.viridis) fig.set_size_inches(10, 10, forward=True) pylab.savefig('final_img') pylab.close()
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) pylab.axis('off') pylab.savefig(image) 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(image) pylab.clf()
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) pylab.imshow(new_img, interpolation="nearest", origin="lower", cmap=pylab.cm.hot) pylab.axis("off") pylab.savefig("asinh_beta_05.png") pylab.clf() new_img = img_scale.asinh(img_data, scale_min=min_val, non_linear=2.0)
for wl in ['8.0', '4.5', '3.6']: data.append(fits.getdata('Downloads/SAGE_LMC_IRAC'+wl+'_2_mosaic.fits')) data = np.array(data) data = np.swapaxes(data, 0, 2) data = np.swapaxes(data, 0, 1) data = block_reduce(data, block_size=(2, 2, 1)) for i in range(3): tmp = np.nanmin(data[:, :, i]) data[:, :, i] += np.abs(tmp) for i in range(3): tmp = np.nanmax(data[:, :, i]) data[:, :, i] *= 1.0/tmp data[:, :, 0] = IS.linear(data[:, :, 0], scale_min=0.0027, scale_max=0.006) data[:, :, 1] = IS.linear(data[:, :, 1], scale_min=0.00025, scale_max=0.0016) data[:, :, 2] = IS.linear(data[:, :, 2], scale_min=0.0005, scale_max=0.0021) ''' fig = plt.figure(dpi=100) ax = fig.add_subplot(111) col = ['r', 'g', 'b'] for i in range(3): tmp = data[:, :, i] ax.hist(tmp[~np.isnan(tmp)], bins='auto', color=col[i], histtype='step') #ax.set_xscale('log') #ax.set_yscale('log') plt.show() ''' fig = plt.figure(figsize=(4.983, 4.983))
import pyfits import numpy as np import pylab as py import img_scale Target_name = str(raw_input('Object Name:')) print '' R = str(raw_input('R filter filename:')) print '' B = str(raw_input('B filter filename:')) print '' V = str(raw_input('V filter filename:')) print '' r = pyfits.getdata(R) v = pyfits.getdata(V) b = pyfits.getdata(B) img = np.zeros((b.shape[0], b.shape[1], 3), dtype=float) img[:, :, 0] = img_scale.linear(r, scale_min=0, scale_max=10000) img[:, :, 1] = img_scale.linear(v, scale_min=0, scale_max=10000) img[:, :, 2] = img_scale.linear(b, scale_min=0, scale_max=10000) py.clf() py.imshow(img, aspect='equal') py.title('Blue = B, Visible = V, Red = R') py.savefig(Target_name + '_RGB.png')
def MakeMovieImages(Ntimesteps, imagesDir, outputDir, movie_array, file_names, stretchValues, tracerNames, rotationPerMyr=rotationPerMyr, tstretch=tstretch): print('making images...') for i in range(Ntimesteps): output_name = str(outputDir + 'rgb_' + str(i) + '.png') currentTime = (float(i) / float(tstretch)) if EndAtCorrectRot: rot_angle = (-1. * (Ntimesteps - 1) * (rotationPerMyr / tstretch)) + (i * rotationPerMyr / tstretch) else: rot_angle = (i * rotationPerMyr / tstretch) if '.fits' in (movie_array[i, 0]): stindex = np.where(file_names == movie_array[i, 0]) tracerR = (tracerNames[stindex])[0] imgR = img_scale.linear(pyfits.getdata( str(imagesDir + movie_array[i, 0])), scale_min=stretchValues[stindex, 0], scale_max=stretchValues[stindex, 1]) if FadeTracersStart: try: if movie_array[i - framerate, 0] != movie_array[i, 0]: stretchValues[stindex, 1] = stretchValues[stindex, 1] / 1.1 except: print("Fade start has failed") if FadeTracersEnd: try: if movie_array[i + framerate, 0] != movie_array[i, 0]: stretchValues[stindex, 1] = stretchValues[stindex, 1] * 1.1 except: print("Nearing end of the movie") else: imgR = None tracerR = 'N/A' if '.fits' in (movie_array[i, 1]): stindex = np.where(file_names == movie_array[i, 1]) imgG = img_scale.linear(pyfits.getdata( str(imagesDir + movie_array[i, 1])), scale_min=stretchValues[stindex, 0], scale_max=stretchValues[stindex, 1]) tracerG = (tracerNames[stindex])[0] if FadeTracersStart: try: if movie_array[i - framerate, 1] != movie_array[i, 1]: stretchValues[stindex, 1] = stretchValues[stindex, 1] / 1.1 except: print("Fade start has failed") if FadeTracersEnd: try: if movie_array[i + framerate, 1] != movie_array[i, 1]: stretchValues[stindex, 1] = stretchValues[stindex, 1] * 1.1 except: print("Nearing end of the movie") else: imgG = None tracerG = 'N/A' if '.fits' in (movie_array[i, 2]): stindex = np.where(file_names == movie_array[i, 2]) tracerB = (tracerNames[stindex])[0] imgB = img_scale.linear(pyfits.getdata( str(imagesDir + movie_array[i, 2])), scale_min=stretchValues[stindex, 0], scale_max=stretchValues[stindex, 1]) if FadeTracersStart: try: if movie_array[i - framerate, 2] != movie_array[i, 2]: stretchValues[stindex, 1] = stretchValues[stindex, 1] / 1.1 except: print("Fade start has failed") if FadeTracersEnd: try: if movie_array[i + framerate, 2] != movie_array[i, 2]: stretchValues[stindex, 1] = stretchValues[stindex, 1] * 1.1 except: print("Nearing end of the movie") else: imgB = None tracerB = 'N/A' assemble3colImage(imgR, imgG, imgB, rot_angle, output_name, tracerR, tracerG, tracerB, currentTime)