Exemplo n.º 1
0
def res_star(pid, scan_name, start, end, return_dict):
    cata = spi.load_obj('../data/%s_starset_new' % name)
    cata_a = np.array(list(cata))
    cata_len = len(cata)
    cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)

    for star_num in range(start, end + 1):
        order = 0
        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

        csv_file = '../data/%s/star/list/%s.csv' % (scan_name, star)
        data = []
        time_list = []
        with open(csv_file, 'rb') as file:
            reader = csv.reader(file)
            first = reader.next()
            last = float(first[0])
            time_list.append(last)
            data.append([])
            data[0].append(first[6:8])
            i = 0

            for row in reader:
                time = float(row[0])
                if time - last > 500:
                    data.append([])
                    i += 1
                    data[i].append(row[6:8])
                    last = time
                    time_list.append(last)
                else:
                    data[i].append(row[6:8])

        output = "../plots/%s/star/res/%s.csv" % (scan_name, scan_name)
        dir = os.path.dirname(output)
        if not os.path.exists(dir):
            os.makedirs(dir)

        res_list = map(get_res, data)
        print map(get_pos, data)
        '''
Exemplo n.º 2
0
def res_star(pid, scan_name, start, end, return_dict):
	cata = spi.load_obj('../data/%s_starset_new'%name)
	cata_a = np.array(list(cata))
	cata_len = len(cata)
	cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)
  
	for star_num in range(start, end+1): 
		order = 0
		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
	  
		csv_file = '../data/%s/star/list/%s.csv'%(scan_name, star)
		data = []
		time_list = []
		with open(csv_file, 'rb') as file:
			reader = csv.reader(file)
			first = reader.next()
			last = float(first[0])
			time_list.append(last)
			data.append([])
			data[0].append(first[6:8])
			i = 0

			for row in reader:
			  time = float(row[0])
			  if time - last > 500:
			    data.append([])
			    i += 1
			    data[i].append(row[6:8])
			    last = time
			    time_list.append(last)
			  else:
			    data[i].append(row[6:8])
		
		output = "../plots/%s/star/res/%s.csv"%(scan_name, scan_name)
		dir = os.path.dirname(output)
		if not os.path.exists(dir):
			os.makedirs(dir)

		res_list = map(get_res, data)
		print map(get_pos, data)
		'''
Exemplo n.º 3
0
def main_single():

	name = 'AIS_GAL_SCAN_00014_0001'

	cata = spi.load_obj('../data/%s_starset_extra_full'%name)
	cata_a = np.array(list(cata))
	cata_len = len(cata)
	cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)
	star_list = load_obj("../data/%s/star/extra/list_new/star_detector"%name)
	star_list = sorted(star_list, key=getKey)
	#print star_list
	plot_list = []
	stars = []
	istar = star_list[0]
	stars.append(istar[0])

	for i in range(5989):
		flux_list = []
		star_count = []
		time_list = []
		bkg_time_list = []
		bkg_count = []
		star_num = '%d'%i
		csv_file = "../data/%s/star/extra/list_new/star_%s-0.csv"%(name, star_num)
		bkg_csv_file = "../data/%s/star/extra/bkg/star_bkg_%s-0.csv"%(name, star_num)
		star_co = cata_a[i, 0:2]

		star_data = np.genfromtxt(csv_file, delimiter=',')
		bkg_data = np.genfromtxt(bkg_csv_file, delimiter=',')

		star_count, edges = np.histogram(star_data[:,0]-star_data[0,0], bins=np.arange(62)*1000)

		bkg_count, edges = np.histogram(bkg_data[:,0]-star_data[0,0], bins=np.arange(62)*1000)

		star_flux = np.array(star_count) - np.array(bkg_count)*64./40.
		#star_flux[star_flux<0] = 0
		star_len = cut_tail(star_flux)

		time_array = np.arange(star_flux.shape[0])

		mag = cata_list[i, 5]

		flux_list.append((time_array, star_flux, i, cata_list[i, 5]))
		flux_list = sorted(flux_list, key=getMag)
		f, axes = plt.subplots(len(flux_list), 1, squeeze=False)
		for plot_num in range(len(flux_list)):
			star_flux = flux_list[plot_num][1]
			time_array = flux_list[plot_num][0]
			res_flux = flux_list[plot_num][-1]
			axes[plot_num,0].plot(time_array, star_flux, '-o')
			axes[plot_num,0].text(0.95, 0.85, 'NUV: %.3f'%flux_list[plot_num][3], verticalalignment='bottom', horizontalalignment='right', transform=axes[plot_num,0].transAxes, color='green', fontsize=10)
			#axes[plot_num,0].set_ylabel('Num of Photons')
			ylim = axes[plot_num,0].get_ylim()
			if plot_num == 0:
				xlim = axes[plot_num,0].get_xlim()
			axes[plot_num,0].set_xlim([0, 61])
			axes[plot_num,0].set_ylim([ylim[0]+np.absolute(ylim[1]-ylim[0])*0.01, ylim[1]])

			axes[plot_num,0].set_xlabel('time/s')
			plt.legend()
			plt.savefig('../plots/%s/star/extra/single/star%d.png'%(name, flux_list[plot_num][2]),dpi=190)  
			plt.clf()
