Lv2_dj_lsp.py
def rebin_lc(corr_lc_files,corr_bg_files,bg_scale,tbin,cmpltness):
	"""
	Rebinning the original light curve that was corrected through xrtlccorr

	lc_files - list of corrected light curve files
	tbin - size of new time bins
	cmpltness - level of completeness for the bins
	"""

	"""
	#### time order the lc files!!!
	start_times = [fits.open(lc_files[i])[1].header['TIMEZERO'] for i in range(len(lc_files))]
	time_ordered = np.argsort(start_times)
	ordered_eventlist = np.array(lc_files)[time_ordered]

	times = []
	rates = []
	errors = []
	for i in tqdm(range(len(ordered_eventlist))): #getting every corrected light curve FITS file
		data_arrays = fits.open(ordered_eventlist[i])[1].data
		tstart = fits.open(ordered_eventlist[i])[1].header['TIMEZERO'] #get TIMEZERO
		times += list(tstart+data_arrays['TIME']) #add to an overall list, the 'TIME' array from the corrected light curve FITS file, plus timezero
		rates += list(data_arrays['RATE']) #get the corresponding column for the rates
		errors += list(data_arrays['ERROR']) #get the corresponding column for the errors

	times = np.array(times)
	trunc_times = times-times[0]
	rates = np.array(rates)
	errors = np.array(errors)
	"""
	times,rates,errors,fracexp = Lv2_swift_lc.get_bgsub(corr_lc_files,corr_bg_files,bg_scale)
	trunc_times = times-times[0]

	rebinned_time = []
	rebinned_rate = []
	rebinned_errs = []
	rebinned_fracexp = []
	completeness = []

	time_bins = np.arange(0,trunc_times[-1]+tbin,tbin)
	print('Rebinning...')
	for i in tqdm(range(len(time_bins)-1)):
		time_interval = trunc_times[(trunc_times>=time_bins[i])&(trunc_times<time_bins[i+1])]
		rate_interval = rates[(trunc_times>=time_bins[i])&(trunc_times<time_bins[i+1])]
		error_interval = errors[(trunc_times>=time_bins[i])&(trunc_times<time_bins[i+1])]
		fracexp_interval = fracexp[(trunc_times>=time_bins[i])&(trunc_times<time_bins[i+1])]

		comp = len(time_interval)/(tbin/10)

		if len(time_interval) != 0 and comp >= cmpltness:
			mean_time = np.mean(time_interval)
			mean_rate = np.mean(rate_interval)
			mean_error = np.sqrt(np.sum(error_interval**2))/np.size(error_interval)
			sum_fracexp = sum(fracexp_interval)

			rebinned_time.append(mean_time)
			rebinned_rate.append(mean_rate)
			rebinned_errs.append(mean_error)
			rebinned_fracexp.append(sum_fracexp)
			completeness.append(len(time_interval)/(tbin/10))

	#plt.hist(completeness,bins=10)
	#plt.xlabel('Completeness (fraction)',fontsize=12)
	#plt.ylabel('Number',fontsize=12)
	#plt.show()

	#print(len(rebinned_time))

	return np.array(rebinned_time),np.array(rebinned_rate),np.array(rebinned_errs),np.array(rebinned_fracexp)

	Rebinning the original light curve that was corrected through xrtlccorr

	lc_files - list of corrected light curve files
	tbin - size of new time bins
	cmpltness - level of completeness for the bins
	
Rebinning the original light curve that was corrected through xrtlccorr
lc_files - list of corrected light curve files
tbin - size of new time bins
cmpltness - level of completeness for the bins
Rebinning the original light curve that was corrected through xrtlccorr lc_files - list of corrected light curve files tbin - size of new time bins cmpltness - level of completeness for the bins
def rebin_lc(corr_lc_files,corr_bg_files,bg_scale,tbin,cmpltness):
	times,rates,errors,fracexp = Lv2_swift_lc.get_bgsub(corr_lc_files,corr_bg_files,bg_scale)
	trunc_times = times-times[0]
	rebinned_time = []
	rebinned_rate = []
	rebinned_errs = []
	rebinned_fracexp = []
	completeness = []
	time_bins = np.arange(0,trunc_times[-1]+tbin,tbin)
	print('Rebinning...')
	for i in tqdm(range(len(time_bins)-1)):
		time_interval = trunc_times[(trunc_times>=time_bins[i])&(trunc_times<time_bins[i+1])]
		rate_interval = rates[(trunc_times>=time_bins[i])&(trunc_times<time_bins[i+1])]
		error_interval = errors[(trunc_times>=time_bins[i])&(trunc_times<time_bins[i+1])]
		fracexp_interval = fracexp[(trunc_times>=time_bins[i])&(trunc_times<time_bins[i+1])]
		comp = len(time_interval)/(tbin/10)
		if len(time_interval) != 0 and comp >= cmpltness:
			mean_time = np.mean(time_interval)
			mean_rate = np.mean(rate_interval)
			mean_error = np.sqrt(np.sum(error_interval**2))/np.size(error_interval)
			sum_fracexp = sum(fracexp_interval)
			rebinned_time.append(mean_time)
			rebinned_rate.append(mean_rate)
			rebinned_errs.append(mean_error)
			rebinned_fracexp.append(sum_fracexp)
			completeness.append(len(time_interval)/(tbin/10))
	return np.array(rebinned_time),np.array(rebinned_rate),np.array(rebinned_errs),np.array(rebinned_fracexp)
