def get_corr_map_photon(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) if len2<=80 or len1<=80: return count, np.array([0.0, 0.0]) if len2>len1: for i in range(len2): #print(i) tmp_co = np.roll(coo2, i, axis=0)[0:len1,:]-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) else: for i in range(len1): #print(i) tmp_co = coo2-np.roll(coo1, i, axis=0)[0:len2,:] 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) print co_rel.shape if co_rel.shape[0]>1000: centroid = ck.find_centroid(co_rel[1:], bandwidth, 11, bound) else: return count, np.array([0.0, 0.0]) return count, centroid
def get_corr_map_(coo1, coo2, skypos, skyrange, sec): 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(len2): print(i) tmp_co = np.roll(coo2, i, axis=0)[0:len1,:]-coo1 tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=0.01,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=0.01,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) else: for i in range(len1): print(i) tmp_co = coo2-np.roll(coo1, i, axis=0)[0:len2,:] tmp_co = tmp_co[np.absolute(tmp_co[:,0])<=0.01,:] tmp_co = tmp_co[np.absolute(tmp_co[:,1])<=0.01,:] co_rel = np.concatenate((co_rel, tmp_co), axis = 0) return co_rel[1:]
def get_corr_map_fast(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) print co_rel.shape if co_rel.shape[0]>50: centroid = ck.find_centroid(co_rel[1:], bandwidth, 11, bound) else: return count, np.array([0.0, 0.0]) return count, centroid
def get_corr_map(coo1, coo2, skypos, skyrange): imsz = imagetools.deg2pix(skypos, skyrange, 0.001) 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.001) if len2>len1: for i in range(len2): print(i) co_rel = np.concatenate((co_rel, np.roll(coo2, i, axis=0)[0:len1,:]-coo1), axis = 0) if (i+1)%200 == 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]] ])) count += H co_rel = np.array([[0, 0]]) else: for i in range(len1): print(i) co_rel = np.concatenate((co_rel, coo2-np.roll(coo1, i, axis=0)[0:len2,:]), axis = 0) if (i+1)%200 == 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]] ])) count += H co_rel = np.array([[0, 0]]) if co_rel.shape[0]>1: 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]] ])) count += H return count
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(len2): #print(i) tmp_co = np.roll(coo2, i, axis=0)[0:len1,:]-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) ''' if (i+1)%200 == 0: writer.writerows(co_rel[1:]) 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]] ])) count += H co_rel = np.array([[0, 0]]) ''' else: for i in range(len1): #print(i) tmp_co = coo2-np.roll(coo1, i, axis=0)[0:len2,:] 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 (i+1)%200 == 0: writer.writerows(co_rel[1:]) 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]] ])) count += H co_rel = np.array([[0, 0]]) ''' ''' if co_rel.shape[0]>1: #writer.writerows(co_rel[1:]) 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]] ])) count += H #csvfile.close() ''' print co_rel.shape if co_rel.shape[0]>50: centroid = ck.find_centroid(co_rel[1:], bandwidth, 11, bound) else: return count, np.array([0.0, 0.0]) return count, centroid
def run_one_r(pid, scan_name, step, start, end, return_dict): num_co = int(1/step) hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits'%scan_name) co_data = hdulist[1].data length = co_data.shape[0] print length for initial_sec in range(start, end): file_path = '../data/%s/cata/centroids%d_half.npy'%(scan_name, initial_sec) if os.path.exists(file_path): print 'skip:%d'%initial_sec continue intitial_asp = co_data[initial_sec] center = np.array([intitial_asp[1], intitial_asp[2]]) print(intitial_asp) skypos = [0.0, 0.0] skyrange = [0.3, 0.3] wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001) initial_time = intitial_asp[0]-0.5 tranges = [] for sec in range(num_co): tranges.append([initial_time+step*sec, initial_time+step*(sec+1)]) print tranges data = get_data(tranges, scan_name) print len(data) output = "../data/%s/cata/%s.csv"%(scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) centroids = [] for sec in range(num_co): if len(data[sec]) ==0: centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:,-3:-1] coo2 = catalog_fits.get_catalog(center, 0.69) coo1 = angle_filter(coo1, center, 0.4) coo2 = angle_filter(coo2, center, 0.4) count, centroid = get_corr_map_fast(coo2, coo1, skypos, skyrange, sec, 0.20, 0.008) centroids.append(centroid) print centroid print centroids np.save('../data/%s/cata/centroids%d_half.npy'%(scan_name, initial_sec), centroids)
def plot_co(co, pixsz, skypos, skyrange, weights=None): bound = skyrange[0]/2. imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=pixsz) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(co[:,0:2],1),1) if weights is not None: H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ]), weights=weights) else: H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,bins=imsz, range=([ [0,imsz[0]],[0,imsz[1]] ])) h = H.copy() #np.flip(h,axis=0) ''' hist_size = [100,100] H,xedges,yedges=np.histogram2d(co[:,1], co[:,0],\ bins=hist_size, range=([ [-bound,bound],[-bound,bound] ])) h = H.copy() ''' plt.imshow(h+10**-10,interpolation='None', cmap=plt.get_cmap('Greys'),\ aspect='equal', extent=[bound*3600, -bound*3600, -bound*3600, bound*3600], origin='lower',vmin=0) #norm=LogNorm(10**0,np.max(h))) plt.axhline(y=0, color='b', linestyle='dashed', linewidth=1) plt.axvline(x=0, color='b', linestyle='dashed', linewidth=1) plt.xlabel(r'$\Delta gl$') plt.ylabel(r'$\Delta gb$') plt.xlim(-bound*3600,bound*3600) plt.ylim(-bound*3600,bound*3600) ''' 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 c = np.array([-bound+cx*bound*2/hist_size[0], -bound+cy*bound*2/hist_size[0]]) print c*3600 ''' c = centroid(5,H,wcs) print(c*3600) plt.plot(c[0]*3600,c[1]*3600,'+r', markersize=8, mew=1)
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 run_one_r_sec(pid, scan_name, step, resolution, asp_cal, start, end, dis_map, return_dict): print('run one r sec') num_co = int(resolution/step) #load asp file hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits'%scan_name) co_data = hdulist[1].data length = co_data.shape[0] ''' try: asp_cal = np.load('../data/photon_list/%s_asp_new.npy'%scan_name) except IOError: T = co_data['T'] ra = co_data['ra'] dec = co_data['dec'] roll = co_data['roll'] t_new = np.arange((T.shape[0]-1)*200)*0.005+T[0] ra_new = np.interp(t_new, T, ra) dec_new = np.interp(t_new, T, dec) roll_new = np.interp(t_new, T, roll) asp_cal = np.array([t_new, ra_new, dec_new, roll_new]).T np.save('../data/photon_list/%s_asp_new.npy'%scan_name, asp_cal) ''' #cal_initial = int((co_data[1][0]-0.5)*1000) #offsets = np.load('../data/%s/cata/offsets_inter_half_sec.npy'%scan_name) angle_list = [0.] print length data1 = [] data2 = [] data3 = [] start = 700 c_list = [] for start in range(701, 1500, 50): print start data1 = [] data2 = [] data3 = [] for initial_sec in range(start, start+50): print 'time:%d'%initial_sec file_path = '../data/%s/cata/centroids_rot%d.npy'%(scan_name, initial_sec) intitial_asp = co_data[initial_sec] rot = intitial_asp[3] #center = np.array([intitial_asp[1], intitial_asp[2]]) #use the first order calibrated asp instead of the original one #center = cal_asp_r(offsets, cal_initial, intitial_asp[0]*1000, intitial_asp[1:3], 200) #print(intitial_asp) skypos = [0.0, 0.0] skyrange = [0.02, 0.02] if step == 1: skyrange = [0.04, 0.04]#[0.3, 0.3] elif step == 0.5: skyrange = [0.02, 0.02] initial_time = intitial_asp[0]-step/2. tranges = [] for sec in range(num_co): tranges.append([initial_time+step*sec, initial_time+step*(sec+1)]) print tranges time_c = np.mean(tranges, axis=1) print 'center time:' print time_c #data = get_data_cal(tranges, scan_name, cal_initial, offsets) data = get_data(tranges, scan_name) print 'number of the photons:' print len(data) centroids = [] center_time = [] for sec in range(num_co): center_time.append(time_c[sec]) if len(data[sec]) == 0: centroid = np.array([0.0, 0.0, 0.0]) centroids.append(centroid) print centroid continue arg = np.argmin(np.absolute(asp_cal[:,0]-time_c[sec])) center = asp_cal[arg, 1:3] data_sec = dis_correct(np.array(data[sec], dtype='float64'), dis_map, asp_cal) coo1 = np.array(data_sec, dtype='float64') aperture = 0.69 #coo1 = np.array(data[sec], dtype='float64')[:,-3:-1] #coo2 = catalog_fits.get_catalog_tycho(center, aperture) coo2 = catalog_fits.get_catalog(center, aperture) #coo1 = angle_filter(coo1, center, 0.6) #coo2 = angle_filter(coo2, center, 0.6) ''' fig = plt.gcf() fig.set_size_inches(8,8) plt.plot(coo1[:,0], coo1[:,1], '.k', markersize=0.1) plt.plot(coo3[:,0], coo3[:,1], '+r', markersize=12) plt.plot(coo2[:,0], coo2[:,1], '+b', markersize=8) #plt.show() plt.ylabel('Dec') plt.xlabel('RA') plt.xlim(center[0]-0.65, center[0]+0.65) plt.ylim(center[1]-0.65, center[1]+0.65) plt.tight_layout() plt.savefig('/home/dw1519/galex/plots/photons.png', dpi=190) plt.clf() plt.close() ''' ''' #plot field #plt.plot(asp_cal[:,1],'.b') #plt.show() print center print coo1.shape print np.min(coo1[:,0]), np.max(coo1[:,0]) print np.min(coo1[:,1]), np.max(coo1[:,1]) wcs = imagetools.define_wcs(center,[1.5,1.5],width=False,height=False,verbose=0,pixsz=0.002) imsz = imagetools.deg2pix(center, [1.5,1.5], 0.002) foc = wcs.sip_pix2foc(wcs.wcs_world2pix(coo1,1),1) H,xedges,yedges=np.histogram2d(foc[:,1]-0.5, foc[:,0]-0.5,\ bins=imsz, range=([ [0,imsz[0]],[0,imsz[1
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, 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 run_one_r_sec(pid, scan_name, step, start, end, return_dict): num_co = int(1 / step) hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits' % scan_name) co_data = hdulist[1].data length = co_data.shape[0] cal_initial = int((co_data[1][0] - 0.5) * 1000) offsets = np.load('../data/%s/cata/offsets1_10_new_inter_half_fine.npy' % scan_name) print length for initial_sec in range(start, end): file_path = '../data/%s/cata/centroids_sec%d.npy' % (scan_name, initial_sec) if os.path.exists(file_path): print 'skip:%d' % initial_sec continue intitial_asp = co_data[initial_sec] #center = np.array([intitial_asp[1], intitial_asp[2]]) #use the first order calibrated asp instead of the original one center = cal_asp_r(offsets, cal_initial, intitial_asp[0] * 1000, intitial_asp[1:3], 200) print(intitial_asp) skypos = [0.0, 0.0] skyrange = [0.1, 0.1] wcs = imagetools.define_wcs(skypos, skyrange, width=False, height=False, verbose=0, pixsz=0.0001) initial_time = intitial_asp[0] - 0.5 tranges = [] for sec in range(num_co): tranges.append( [initial_time + step * sec, initial_time + step * (sec + 1)]) print tranges data = get_data_cal(tranges, scan_name, cal_initial, offsets) print len(data) output = "../data/%s/cata/%s.csv" % (scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) centroids = [] for sec in range(num_co): if len(data[sec]) == 0: centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:, -3:-1] coo2 = catalog_fits.get_catalog(center, 0.69) coo1 = angle_filter(coo1, center, 1.) coo2 = angle_filter(coo2, center, 1.) count, centroid = get_corr_map_fast(coo2, coo1, skypos, skyrange, sec, 0.03, 0.0015) centroids.append(centroid) print centroid print centroids np.save( '../data/%s/cata/centroids_sec%d.npy' % (scan_name, initial_sec), centroids)
data = np.concatenate((np.array([gal.l.deg]).T, np.array([gal.b.deg]).T), axis=1) H = hist_g(data, wcs, imsz) count += H trange[1] = float(time)/1000 tranges.append(trange) #trange = [0, 0] return_dict[pid] = (count, tranges) if __name__ == '__main__': if False: skypos, skyrange = pos_range.get_pos_range(name_list='../data/name_list') tranges = [] trange = [0, 0] imsz = imagetools.deg2pix(skypos, skyrange, 0.002) count = np.zeros(imsz) wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.002) print imsz hdulist = pyfits.open('../data/AIS_GAL_SCAN_00005_0001-asprta.fits') co_data = hdulist[1].data step = 10 offsets = np.load('../data/new/offsets300-1343_10_new.npy') length = offsets.shape[0] print length for i in range(length-1): offsets[i+1] = offsets[i+1] + offsets[i] offsets = np.append(offsets, np.array([[0.,0.]]), axis=0) print offsets.shape initial = int((co_data[300][0]-0.5)*1000)
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) #print cx,cy ''' plt.imshow(np.log2(hp+10**-10),interpolation='None', cmap=plt.get_cmap('Greys'), aspect='equal', extent=[0.3, -0.3, 0.3, -0.3], 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.3, 0.3) plt.ylim(-0.3, 0.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(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 run_one_r(pid, scan_name, step, start, end, return_dict): print 'run_one_r' num_co = int(1 / step) hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits' % scan_name) co_data = hdulist[1].data length = co_data.shape[0] plt.plot(co_data['T']) plt.show() cal_initial = int((co_data[1][0] - 0.5) * 1000) print cal_initial offsets = np.load('../data/%s/cata/offsets1_10_new_inter_half_fine.npy' % scan_name) print length print co_data[-10] print co_data[0] print co_data[-1][0] - co_data[0][0] #print offsets[300*200:301*200] for initial_sec in range(start, end): file_path = '../data/%s/cata/centroids%d_half.npy' % (scan_name, initial_sec) ''' if os.path.exists(file_path): print 'skip:%d'%initial_sec continue ''' intitial_asp = co_data[initial_sec] center = np.array([intitial_asp[1], intitial_asp[2]]) print(intitial_asp) skypos = [0.0, 0.0] skyrange = [0.2, 0.2] wcs = imagetools.define_wcs(skypos, skyrange, width=False, height=False, verbose=0, pixsz=0.0001) initial_time = intitial_asp[0] - 0.5 tranges = [] for sec in range(num_co): tranges.append( [initial_time + step * sec, initial_time + step * (sec + 1)]) print tranges data = get_data_cal(tranges, scan_name, cal_initial, offsets) #data = get_data(tranges, scan_name) print len(data) output = "../data/%s/cata/%s.csv" % (scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) centroids = [] for sec in range(num_co): if len(data[sec]) == 0: centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:, -3:-1] coo2 = catalog_fits.get_catalog(center, 0.69) coo1 = angle_filter(coo1, center, 0.5) coo2 = angle_filter(coo2, center, 0.5) get_corr_map(coo2, coo1, skypos, skyrange, sec, 0.05, 0.008) '''
def run_one_photon_half(pid, scan_name, step, start, end, return_dict): num_co = int(0.5 / step) hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits' % scan_name) co_data = hdulist[1].data length = co_data.shape[0] print length for initial_sec in range(start, end): file_path = '../data/%s/cata/centroids_half_photon%d.npy' % ( scan_name, initial_sec) if os.path.exists(file_path): print 'skip:%d' % initial_sec continue intitial_asp = co_data[initial_sec] print(intitial_asp) center = np.array([intitial_asp[1], intitial_asp[2]]) centroids = [] for part in range(2): print 'part:%d' % part skypos = [0.0, 0.0] skyrange = [0.1, 0.1] wcs = imagetools.define_wcs(skypos, skyrange, width=False, height=False, verbose=0, pixsz=0.0001) initial_time = intitial_asp[0] - 0.5 tranges = [] for sec in range(num_co): tranges.append([ initial_time + step * sec + part * 0.5, initial_time + step * (sec + 1) + part * 0.5 ]) print tranges data = get_data(tranges, scan_name) print len(data) output = "../data/%s/cata/%s.csv" % (scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) if len(data[2]) == 0: for sec in range(4): centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue else: coo2 = np.array(data[2], dtype='float64')[:, -3:-1] coo2 = angle_filter(coo2, center, 0.4) for sec in [0, 1, 3, 4]: if len(data[sec]) == 0: centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:, -3:-1] coo1 = angle_filter(coo1, center, 0.4) count, centroid = get_corr_map(coo2, coo1, skypos, skyrange, sec, 0.05, 0.004) centroids.append(centroid) print centroid print centroids np.save( '../data/%s/cata/centroids_half_photon%d.npy' % (scan_name, initial_sec), centroids)
def run_one_photon(pid, scan_name, start, end, return_dict): cata = spi.load_obj('../data/%s_starset_new' % scan_name) cata_a = np.array(list(cata)) cata_len = len(cata) skypos = [0.0, 0.0] skyrange = [0.2, 0.2] wcs = imagetools.define_wcs(skypos, skyrange, width=False, height=False, verbose=0, pixsz=0.0001) for star_num in range(start, end + 1): order = 1 star = 'star_%d-%d' % (star_num, order) if not os.path.exists('../data/%s/star/list/%s.csv' % (scan_name, star)): print 'skip:%s' % star continue data, time_list, count = get_data_star(scan_name, star) length = len(data) mean = np.mean(count) if mean <= 80: print 'skip:%s' % star continue output = "../data/%s/star/co_photon/%s.csv" % (scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) centroids = [] for sec in range(length): if len(data[sec]) == 0: centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:, -3:-1] #coo2 = np.array(data[sec+1], dtype='float64')[:,-3:-1] coo2 = np.array([cata_a[star_num, :]]) count, centroid = get_corr_map(coo2, coo1, skypos, skyrange, sec, 0.03, 0.004) centroids.append(centroid) print centroid print centroids np.save( '../data/%s/star/co_photon/centroids%d-%d_c.npy' % (scan_name, star_num, order), centroids) time = np.array(time_list) centers = np.array(centroids) ''' for i in range(1,centers.shape[0]): centers[i,:] += centers[i-1,:] ''' print time print centers f, axes = plt.subplots(2, 1) axes[0].plot(time, centers[:, 0]) axes[0].set_ylabel(r'$\delta RA/degree$') ylim = axes[0].get_ylim() axes[0].set_ylim(ylim + np.absolute(ylim) * 0.01) plt.setp(axes[0].get_xticklabels(), visible=False) #plt.setp( axes[0].get_yticklabels(), visible=False) axes[1].plot(time, centers[:, 1]) axes[1].set_ylabel(r'$\delta DEC/degree$') axes[1].set_xlabel('time/s') plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0, hspace=0) plt.savefig('../plots/%s/star/co_photon/offset%d-%d_c.png' % (scan_name, star_num, order), dpi=190) plt.clf() '''
def run_one_r_o(pid, scan_name, step, start, end, return_dict): num_co = int(1 / step) hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits' % scan_name) co_data = hdulist[1].data length = co_data.shape[0] print length for initial_sec in range(start, end): file_path = '../data/%s/cata/centroids_new%d.npy' % (scan_name, initial_sec) if os.path.exists(file_path): print 'skip:%d' % initial_sec continue intitial_asp = co_data[initial_sec] center = np.array([intitial_asp[1], intitial_asp[2]]) print(intitial_asp) skypos = [0.0, 0.0] skyrange = [0.3, 0.3] wcs = imagetools.define_wcs(skypos, skyrange, width=False, height=False, verbose=0, pixsz=0.0001) initial_time = intitial_asp[0] - 0.5 tranges = [] for sec in range(num_co): tranges.append( [initial_time + step * sec, initial_time + step * (sec + 1)]) print tranges data = get_data(tranges, scan_name) print len(data) output = "../data/%s/cata/%s.csv" % (scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) centroids = [] out_mask = [] for sec in range(num_co): if len(data[sec]) == 0: centroid = np.array([0.0, 0.0]) out_mask.append(1) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:, -3:-1] coo2 = catalog_fits.get_catalog(center, 0.69) coo1 = angle_filter(coo1, center, 1.) coo2 = angle_filter(coo2, center, 1.) count, centroid, out = get_corr_map_o(coo2, coo1, skypos, skyrange, sec, 0.15, 0.008) centroids.append(centroid) out_mask.append(out) print centroid print centroids np.save( '../data/%s/cata/centroids_new%d.npy' % (scan_name, initial_sec), centroids) np.save('../data/%s/cata/out_mask%d.npy' % (scan_name, initial_sec), out_mask)
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(len2): #print(i) tmp_co = np.roll(coo2, i, axis=0)[0:len1, :] - 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) ''' if (i+1)%200 == 0: writer.writerows(co_rel[1:]) 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]] ])) count += H co_rel = np.array([[0, 0]]) ''' else: for i in range(len1): #print(i) tmp_co = coo2 - np.roll(coo1, i, axis=0)[0:len2, :] 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 (i+1)%200 == 0: writer.writerows(co_rel[1:]) 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]] ])) count += H co_rel = np.array([[0, 0]]) ''' ''' if co_rel.shape[0]>1: #writer.writerows(co_rel[1:]) 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]] ])) count += H #csvfile.close() ''' print co_rel.shape if co_rel.shape[0] > 50: centroid = ck.find_centroid(co_rel[1:], bandwidth, 11, bound) else: return count, np.array([0.0, 0.0]) return count, centroid
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
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, info_list, d3, outdir): imsz = imagetools.deg2pix(skypos, skyrange, pixsz).astype(int) count = np.zeros(imsz) #print(imsz) bound = skyrange[0] / 0.000554 / 2400. * 36000. * 800 * 0.001666 co_rel = np.array([[0, 0]]) infos = np.array([[0, 0, 0]]) rot = np.array([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) ''' photon_len = coo2.shape[0] star_len = coo1.shape[0] print 'repeat coo1' coo1 = np.repeat(coo1, photon_len, axis=0) print coo1.shape print 'repeat d3' d3 = np.tile(d3, (star_len,1)) print d3.shape print 'convert coo1' xi, eta = gn.gnomfwd_simple(coo1[:,0], coo1[:,1], d3[:,1], d3[:,2], -d3[:,3], 1/36000., 0) print 'tile coo2' co_rel = np.tile(coo2, (star_len,1)) - np.array([xi,eta]).T mask = (np.absolute(co_rel[:,0])<=bound) & (np.absolute(co_rel[:,1])<=bound) co_rel = co_rel[mask] print 'tile infos' infos = np.tile(info_list, (star_len,1))[mask] print infos.shape ''' if len2 > len1: for i in range(len1): ones = np.ones(d3.shape[0]) xi, eta = gn.gnomfwd_simple(coo1[i, 0] * ones, coo1[i, 1] * ones, d3[:, 1], d3[:, 2], -d3[:, 3], 1 / 36000., 0) tmp_co = coo2 - np.array([xi, eta]).T 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) #rot = np.concatenate((rot, d3[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) rot = np.concatenate((rot, np.repeat(d3[i], tmp_co.shape[0])), axis=0) path = os.path.dirname('{0}/test/test'.format(outdir)) if not os.path.exists(path): os.makedirs(path) np.save('{0}/test/{1}.npy'.format(outdir, idx), co_rel) #np.save('{0}/radec/{1}.npy'.format(outdir, idx), co_radec) np.save('{0}/test/info_{1}.npy'.format(outdir, idx), infos) return [0, 0], 0, 0
def run_one_r_sec(pid, scan_name, step, start, end, return_dict): print('run one r sec') pixsz = 0.000416666666666667 #skypos_count = [5.,-9.5] #skyrange_count = [2., 3.] #tranges_count = [[0,0]] #imsz_count = imsz = imagetools.deg2pix_g(skypos_count, skyrange_count, pixsz) #wcs_count = imagetools.define_wcs_g(skypos_count,skyrange_count,width=False,height=False,verbose=0,pixsz=pixsz) #count = np.zeros(imsz_count) num_co = int(1/step) hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits'%scan_name) co_data = hdulist[1].data length = co_data.shape[0] #cal_initial = int((co_data[1][0]-0.5)*1000) #offsets = np.load('../data/%s/cata/offsets_inter_half_sec.npy'%scan_name) angle_list = [0.] print length for initial_sec in range(start, end): print 'time:%d'%initial_sec file_path = '../data/%s/cata/centroids_sec%d.npy'%(scan_name, initial_sec) ''' if os.path.exists(file_path): print 'skip:%d'%initial_sec continue ''' intitial_asp = co_data[initial_sec] rot = intitial_asp[3] center = np.array([intitial_asp[1], intitial_asp[2]]) #use the first order calibrated asp instead of the original one #center = cal_asp_r(offsets, cal_initial, intitial_asp[0]*1000, intitial_asp[1:3], 200) #print(intitial_asp) skypos = [0.0, 0.0] skyrange = [0.2, 0.2] wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001) initial_time = intitial_asp[0]-0.5 tranges = [] for sec in range(num_co): tranges.append([initial_time+step*sec, initial_time+step*(sec+1)]) print tranges #data = get_data_cal(tranges, scan_name, cal_initial, offsets) data = get_data(tranges, scan_name) print len(data) output = "../data/%s/cata/%s.csv"%(scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) centroids = [] for sec in range(num_co): if len(data[sec]) ==0: centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:,-3:-1] coo2 = catalog_fits.get_catalog(center, 0.69) coo1 = angle_filter(coo1, center, 0.5) coo2 = angle_filter(coo2, center, 0.5) xi, eta = gn.gnomfwd_simple(coo1[:,0], coo1[:,1], center[0], center[1], -rot, 1/36000., 0.0) max_now = -1000 cent_now = [] for angle in angle_list: coo1[:,0], coo1[:,1] = gn.gnomrev_simple(xi,eta,center[0],center[1],-(rot+angle),1/36000.,0.) centroid, max_value = get_corr_map(coo2, coo1, skypos, skyrange, sec, 0.2, 0.004) if max_value>max_now: max_now = max_value cent_now = np.append(centroid, angle) #centroid.append(angle) centroids.append(cent_now) print centroids np.save('../data/%s/cata/centroids_rot%d.npy'%(scan_name, initial_sec), centroids)
def run_one_r(pid, scan_name, step, start, end, return_dict): print 'run_one_r' num_co = int(1/step) hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits'%scan_name) co_data = hdulist[1].data length = co_data.shape[0] plt.plot(co_data['T']) plt.show() cal_initial = int((co_data[1][0]-0.5)*1000) print cal_initial offsets = np.load('../data/%s/cata/offsets1_10_new_inter_half_fine.npy'%scan_name) print length print co_data[-10] print co_data[0] print co_data[-1][0]-co_data[0][0] #print offsets[300*200:301*200] for initial_sec in range(start, end): file_path = '../data/%s/cata/centroids%d_half.npy'%(scan_name, initial_sec) ''' if os.path.exists(file_path): print 'skip:%d'%initial_sec continue ''' intitial_asp = co_data[initial_sec] center = np.array([intitial_asp[1], intitial_asp[2]]) print(intitial_asp) skypos = [0.0, 0.0] skyrange = [0.2, 0.2] wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001) initial_time = intitial_asp[0]-0.5 tranges = [] for sec in range(num_co): tranges.append([initial_time+step*sec, initial_time+step*(sec+1)]) print tranges data = get_data_cal(tranges, scan_name, cal_initial, offsets) #data = get_data(tranges, scan_name) print len(data) output = "../data/%s/cata/%s.csv"%(scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) centroids = [] for sec in range(num_co): if len(data[sec]) ==0: centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:,-3:-1] coo2 = catalog_fits.get_catalog(center, 0.69) coo1 = angle_filter(coo1, center, 0.5) coo2 = angle_filter(coo2, center, 0.5) get_corr_map(coo2, coo1, skypos, skyrange, sec, 0.05, 0.008) '''
else: step = 0.5 num_co = int(1/step) hdulist = pyfits.open('../data/AIS_GAL_SCAN_00005_0001-asprta.fits') co_data = hdulist[1].data intitial_asp = co_data[initial_sec] center = np.array([intitial_asp[1], intitial_asp[2]]) print(intitial_asp) skypos = [0.0, 0.0] skyrange = [0.04, 0.04] wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001) initial_time = intitial_asp[0]-0.5 tranges = [] for sec in range(num_co+1): tranges.append([initial_time+step*sec, initial_time+step*(sec+1)]) print tranges data = get_data(tranges) print len(data) centroids = [] for sec in range(num_co): coo1 = np.array(data[sec], dtype='float64')[:,-3:-1]
def run_one_r_sec(pid, scan_name, step, start, end, return_dict): num_co = int(1/step) hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits'%scan_name) co_data = hdulist[1].data length = co_data.shape[0] cal_initial = int((co_data[1][0]-0.5)*1000) offsets = np.load('../data/%s/cata/offsets1_10_new_inter_half_fine.npy'%scan_name) print length for initial_sec in range(start, end): file_path = '../data/%s/cata/centroids_sec%d.npy'%(scan_name, initial_sec) if os.path.exists(file_path): print 'skip:%d'%initial_sec continue intitial_asp = co_data[initial_sec] #center = np.array([intitial_asp[1], intitial_asp[2]]) #use the first order calibrated asp instead of the original one center = cal_asp_r(offsets, cal_initial, intitial_asp[0]*1000, intitial_asp[1:3], 200) print(intitial_asp) skypos = [0.0, 0.0] skyrange = [0.1, 0.1] wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001) initial_time = intitial_asp[0]-0.5 tranges = [] for sec in range(num_co): tranges.append([initial_time+step*sec, initial_time+step*(sec+1)]) print tranges data = get_data_cal(tranges, scan_name, cal_initial, offsets) print len(data) output = "../data/%s/cata/%s.csv"%(scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) centroids = [] for sec in range(num_co): if len(data[sec]) ==0: centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:,-3:-1] coo2 = catalog_fits.get_catalog(center, 0.69) coo1 = angle_filter(coo1, center, 1.) coo2 = angle_filter(coo2, center, 1.) count, centroid = get_corr_map_fast(coo2, coo1, skypos, skyrange, sec, 0.03, 0.0015) centroids.append(centroid) print centroid print centroids np.save('../data/%s/cata/centroids_sec%d.npy'%(scan_name, initial_sec), centroids)
if __name__ == '__main__': initial_sec = 451 hdulist = pyfits.open('../data/AIS_GAL_SCAN_00005_0001-asprta.fits') co_data = hdulist[1].data intitial_asp = co_data[initial_sec] skypos = [intitial_asp[1], intitial_asp[2]] skyrange = [1.38,1.38] tranges = [] trange = [0, 0] imsz = imagetools.deg2pix(skypos, skyrange, 0.002) count = np.zeros(imsz) print imsz print skypos wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.002) with open('../data/csv_list') as f: csv_list = f.read().splitlines() for csv_file in csv_list: with open(csv_file, 'rb') as file: reader = csv.reader(file) data = [] i = 1 initial_time = trange[0] = int(intitial_asp[0]*1000) print initial_time for row in reader: time = int(row[0]) if time < (initial_time + 0): continue if time >= (initial_time + 1000):
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 run_one_photon(pid, scan_name, start, end, return_dict): cata = spi.load_obj('../data/%s_starset_new'%scan_name) cata_a = np.array(list(cata)) cata_len = len(cata) skypos = [0.0, 0.0] skyrange = [0.2, 0.2] wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001) for star_num in range(start, end+1): order = 1 star = 'star_%d-%d'%(star_num, order) if not os.path.exists('../data/%s/star/list/%s.csv'%(scan_name, star)): print 'skip:%s'%star continue data, time_list, count = get_data_star(scan_name, star) length = len(data) mean = np.mean(count) if mean <= 80: print 'skip:%s'%star continue output = "../data/%s/star/co_photon/%s.csv"%(scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) centroids = [] for sec in range(length): if len(data[sec]) ==0: centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:,-3:-1] #coo2 = np.array(data[sec+1], dtype='float64')[:,-3:-1] coo2 = np.array([cata_a[star_num,:]]) count, centroid = get_corr_map(coo2, coo1, skypos, skyrange, sec, 0.03, 0.004) centroids.append(centroid) print centroid print centroids np.save('../data/%s/star/co_photon/centroids%d-%d_c.npy'%(scan_name, star_num, order), centroids) time = np.array(time_list) centers = np.array(centroids) ''' for i in range(1,centers.shape[0]): centers[i,:] += centers[i-1,:] ''' print time print centers f, axes = plt.subplots(2, 1) axes[0].plot(time, centers[:,0]) axes[0].set_ylabel(r'$\delta RA/degree$') ylim = axes[0].get_ylim() axes[0].set_ylim(ylim+np.absolute(ylim)*0.01) plt.setp( axes[0].get_xticklabels(), visible=False) #plt.setp( axes[0].get_yticklabels(), visible=False) axes[1].plot(time, centers[:,1]) axes[1].set_ylabel(r'$\delta DEC/degree$') axes[1].set_xlabel('time/s') plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0, hspace=0) plt.savefig('../plots/%s/star/co_photon/offset%d-%d_c.png'%(scan_name,star_num,order),dpi=190) plt.clf() '''
def run_one_r_sec(pid, scan_name, step, start, end, return_dict): pixsz = 0.000416666666666667 skypos_count = [5.,-9.5] skyrange_count = [2., 3.] tranges_count = [[0,0]] imsz_count = imsz = imagetools.deg2pix_g(skypos_count, skyrange_count, pixsz) wcs_count = imagetools.define_wcs_g(skypos_count,skyrange_count,width=False,height=False,verbose=0,pixsz=pixsz) count = np.zeros(imsz_count) num_co = int(1/step) hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits'%scan_name) co_data = hdulist[1].data length = co_data.shape[0] cal_initial = int((co_data[1][0]-0.5)*1000) offsets = np.load('../data/%s/cata/offsets_inter_half_sec.npy'%scan_name) angle_list = [-0.035, -0.03, -0.025, -0.02, -0.015, -0.01, -0.005, 0, 0.005, 0.01, 0.015, 0.02, 0.025, 0.03, 0.035] print length for initial_sec in range(start, end): print 'time:%d'%initial_sec file_path = '../data/%s/cata/centroids_sec%d.npy'%(scan_name, initial_sec) ''' if os.path.exists(file_path): print 'skip:%d'%initial_sec continue ''' intitial_asp = co_data[initial_sec] rot = intitial_asp[3] center = np.array([intitial_asp[1], intitial_asp[2]]) #use the first order calibrated asp instead of the original one center = cal_asp_r(offsets, cal_initial, intitial_asp[0]*1000, intitial_asp[1:3], 200) #print(intitial_asp) skypos = [0.0, 0.0] skyrange = [0.02, 0.02] wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.0001) initial_time = intitial_asp[0]-0.5 tranges = [] for sec in range(num_co): tranges.append([initial_time+step*sec, initial_time+step*(sec+1)]) print tranges data = get_data_cal(tranges, scan_name, cal_initial, offsets) print len(data) output = "../data/%s/cata/%s.csv"%(scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) centroids = [] for sec in range(num_co): if len(data[sec]) ==0: centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:,-3:-1] coo2 = catalog_fits.get_catalog(center, 0.69) coo1 = angle_filter(coo1, center, 1.) coo2 = angle_filter(coo2, center, 1.) xi, eta = gn.gnomfwd_simple(coo1[:,0], coo1[:,1], center[0], center[1], -rot, 1/36000., 0.0) max_now = -1000 cent_now = [] for angle in angle_list: coo1[:,0], coo1[:,1] = gn.gnomrev_simple(xi,eta,center[0],center[1],-(rot+angle),1/36000.,0.) centroid, max_value = get_corr_map(coo2, coo1, skypos, skyrange, sec, 0.02, 0.004) if max_value>max_now: max_now = max_value cent_now = np.append(centroid, angle) #centroid.append(angle) coo1[:,0], coo1[:,1] = gn.gnomrev_simple(xi,eta,center[0]-cent_now[0],center[1]-cent_now[1],-(rot+cent_now[2]),1/36000.,0.) sky_data = SkyCoord(coo1, unit='deg', frame=FK5, equinox='J2000.0') gal = sky_data.transform_to(Galactic) data_count = np.concatenate((np.array([gal.l.deg]).T, np.array([gal.b.deg]).T), axis=1) H = hist_g(data_count, wcs_count, imsz_count) count += H sky_data=gal=data_count=H = None gc.collect() #xi2, eta2 = gn.gnomfwd_simple(coo2[:,0], coo2[:,1], center[0], center[1], -rot, 1/36000., 0.0) #r, phi = cart2pol(xi, eta) #r2, phi2 = cart2pol(xi2, eta2) #coo1 = np.array([r,phi]).T #coo2 = np.array([r2,phi2]).T #get_corr_map(coo2, coo1, skypos, skyrange, sec, 0.05, 0.0015) centroids.append(cent_now) print cent_now print centroids #np.save('../data/%s/cata/centroids_rot%d.npy'%(scan_name, initial_sec), centroids) hdu = pyfits.PrimaryHDU(count) hdu = imagetools.fits_header('NUV', skypos_count, tranges_count, skyrange_count, hdu=hdu, wcs=wcs_count) hdulist = pyfits.HDUList([hdu]) hdulist.writeto('../fits/count_map_%s_gal_sec_rot_count.fits'%(scan_name), clobber=False)
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): 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
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]/0.000554/2400.*36000.*800*0.001666 co_rel = np.array([[0,0]]) infos = np.array([[0,0,0]]) rot = np.array([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) ''' photon_len = coo2.shape[0] star_len = coo1.shape[0] print 'repeat coo1' coo1 = np.repeat(coo1, photon_len, axis=0) print coo1.shape print 'repeat d3' d3 = np.tile(d3, (star_len,1)) print d3.shape print 'convert coo1' xi, eta = gn.gnomfwd_simple(coo1[:,0], coo1[:,1], d3[:,1], d3[:,2], -d3[:,3], 1/36000., 0) print 'tile coo2' co_rel = np.tile(coo2, (star_len,1)) - np.array([xi,eta]).T mask = (np.absolute(co_rel[:,0])<=bound) & (np.absolute(co_rel[:,1])<=bound) co_rel = co_rel[mask] print 'tile infos' infos = np.tile(info_list, (star_len,1))[mask] print infos.shape ''' if len2>len1: for i in range(len1): ones = np.ones(d3.shape[0]) xi, eta = gn.gnomfwd_simple(coo1[i,0]*ones, coo1[i,1]*ones, d3[:,1], d3[:,2], -d3[:,3], 1/36000., 0) tmp_co = coo2-np.array([xi,eta]).T 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) #rot = np.concatenate((rot, d3[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) rot = np.concatenate((rot, np.repeat(d3[i], tmp_co.shape[0])), axis=0) path = os.path.dirname('{0}/test/test'.format(outdir)) if not os.path.exists(path): os.makedirs(path) np.save('{0}/test/{1}.npy'.format(outdir, idx), co_rel) #np.save('{0}/radec/{1}.npy'.format(outdir, idx), co_radec) np.save('{0}/test/info_{1}.npy'.format(outdir, idx), infos) return [0,0], 0, 0
def run_one_r_sec(pid, scan_name, step, start, end, return_dict): print('run one r sec') pixsz = 0.000416666666666667 #skypos_count = [5.,-9.5] #skyrange_count = [2., 3.] #tranges_count = [[0,0]] #imsz_count = imsz = imagetools.deg2pix_g(skypos_count, skyrange_count, pixsz) #wcs_count = imagetools.define_wcs_g(skypos_count,skyrange_count,width=False,height=False,verbose=0,pixsz=pixsz) #count = np.zeros(imsz_count) num_co = int(1 / step) hdulist = pyfits.open('../AIS_GAL_SCAN/asprta/%s-asprta.fits' % scan_name) co_data = hdulist[1].data length = co_data.shape[0] #cal_initial = int((co_data[1][0]-0.5)*1000) #offsets = np.load('../data/%s/cata/offsets_inter_half_sec.npy'%scan_name) angle_list = [0.] print length for initial_sec in range(start, end): print 'time:%d' % initial_sec file_path = '../data/%s/cata/centroids_sec%d.npy' % (scan_name, initial_sec) ''' if os.path.exists(file_path): print 'skip:%d'%initial_sec continue ''' intitial_asp = co_data[initial_sec] rot = intitial_asp[3] center = np.array([intitial_asp[1], intitial_asp[2]]) #use the first order calibrated asp instead of the original one #center = cal_asp_r(offsets, cal_initial, intitial_asp[0]*1000, intitial_asp[1:3], 200) #print(intitial_asp) skypos = [0.0, 0.0] skyrange = [0.2, 0.2] wcs = imagetools.define_wcs(skypos, skyrange, width=False, height=False, verbose=0, pixsz=0.0001) initial_time = intitial_asp[0] - 0.5 tranges = [] for sec in range(num_co): tranges.append( [initial_time + step * sec, initial_time + step * (sec + 1)]) print tranges #data = get_data_cal(tranges, scan_name, cal_initial, offsets) data = get_data(tranges, scan_name) print len(data) output = "../data/%s/cata/%s.csv" % (scan_name, scan_name) dir = os.path.dirname(output) if not os.path.exists(dir): os.makedirs(dir) centroids = [] for sec in range(num_co): if len(data[sec]) == 0: centroid = np.array([0.0, 0.0]) centroids.append(centroid) print centroid continue coo1 = np.array(data[sec], dtype='float64')[:, -3:-1] coo2 = catalog_fits.get_catalog(center, 0.69) coo1 = angle_filter(coo1, center, 0.5) coo2 = angle_filter(coo2, center, 0.5) xi, eta = gn.gnomfwd_simple(coo1[:, 0], coo1[:, 1], center[0], center[1], -rot, 1 / 36000., 0.0) max_now = -1000 cent_now = [] for angle in angle_list: coo1[:, 0], coo1[:, 1] = gn.gnomrev_simple(xi, eta, center[0], center[1], -(rot + angle), 1 / 36000., 0.) centroid, max_value = get_corr_map(coo2, coo1, skypos, skyrange, sec, 0.2, 0.004) if max_value > max_now: max_now = max_value cent_now = np.append(centroid, angle) #centroid.append(angle) centroids.append(cent_now) print centroids np.save( '../data/%s/cata/centroids_rot%d.npy' % (scan_name, initial_sec), centroids)