Exemplo n.º 4
0
def main_res():

	name = 'AIS_GAL_SCAN_00032_0001'

	asp = np.load('../data/photon_list/AIS_GAL_SCAN_00032_0001_asp_cal.npy')
	asp_uni, uni_index=np.unique(asp[:,0], True)
	asp_uni = asp[uni_index]
	ix_tmp = (np.round(asp_uni[:,0]-asp_uni[0,0])+1).astype(int)
	dead_tmp = np.zeros(ix_tmp.shape[0])
	scst_tmp = pyfits.open('../AIS_GAL_SCAN/scst/%s-scst.fits'%name)[1].data
	limit = scst_tmp['t_dead_nuv'].shape[0]-1
	ix_tmp[ix_tmp>limit] = limit
	dead_tmp = scst_tmp['t_dead_nuv'][ix_tmp]

	cata = spi.load_obj('../data/%s_starset_extra_full'%name)
	cata_a = np.array(list(cata))
	cata_len = len(cata)
	cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)
	star_list = load_obj("../data/%s/star/extra/list_new/star_detector"%name)
	star_list = sorted(star_list, key=getKey)
	#print star_list
	plot_list = []
	stars = []
	istar = star_list[0]
	stars.append(istar[0])
	for i in range(1,len(star_list)):
		if star_list[i][2] - istar[2]<=100:
			stars.append(star_list[i][0])
		else:
			plot_list.append(stars)
			istar = star_list[i]
			stars = []
			stars.append(istar[0])

	group_num = 0
	flux_stat = []
	for plot in plot_list:
		#f, axes = plt.subplots(len(plot), 1, squeeze=False)
		print('group_num:%d'%group_num)
		plot_num = 0
		xlim = [0,60] 
		if len(plot) == 1:
			group_num += 1
			continue
		flux_list = []
		for i in plot:
	#for i in range(397):
			star_count = []
			time_list = []
			bkg_time_list = []
			bkg_count = []
			star_num = '%d'%i
			csv_file = "../data/%s/star/extra/list_new/star_%s-0.csv"%(name, star_num)
			bkg_csv_file = "../data/%s/star/extra/bkg/star_bkg_%s-0.csv"%(name, star_num)
			star_co = cata_a[i, 0:2]

			star_data = np.genfromtxt(csv_file, delimiter=',')
			bkg_data = np.genfromtxt(bkg_csv_file, delimiter=',')

			star_count, edges = np.histogram(star_data[:,0]-star_data[0,0], bins=np.arange(62)*1000)

			bkg_count, edges = np.histogram(bkg_data[:,0]-star_data[0,0], bins=np.arange(62)*1000)

			index_0 = (star_data[0,0]-asp_uni[0,0]*1000)/5
			index_1 = (star_data[-1,0]-asp_uni[0,0]*1000)/5

			#print i, cata_list[i, 0]
			#print star_co
			#print np.median(star_data[:,-3:-1], axis=0)

			if index_1-index_0>12400:
				continue

			star_track = asp_uni[index_0:index_1+1,:]
			dead_t = dead_tmp[index_0:index_1+1]
			ra = np.ones(star_track.shape[0])*star_co[0]
			dec = np.ones(star_track.shape[0])*star_co[1]
			xi, eta = gn.gnomfwd_simple(ra, dec, star_track[:,1], star_track[:,2], -star_track[:,3], 1/36000., 0.0)
			res_list = res_star.get_res_new(xi, eta, '../fits/flat/NUV_flat.fits')
			if res_list == None:
				continue
			res_list_d = res_list*(1-dead_t)

			res_flux = running_sum(res_list_d, 200, 61)
			res_len = cut_tail(res_flux)

			star_flux = np.array(star_count) - np.array(bkg_count)*64./40.
			star_flux[star_flux<0] = 0
			star_len = cut_tail(star_flux)

			delta = star_len-res_len
			if delta>0 and delta<3:
				star_flux = star_flux[:star_len]
				res_flux = res_flux[:star_len]
			elif delta >= 3 or delta<=-3:
				continue
			else:
				star_flux = star_flux[:res_len]
				res_flux = res_flux[:res_len]

			if np.mean(star_flux)<5:
				continue

			res_flux = res_flux/np.mean(res_flux)
			star_flux = star_flux/np.mean(star_flux)
			time_array = np.arange(res_flux.shape[0])

			var, likeli = likelihood(star_flux, res_flux)

			mag = cata_list[i, 5]
			flux_stat.append((mag, likeli, var, star_flux, res_flux))
			print '%.3f  %.3f  %.3f'%(mag, var, likeli)
			'''
			plt.plot(time_array, star_flux)
			plt.xlabel('t/s')
			plt.ylabel('Number of Photons')
			plt.savefig('../plots/%s/star/star_flux/%s-0.png'%(name, star_num), dpi=190)
			plt.clf()
			'''
			flux_list.append((time_array, star_flux, i, cata_list[i, 5], res_flux))
		if len(flux_list)>1:
			flux_list = sorted(flux_list, key=getMag)
			f, axes = plt.subplots(len(flux_list), 1, squeeze=False)
			for plot_num in range(len(flux_list)):
				star_flux = flux_list[plot_num][1]
				time_array = flux_list[plot_num][0]
				res_flux = flux_list[plot_num][-1]
				axes[plot_num,0].plot(time_array, star_flux, '-o')
				axes[plot_num,0].plot(time_array, res_flux, '-o')
				axes[plot_num,0].text(0.95, 0.8, 'NUV: %.3f'%flux_list[plot_num][3], verticalalignment='bottom', horizontalalignment='right', transform=axes[plot_num,0].transAxes, color='green', fontsize=10)
				#axes[plot_num,0].set_ylabel('Num of Photons')
				ylim = axes[plot_num,0].get_ylim()
				if plot_num == 0:
					xlim = axes[plot_num,0].get_xlim()
				axes[plot_num,0].set_xlim([0, 61])
				axes[plot_num,0].set_ylim([ylim[0]+np.absolute(ylim[1]-ylim[0])*0.01, ylim[1]])
				if plot_num<len(flux_list)-1:
					plt.setp( axes[plot_num,0].get_xticklabels(), visible=False)
				else:
					axes[plot_num,0].set_xlabel('time/s')
				plt.setp( axes[plot_num,0].get_yticklabels(), visible=False)
			plt.subplots_adjust(left=None, bottom=None, right=None, top=None,
			            wspace=0, hspace=0)
			plt.legend()
			plt.savefig('../plots/%s/star/extra/cons_res_flat/cons%d_track.png'%(name, group_num),dpi=190)  
			plt.clf()
		group_num += 1
		save_obj(flux_stat, '../plots/%s/star/extra/cons_res_flat/flux_stat'%(name))
