def get_corr_map(co, sec, pixsz, bound, weights): imsz = [2 * bound / pixsz, 2 * bound / pixsz] H,xedges,yedges=np.histogram2d(co[:,1], co[:,0],\ bins=imsz, range=[[-bound,bound],[-bound,bound]], weights=weights*10) print np.max(H) t = np.percentile(H, 90) t = 1 print 'threshold:{0}'.format(t) hp = H.copy() #plt.colorbar() ''' plt.plot(co_rel[:,0],co_rel[:,1], '.k') plt.xlim(-0.02,0.02) plt.ylim(-0.02,0.02) ''' #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx)) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) #print c_data if c_data is not None: #cy, cx, max_value, flux, x, y = c_data cy, cx, max_value, flux = c_data #cy+=0.5 #cx+=0.5 centroid = [-bound + cx * pixsz, -bound + cy * pixsz] else: centroid = [0., 0.] max_value = 0 flux = 500 plt.imshow(np.log2(hp + 10**-10), interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[bound, -bound, -bound, bound], origin='lower', vmin=0) #plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', norm=LogNorm(10**0,np.max(hp))) plt.colorbar() plt.xlim(-bound, bound) plt.ylim(-bound, bound) plt.ylabel('gb') plt.xlabel('gl') plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) plt.plot(centroid[0], centroid[1], '+r', markersize=8) #plt.plot(c_sex[0],c_sex[1],'+g', markersize=8) plt.show() #plt.savefig('/home/dw1519/dw1519/galex/plots/co239_fix/{0}.pdf'.format(idx)) #plt.clf() return centroid, max_value, flux
def imatrix(data,H): M = int((data.shape[0])**.5) data = data.reshape(M,M) center = c3.find_centroid(data) dx , dy = center[0] , center[1] chi = np.dot(np.linalg.inv(ms.B(H*M)) , ms.I(H*M)) hx = np.dot(phi(-dx, H , M) , chi) hy = np.dot(chi.T , phi(-dy, H , M).T) hf = np.kron(hx.T, hy) return hf
def get_corr_map(co, sec, pixsz, bound, weights): imsz = [2*bound/pixsz, 2*bound/pixsz] H,xedges,yedges=np.histogram2d(co[:,1], co[:,0],\ bins=imsz, range=[[-bound,bound],[-bound,bound]], weights=weights*10) print np.max(H) t = np.percentile(H, 90) t = 1 print 'threshold:{0}'.format(t) hp = H.copy() #plt.colorbar() ''' plt.plot(co_rel[:,0],co_rel[:,1], '.k') plt.xlim(-0.02,0.02) plt.ylim(-0.02,0.02) ''' #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx)) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) #print c_data if c_data is not None: #cy, cx, max_value, flux, x, y = c_data cy, cx, max_value, flux = c_data #cy+=0.5 #cx+=0.5 centroid = [-bound+cx*pixsz, -bound+cy*pixsz] else: centroid = [0.,0.] max_value = 0 flux = 500 plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[bound, -bound, -bound, bound], origin='lower', vmin=0) #plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', norm=LogNorm(10**0,np.max(hp))) plt.colorbar() plt.xlim(-bound, bound) plt.ylim(-bound, bound) plt.ylabel('gb') plt.xlabel('gl') plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) plt.plot(centroid[0],centroid[1],'+r', markersize=8) #plt.plot(c_sex[0],c_sex[1],'+g', markersize=8) plt.show() #plt.savefig('/home/dw1519/dw1519/galex/plots/co239_fix/{0}.pdf'.format(idx)) #plt.clf() return centroid, max_value, flux
def _find_centroid(filename): try: hdulist = pyfits.open(filename) except IOError as e: print "I/O error({0}): {1}".format(e.errno, e.strerror) hdulist = None except: print "Unexpected error:", sys.exc_info()[0] raise if hdulist is not None: w = pywcs.WCS(hdulist[0].header, hdulist) data = hdulist[0].data data = data.byteswap(True).newbyteorder() cy, cx = c3.find_centroid(data) else: return None return cx, cy
def _find_centroid(filename): try: hdulist = pyfits.open(filename) except IOError as e: print "I/O error({0}): {1}".format(e.errno, e.strerror) hdulist = None except: print "Unexpected error:", sys.exc_info()[0] raise if hdulist is not None: w = pywcs.WCS(hdulist[0].header, hdulist) data = hdulist[0].data data = data.byteswap(True).newbyteorder() cy, cx = c3.find_centroid(data) else: return None return cx,cy
def get_corr_map(coo1, coo2, skypos, skyrange, sec, bound, bandwidth): imsz = imagetools.deg2pix(skypos, skyrange, 0.0001) count = np.zeros(imsz) #print(imsz) co_rel = np.array([[0, 0]]) len1 = coo1.shape[0] len2 = coo2.shape[0] print(len1, len2) wcs = imagetools.define_wcs(skypos, skyrange, width=False, height=False, verbose=0, pixsz=0.0001) #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile: #writer = csv.writer(csvfile) if len2 > len1: for i in range(len1): #print(i) tmp_co = coo2 - coo1[i, :] tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :] tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :] co_rel = np.concatenate((co_rel, tmp_co), axis=0) else: for i in range(len2): #print(i) tmp_co = coo2[i, :] - coo1 tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :] tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :] co_rel = np.concatenate((co_rel, tmp_co), axis=0) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:], 1), 1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ])) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() cy, cx, max_value = c3.find_centroid(data) centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]], 1), 1)[0] if centroid[0] > 1: centroid[0] = centroid[0] - 360. return centroid, max_value
def find_centroid(filename): try: hdulist = pyfits.open(filename) except IOError as e: print "I/O error({0}): {1}: {2}".format(e.errno, e.strerror, filename) hdulist = None except: print "Unexpected error:", sys.exc_info()[0] raise if hdulist is not None: hdulist = pyfits.open(filename) w = pywcs.WCS(hdulist[0].header, hdulist) data = hdulist[0].data data = data.byteswap(True).newbyteorder() cy, cx = c3.find_centroid(data) centroid = w.wcs_pix2world(w.sip_foc2pix([[cx, cy]],1),1)[0] if centroid[0]>1: centroid[0] = centroid[0]-360. else: centroid = [0,0] return centroid
def centroid(t,H,wcs): print 'threshold:{0}'.format(t) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) if c_data is not None: cy, cx, max_value, flux = c_data cy+=0.5 cx+=0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0] print(cx,cy) print(centroid) else: centroid = [0.,0.] max_value = 0 flux = 500 if centroid[0]>1: centroid[0] = centroid[0]-360. return centroid
def find_centroid(filename): try: hdulist = pyfits.open(filename) except IOError as e: print "I/O error({0}): {1}: {2}".format(e.errno, e.strerror, filename) hdulist = None except: print "Unexpected error:", sys.exc_info()[0] raise if hdulist is not None: hdulist = pyfits.open(filename) w = pywcs.WCS(hdulist[0].header, hdulist) data = hdulist[0].data data = data.byteswap(True).newbyteorder() cy, cx = c3.find_centroid(data) centroid = w.wcs_pix2world(w.sip_foc2pix([[cx, cy]], 1), 1)[0] if centroid[0] > 1: centroid[0] = centroid[0] - 360. else: centroid = [0, 0] return centroid
def get_corr_map(coo1, coo2, skypos, skyrange, sec, bound, bandwidth): imsz = imagetools.deg2pix(skypos, skyrange, 0.0001) count = np.zeros(imsz) #print(imsz) co_rel = np.array([[0,0]]) len1 = coo1.shape[0] len2 = coo2.shape[0] print(len1,len2) wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001) #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile: #writer = csv.writer(csvfile) if len2>len1: for i in range(len1): #print(i) tmp_co = coo2-coo1[i,:] tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) else: for i in range(len2): #print(i) tmp_co = coo2[i,:]-coo1 tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ])) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() cy, cx, max_value = c3.find_centroid(data) centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0] if centroid[0]>1: centroid[0] = centroid[0]-360. return centroid, max_value
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix, info_list, d3, outdir): imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) count = np.zeros(imsz) #print(imsz) bound = skyrange[0] co_rel = np.array([[0, 0]]) infos = np.array([[0, 0, 0]]) len1 = coo1.shape[0] len2 = coo2.shape[0] print(len1, len2) wcs = imagetools.define_wcs(skypos, skyrange, width=False, height=False, verbose=0, pixsz=pixsz) #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile: #writer = csv.writer(csvfile) if len2 > len1: for i in range(len1): #print(i) tmp_co = coo2 - coo1[i, :] mask = (np.absolute(tmp_co[:, 0]) <= bound) & (np.absolute( tmp_co[:, 1]) <= bound) tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :] tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :] co_rel = np.concatenate((co_rel, tmp_co), axis=0) infos = np.concatenate((infos, info_list[mask]), axis=0) else: for i in range(len2): #print(i) tmp_co = coo2[i, :] - coo1 tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :] tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :] co_rel = np.concatenate((co_rel, tmp_co), axis=0) infos = np.concatenate( (infos, np.repeat(info_list[i], tmp_co.shape[0])), axis=0) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:], 1), 1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ])) t = np.percentile(H, 90) t = 50 print 'threshold:{0}'.format(t) hp = H.copy() #plt.colorbar() #plt.plot(co_rel[:,0],co_rel[:,1], 'o', alpha=0.05) #plt.xlim(-0.005,0.005) #plt.ylim(-0.005,0.005) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) if c_data is not None: cy, cx, max_value, flux = c_data cy += 0.5 cx += 0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]], 1), 1)[0] else: centroid = [0., 0.] max_value = 0 flux = 500 if centroid[0] > 1: centroid[0] = centroid[0] - 360. #print 'max:{0}'.format(max_value) print hp.shape #plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', vmin=0) plt.imshow(hp + 10**-10, interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02 * 3600, -0.02 * 3600, 0.02 * 3600, -0.02 * 3600], origin='upper', norm=LogNorm(10**0, np.max(hp))) plt.colorbar() plt.xlim(-0.02 * 3600, 0.02 * 3600) plt.ylim(-0.02 * 3600, 0.02 * 3600) plt.ylabel('gb') plt.xlabel('gl') plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) plt.plot(centroid[0] * 3600, centroid[1] * 3600, '+r', markersize=8) #plt.show() rot = np.mean(d3) / 180. * np.pi l = np.linspace(0, 8., 5) x_y = np.sin(-rot) * l x_x = np.cos(-rot) * l y_y = np.sin(-rot + np.pi / 2.) * l y_x = np.cos(-rot + np.pi / 2.) * l plt.plot(x_x, x_y, '--g') plt.plot(y_x, y_y, '--g') co_rel = co_rel * 3600 mask = (co_rel[1:, 0]**2 + co_rel[1:, 1]**2) <= (2.5**2) num = np.sum(mask) plt.title('t={0}-{1}s, photons within d=5\" circle:{2}'.format( idx / 2 - 50, idx / 2, num)) plt.savefig('{0}/{1}.pdf'.format(outdir, idx)) plt.clf() np.save('{0}/{1}.npy'.format(outdir, idx), co_rel) plt.imshow(hp + 10**-10, interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02 * 3600, -0.02 * 3600, 0.02 * 3600, -0.02 * 3600], origin='upper', norm=LogNorm(10**0, np.max(hp))) plt.colorbar() plt.xlim(-0.01 * 3600, 0.01 * 3600) plt.ylim(-0.01 * 3600, 0.01 * 3600) plt.ylabel('gb') plt.xlabel('gl') plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) #plt.plot(centroid[0]*3600,centroid[1]*3600,'+r', markersize=8) #plt.show() rot = np.mean(d3) / 180. * np.pi l = np.linspace(0, 8., 5) x_y = np.sin(-rot) * l x_x = np.cos(-rot) * l y_y = np.sin(-rot + np.pi / 2.) * l y_x = np.cos(-rot + np.pi / 2.) * l #plt.plot(x_x, x_y, '--g') #plt.plot(y_x, y_y, '--g') #mask = (co_rel[1:,0]**2+co_rel[1:,1]**2) <= (2.5**2) #num = np.sum(mask) plt.title('t={0}-{1}s'.format(idx / 2 - 50, idx / 2)) plt.savefig('{0}/zoom_{1}.pdf'.format(outdir, idx)) plt.clf() ''' plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,0], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face') cb1 = plt.colorbar() cb1.set_label('xa') plt.xlim(-0.02*3600, 0.02*3600) plt.ylim(-0.02*3600, 0.02*3600) plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/xa_{0}.png'.format(idx)) plt.clf() plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,1], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face') cb1 = plt.colorbar() cb1.set_label('ya') plt.xlim(-0.02*3600, 0.02*3600) plt.ylim(-0.02*3600, 0.02*3600) plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/ya_{0}.png'.format(idx)) plt.clf() plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,2], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face') cb1 = plt.colorbar() cb1.set_label('q') plt.xlim(-0.02*3600, 0.02*3600) plt.ylim(-0.02*3600, 0.02*3600) plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/q_{0}.png'.format(idx), dpi=190) plt.clf() ''' ''' n, bins, patches = plt.hist(infos[1:,1], 30, normed=1, facecolor='green', alpha=0.5) plt.savefig('/home/dw1519/dw1519/galex/plots/co239_s/yahist_{0}.pdf'.format(idx), dpi=190) plt.clf() mask = (co_rel[:,0]<-25) & (co_rel[:,0]>-45) & (co_rel[:,1]>42) & (co_rel[:,1]<66) n, bins, patches = plt.hist(infos[mask,1], 30, normed=1, facecolor='green', alpha=0.5) plt.savefig('/home/dw1519/dw1519/galex/plots/co239_s/yahist_gh_{0}.pdf'.format(idx), dpi=190) plt.clf() ''' return centroid, max_value, flux
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix, weight, flux=None): imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) count = np.zeros(imsz) #print(imsz) weights = np.array([]) bound = skyrange[0]/2. co_rel = np.array([[0,0]]) len1 = coo1.shape[0] len2 = coo2.shape[0] print(len1,len2) wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz) #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile: #writer = csv.writer(csvfile) ''' sky_data = SkyCoord(coo1, unit='deg', frame=FK5, equinox='J2000.0') gal = sky_data.transform_to(Galactic) coo1 = np.concatenate((np.array([gal.l.deg]).T, np.array([gal.b.deg]).T), axis=1) sky_data = SkyCoord(coo2, unit='deg', frame=FK5, equinox='J2000.0') gal = sky_data.transform_to(Galactic) coo2 = np.concatenate((np.array([gal.l.deg]).T, np.array([gal.b.deg]).T), axis=1) ''' if len2>len1: for i in range(len1): #print(i) tmp_co = coo2-coo1[i,:] mask = (np.absolute(tmp_co[:,0])<=bound) & (np.absolute(tmp_co[:,1])<=bound) tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) if flux is not None: f = flux[i] else: f = 1. weights = np.concatenate((weights,weight[mask]/f*50.), axis=0) else: for i in range(len2): #print(i) tmp_co = coo2[i,:]-coo1 mask = (np.absolute(tmp_co[:,0])<=bound) & (np.absolute(tmp_co[:,1])<=bound) tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) if flux is not None: f = flux[mask] else: f = np.ones(tmp_co.shape[0]) weights = np.concatenate((weights,np.repeat(weight[i], tmp_co.shape[0])/f), axis=0) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]), weights=weights) print H.shape t = np.percentile(H, 90) t = 1 print 'threshold:{0}'.format(t) #hp = H.copy() #plt.colorbar() ''' plt.plot(co_rel[:,0],co_rel[:,1], '.k') plt.xlim(-0.02,0.02) plt.ylim(-0.02,0.02) ''' #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx)) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) #print c_data if c_data is not None: #cy, cx, max_value, flux, x, y = c_data cy, cx, max_value, flux = c_data cy+=0.5 cx+=0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0] #c_sex = wcs.wcs_pix2world(wcs.sip_foc2pix([[x+0.5, y+0.5]],1),1)[0] #print c_sex else: centroid = [0.,0.] max_value = 0 flux = 500 if centroid[0]>1: centroid[0] = centroid[0]-360. #if c_sex[0]>1: # c_sex[0] = c_sex[0]-360. #print 'max:{0}'.format(max_value) #print cx,cy ''' plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[bound, -bound, -bound, bound], origin='lower', vmin=0) #plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', norm=LogNorm(10**0,np.max(hp))) plt.colorbar() plt.xlim(-bound/3, bound/3) plt.ylim(-bound/3, bound/3) plt.ylabel('gb') plt.xlabel('gl') plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) plt.plot(centroid[0],centroid[1],'+r', markersize=8) #plt.plot(c_sex[0],c_sex[1],'+g', markersize=8) plt.show() #plt.savefig('/home/dw1519/dw1519/galex/plots/co239_fix/{0}.pdf'.format(idx)) #plt.clf() ''' return centroid, max_value, flux
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix): imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) count = np.zeros(imsz) #print(imsz) bound = skyrange[0] co_rel = np.array([[0,0]]) len1 = coo1.shape[0] len2 = coo2.shape[0] print(len1,len2) wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz) #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile: #writer = csv.writer(csvfile) if len2>len1: for i in range(len1): #print(i) tmp_co = coo2-coo1[i,:] tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) else: for i in range(len2): #print(i) tmp_co = coo2[i,:]-coo1 tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ])) t = np.percentile(H, 90) t = 1 print 'threshold:{0}'.format(t) hp = H.copy() #plt.colorbar() #plt.plot(co_rel[:,0],co_rel[:,1], 'o', alpha=0.05) #plt.xlim(-0.005,0.005) #plt.ylim(-0.005,0.005) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) if c_data is not None: cy, cx, max_value, flux = c_data cy+=0.5 cx+=0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0] else: centroid = [0.,0.] max_value = 0 flux = 500 if centroid[0]>1: centroid[0] = centroid[0]-360. #print 'max:{0}'.format(max_value) print hp.shape #plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', vmin=0) plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', norm=LogNorm(10**0,np.max(hp))) plt.colorbar() plt.xlim(-0.02*3600, 0.02*3600) plt.ylim(-0.02*3600, 0.02*3600) plt.ylabel('gb') plt.xlabel('gl') plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) plt.plot(centroid[0]*3600,centroid[1]*3600,'+r', markersize=8) #plt.show() plt.savefig('/home/dw1519/dw1519/galex/plots/co239_orignal/{0}.pdf'.format(idx)) plt.clf() return centroid, max_value, flux
plt.subplot(1,3,2) plt.imshow(qw, interpolation = "None" , origin = "lower") plt.colorbar() plt.subplot(1,3,3) plt.imshow(qq, interpolation = "None" , origin = "lower") plt.colorbar() plt.show() M , H = 25 , 3 y = profile.makeGaussian(M, M/5. ,0.1, (M/2.+0.83, M/2.+1.45)) y /= y.sum() import c3 print c3.find_centroid(y) #data model = profile.makeGaussian(H*M, H*M/5. ,0.1, (H*M/2., H*M/2.)) #model hh = sampler.imatrix(y.flatten() , H) #sampling matrix ww = model.flatten().dot(hh).reshape(M,M) #model rendered on data grid ww = ww/ww.sum() plt.subplot(1,4,1) plt.imshow(y, interpolation = "None" , origin = "lower") plt.title("data") plt.colorbar() plt.subplot(1,4,2) plt.imshow(model, interpolation = "None" , origin = "lower") plt.title("model") plt.colorbar() plt.subplot(1,4,3)
#anderson = pf.open("anderson.fits")[0].data #X = np.exp(np.loadtxt("noregwfc_mean_iter_2.txt")).reshape(100,100) #X1 = np.exp(np.loadtxt("noregwfc_mean_iter_1.txt")).reshape(100,100) fl= 1e-5 f = .05 g = 0.01 H = 3 X = np.exp(np.loadtxt("superb_wfc_mean_iter_5_nfl.txt")) Z = (X).reshape(25*H,25*H) print Z.sum() import c3 x0 , y0 = c3.find_centroid(Z) print x0, y0 import scipy from scipy import ndimage Z2 = scipy.ndimage.interpolation.shift(Z, [x0,y0], output=None, order=3, mode='nearest', prefilter=True) k = np.array([[True, False, True], [False, False, False], [True, False, True]]) Z2 = ndimage.convolve(Z2, k, mode='nearest') Z2 = Z2 * Z.sum() /Z2.sum() data = pf.open("f160w_25_457_557_457_557_pixels.fits")[0].data mask = pf.open("f160w_25_457_557_457_557_dq.fits")[0].data
def q_fit(out, sacn): #out='/scratch/dw1519/galex/co/co32_1-10_new' co_list = [] info_list = [] co_files = sorted(glob.glob(out+"/[0-9]*.npy"), key=get_key) info_files = sorted(glob.glob(out+"/info_*"), key=get_key_info) ''' for i in range(0, 27): co = np.load(out+'/radec/{0}.npy'.format((i+1)*100))/36000./800/0.001666*2400 info = np.load(out+'/info_{0}.npy'.format((i+1)*100))[1:] ''' for cf, inf in zip(co_files, info_files): co = np.load(cf)[1:]/36000./800/0.001666*2400 info = np.load(inf)[1:] co_list.append(co) info_list.append(info) co = np.concatenate(co_list, axis=0) info = np.concatenate(info_list, axis=0) mask1 = (co[:,1]>=-15) & (co[:,1]<=15) mask2 = (co[:,0]>=-15) & (co[:,0]<=15) centroids = [] for q in range(0,32): print('q={0}'.format(q)) mask3 = info[:,2] == q hist_size = [100,100] H,xedges,yedges=np.histogram2d(co[mask1&mask2&mask3,1], co[mask1&mask2&mask3,0],\ bins=hist_size, range=([ [-15,15],[-15,15] ])) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() t=50 c_data = c3.find_centroid(data, t) if c_data is not None: cy, cx, max_value, flux = c_data centroids.append([-15.+cx*30./hist_size[0], -15.+cy*30./hist_size[0]]) else: centroids.append([0,0]) np.save(out+'/centroids_q.npy', centroids) q = np.arange(32) centroids = np.array(centroids) plt.plot(q, centroids[:,0], '.k') plt.xlabel('q') plt.ylabel(r'mean $\Delta x$ [pixel]') plt.title(r'scan{0:>5}'.format(scan)) plt.savefig(out+'/q_cx.png', dpi=190) plt.clf() plt.plot(q, centroids[:,1], '.k') plt.xlabel('q') plt.ylabel(r'mean $\Delta y$ [pixel]') plt.title(r'scan{0:>5}'.format(scan)) plt.savefig(out+'/q_cy.png', dpi=190) plt.clf() ''' c = np.load(out+'/centroids.npy') ya = np.arange(30)+2 slope, intercept, r_value, p_value, std_err = stats.linregress(ya, c[:,1]) print(slope, intercept, r_value, p_value, std_err) np.save(out+'/q_fit.npy', [slope, intercept, r_value, p_value, std_err]) ''' #q hist mask = (co[:,0]>=-15) & (co[:,0]<=15) & (info[:,2]<24) imsz = [24, 60] H,xedges,yedges=np.histogram2d(info[mask,2], co[mask,0],\ bins=imsz) plt.imshow(H,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal',\ extent=[-15, 15, 0, 24], origin='lower', norm=LogNorm()) q = np.arange(32) plt.plot(centroids[:,0], q, 'or') plt.xlim(-15,15) plt.ylim(0,24) plt.title('scan{0:>5}'.format(scan)) plt.xlabel(r'$\Delta x$ [pixel]') plt.ylabel('q') plt.savefig(out+'/q-x_tot_fit.png', dpi=190) plt.clf() mask = (co[:,1]>=-15) & (co[:,1]<=15) & (info[:,2]<24) imsz = [24, 60] H,xedges,yedges=np.histogram2d(info[mask,2], co[mask,1],\ bins=imsz) plt.imshow(H,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal',\ extent=[-15, 15, 0, 24], origin='lower', norm=LogNorm()) plt.plot(centroids[:,1], q, 'or') plt.xlim(-15,15) plt.ylim(0,24) plt.title('scan{0:>5}'.format(scan)) plt.xlabel(r'$\Delta y$ [pixel]') plt.ylabel('q') plt.savefig(out+'/q-y_tot_fit.png', dpi=190) plt.clf()
h = hist_g(photon_data, wcs, imsz) count += h ''' tranges = [[0,0]] hdu = pyfits.PrimaryHDU(count) hdu = imagetools.fits_header('NUV', skypos, tranges, skyrange, hdu=hdu, wcs=wcs) hdulist = pyfits.HDUList([hdu]) hdulist.writeto('../fits/scan_map/fake2.fits', clobber=False) ''' t = 1 H = h.copy() data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) if c_data is not None: cy, cx, max_value, flux = c_data cy+=0#0.5 cx+=0#0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0] else: centroid = [0.,0.] max_value = 0 flux = 500 if centroid[0]>1: centroid[0] = centroid[0]-360. #print 'max:{0}'.format(max_value) fig = plt.gcf() fig.set_size_inches(8,8) plt.imshow(h,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.025,-0.025,0.025,-0.025], origin='upper', imlim=[-0.02,0.02, -0.02,0.02])
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix, info_list, d3, outdir): imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) count = np.zeros(imsz) #print(imsz) bound = skyrange[0] co_rel = np.array([[0,0]]) infos = np.array([[0,0,0]]) len1 = coo1.shape[0] len2 = coo2.shape[0] print(len1,len2) wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz) #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile: #writer = csv.writer(csvfile) if len2>len1: for i in range(len1): #print(i) tmp_co = coo2-coo1[i,:] mask = (np.absolute(tmp_co[:,0])<=bound) & (np.absolute(tmp_co[:,1])<=bound) tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) infos = np.concatenate((infos,info_list[mask]), axis=0) else: for i in range(len2): #print(i) tmp_co = coo2[i,:]-coo1 tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) infos = np.concatenate((infos,np.repeat(info_list[i], tmp_co.shape[0])), axis=0) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ])) t = np.percentile(H, 90) t = 50 print 'threshold:{0}'.format(t) hp = H.copy() #plt.colorbar() #plt.plot(co_rel[:,0],co_rel[:,1], 'o', alpha=0.05) #plt.xlim(-0.005,0.005) #plt.ylim(-0.005,0.005) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) if c_data is not None: cy, cx, max_value, flux = c_data cy+=0.5 cx+=0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0] else: centroid = [0.,0.] max_value = 0 flux = 500 if centroid[0]>1: centroid[0] = centroid[0]-360. #print 'max:{0}'.format(max_value) print hp.shape #plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', vmin=0) plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', norm=LogNorm(10**0,np.max(hp))) plt.colorbar() plt.xlim(-0.02*3600, 0.02*3600) plt.ylim(-0.02*3600, 0.02*3600) plt.ylabel('gb') plt.xlabel('gl') plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) plt.plot(centroid[0]*3600,centroid[1]*3600,'+r', markersize=8) #plt.show() rot = np.mean(d3)/180.*np.pi l = np.linspace(0, 8., 5) x_y = np.sin(-rot)*l x_x = np.cos(-rot)*l y_y = np.sin(-rot+np.pi/2.)*l y_x = np.cos(-rot+np.pi/2.)*l plt.plot(x_x, x_y, '--g') plt.plot(y_x, y_y, '--g') co_rel = co_rel*3600 mask = (co_rel[1:,0]**2+co_rel[1:,1]**2) <= (2.5**2) num = np.sum(mask) plt.title('t={0}-{1}s, photons within d=5\" circle:{2}'.format(idx/2-50, idx/2, num)) plt.savefig('{0}/{1}.pdf'.format(outdir,idx)) plt.clf() np.save('{0}/{1}.npy'.format(outdir,idx), co_rel) plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02*3600, -0.02*3600, 0.02*3600, -0.02*3600], origin='upper', norm=LogNorm(10**0,np.max(hp))) plt.colorbar() plt.xlim(-0.01*3600, 0.01*3600) plt.ylim(-0.01*3600, 0.01*3600) plt.ylabel('gb') plt.xlabel('gl') plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) plt.plot(centroid[0]*3600,centroid[1]*3600,'+r', markersize=8) #plt.show() rot = np.mean(d3)/180.*np.pi l = np.linspace(0, 8., 5) x_y = np.sin(-rot)*l x_x = np.cos(-rot)*l y_y = np.sin(-rot+np.pi/2.)*l y_x = np.cos(-rot+np.pi/2.)*l plt.plot(x_x, x_y, '--g') plt.plot(y_x, y_y, '--g') mask = (co_rel[1:,0]**2+co_rel[1:,1]**2) <= (2.5**2) num = np.sum(mask) plt.title('t={0}-{1}s'.format(idx/2-50, idx/2)) plt.savefig('{0}/zoom_{1}.pdf'.format(outdir,idx)) plt.clf() ''' plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,0], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face') cb1 = plt.colorbar() cb1.set_label('xa') plt.xlim(-0.02*3600, 0.02*3600) plt.ylim(-0.02*3600, 0.02*3600) plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/xa_{0}.png'.format(idx)) plt.clf() plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,1], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face') cb1 = plt.colorbar() cb1.set_label('ya') plt.xlim(-0.02*3600, 0.02*3600) plt.ylim(-0.02*3600, 0.02*3600) plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/ya_{0}.png'.format(idx)) plt.clf() plt.scatter(co_rel[1:,0], co_rel[1:,1], c=infos[1:,2], s=.5, alpha=0.3, cmap=plt.get_cmap('jet'), marker='o',edgecolors='face') cb1 = plt.colorbar() cb1.set_label('q') plt.xlim(-0.02*3600, 0.02*3600) plt.ylim(-0.02*3600, 0.02*3600) plt.savefig('/home/dw1519/dw1519/galex/plots/co32-10/q_{0}.png'.format(idx), dpi=190) plt.clf() ''' ''' n, bins, patches = plt.hist(infos[1:,1], 30, normed=1, facecolor='green', alpha=0.5) plt.savefig('/home/dw1519/dw1519/galex/plots/co239_s/yahist_{0}.pdf'.format(idx), dpi=190) plt.clf() mask = (co_rel[:,0]<-25) & (co_rel[:,0]>-45) & (co_rel[:,1]>42) & (co_rel[:,1]<66) n, bins, patches = plt.hist(infos[mask,1], 30, normed=1, facecolor='green', alpha=0.5) plt.savefig('/home/dw1519/dw1519/galex/plots/co239_s/yahist_gh_{0}.pdf'.format(idx), dpi=190) plt.clf() ''' return centroid, max_value, flux
def get_corr_map(pid, coo1, coo2, skypos, skyrange, pixsz, time, suffix, weight, flux=None): imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) count = np.zeros(imsz) bound = skyrange[0]/2. wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz) catalog = SkyCoord(coo1, unit='deg', frame='fk5', equinox='J2000.0') sky_data = SkyCoord(coo2, unit='deg', frame='fk5', equinox='J2000.0') print '{1}:catalog:{0}'.format(catalog.shape[0], pid) print '{1}:data:{0}'.format(sky_data.shape[0], pid) idxc, idxcatalog, d2d_p, d3d_p = sky_data.search_around_sky(catalog, 0.0045*u.deg) print '{1}:match:{0}'.format(idxc.shape[0], pid) if idxc.shape[0]<10: centroid = [0.,0.] max_value = 0 flux = 500 return centroid, max_value, flux, idxc.shape[0] co_rel = coo2[idxcatalog] - coo1[idxc] if flux is not None: weights = weight[idxcatalog]/flux[idxc]*50. else: weights = weight[idxcatalog] foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel,1),1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]), weights=weights) t = np.percentile(H, 90) t = 1 print '{1}:threshold:{0}'.format(t, pid) #hp = H.copy() #plt.colorbar() ''' plt.plot(co_rel[:,0],co_rel[:,1], '.k') plt.xlim(-0.02,0.02) plt.ylim(-0.02,0.02) ''' #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx)) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) #print c_data if c_data is not None: #cy, cx, max_value, flux, x, y = c_data cy, cx, max_value, flux = c_data cy+=0.5 cx+=0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0] #c_sex = wcs.wcs_pix2world(wcs.sip_foc2pix([[x+0.5, y+0.5]],1),1)[0] #print c_sex else: centroid = [0.,0.] max_value = 0 flux = 500 if centroid[0]>1: centroid[0] = centroid[0]-360. #if c_sex[0]>1: # c_sex[0] = c_sex[0]-360. #print 'max:{0}'.format(max_value) #print cx,cy ''' plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[bound, -bound, -bound, bound], origin='lower', vmin=0) #plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', norm=LogNorm(10**0,np.max(hp))) plt.colorbar() plt.xlim(-bound/3, bound/3) plt.ylim(-bound/3, bound/3) plt.ylabel('gb') plt.xlabel('gl') plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) plt.plot(centroid[0],centroid[1],'+r', markersize=8) #plt.plot(c_sex[0],c_sex[1],'+g', markersize=8) plt.show() #plt.savefig('/home/dw1519/dw1519/galex/plots/co239_fix/{0}.pdf'.format(idx)) #plt.clf() ''' return centroid, max_value, flux, idxc.shape[0]
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix): imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) count = np.zeros(imsz) #print(imsz) bound = skyrange[0] co_rel = np.array([[0, 0]]) len1 = coo1.shape[0] len2 = coo2.shape[0] print(len1, len2) wcs = imagetools.define_wcs(skypos, skyrange, width=False, height=False, verbose=0, pixsz=pixsz) #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile: #writer = csv.writer(csvfile) if len2 > len1: for i in range(len1): #print(i) tmp_co = coo2 - coo1[i, :] tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :] tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :] co_rel = np.concatenate((co_rel, tmp_co), axis=0) else: for i in range(len2): #print(i) tmp_co = coo2[i, :] - coo1 tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :] tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :] co_rel = np.concatenate((co_rel, tmp_co), axis=0) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:], 1), 1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ])) t = np.percentile(H, 90) t = 1 print 'threshold:{0}'.format(t) hp = H.copy() #plt.colorbar() ''' plt.plot(co_rel[:,0],co_rel[:,1], '.k') plt.xlim(-0.02,0.02) plt.ylim(-0.02,0.02) ''' #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx)) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) if c_data is not None: cy, cx, max_value, flux = c_data cy += 0.5 cx += 0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]], 1), 1)[0] else: centroid = [0., 0.] max_value = 0 flux = 500 if centroid[0] > 1: centroid[0] = centroid[0] - 360. #print 'max:{0}'.format(max_value) print hp.shape return centroid, max_value, flux
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix): imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) count = np.zeros(imsz) #print(imsz) bound = skyrange[0] co_rel = np.array([[0,0]]) len1 = coo1.shape[0] len2 = coo2.shape[0] print(len1,len2) wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz) #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile: #writer = csv.writer(csvfile) if len2>len1: for i in range(len1): #print(i) tmp_co = coo2-coo1[i,:] tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) else: for i in range(len2): #print(i) tmp_co = coo2[i,:]-coo1 tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ])) t = np.percentile(H, 90) t = 1 print 'threshold:{0}'.format(t) hp = H.copy() #plt.colorbar() ''' plt.plot(co_rel[:,0],co_rel[:,1], '.k') plt.xlim(-0.02,0.02) plt.ylim(-0.02,0.02) ''' #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx)) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) if c_data is not None: cy, cx, max_value, flux = c_data cy+=0.5 cx+=0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0] else: centroid = [0.,0.] max_value = 0 flux = 500 if centroid[0]>1: centroid[0] = centroid[0]-360. #print 'max:{0}'.format(max_value) print hp.shape fig = plt.gcf() fig.set_size_inches(8,8) plt.imshow(hp,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.02,-0.02, 0.02,-0.02], origin='upper', imlim=[-0.02,0.02, -0.02,0.02]) #plt.imshow(hp,interpolation='None', cmap=plt.get_cmap('Greys'), extent=[0.02,-0.02,0.02,-0.02]) plt.xlabel(r'$\Delta RA$') plt.ylabel(r'$\Delta Dec$') plt.plot(centroid[0],centroid[1],'+r', markersize=8) plt.xlim(0.02, -0.02) plt.ylim(0.02, -0.02) plt.tight_layout() #plt.subplots_adjust(left=0.12, bottom=0.07, right=0.95, top=0.97, wspace=0, hspace=0) plt.savefig('/home/dw1519/galex/plots/co%s.png'%suffix, dpi=190) #plt.show() plt.clf() return centroid, max_value, flux
import numpy as np from matplotlib.colors import LogNorm from mpl_toolkits.axes_grid1 import make_axes_locatable fl=1e-5 f = .05 g = .01 H = 3 #X = np.exp(np.loadtxt("superb_wfc_mean_iter_5_nfl.txt")) X = np.exp(np.loadtxt("superb_wfc_mean_iter_0.txt")) Z = (X).reshape(25*H,25*H) print Z.sum() import c3 x0 , y0 = c3.find_centroid(Z) print x0, y0 import scipy from scipy import ndimage Z2 = scipy.ndimage.interpolation.shift(Z, [-x0,-y0], output=None, order=3, mode='nearest', prefilter=True) k = np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]]) Z2 = ndimage.convolve(Z2, k, mode='nearest') Z2 = Z2 * Z.sum() /Z2.sum() plt.figure(figsize=(10,10)) ax = plt.gca()
def q_fit(out, sacn): #out='/scratch/dw1519/galex/co/co32_1-10_new' co_list = [] info_list = [] co_files = sorted(glob.glob(out + "/[0-9]*.npy"), key=get_key) info_files = sorted(glob.glob(out + "/info_*"), key=get_key_info) ''' for i in range(0, 27): co = np.load(out+'/radec/{0}.npy'.format((i+1)*100))/36000./800/0.001666*2400 info = np.load(out+'/info_{0}.npy'.format((i+1)*100))[1:] ''' for cf, inf in zip(co_files, info_files): co = np.load(cf)[1:] / 36000. / 800 / 0.001666 * 2400 info = np.load(inf)[1:] co_list.append(co) info_list.append(info) co = np.concatenate(co_list, axis=0) info = np.concatenate(info_list, axis=0) mask1 = (co[:, 1] >= -15) & (co[:, 1] <= 15) mask2 = (co[:, 0] >= -15) & (co[:, 0] <= 15) centroids = [] for q in range(0, 32): print('q={0}'.format(q)) mask3 = info[:, 2] == q hist_size = [100, 100] H,xedges,yedges=np.histogram2d(co[mask1&mask2&mask3,1], co[mask1&mask2&mask3,0],\ bins=hist_size, range=([ [-15,15],[-15,15] ])) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() t = 50 c_data = c3.find_centroid(data, t) if c_data is not None: cy, cx, max_value, flux = c_data centroids.append([ -15. + cx * 30. / hist_size[0], -15. + cy * 30. / hist_size[0] ]) else: centroids.append([0, 0]) np.save(out + '/centroids_q.npy', centroids) q = np.arange(32) centroids = np.array(centroids) plt.plot(q, centroids[:, 0], '.k') plt.xlabel('q') plt.ylabel(r'mean $\Delta x$ [pixel]') plt.title(r'scan{0:>5}'.format(scan)) plt.savefig(out + '/q_cx.png', dpi=190) plt.clf() plt.plot(q, centroids[:, 1], '.k') plt.xlabel('q') plt.ylabel(r'mean $\Delta y$ [pixel]') plt.title(r'scan{0:>5}'.format(scan)) plt.savefig(out + '/q_cy.png', dpi=190) plt.clf() ''' c = np.load(out+'/centroids.npy') ya = np.arange(30)+2 slope, intercept, r_value, p_value, std_err = stats.linregress(ya, c[:,1]) print(slope, intercept, r_value, p_value, std_err) np.save(out+'/q_fit.npy', [slope, intercept, r_value, p_value, std_err]) ''' #q hist mask = (co[:, 0] >= -15) & (co[:, 0] <= 15) & (info[:, 2] < 24) imsz = [24, 60] H,xedges,yedges=np.histogram2d(info[mask,2], co[mask,0],\ bins=imsz) plt.imshow(H,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal',\ extent=[-15, 15, 0, 24], origin='lower', norm=LogNorm()) q = np.arange(32) plt.plot(centroids[:, 0], q, 'or') plt.xlim(-15, 15) plt.ylim(0, 24) plt.title('scan{0:>5}'.format(scan)) plt.xlabel(r'$\Delta x$ [pixel]') plt.ylabel('q') plt.savefig(out + '/q-x_tot_fit.png', dpi=190) plt.clf() mask = (co[:, 1] >= -15) & (co[:, 1] <= 15) & (info[:, 2] < 24) imsz = [24, 60] H,xedges,yedges=np.histogram2d(info[mask,2], co[mask,1],\ bins=imsz) plt.imshow(H,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal',\ extent=[-15, 15, 0, 24], origin='lower', norm=LogNorm()) plt.plot(centroids[:, 1], q, 'or') plt.xlim(-15, 15) plt.ylim(0, 24) plt.title('scan{0:>5}'.format(scan)) plt.xlabel(r'$\Delta y$ [pixel]') plt.ylabel('q') plt.savefig(out + '/q-y_tot_fit.png', dpi=190) plt.clf()
def get_corr_map(pid, coo1, coo2, skypos, skyrange, pixsz, time, suffix, weight, flux=None): imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) count = np.zeros(imsz) bound = skyrange[0] / 2. wcs = imagetools.define_wcs(skypos, skyrange, width=False, height=False, verbose=0, pixsz=pixsz) catalog = SkyCoord(coo1, unit='deg', frame='fk5', equinox='J2000.0') sky_data = SkyCoord(coo2, unit='deg', frame='fk5', equinox='J2000.0') print '{1}:catalog:{0}'.format(catalog.shape[0], pid) print '{1}:data:{0}'.format(sky_data.shape[0], pid) idxc, idxcatalog, d2d_p, d3d_p = sky_data.search_around_sky( catalog, 0.0045 * u.deg) print '{1}:match:{0}'.format(idxc.shape[0], pid) if idxc.shape[0] < 10: centroid = [0., 0.] max_value = 0 flux = 500 return centroid, max_value, flux, idxc.shape[0] co_rel = coo2[idxcatalog] - coo1[idxc] if flux is not None: weights = weight[idxcatalog] / flux[idxc] * 50. else: weights = weight[idxcatalog] foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel, 1), 1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]), weights=weights) t = np.percentile(H, 90) t = 1 print '{1}:threshold:{0}'.format(t, pid) #hp = H.copy() #plt.colorbar() ''' plt.plot(co_rel[:,0],co_rel[:,1], '.k') plt.xlim(-0.02,0.02) plt.ylim(-0.02,0.02) ''' #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx)) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) #print c_data if c_data is not None: #cy, cx, max_value, flux, x, y = c_data cy, cx, max_value, flux = c_data cy += 0.5 cx += 0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]], 1), 1)[0] #c_sex = wcs.wcs_pix2world(wcs.sip_foc2pix([[x+0.5, y+0.5]],1),1)[0] #print c_sex else: centroid = [0., 0.] max_value = 0 flux = 500 if centroid[0] > 1: centroid[0] = centroid[0] - 360. #if c_sex[0]>1: # c_sex[0] = c_sex[0]-360. #print 'max:{0}'.format(max_value) #print cx,cy ''' plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[bound, -bound, -bound, bound], origin='lower', vmin=0) #plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', norm=LogNorm(10**0,np.max(hp))) plt.colorbar() plt.xlim(-bound/3, bound/3) plt.ylim(-bound/3, bound/3) plt.ylabel('gb') plt.xlabel('gl') plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) plt.plot(centroid[0],centroid[1],'+r', markersize=8) #plt.plot(c_sex[0],c_sex[1],'+g', markersize=8) plt.show() #plt.savefig('/home/dw1519/dw1519/galex/plots/co239_fix/{0}.pdf'.format(idx)) #plt.clf() ''' return centroid, max_value, flux, idxc.shape[0]
import c3 import profile y = profile.makeGaussian(33,6,0,(14.78,18.1)) print -16.5+14.78 , -16.5+18.1 print c3.find_centroid(y)
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix): imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) count = np.zeros(imsz) #print(imsz) bound = skyrange[0] co_rel = np.array([[0,0]]) len1 = coo1.shape[0] len2 = coo2.shape[0] print(len1,len2) wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz) #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile: #writer = csv.writer(csvfile) if len2>len1: for i in range(len1): #print(i) tmp_co = coo2-coo1[i,:] tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) else: for i in range(len2): #print(i) tmp_co = coo2[i,:]-coo1 tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=bound,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=bound,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:],1),1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ])) t = np.percentile(H, 90) t = 1 print 'threshold:{0}'.format(t) hp = H.copy() #plt.colorbar() ''' plt.plot(co_rel[:,0],co_rel[:,1], '.k') plt.xlim(-0.02,0.02) plt.ylim(-0.02,0.02) ''' #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx)) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) if c_data is not None: cy, cx, max_value, flux = c_data cy+=0.5 cx+=0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]],1),1)[0] else: centroid = [0.,0.] max_value = 0 flux = 500 if centroid[0]>1: centroid[0] = centroid[0]-360. #print 'max:{0}'.format(max_value) print hp.shape return centroid, max_value, flux
def get_corr_map(coo1, coo2, skypos, skyrange, sec, pixsz, idx, suffix, weight): imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) count = np.zeros(imsz) #print(imsz) weights = np.array([]) bound = skyrange[0] co_rel = np.array([[0, 0]]) len1 = coo1.shape[0] len2 = coo2.shape[0] print(len1, len2) wcs = imagetools.define_wcs(skypos, skyrange, width=False, height=False, verbose=0, pixsz=pixsz) #with open('../data/try2_%d.csv'%sec, 'wb') as csvfile: #writer = csv.writer(csvfile) sky_data = SkyCoord(coo1, unit='deg', frame=FK5, equinox='J2000.0') gal = sky_data.transform_to(Galactic) coo1 = np.concatenate((np.array([gal.l.deg]).T, np.array([gal.b.deg]).T), axis=1) sky_data = SkyCoord(coo2, unit='deg', frame=FK5, equinox='J2000.0') gal = sky_data.transform_to(Galactic) coo2 = np.concatenate((np.array([gal.l.deg]).T, np.array([gal.b.deg]).T), axis=1) if len2 > len1: for i in range(len1): #print(i) tmp_co = coo2 - coo1[i, :] mask = (np.absolute(tmp_co[:, 0]) <= bound) & (np.absolute( tmp_co[:, 1]) <= bound) tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :] tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :] co_rel = np.concatenate((co_rel, tmp_co), axis=0) weights = np.concatenate((weights, weight[mask]), axis=0) else: for i in range(len2): #print(i) tmp_co = coo2[i, :] - coo1 mask = (np.absolute(tmp_co[:, 0]) <= bound) & (np.absolute( tmp_co[:, 1]) <= bound) tmp_co = tmp_co[np.absolute(tmp_co[:, 0]) <= bound, :] tmp_co = tmp_co[np.absolute(tmp_co[:, 1]) <= bound, :] co_rel = np.concatenate((co_rel, tmp_co), axis=0) weights = np.concatenate( (weights, np.repeat(weight[i], tmp_co.shape[0])), axis=0) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co_rel[1:], 1), 1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]))#, weights=weights) t = np.percentile(H, 90) t = 1 print 'threshold:{0}'.format(t) hp = H.copy() #plt.colorbar() ''' plt.plot(co_rel[:,0],co_rel[:,1], '.k') plt.xlim(-0.02,0.02) plt.ylim(-0.02,0.02) ''' #plt.savefig('/home/dw1519/galex/plots/co3/{0}.png'.format(idx)) data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) #print c_data if c_data is not None: #cy, cx, max_value, flux, x, y = c_data cy, cx, max_value, flux = c_data cy += 0.5 cx += 0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]], 1), 1)[0] #c_sex = wcs.wcs_pix2world(wcs.sip_foc2pix([[x+0.5, y+0.5]],1),1)[0] #print c_sex else: centroid = [0., 0.] max_value = 0 flux = 500 if centroid[0] > 1: centroid[0] = centroid[0] - 360. #if c_sex[0]>1: # c_sex[0] = c_sex[0]-360. #print 'max:{0}'.format(max_value) ''' plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', vmin=0) #plt.imshow(hp+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.01*3600, -0.01*3600, 0.01*3600, -0.01*3600], origin='upper', norm=LogNorm(10**0,np.max(hp))) plt.colorbar() plt.xlim(-0.01*3600/2, 0.01*3600/2) plt.ylim(-0.01*3600/2, 0.01*3600/2) plt.ylabel('gb') plt.xlabel('gl') plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) plt.plot(centroid[0]*3600,centroid[1]*3600,'+r', markersize=8) plt.plot(c_sex[0]*3600,c_sex[1]*3600,'+g', markersize=8) plt.show() #plt.savefig('/home/dw1519/dw1519/galex/plots/co239_fix/{0}.pdf'.format(idx)) #plt.clf() ''' return centroid, max_value, flux
h = hist_g(photon_data, wcs, imsz) count += h ''' tranges = [[0,0]] hdu = pyfits.PrimaryHDU(count) hdu = imagetools.fits_header('NUV', skypos, tranges, skyrange, hdu=hdu, wcs=wcs) hdulist = pyfits.HDUList([hdu]) hdulist.writeto('../fits/scan_map/fake2.fits', clobber=False) ''' t = 1 H = h.copy() data = H.byteswap(True).newbyteorder() data = data.copy(order='C') data = data.byteswap(True).newbyteorder() c_data = c3.find_centroid(data, t) if c_data is not None: cy, cx, max_value, flux = c_data cy += 0 #0.5 cx += 0 #0.5 centroid = wcs.wcs_pix2world(wcs.sip_foc2pix([[cx, cy]], 1), 1)[0] else: centroid = [0., 0.] max_value = 0 flux = 500 if centroid[0] > 1: centroid[0] = centroid[0] - 360. #print 'max:{0}'.format(max_value) fig = plt.gcf() fig.set_size_inches(8, 8) plt.imshow(h,