def rebin_lc ( corr_lc_files , corr_bg_files , bg_scale , tbin , cmpltness ) : """
	#### time order the lc files!!!
	start_times = [fits.open(lc_files[i])[1].header['TIMEZERO'] for i in range(len(lc_files))]
	time_ordered = np.argsort(start_times)
	ordered_eventlist = np.array(lc_files)[time_ordered]

	times = []
	rates = []
	errors = []
	for i in tqdm(range(len(ordered_eventlist))): #getting every corrected light curve FITS file
		data_arrays = fits.open(ordered_eventlist[i])[1].data
		tstart = fits.open(ordered_eventlist[i])[1].header['TIMEZERO'] #get TIMEZERO
		times += list(tstart+data_arrays['TIME']) #add to an overall list, the 'TIME' array from the corrected light curve FITS file, plus timezero
		rates += list(data_arrays['RATE']) #get the corresponding column for the rates
		errors += list(data_arrays['ERROR']) #get the corresponding column for the errors

	times = np.array(times)
	trunc_times = times-times[0]
	rates = np.array(rates)
	errors = np.array(errors)
	""" times , rates , errors , fracexp = Lv2_swift_lc . get_bgsub ( corr_lc_files , corr_bg_files , bg_scale ) trunc_times = times - times [ 0 ] rebinned_time = [ ] rebinned_rate = [ ] rebinned_errs = [ ] rebinned_fracexp = [ ] completeness = [ ] time_bins = np . arange ( 0 , trunc_times [ - 1 ] + tbin , tbin ) print ( 'Rebinning...' ) for i in tqdm ( range ( len ( time_bins ) - 1 ) ) : time_interval = trunc_times [ ( trunc_times >= time_bins [ i ] ) & ( trunc_times < time_bins [ i + 1 ] ) ] rate_interval = rates [ ( trunc_times >= time_bins [ i ] ) & ( trunc_times < time_bins [ i + 1 ] ) ] error_interval = errors [ ( trunc_times >= time_bins [ i ] ) & ( trunc_times < time_bins [ i + 1 ] ) ] fracexp_interval = fracexp [ ( trunc_times >= time_bins [ i ] ) & ( trunc_times < time_bins [ i + 1 ] ) ] comp = len ( time_interval ) / ( tbin / 10 ) if len ( time_interval ) != 0 and comp >= cmpltness : mean_time = np . mean ( time_interval ) mean_rate = np . mean ( rate_interval ) mean_error = np . sqrt ( np . sum ( error_interval ** 2 ) ) / np . size ( error_interval ) sum_fracexp = sum ( fracexp_interval ) rebinned_time . append ( mean_time ) rebinned_rate . append ( mean_rate ) rebinned_errs . append ( mean_error ) rebinned_fracexp . append ( sum_fracexp ) completeness . append ( len ( time_interval ) / ( tbin / 10 ) ) return np . array ( rebinned_time ) , np . array ( rebinned_rate ) , np . array ( rebinned_errs ) , np . array ( rebinned_fracexp )
Rebinning the original light curve that was corrected through xrtlccorr
lc_files - list of corrected light curve files
tbin - size of new time bins
cmpltness - level of completeness for the bins
Rebinning the original light curve that was corrected through xrtlccorr lc_files - list of corrected light curve files tbin - size of new time bins cmpltness - level of completeness for the bins
"""
	Rebinning the original light curve that was corrected through xrtlccorr

	lc_files - list of corrected light curve files
	tbin - size of new time bins
	cmpltness - level of completeness for the bins
	""" """
	#### time order the lc files!!!
	start_times = [fits.open(lc_files[i])[1].header['TIMEZERO'] for i in range(len(lc_files))]
	time_ordered = np.argsort(start_times)
	ordered_eventlist = np.array(lc_files)[time_ordered]

	times = []
	rates = []
	errors = []
	for i in tqdm(range(len(ordered_eventlist))): #getting every corrected light curve FITS file
		data_arrays = fits.open(ordered_eventlist[i])[1].data
		tstart = fits.open(ordered_eventlist[i])[1].header['TIMEZERO'] #get TIMEZERO
		times += list(tstart+data_arrays['TIME']) #add to an overall list, the 'TIME' array from the corrected light curve FITS file, plus timezero
		rates += list(data_arrays['RATE']) #get the corresponding column for the rates
		errors += list(data_arrays['ERROR']) #get the corresponding column for the errors

	times = np.array(times)
	trunc_times = times-times[0]
	rates = np.array(rates)
	errors = np.array(errors)
	""" #plt.hist(completeness,bins=10) #plt.xlabel('Completeness (fraction)',fontsize=12) #plt.ylabel('Number',fontsize=12) #plt.show() #print(len(rebinned_time))
corr_lc_files
corr_bg_files
bg_scale
tbin
cmpltness