Exemplo n.º 5
0
def main_new():

	name = 'AIS_GAL_SCAN_00014_0001'
	cata = spi.load_obj('../data/%s_starset_extra_full'%name)
	cata_a = np.array(list(cata))
	cata_len = len(cata)
	cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)
	star_list = load_obj("../data/%s/star/extra/list_new/star_detector"%name)
	star_list = sorted(star_list, key=getKey)
	print star_list
	plot_list = []
	stars = []
	istar = star_list[0]
	stars.append(istar[0])
	for i in range(1,len(star_list)):
		if star_list[i][2] - istar[2]<=100:
			stars.append(star_list[i][0])
		else:
			plot_list.append(stars)
			istar = star_list[i]
			stars = []
			stars.append(istar[0])

	group_num = 0
	for plot in plot_list:
		#f, axes = plt.subplots(len(plot), 1, squeeze=False)
		plot_num = 0
		xlim = [0,60] 
		if len(plot) == 1:
			continue
		flux_list = []
		for i in plot:
	#for i in range(397):
			star_count = []
			time_list = []
			bkg_time_list = []
			bkg_count = []
			star_num = '%d'%i
			csv_file = "../data/%s/star/extra/list_new/star_%s-0.csv"%(name, star_num)
			bkg_csv_file = "../data/%s/star/extra/bkg/star_bkg_%s-0.csv"%(name, star_num)

			star_data = np.genfromtxt(csv_file, delimiter=',')
			bkg_data = np.genfromtxt(bkg_csv_file, delimiter=',')

			star_count, edges = np.histogram(star_data[:,0]-star_data[0,0], bins=np.arange(62)*1000)

			bkg_count, edges = np.histogram(bkg_data[:,0]-star_data[0,0], bins=np.arange(62)*1000)

			star_flux = np.array(star_count) - np.array(bkg_count)*64./40.
			star_flux[star_flux<0] = 0
			if np.mean(star_flux)<5:
				continue
			time_array = np.arange(61)
			'''
			plt.plot(time_array, star_flux)
			plt.xlabel('t/s')
			plt.ylabel('Number of Photons')
			plt.savefig('../plots/%s/star/star_flux/%s-0.png'%(name, star_num), dpi=190)
			plt.clf()
			'''
			flux_list.append((time_array, star_flux, i, cata_list[i, 5]))
		if len(flux_list)>1:
			flux_list = sorted(flux_list, key=getMag)
			f, axes = plt.subplots(len(flux_list), 1, squeeze=False)
			for plot_num in range(len(flux_list)):
				star_flux = flux_list[plot_num][1]
				time_array = flux_list[plot_num][0]
				axes[plot_num,0].plot(time_array, star_flux)
				axes[plot_num,0].text(0.95, 0.85, 'NUV: %.3f'%flux_list[plot_num][3], verticalalignment='bottom', horizontalalignment='right', transform=axes[plot_num,0].transAxes, color='green', fontsize=10)
				#axes[plot_num,0].set_ylabel('Num of Photons')
				ylim = axes[plot_num,0].get_ylim()
				if plot_num == 0:
					xlim = axes[plot_num,0].get_xlim()
				axes[plot_num,0].set_xlim([0, xlim[1]])
				axes[plot_num,0].set_ylim([ylim[0]+np.absolute(ylim[1]-ylim[0])*0.01, ylim[1]])
				if plot_num<len(flux_list)-1:
					plt.setp( axes[plot_num,0].get_xticklabels(), visible=False)
				else:
					axes[plot_num,0].set_xlabel('time/s')
				#plot_num+=1
			plt.subplots_adjust(left=None, bottom=None, right=None, top=None,
			            wspace=0, hspace=0)
			plt.legend()
			plt.savefig('../plots/%s/star/extra/cons_new/cons%d_track.png'%(name, group_num),dpi=190)  
			plt.clf()
		group_num += 1
Exemplo n.º 6
0
def res_star_new(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)
    cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)

    asp = np.load('../data/photon_list/AIS_GAL_SCAN_00014_0001_asp_cal.npy')
    asp_uni, uni_index = np.unique(asp[:, 0], True)
    asp_uni = asp[uni_index]
    ix_tmp = (np.round(asp_uni[:, 0] - asp_uni[0, 0]) + 1).astype(int)
    dead_tmp = np.zeros(ix_tmp.shape[0])
    scst_tmp = pyfits.open('../AIS_GAL_SCAN/scst/%s-scst.fits' %
                           scan_name)[1].data
    limit = scst_tmp['t_dead_nuv'].shape[0] - 1
    ix_tmp[ix_tmp > limit] = limit
    dead_tmp = scst_tmp['t_dead_nuv'][ix_tmp]

    for star_num in range(start, end + 1):
        star_co = cata_a[star_num, 0:2]

        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

        csv_file = '../data/%s/star/list/%s.csv' % (scan_name, star)
        count = []
        time_list = []
        with open(csv_file, 'rb') as file:
            reader = csv.reader(file)
            first = float(reader.next()[0])
            final = 0
            last = 0
            reader = csv.reader(file)
            for row in reader:
                time = float(row[0])  #time = int(float(row[0])/1000.)
                if time - last > 200:
                    count.append(1)
                    last = time
                    time_list.append(last)
                else:
                    count[-1] += 1
                final = time

        time_list = np.array(time_list) / 1000.
        index_0 = (first - asp_uni[0, 0] * 1000) / 5
        index_1 = (final - asp_uni[0, 0] * 1000) / 5

        star_track = asp_uni[index_0:index_1 + 1, :]
        dead_t = dead_tmp[index_0:index_1 + 1]
        ra = np.ones(star_track.shape[0]) * star_co[0]
        dec = np.ones(star_track.shape[0]) * star_co[1]

        xi, eta = gn.gnomfwd_simple(ra, dec, star_track[:, 1], star_track[:,
                                                                          2],
                                    -star_track[:, 3], 1 / 36000., 0.0)

        output = "../plots/%s/star/res/%s.csv" % (scan_name, scan_name)
        dir = os.path.dirname(output)
        if not os.path.exists(dir):
            os.makedirs(dir)
        print dead_t
        res_list = get_res_new(xi, eta)
        res_list_d = res_list * (1 - dead_t)
        '''
		plt.plot(star_track[:,0], res_list_d)
		plt.xlabel('t/s')
		plt.ylabel('response')
		plt.savefig('../plots/%s/star/res/res%d-%d_track_d.png'%(scan_name, star_num, order), dpi=190)
		plt.clf()

		plt.plot(star_track[:,0], res_list)
		plt.xlabel('t/s')
		plt.ylabel('response')
		plt.savefig('../plots/%s/star/res/res%d-%d_track.png'%(scan_name, star_num, order), dpi=190)
		plt.clf()
		'''

        f, axes = plt.subplots(2, 1)
        axes[0].plot(time_list, count)
        axes[0].set_ylabel('Num of Photons')
        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(star_track[:, 0], res_list_d)
        axes[1].set_ylabel('Response')
        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/res/2p/res%d-%d_track.png' %
                    (scan_name, star_num, order),
                    dpi=190)
        plt.clf()
