def get_luminosity_and_flux(tbdata, xmm=False): # ### Extract magnitude table and error table ### flux = vari_funcs.flux4_stacks(tbdata) flux, tbdata = vari_funcs.noneg(flux, tbdata) # tbdata = tbdata[np.nanmean(flux,axis=1)>1e4] flux, fluxerr, tbdata = vari_funcs.create_quad_error_array(sigtb, tbdata, aper=4) ### Normalise ### fluxnorm, fluxerrnorm = vari_funcs.normalise_flux_and_errors(flux, fluxerr) ### Find luminosity distance ### z = tbdata['z_spec'] #[mask] z[z == -1] = tbdata['z_p'][z == -1] DL = cosmo.luminosity_distance(z) DL = DL.to(u.m) ### Get AB magnitude ### # abmag = tbdata['KMAG_20'] ### Convert to luminosity using formula worked out in lab book ### # L = 10 ** (-abmag/2.5) * 3631 * 1e-26 * (3e8/0.34e-6) * 4 * np.pi * (DL.value**2) # gives luminosity in W L = tbdata['M_K_z_p'] return tbdata, L, fluxnorm, fluxerrnorm
def prep_data(tbdata): ### Remove edges ### tbdata = vari_funcs.remove_edges(tbdata) ## Create arrays of flux values ### flux = vari_funcs.flux4_stacks(tbdata) ### remove values that are negative ### flux, tbdata = vari_funcs.noneg(flux, tbdata) ### Get error arrays ### flux, fluxerr, tbdata = vari_funcs.create_quad_error_array(sigtb, tbdata, aper=4) return flux, fluxerr, tbdata
def get_luminosity_and_flux(tbdata, xmm=False): ### Extract magnitude table and error table ### flux = vari_funcs.flux4_stacks(tbdata) flux, tbdata = vari_funcs.noneg(flux, tbdata) # tbdata = tbdata[np.nanmean(flux,axis=1)>1e4] flux, fluxerr, tbdata = vari_funcs.create_quad_error_array(sigtb, tbdata, aper=4) ### Normalise ### fluxnorm, fluxerrnorm = vari_funcs.normalise_flux_and_errors(flux, fluxerr) ### Get Luminosity ### L = tbdata['M_K_z_p'] L[L == 99] = np.nan mask = ~np.isnan(L) tbdata = tbdata[mask] L = L[mask] fluxnorm = fluxnorm[mask] fluxerrnorm = fluxerrnorm[mask] return tbdata, L, fluxnorm, fluxerrnorm
def get_luminosity_and_flux(tbdata, xmm=False): # ### Extract magnitude table and error table ### flux = vari_funcs.flux4_stacks(tbdata) flux, tbdata = vari_funcs.noneg(flux, tbdata) # tbdata = tbdata[np.nanmean(flux,axis=1)>1e4] flux, fluxerr, tbdata = vari_funcs.create_quad_error_array(sigtb, tbdata, aper=4) ### Normalise ### fluxnorm, fluxerrnorm = vari_funcs.normalise_flux_and_errors(flux, fluxerr) L = tbdata['KFLUX_20'] ### remove any that have -ve val ### L[L < 0] = np.nan # remove those with null values # L[L > -5] = np.nan # remove faintest as seem spurious mask = ~np.isnan(L) # [mask] return tbdata[mask], L[mask], fluxnorm[mask], fluxerrnorm[mask]
def run_max_likely(tbdata): posvar = np.linspace(0,2,5000) ### Remove edges ### tbdata = vari_funcs.remove_edges(tbdata) sigtb = Table.read('sigma_tables/quad_epoch_sigma_table_extra_clean_no06_2arcsec.fits') ### Extract magnitude table and error table ### flux = vari_funcs.flux4_stacks(tbdata) flux, tbdata = vari_funcs.noneg(flux, tbdata) # tbdata = tbdata[np.nanmean(flux,axis=1)>1e4] flux, fluxerr, tbdata = vari_funcs.create_quad_error_array(sigtb, tbdata, aper=4) ### Normalise ### fluxnorm, fluxerrnorm = vari_funcs.normalise_flux_and_errors(flux, fluxerr) ### Get sig values ### numobs = np.shape(fluxnorm)[0] meanflux = np.nanmean(fluxnorm, axis=1) out = np.array([vari_funcs.maximum_likelihood(fluxnorm[n,:], fluxerrnorm[n,:], meanflux[n], posvar, n=n, printn=100) for n in range(numobs)]) return out, tbdata
def find_number(tb): ### Get flux ### flux = vari_funcs.flux4_stacks(tb) bins = np.array([13, 15]) bins = np.append(bins, np.arange(16, 24, 0.2)) bins = np.append(bins, [24]) bins = 10**((30 - bins) / 2.5) bins = np.flip(bins, axis=0) #bins = bins[16:44] #because of flux limit num = np.zeros(len(bins)) ### Bin data ### for n, binedge in enumerate(bins): # print(binedge) if n == np.size(bins) - 1: break mag, _ = vari_funcs.fluxbin(binedge, bins[n + 1], flux, tb) num[n] = len(mag) return num, bins
plt.close('all') #close any open plots from matplotlib.offsetbox import OffsetImage, AnnotationBbox font = {'family' : 'DejaVu Sans', 'weight' : 'normal', 'size' : 14} plt.rc('font', **font) ### Open the fits files and get data ### varys = fits.open('variable_tables/no06_variables_chi30_2arcsec.fits')[1].data sigtb = Table.read('sigma_tables/quad_epoch_sigma_table_extra_clean_no06_2arcsec.fits') #varys = vari_funcs.chandra_only(varys) flux = vari_funcs.flux4_stacks(varys) flux, varys = vari_funcs.noneg(flux, varys) flux, fluxerr, newvarys = vari_funcs.create_quad_error_array(sigtb, varys, aper=4) #flux,fluxerr = vari_funcs.normalise_flux_and_errors(flux, fluxerr) #set up time variable for plot t = np.linspace(1, 8, num=8) years = ['05B', '06B', '07B', '08B', '09B', '10B', '11B', '12B'] xcurve = [1,3,4,5,6,7,8] ### reduce to just single lightcurve ### obnum = 62243 mask = newvarys['NUMBER_05B'] == obnum flux = flux[mask].reshape(len(xcurve)) fluxerr = fluxerr[mask].reshape(len(xcurve)) obdata = newvarys[mask]
def get_mean_flux(tbdata): flux = vari_funcs.flux4_stacks(tbdata) meanflux = np.nanmean(flux, axis=1) return meanflux
quaddata = vari_funcs.quadrants(tbdata, '05B') chanquaddata = vari_funcs.quadrants(chandata, '05B') squaddata = vari_funcs.quadrants(sdata, '05B') sigsqdict = {} sigdict = {} finalchisq = np.array([]) galchisq = np.array([]) oldchisq = np.array([]) for m, qtbdata in enumerate(quaddata): ### get quad arrays for chan and stars ### qchandata = chanquaddata[m] qsdata = squaddata[m] ## Create arrays of flux values ### fluxn = vari_funcs.flux4_stacks(qtbdata) fluxchann = vari_funcs.flux4_stacks(qchandata) sfluxn = vari_funcs.flux4_stacks(qsdata) ### remove values that are negative ### fluxn, qtbdata = vari_funcs.noneg(fluxn, qtbdata) fluxchann, qchandata = vari_funcs.noneg(fluxchann, qchandata) sfluxn, qsdata = vari_funcs.noneg(sfluxn, qsdata) fluxerr = vari_funcs.fluxerr4_stacks(qtbdata) fluxerrchan = vari_funcs.fluxerr4_stacks(qchandata) sfluxerr = vari_funcs.fluxerr4_stacks(qsdata) print(len(fluxn) + len(sfluxn)) if m == 3:
return I1minI2, z, zlimsmask, Iuplimsmask, Ilolimsmask, tbdata[mask] I1minI2, z, zlimsmask, Iuplimsmask, Ilolimsmask, tbdata = get_data(tbdata) varyI1minI2, varyz, varyzlimsmask, varyIuplimsmask, varyIlolimsmask, varydata = get_data( varydata) noxvaryI1minI2, noxvaryz, noxvaryzlimsmask, noxvaryIuplimsmask, noxvaryIlolimsmask, noxvarydata = get_data( noxvarydata) xvaryI1minI2, xvaryz, xvaryzlimsmask, xvaryIuplimsmask, xvaryIlolimsmask, xvarydata = get_data( xvarydata) devI1minI2, devz, devzlimsmask, devIuplimsmask, devIlolimsmask, devdata = get_data( devdata) xI1minI2, xz, xzlimsmask, xIuplimsmask, xIlolimsmask, xdata = get_data(xdata) ### flux ### varyL = vari_funcs.flux4_stacks(varydata) varyL = np.nanmean(varyL, axis=1) xvaryL = vari_funcs.flux4_stacks(xvarydata) xvaryL = np.nanmean(xvaryL, axis=1) noxvaryL = vari_funcs.flux4_stacks(noxvarydata) noxvaryL = np.nanmean(noxvaryL, axis=1) #colmap = 'cool' # #### M_star ### #varyL = varydata['Mstar_z_p'] #xvaryL = xvarydata['Mstar_z_p'] #noxvaryL = noxvarydata['Mstar_z_p'] #def ignore_zeros(m, z, I1minI2, zlimsmask, Iuplimsmask, Ilolimsmask, tbdata): # m[m==0] = np.nan # mask = ~np.isnan(m) # z = z[mask]