Exemplo n.º 7
0
def res_star_new(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)
	cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)

	asp = np.load('../data/photon_list/AIS_GAL_SCAN_00014_0001_asp_cal.npy')
	asp_uni, uni_index=np.unique(asp[:,0], True)
	asp_uni = asp[uni_index]
	ix_tmp = (np.round(asp_uni[:,0]-asp_uni[0,0])+1).astype(int)
	dead_tmp = np.zeros(ix_tmp.shape[0])
	scst_tmp = pyfits.open('../AIS_GAL_SCAN/scst/%s-scst.fits'%scan_name)[1].data
	limit = scst_tmp['t_dead_nuv'].shape[0]-1
	ix_tmp[ix_tmp>limit] = limit
	dead_tmp = scst_tmp['t_dead_nuv'][ix_tmp]

	for star_num in range(start, end+1): 
		star_co = cata_a[star_num, 0:2]


		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
	  
		csv_file = '../data/%s/star/list/%s.csv'%(scan_name, star)
		count = []
		time_list = []
		with open(csv_file, 'rb') as file:
			reader = csv.reader(file)
			first = float(reader.next()[0])
			final = 0
			last = 0
			reader = csv.reader(file)
			for row in reader:
				time = float(row[0])#time = int(float(row[0])/1000.)
				if time - last > 200:
					count.append(1)
					last = time
					time_list.append(last)
				else:
					count[-1] += 1
				final = time

		time_list = np.array(time_list)/1000.
		index_0 = (first-asp_uni[0,0]*1000)/5
		index_1 = (final-asp_uni[0,0]*1000)/5

		star_track = asp_uni[index_0:index_1+1,:]
		dead_t = dead_tmp[index_0:index_1+1]
		ra = np.ones(star_track.shape[0])*star_co[0]
		dec = np.ones(star_track.shape[0])*star_co[1]

		xi, eta = gn.gnomfwd_simple(ra, dec, star_track[:,1], star_track[:,2], -star_track[:,3], 1/36000., 0.0)

		output = "../plots/%s/star/res/%s.csv"%(scan_name, scan_name)
		dir = os.path.dirname(output)
		if not os.path.exists(dir):
			os.makedirs(dir)
		print dead_t
		res_list = get_res_new(xi, eta)
		res_list_d = res_list*(1-dead_t)

		'''
		plt.plot(star_track[:,0], res_list_d)
		plt.xlabel('t/s')
		plt.ylabel('response')
		plt.savefig('../plots/%s/star/res/res%d-%d_track_d.png'%(scan_name, star_num, order), dpi=190)
		plt.clf()

		plt.plot(star_track[:,0], res_list)
		plt.xlabel('t/s')
		plt.ylabel('response')
		plt.savefig('../plots/%s/star/res/res%d-%d_track.png'%(scan_name, star_num, order), dpi=190)
		plt.clf()
		'''

		f, axes = plt.subplots(2, 1)
		axes[0].plot(time_list, count)
		axes[0].set_ylabel('Num of Photons')
		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(star_track[:,0], res_list_d)
		axes[1].set_ylabel('Response')
		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/res/2p/res%d-%d_track.png'%(scan_name,star_num,order),dpi=190)  
		plt.clf()
    hdulist = pyfits.open('../data/asprta/AIS_GAL_SCAN_00005_0001-asprta.fits')
    co_data = hdulist[1].data

    step = 10
    offsets = np.load('../data/05_r/cata/offsets300-1343_10_new.npy')
    print offsets.shape
    initial = int((co_data[300][0]-0.5)*1000)

    skypos_f, skyrange_f = ([0, 0], [1.33333336,1.33333336])
    imsz_f = imagetools.deg2pix(skypos_f, skyrange_f, 0.0016666667)
    count_f = np.zeros(imsz_f)
    wcs_f = imagetools.define_wcs(skypos_f,skyrange_f,width=False,height=False,verbose=0,pixsz=0.0016666667)
    print imsz_f

    cata = spi.load_obj('stars05')
    cata_a = np.array(list(cata))
    cata_len = len(cata)
    cata_a = cata_a*np.pi/180.
    X, Y, Z = pycoo.spherical_to_cartesian(1, cata_a[:,1], cata_a[:,0])
    cata_car = np.array([X,Y,Z], dtype='float64').T
    rad = np.cos(0.00250*np.pi/180.)

    with open('../data/csv_list05_full') as f:
      csv_list = f.read().splitlines() 
      for csv_file in csv_list:
        print csv_file
        with open(csv_file, 'rb') as file:
          reader = csv.reader(file)
          data = []
          data_f = []
def main_single():

    name = 'AIS_GAL_SCAN_00014_0001'

    cata = spi.load_obj('../data/%s_starset_extra_full' % name)
    cata_a = np.array(list(cata))
    cata_len = len(cata)
    cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)
    star_list = load_obj("../data/%s/star/extra/list_new/star_detector" % name)
    star_list = sorted(star_list, key=getKey)
    #print star_list
    plot_list = []
    stars = []
    istar = star_list[0]
    stars.append(istar[0])

    for i in range(5989):
        flux_list = []
        star_count = []
        time_list = []
        bkg_time_list = []
        bkg_count = []
        star_num = '%d' % i
        csv_file = "../data/%s/star/extra/list_new/star_%s-0.csv" % (name,
                                                                     star_num)
        bkg_csv_file = "../data/%s/star/extra/bkg/star_bkg_%s-0.csv" % (
            name, star_num)
        star_co = cata_a[i, 0:2]

        star_data = np.genfromtxt(csv_file, delimiter=',')
        bkg_data = np.genfromtxt(bkg_csv_file, delimiter=',')

        star_count, edges = np.histogram(star_data[:, 0] - star_data[0, 0],
                                         bins=np.arange(62) * 1000)

        bkg_count, edges = np.histogram(bkg_data[:, 0] - star_data[0, 0],
                                        bins=np.arange(62) * 1000)

        star_flux = np.array(star_count) - np.array(bkg_count) * 64. / 40.
        #star_flux[star_flux<0] = 0
        star_len = cut_tail(star_flux)

        time_array = np.arange(star_flux.shape[0])

        mag = cata_list[i, 5]

        flux_list.append((time_array, star_flux, i, cata_list[i, 5]))
        flux_list = sorted(flux_list, key=getMag)
        f, axes = plt.subplots(len(flux_list), 1, squeeze=False)
        for plot_num in range(len(flux_list)):
            star_flux = flux_list[plot_num][1]
            time_array = flux_list[plot_num][0]
            res_flux = flux_list[plot_num][-1]
            axes[plot_num, 0].plot(time_array, star_flux, '-o')
            axes[plot_num, 0].text(0.95,
                                   0.85,
                                   'NUV: %.3f' % flux_list[plot_num][3],
                                   verticalalignment='bottom',
                                   horizontalalignment='right',
                                   transform=axes[plot_num, 0].transAxes,
                                   color='green',
                                   fontsize=10)
            #axes[plot_num,0].set_ylabel('Num of Photons')
            ylim = axes[plot_num, 0].get_ylim()
            if plot_num == 0:
                xlim = axes[plot_num, 0].get_xlim()
            axes[plot_num, 0].set_xlim([0, 61])
            axes[plot_num, 0].set_ylim(
                [ylim[0] + np.absolute(ylim[1] - ylim[0]) * 0.01, ylim[1]])

            axes[plot_num, 0].set_xlabel('time/s')
            plt.legend()
            plt.savefig('../plots/%s/star/extra/single/star%d.png' %
                        (name, flux_list[plot_num][2]),
                        dpi=190)
            plt.clf()
Exemplo n.º 10
0
def main_res():

    name = 'AIS_GAL_SCAN_00032_0001'

    asp = np.load('../data/photon_list/AIS_GAL_SCAN_00032_0001_asp_cal.npy')
    asp_uni, uni_index = np.unique(asp[:, 0], True)
    asp_uni = asp[uni_index]
    ix_tmp = (np.round(asp_uni[:, 0] - asp_uni[0, 0]) + 1).astype(int)
    dead_tmp = np.zeros(ix_tmp.shape[0])
    scst_tmp = pyfits.open('../AIS_GAL_SCAN/scst/%s-scst.fits' % name)[1].data
    limit = scst_tmp['t_dead_nuv'].shape[0] - 1
    ix_tmp[ix_tmp > limit] = limit
    dead_tmp = scst_tmp['t_dead_nuv'][ix_tmp]

    cata = spi.load_obj('../data/%s_starset_extra_full' % name)
    cata_a = np.array(list(cata))
    cata_len = len(cata)
    cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)
    star_list = load_obj("../data/%s/star/extra/list_new/star_detector" % name)
    star_list = sorted(star_list, key=getKey)
    #print star_list
    plot_list = []
    stars = []
    istar = star_list[0]
    stars.append(istar[0])
    for i in range(1, len(star_list)):
        if star_list[i][2] - istar[2] <= 100:
            stars.append(star_list[i][0])
        else:
            plot_list.append(stars)
            istar = star_list[i]
            stars = []
            stars.append(istar[0])

    group_num = 0
    flux_stat = []
    for plot in plot_list:
        #f, axes = plt.subplots(len(plot), 1, squeeze=False)
        print('group_num:%d' % group_num)
        plot_num = 0
        xlim = [0, 60]
        if len(plot) == 1:
            group_num += 1
            continue
        flux_list = []
        for i in plot:
            #for i in range(397):
            star_count = []
            time_list = []
            bkg_time_list = []
            bkg_count = []
            star_num = '%d' % i
            csv_file = "../data/%s/star/extra/list_new/star_%s-0.csv" % (
                name, star_num)
            bkg_csv_file = "../data/%s/star/extra/bkg/star_bkg_%s-0.csv" % (
                name, star_num)
            star_co = cata_a[i, 0:2]

            star_data = np.genfromtxt(csv_file, delimiter=',')
            bkg_data = np.genfromtxt(bkg_csv_file, delimiter=',')

            star_count, edges = np.histogram(star_data[:, 0] - star_data[0, 0],
                                             bins=np.arange(62) * 1000)

            bkg_count, edges = np.histogram(bkg_data[:, 0] - star_data[0, 0],
                                            bins=np.arange(62) * 1000)

            index_0 = (star_data[0, 0] - asp_uni[0, 0] * 1000) / 5
            index_1 = (star_data[-1, 0] - asp_uni[0, 0] * 1000) / 5

            #print i, cata_list[i, 0]
            #print star_co
            #print np.median(star_data[:,-3:-1], axis=0)

            if index_1 - index_0 > 12400:
                continue

            star_track = asp_uni[index_0:index_1 + 1, :]
            dead_t = dead_tmp[index_0:index_1 + 1]
            ra = np.ones(star_track.shape[0]) * star_co[0]
            dec = np.ones(star_track.shape[0]) * star_co[1]
            xi, eta = gn.gnomfwd_simple(ra, dec, star_track[:, 1],
                                        star_track[:, 2], -star_track[:, 3],
                                        1 / 36000., 0.0)
            res_list = res_star.get_res_new(xi, eta,
                                            '../fits/flat/NUV_flat.fits')
            if res_list == None:
                continue
            res_list_d = res_list * (1 - dead_t)

            res_flux = running_sum(res_list_d, 200, 61)
            res_len = cut_tail(res_flux)

            star_flux = np.array(star_count) - np.array(bkg_count) * 64. / 40.
            star_flux[star_flux < 0] = 0
            star_len = cut_tail(star_flux)

            delta = star_len - res_len
            if delta > 0 and delta < 3:
                star_flux = star_flux[:star_len]
                res_flux = res_flux[:star_len]
            elif delta >= 3 or delta <= -3:
                continue
            else:
                star_flux = star_flux[:res_len]
                res_flux = res_flux[:res_len]

            if np.mean(star_flux) < 5:
                continue

            res_flux = res_flux / np.mean(res_flux)
            star_flux = star_flux / np.mean(star_flux)
            time_array = np.arange(res_flux.shape[0])

            var, likeli = likelihood(star_flux, res_flux)

            mag = cata_list[i, 5]
            flux_stat.append((mag, likeli, var, star_flux, res_flux))
            print '%.3f  %.3f  %.3f' % (mag, var, likeli)
            '''
			plt.plot(time_array, star_flux)
			plt.xlabel('t/s')
			plt.ylabel('Number of Photons')
			plt.savefig('../plots/%s/star/star_flux/%s-0.png'%(name, star_num), dpi=190)
			plt.clf()
			'''
            flux_list.append(
                (time_array, star_flux, i, cata_list[i, 5], res_flux))
        if len(flux_list) > 1:
            flux_list = sorted(flux_list, key=getMag)
            f, axes = plt.subplots(len(flux_list), 1, squeeze=False)
            for plot_num in range(len(flux_list)):
                star_flux = flux_list[plot_num][1]
                time_array = flux_list[plot_num][0]
                res_flux = flux_list[plot_num][-1]
                axes[plot_num, 0].plot(time_array, star_flux, '-o')
                axes[plot_num, 0].plot(time_array, res_flux, '-o')
                axes[plot_num, 0].text(0.95,
                                       0.8,
                                       'NUV: %.3f' % flux_list[plot_num][3],
                                       verticalalignment='bottom',
                                       horizontalalignment='right',
                                       transform=axes[plot_num, 0].transAxes,
                                       color='green',
                                       fontsize=10)
                #axes[plot_num,0].set_ylabel('Num of Photons')
                ylim = axes[plot_num, 0].get_ylim()
                if plot_num == 0:
                    xlim = axes[plot_num, 0].get_xlim()
                axes[plot_num, 0].set_xlim([0, 61])
                axes[plot_num, 0].set_ylim(
                    [ylim[0] + np.absolute(ylim[1] - ylim[0]) * 0.01, ylim[1]])
                if plot_num < len(flux_list) - 1:
                    plt.setp(axes[plot_num, 0].get_xticklabels(),
                             visible=False)
                else:
                    axes[plot_num, 0].set_xlabel('time/s')
                plt.setp(axes[plot_num, 0].get_yticklabels(), visible=False)
            plt.subplots_adjust(left=None,
                                bottom=None,
                                right=None,
                                top=None,
                                wspace=0,
                                hspace=0)
            plt.legend()
            plt.savefig(
                '../plots/%s/star/extra/cons_res_flat/cons%d_track.png' %
                (name, group_num),
                dpi=190)
            plt.clf()
        group_num += 1
        save_obj(flux_stat,
                 '../plots/%s/star/extra/cons_res_flat/flux_stat' % (name))
Exemplo n.º 11
0
def main_new():

    name = 'AIS_GAL_SCAN_00014_0001'
    cata = spi.load_obj('../data/%s_starset_extra_full' % name)
    cata_a = np.array(list(cata))
    cata_len = len(cata)
    cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)
    star_list = load_obj("../data/%s/star/extra/list_new/star_detector" % name)
    star_list = sorted(star_list, key=getKey)
    print star_list
    plot_list = []
    stars = []
    istar = star_list[0]
    stars.append(istar[0])
    for i in range(1, len(star_list)):
        if star_list[i][2] - istar[2] <= 100:
            stars.append(star_list[i][0])
        else:
            plot_list.append(stars)
            istar = star_list[i]
            stars = []
            stars.append(istar[0])

    group_num = 0
    for plot in plot_list:
        #f, axes = plt.subplots(len(plot), 1, squeeze=False)
        plot_num = 0
        xlim = [0, 60]
        if len(plot) == 1:
            continue
        flux_list = []
        for i in plot:
            #for i in range(397):
            star_count = []
            time_list = []
            bkg_time_list = []
            bkg_count = []
            star_num = '%d' % i
            csv_file = "../data/%s/star/extra/list_new/star_%s-0.csv" % (
                name, star_num)
            bkg_csv_file = "../data/%s/star/extra/bkg/star_bkg_%s-0.csv" % (
                name, star_num)

            star_data = np.genfromtxt(csv_file, delimiter=',')
            bkg_data = np.genfromtxt(bkg_csv_file, delimiter=',')

            star_count, edges = np.histogram(star_data[:, 0] - star_data[0, 0],
                                             bins=np.arange(62) * 1000)

            bkg_count, edges = np.histogram(bkg_data[:, 0] - star_data[0, 0],
                                            bins=np.arange(62) * 1000)

            star_flux = np.array(star_count) - np.array(bkg_count) * 64. / 40.
            star_flux[star_flux < 0] = 0
            if np.mean(star_flux) < 5:
                continue
            time_array = np.arange(61)
            '''
			plt.plot(time_array, star_flux)
			plt.xlabel('t/s')
			plt.ylabel('Number of Photons')
			plt.savefig('../plots/%s/star/star_flux/%s-0.png'%(name, star_num), dpi=190)
			plt.clf()
			'''
            flux_list.append((time_array, star_flux, i, cata_list[i, 5]))
        if len(flux_list) > 1:
            flux_list = sorted(flux_list, key=getMag)
            f, axes = plt.subplots(len(flux_list), 1, squeeze=False)
            for plot_num in range(len(flux_list)):
                star_flux = flux_list[plot_num][1]
                time_array = flux_list[plot_num][0]
                axes[plot_num, 0].plot(time_array, star_flux)
                axes[plot_num, 0].text(0.95,
                                       0.85,
                                       'NUV: %.3f' % flux_list[plot_num][3],
                                       verticalalignment='bottom',
                                       horizontalalignment='right',
                                       transform=axes[plot_num, 0].transAxes,
                                       color='green',
                                       fontsize=10)
                #axes[plot_num,0].set_ylabel('Num of Photons')
                ylim = axes[plot_num, 0].get_ylim()
                if plot_num == 0:
                    xlim = axes[plot_num, 0].get_xlim()
                axes[plot_num, 0].set_xlim([0, xlim[1]])
                axes[plot_num, 0].set_ylim(
                    [ylim[0] + np.absolute(ylim[1] - ylim[0]) * 0.01, ylim[1]])
                if plot_num < len(flux_list) - 1:
                    plt.setp(axes[plot_num, 0].get_xticklabels(),
                             visible=False)
                else:
                    axes[plot_num, 0].set_xlabel('time/s')
                #plot_num+=1
            plt.subplots_adjust(left=None,
                                bottom=None,
                                right=None,
                                top=None,
                                wspace=0,
                                hspace=0)
            plt.legend()
            plt.savefig('../plots/%s/star/extra/cons_new/cons%d_track.png' %
                        (name, group_num),
                        dpi=190)
            plt.clf()
        group_num += 1
Exemplo n.º 12
0
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()
        '''
        offsets = np.load('../data/05_r/cata/offsets300-1343_10_new.npy')
        print offsets.shape
        initial = int((co_data[300][0] - 0.5) * 1000)

        skypos_f, skyrange_f = ([0, 0], [1.33333336, 1.33333336])
        imsz_f = imagetools.deg2pix(skypos_f, skyrange_f, 0.0016666667)
        count_f = np.zeros(imsz_f)
        wcs_f = imagetools.define_wcs(skypos_f,
                                      skyrange_f,
                                      width=False,
                                      height=False,
                                      verbose=0,
                                      pixsz=0.0016666667)
        print imsz_f

        cata = spi.load_obj('stars05')
        cata_a = np.array(list(cata))
        cata_len = len(cata)
        cata_a = cata_a * np.pi / 180.
        X, Y, Z = pycoo.spherical_to_cartesian(1, cata_a[:, 1], cata_a[:, 0])
        cata_car = np.array([X, Y, Z], dtype='float64').T
        rad = np.cos(0.00250 * np.pi / 180.)

        with open('../data/csv_list05_full') as f:
            csv_list = f.read().splitlines()
            for csv_file in csv_list:
                print csv_file
                with open(csv_file, 'rb') as file:
                    reader = csv.reader(file)
                    data = []
                    data_f = []
Exemplo n.º 14
0
if __name__ == '__main__':

    if False:
        name = sys.argv[1]
        #name = 'AIS_GAL_SCAN_00032_0001'
        print name

        output = '../data/%s/star/extra/star.csv' % (name)
        path = os.path.dirname(output)
        if not os.path.exists(path):
            os.makedirs(path)
        else:
            print 'exists'

        cata = spi.load_obj('../data/%s_starset_extra_full' % name)
        cata_a = np.array(list(cata))
        cata_len = len(cata)
        cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)

        count_list, imsz_list, wcs_list = [], [], []
        skypos_list, skyrange_list = [], []
        for i in range(cata_list.shape[0]):
            skypos, skyrange = ([cata_list[i, 1], cata_list[i,
                                                            2]], [0.03, 0.03])
            print skypos
            print skyrange
            skypos_list.append(skypos)
            skyrange_list.append(skyrange)
            imsz = imagetools.deg2pix(skypos, skyrange, 0.000416666666666667)
            count = np.zeros(imsz)
Exemplo n.º 15
0
def main():

	name = 'AIS_GAL_SCAN_00014_0001'
	cata = spi.load_obj('../data/%s_starset_extra_full'%name)
	cata_a = np.array(list(cata))
	cata_len = len(cata)
	cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)
	star_list = load_obj("../data/%s/star/extra/list_new/star_detector"%name)
	star_list = sorted(star_list, key=getKey)
	print star_list
	plot_list = []
	stars = []
	istar = star_list[0]
	stars.append(istar[0])
	for i in range(1,len(star_list)):
		if star_list[i][2] - istar[2]<=100:
			stars.append(star_list[i][0])
		else:
			plot_list.append(stars)
			istar = star_list[i]
			stars = []
			stars.append(istar[0])

	group_num = 0
	for plot in plot_list:
		#f, axes = plt.subplots(len(plot), 1, squeeze=False)
		plot_num = 0
		xlim = [0,60] 
		if len(plot) == 1:
			continue
		flux_list = []
		for i in plot:
	#for i in range(397):
			star_count = []
			time_list = []
			bkg_time_list = []
			bkg_count = []
			star_num = '%d'%i
			csv_file = "../data/%s/star/extra/list_new/star_%s-0.csv"%(name, star_num)
			bkg_csv_file = "../data/%s/star/extra/bkg/star_bkg_%s-0.csv"%(name, star_num)
			star_file = open(csv_file, 'rb')
			bkg_file = open(bkg_csv_file, 'rb')
			star_reader = csv.reader(star_file)
			bkg_reader = csv.reader(bkg_file)
			last = 0
			for row in star_reader:
				time = float(row[0])#time = int(float(row[0])/1000.)
				if len(time_list) > 0:
					if time - time_list[0] > 59000:
						break
				if time - last > 1000:
					star_count.append(1)
					last = time
					time_list.append(last)
				else:
					star_count[-1] += 1
			last = 0
			bkg_count = np.zeros(len(star_count))
			for row in bkg_reader:
				time = float(row[0])#time = int(float(row[0])/1000.)
				for j in range(len(star_count)-1):
					if time>=time_list[j] and time<time_list[j+1]:
						bkg_count[j] += 1
						break
				if time>=time_list[-1]:
					bkg_count[-1] += 1
				'''
				if time - last > 1000:
					bkg_count.append(1)
					last = time
					bkg_time_list.append(last)
				else:
					bkg_count[-1] += 1
				'''

			star_flux = np.array(star_count) - np.array(bkg_count)*64./40.
			star_flux[star_flux<0] = 0
			if np.mean(star_flux)<5:
				continue
			#without bkg sub
			star_flux = np.array(star_count)
			time_array = (np.array(time_list)-time_list[0])/1000.
			star_file.close()
			bkg_file.close()
			'''
			plt.plot(time_array, star_flux)
			plt.xlabel('t/s')
			plt.ylabel('Number of Photons')
			plt.savefig('../plots/%s/star/star_flux/%s-0.png'%(name, star_num), dpi=190)
			plt.clf()
			'''
			flux_list.append((time_array, star_flux, i, cata_list[i, 5]))
		if len(flux_list)>1:
			flux_list = sorted(flux_list, key=getMag)
			f, axes = plt.subplots(len(flux_list), 1, squeeze=False)
			for plot_num in range(len(flux_list)):
				star_flux = flux_list[plot_num][1]
				time_array = flux_list[plot_num][0]
				axes[plot_num,0].plot(time_array, star_flux)
				axes[plot_num,0].text(0.95, 0.85, 'NUV: %.3f'%flux_list[plot_num][3], verticalalignment='bottom', horizontalalignment='right', transform=axes[plot_num,0].transAxes, color='green', fontsize=10)
				#axes[plot_num,0].set_ylabel('Num of Photons')
				ylim = axes[plot_num,0].get_ylim()
				if plot_num == 0:
					xlim = axes[plot_num,0].get_xlim()
				axes[plot_num,0].set_xlim([0, xlim[1]])
				axes[plot_num,0].set_ylim([ylim[0]+np.absolute(ylim[1]-ylim[0])*0.01, ylim[1]])
				if plot_num<len(flux_list)-1:
					plt.setp( axes[plot_num,0].get_xticklabels(), visible=False)
				else:
					axes[plot_num,0].set_xlabel('time/s')
				#plot_num+=1
			plt.subplots_adjust(left=None, bottom=None, right=None, top=None,
			            wspace=0, hspace=0)
			plt.legend()
			plt.savefig('../plots/%s/star/extra/cons_no/cons%d_track.png'%(name, group_num),dpi=190)  
			plt.clf()
		group_num += 1
Exemplo n.º 16
0
def main():

    name = 'AIS_GAL_SCAN_00014_0001'
    cata = spi.load_obj('../data/%s_starset_extra_full' % name)
    cata_a = np.array(list(cata))
    cata_len = len(cata)
    cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)
    star_list = load_obj("../data/%s/star/extra/list_new/star_detector" % name)
    star_list = sorted(star_list, key=getKey)
    print star_list
    plot_list = []
    stars = []
    istar = star_list[0]
    stars.append(istar[0])
    for i in range(1, len(star_list)):
        if star_list[i][2] - istar[2] <= 100:
            stars.append(star_list[i][0])
        else:
            plot_list.append(stars)
            istar = star_list[i]
            stars = []
            stars.append(istar[0])

    group_num = 0
    for plot in plot_list:
        #f, axes = plt.subplots(len(plot), 1, squeeze=False)
        plot_num = 0
        xlim = [0, 60]
        if len(plot) == 1:
            continue
        flux_list = []
        for i in plot:
            #for i in range(397):
            star_count = []
            time_list = []
            bkg_time_list = []
            bkg_count = []
            star_num = '%d' % i
            csv_file = "../data/%s/star/extra/list_new/star_%s-0.csv" % (
                name, star_num)
            bkg_csv_file = "../data/%s/star/extra/bkg/star_bkg_%s-0.csv" % (
                name, star_num)
            star_file = open(csv_file, 'rb')
            bkg_file = open(bkg_csv_file, 'rb')
            star_reader = csv.reader(star_file)
            bkg_reader = csv.reader(bkg_file)
            last = 0
            for row in star_reader:
                time = float(row[0])  #time = int(float(row[0])/1000.)
                if len(time_list) > 0:
                    if time - time_list[0] > 59000:
                        break
                if time - last > 1000:
                    star_count.append(1)
                    last = time
                    time_list.append(last)
                else:
                    star_count[-1] += 1
            last = 0
            bkg_count = np.zeros(len(star_count))
            for row in bkg_reader:
                time = float(row[0])  #time = int(float(row[0])/1000.)
                for j in range(len(star_count) - 1):
                    if time >= time_list[j] and time < time_list[j + 1]:
                        bkg_count[j] += 1
                        break
                if time >= time_list[-1]:
                    bkg_count[-1] += 1
                '''
				if time - last > 1000:
					bkg_count.append(1)
					last = time
					bkg_time_list.append(last)
				else:
					bkg_count[-1] += 1
				'''

            star_flux = np.array(star_count) - np.array(bkg_count) * 64. / 40.
            star_flux[star_flux < 0] = 0
            if np.mean(star_flux) < 5:
                continue
            #without bkg sub
            star_flux = np.array(star_count)
            time_array = (np.array(time_list) - time_list[0]) / 1000.
            star_file.close()
            bkg_file.close()
            '''
			plt.plot(time_array, star_flux)
			plt.xlabel('t/s')
			plt.ylabel('Number of Photons')
			plt.savefig('../plots/%s/star/star_flux/%s-0.png'%(name, star_num), dpi=190)
			plt.clf()
			'''
            flux_list.append((time_array, star_flux, i, cata_list[i, 5]))
        if len(flux_list) > 1:
            flux_list = sorted(flux_list, key=getMag)
            f, axes = plt.subplots(len(flux_list), 1, squeeze=False)
            for plot_num in range(len(flux_list)):
                star_flux = flux_list[plot_num][1]
                time_array = flux_list[plot_num][0]
                axes[plot_num, 0].plot(time_array, star_flux)
                axes[plot_num, 0].text(0.95,
                                       0.85,
                                       'NUV: %.3f' % flux_list[plot_num][3],
                                       verticalalignment='bottom',
                                       horizontalalignment='right',
                                       transform=axes[plot_num, 0].transAxes,
                                       color='green',
                                       fontsize=10)
                #axes[plot_num,0].set_ylabel('Num of Photons')
                ylim = axes[plot_num, 0].get_ylim()
                if plot_num == 0:
                    xlim = axes[plot_num, 0].get_xlim()
                axes[plot_num, 0].set_xlim([0, xlim[1]])
                axes[plot_num, 0].set_ylim(
                    [ylim[0] + np.absolute(ylim[1] - ylim[0]) * 0.01, ylim[1]])
                if plot_num < len(flux_list) - 1:
                    plt.setp(axes[plot_num, 0].get_xticklabels(),
                             visible=False)
                else:
                    axes[plot_num, 0].set_xlabel('time/s')
                #plot_num+=1
            plt.subplots_adjust(left=None,
                                bottom=None,
                                right=None,
                                top=None,
                                wspace=0,
                                hspace=0)
            plt.legend()
            plt.savefig('../plots/%s/star/extra/cons_no/cons%d_track.png' %
                        (name, group_num),
                        dpi=190)
            plt.clf()
        group_num += 1
Exemplo n.º 17
0
if __name__ == '__main__':

  if False:
    name = sys.argv[1]
    #name = 'AIS_GAL_SCAN_00032_0001'
    print name

    output = '../data/%s/star/extra/star.csv'%(name)
    path = os.path.dirname(output)
    if not os.path.exists(path):
      os.makedirs(path)
    else:
      print 'exists'

    cata = spi.load_obj('../data/%s_starset_extra_full'%name)
    cata_a = np.array(list(cata))
    cata_len = len(cata)
    cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)

    count_list, imsz_list, wcs_list = [],[],[]
    skypos_list, skyrange_list = [],[]
    for i in range(cata_list.shape[0]):
      skypos, skyrange = ([cata_list[i,1], cata_list[i,2]] , [0.03, 0.03])
      print skypos
      print skyrange
      skypos_list.append(skypos)
      skyrange_list.append(skyrange)
      imsz = imagetools.deg2pix(skypos, skyrange, 0.000416666666666667)
      count = np.zeros(imsz)
      wcs = imagetools.define_wcs(skypos,skyrange,width=False,height=False,verbose=0,pixsz=0.000416666666666667)
Exemplo n.º 18
0
            print num
            res_star_new(0, scan_name, num, num, return_dict)

    if False:
        scan_name = sys.argv[1]
        #scan_name = 'AIS_GAL_SCAN_00014_0001'

        output = '../fits/%s/extra/flat.fits' % (scan_name)
        print output
        path = os.path.dirname(output)
        if not os.path.exists(path):
            os.makedirs(path)
        else:
            print 'exists'

        cata = spi.load_obj('../data/%s_starset_extra_all_star' % scan_name)
        cata_a = np.array(list(cata))
        cata_a = cata_a[np.logical_and(cata_a[:, 4] > 15.5,
                                       cata_a[:, 4] < 17.5)]
        cata_len = len(cata_a)
        cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)

        print cata_len

        asp = np.load('../data/photon_list/%s_asp_cal.npy' % scan_name)
        asp_uni, uni_index = np.unique(asp[:, 0], True)
        asp_uni = asp[uni_index]
        ix_tmp = (np.round(asp_uni[:, 0] - asp_uni[0, 0]) + 1).astype(int)
        dead_tmp = np.zeros(ix_tmp.shape[0])
        scst_tmp = pyfits.open('../AIS_GAL_SCAN/scst/%s-scst.fits' %
                               scan_name)[1].data
Exemplo n.º 19
0
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()
    '''
Exemplo n.º 20
0
			print num
			res_star_new(0, scan_name, num, num, return_dict)

	if False:
		scan_name = sys.argv[1]
		#scan_name = 'AIS_GAL_SCAN_00014_0001'

		output = '../fits/%s/extra/flat.fits'%(scan_name)
		print output
		path = os.path.dirname(output)
		if not os.path.exists(path):
			os.makedirs(path)
		else:
			print 'exists'

		cata = spi.load_obj('../data/%s_starset_extra_all_star'%scan_name)
		cata_a = np.array(list(cata))
		cata_a = cata_a[np.logical_and(cata_a[:,4]>15.5,cata_a[:,4]<17.5)]
		cata_len = len(cata_a)
		cata_list = np.insert(cata_a, 0, np.arange(cata_len), axis=1)

		print cata_len

		asp = np.load('../data/photon_list/%s_asp_cal.npy'%scan_name)
		asp_uni, uni_index=np.unique(asp[:,0], True)
		asp_uni = asp[uni_index]
		ix_tmp = (np.round(asp_uni[:,0]-asp_uni[0,0])+1).astype(int)
		dead_tmp = np.zeros(ix_tmp.shape[0])
		scst_tmp = pyfits.open('../AIS_GAL_SCAN/scst/%s-scst.fits'%scan_name)[1].data
		limit = scst_tmp['t_dead_nuv'].shape[0]-1
		ix_tmp[ix_tmp>limit] = limit