def get_L_O(tbdata): ''' Function to get the monochromatic luminosity at 2500 A Inputs: tbdata = table of data for the objects Outputs: L_O = monochromatic luminosity at 2500A in units of ergs/s/Hz ''' z = vari_funcs.get_z(tbdata) z[z < 0.5] = np.nan z[z > 4] = np.nan ### get luminosity distance ### DL = cosmo.luminosity_distance(z) # need to sort out units DL = DL.to(u.cm) ### get U band magnitude ### umag = tbdata['M_U_z_p'] L_U = 10**((34.1 - umag) / 2.5) L_U = L_U * u.W * (u.Hz)**-1 # Units of W/Hz L_U = L_U.to((u.erg) * (u.s)**-1 * (u.Hz)**-1, equivalencies=u.spectral()) ### Use frequency ratios to find Omag ### Ofreq = constants.c / (2500 * u.AA) Ufreq = constants.c / (3743 * u.AA) L_O = L_U * (Ufreq / Ofreq) # assuming flux propotional to freq**-1 # F_O = F_O.to((u.erg) * (u.s)**-1 * (u.cm)**2 * (u.Hz)**-1, equivalencies=u.spectral()) # units of ergs/s/cm**"/Hz # L_O = L_O.to((u.erg) * (u.s)**-1 * (u.Hz)**-1, equivalencies=u.spectral()) return L_O
def prep_variables(tbdata): z = vari_funcs.get_z(tbdata) # get redshift m = tbdata['Mstar_z_p'] #get mass m, mask = ignore_zeros(m) #mask those with null mass z = z[mask] #apply mask to z array highz = z > 4.5 z[highz] = 4.4 return z, m, highz
def get_xray_L_mixedtable(tbdata, band='Full'): ''' Function to find the X-ray luminosity in a variety of flux bands. Inputs: tbdata = data table for all the objects, must have x-ray boolean incl band = what band of flux should be used: - 'Full' 0.5-10keV (default) - 'Hard' 2-10keV - 'Soft' 0.2-5keV - 'Uhrd' 5-10keV (not recommended) Outputs: flux = broad band flux in units of ergs/cm^2/s L = broad band luminosity in units of ergs/s z = redshift ''' z = vari_funcs.get_z(tbdata) # z[z<0.5] = np.nan # z[z>4] = np.nan ### get luminosity distance ### DL = cosmo.luminosity_distance(z) # need to sort out units DL = DL.to(u.cm) flux = np.zeros(len(tbdata)) for n in range(len(tbdata)): if band == 'Hard': if tbdata['X-ray'][ n] == True: # if it is an X-ray source, get flux from catalogue flux[n] = tbdata['Hard_flux'] # flux# Units of erg cm**-2 s**-1 else: # if it is non X-ray - use the upper limit flux[n] = 6.5e-16 # Units of erg cm**-2 s**-1 elif band == 'Full': if tbdata['X-ray'][n] == True: flux[n] = tbdata['Full_flux'] # Units of erg cm**-2 s**-1 else: flux[n] = 4.4e-16 # Units of erg cm**-2 s**-1 elif band == 'Soft': if tbdata['X-ray'][n] == True: flux[n] = tbdata['Soft_flux'] # Units of erg cm**-2 s**-1 else: flux[n] = 1.4e-16 # Units of erg cm**-2 s**-1 elif band == 'Uhrd': if tbdata['X-ray'][n] == True: flux = tbdata['Uhrd_flux'] # Units of erg cm**-2 s**-1 else: flux[n] = 9.2e-15 # Units of erg cm**-2 s**-1 ### Add units ### flux = flux * (u.erg) * (u.cm)**-2 * (u.s)**-1 ### get luminosity ### L = flux * 4 * np.pi * (DL**2) return flux, L, z
def get_xray_L(tbdata, Xray=True, band='Full'): ''' Function to find the X-ray luminosity in a variety of flux bands. Inputs: tbdata = data table for all the objects Xray = whether the object has an X-ray counterpart. If it does not then the survey limit is used as an upperlimit. Default is True band = what band of flux should be used: - 'Full' 0.5-10keV (default) - 'Hard' 2-10keV - 'Soft' 0.2-5keV - 'Uhrd' 5-10keV (not recommended) Outputs: flux = broad band flux in units of ergs/cm^2/s L = broad band luminosity in units of ergs/s z = redshift ''' z = vari_funcs.get_z(tbdata) # z[z<0.5] = np.nan # z[z>4] = np.nan ### get luminosity distance ### DL = cosmo.luminosity_distance(z) # need to sort out units DL = DL.to(u.cm) if band == 'Hard': if Xray == True: # if it is an X-ray source, get flux from catalogue flux = tbdata['Hard_flux'] flux # Units of erg cm**-2 s**-1 else: # if it is non X-ray - use the upper limit flux = np.zeros(len(tbdata)) flux += 6.5e-16 # Units of erg cm**-2 s**-1 elif band == 'Full': if Xray == True: flux = tbdata['Full_flux'] # Units of erg cm**-2 s**-1 else: flux = 4.4e-16 # Units of erg cm**-2 s**-1 elif band == 'Soft': if Xray == True: flux = tbdata['Soft_flux'] # Units of erg cm**-2 s**-1 else: flux = 1.4e-16 # Units of erg cm**-2 s**-1 elif band == 'Uhrd': if Xray == True: flux = tbdata['Uhrd_flux'] # Units of erg cm**-2 s**-1 else: flux = 9.2e-15 # Units of erg cm**-2 s**-1 ### Add units ### flux = flux * (u.erg) * (u.cm)**-2 * (u.s)**-1 ### get luminosity ### L = flux * 4 * np.pi * (DL**2) return flux, L, z
) #jdata[jdata['X-ray']==True] noxvarydata = Table.read( 'variable_tables/J_and_K_variables_month_varystats_DR11data_chan_notxray.fits' ) #jdata[jdata['X-ray']==False] ### Restrict to J selected #### xvarydata = xvarydata[xvarydata['Chi_J'] > 32.08] noxvarydata = noxvarydata[noxvarydata['Chi_J'] > 32.08] #%% restrict to just chandra ### #tbdata = vari_funcs.field_funcs.chandra_only(tbdata, sem='') noxvarydata = vari_funcs.field_funcs.chandra_only(noxvarydata, sem='') xvarydata = vari_funcs.field_funcs.chandra_only(xvarydata, sem='') #%% histograms of z ### z = vari_funcs.get_z(dr11) noxz = vari_funcs.get_z(noxvarydata) xz = vari_funcs.get_z(xvarydata) allxz = vari_funcs.get_z(fullxray) plt.figure() plt.hist([noxz, xz], bins=50, color=['b', 'r'], histtype='step', label=['Non X-ray', r'X-ray']) #, # normed=True) #plt.hist([xz, allxz], bins=50, color=['r','k'], # histtype='step', label=['X-ray Variable','X-ray Non-Variable'])#, # normed=True) plt.legend()
Kfluxnorm, Kfluxerrnorm = vari_funcs.flux_funcs.normalise_flux_and_errors( Kflux, Kfluxerr) Jfluxnorm, Jfluxerrnorm = vari_funcs.flux_funcs.normalise_flux_and_errors( Jflux, Jfluxerr) #%% All points posvar = np.linspace(0, 2, 5000) Kmeanflux = np.nanmean(Kfluxnorm, axis=1) Jmeanflux = np.nanmean(Jfluxnorm, axis=1) ### Set up arrays for K selected ### allKout = np.array([]) allKouterr = np.array([]) ### Find z for full tbdata ### Kz = vari_funcs.get_z(Kdata) Kbad = [] # array for IDs that do not have a match in the other bad KbadIDs = [] # array for IDs that do not have a match in the other bad for n in range(len(Kdata)): #loop over the selection band obnum = Kdata['ID'][n] #get DR11 number print(obnum) # give an idea of progress ### Get maximum likelihoods in J and K for that object ### Kout = vari_funcs.vary_stats.maximum_likelihood(Kfluxnorm[n, :], Kfluxerrnorm[n, :], Kmeanflux[n], posvar) ### save output into x-ray and band specfic arrays ### allKout = np.append(allKout, Kout[0]) allKouterr = np.append(allKouterr, Kout[1])
def get_xray_L_2(tbdata, Xray=True, band='Hard'): ''' Function to find the monochromatic X-ray luminosity at 2keV in a variety of flux bands. This assumes a power law for flux density and then finds the constant in this equation. The flux density is then used to find the monochromatic flux density which is in turn used to calulate the monochromatic luminosity. Inputs: tbdata = data table for all the objects X-ray = whether the object has an X-ray counterpart. If it does not then the survey limit is used as an upperlimit. Default is True band = what band of flux should be used: - 'Hard' 2-10keV (default) - 'Full' 0.5-10keV - 'Soft' 0.2-5keV - 'Uhrd' 5-10keV (not recommended) Outputs: L_2 = monochromatic luminosity at 2 keV in units of ergs/s/Hz F_2 = monochromatic flux at 2 keV in units of ergs/keV/s/cm^2 flux = broad band flux in units of ergs/cm^2/s z = redshift ''' z = vari_funcs.get_z(tbdata) z[z < 0.5] = np.nan z[z > 4] = np.nan ### get luminosity distance ### DL = cosmo.luminosity_distance(z) # need to sort out units DL = DL.to(u.cm) if band == 'Hard': upplim = 10 ## set band limits in keV lowlim = 2 if Xray == True: # if it is an X-ray source, get flux from catalogue flux = tbdata['Hard_flux'] flux # Units of erg cm**-2 s**-1 else: # if it is non X-ray - use the upper limit flux = np.zeros(len(tbdata)) flux += 6.5e-16 # Units of erg cm**-2 s**-1 elif band == 'Full': upplim = 10 lowlim = 0.5 if Xray == True: flux = tbdata['Full_flux'] # Units of erg cm**-2 s**-1 else: flux = 4.4e-16 # Units of erg cm**-2 s**-1 elif band == 'Soft': upplim = 2 lowlim = 0.5 if Xray == True: flux = tbdata['Soft_flux'] # Units of erg cm**-2 s**-1 else: flux = 1.4e-16 # Units of erg cm**-2 s**-1 elif band == 'Uhrd': upplim = 10 lowlim = 5 if Xray == True: flux = tbdata['Uhrd_flux'] # Units of erg cm**-2 s**-1 else: flux = 9.2e-15 # Units of erg cm**-2 s**-1 ### Add units ### flux = flux * (u.erg) * (u.cm)**-2 * (u.s)**-1 upplim = upplim * u.keV lowlim = lowlim * u.keV ### redshift limits ### # upplim = upplim/(1+z) # lowlim = lowlim/(1+z) ### get integrated flux density ### denom = ((upplim**(0.1)) / (0.1)) - ((lowlim**(0.1)) / (0.1)) print(denom) ### use this and flux value to get the power law constant ### const = flux / denom ### calculate flux density ### nu = 2 * u.keV # 2kev is value to evaluate at F_2 = const * (nu**(-0.9)) ### calculate luminosity density ### L_2 = 4 * np.pi * (DL**2) * F_2 #const * (nu**-0.9) L_2 = L_2.to((u.erg) * (u.s)**-1 * (u.Hz)**-1, equivalencies=u.spectral()) L_2[L_2 == 0] = np.nan return L_2, F_2, flux, z #L_2_w_Hz
import numpy as np #for handling arrays #import math #from astropy.stats import median_absolute_deviation import vari_funcs #my module to help run code neatly plt.close('all') #%% histograms of z ### varydata = fits.open( 'variable_tables/no06_variables_chi30_2arcsec_DR11data_restframe.fits' )[1].data varydatalow = vari_funcs.flux_split(varydata, 'lower') varydataup = vari_funcs.flux_split(varydata, 'upper') zlow = vari_funcs.get_z(varydatalow) zup = vari_funcs.get_z(varydataup) plt.hist( [zlow, zup], color=['m', 'g'], histtype='step', label=[r'$\bar{F} < 8 \times 10^{3}$', r'$\bar{F} \geq 8 \times 10^{3}$'], normed=True) plt.legend() plt.xlabel('z') plt.ylabel('Number') ### with x/nox split ### noxvarydata = fits.open( 'variable_tables/no06_variables_chi30_2arcsec_noXray_DR11data_restframe.fits'
### Import sig data ### Jsigtb = Table.read( 'sigma_tables/quad_epoch_sigma_table_extra_clean_2arcsec_J.fits') Ksigtb = Table.read( 'sigma_tables/quad_epoch_sigma_table_extra_clean_no06_2arcsec_neg.fits') #Jxraydata = Jdata[Jdata['X-ray']==True] #### Limit to Chandra region for simplicity ### #KKdata = vari_funcs.chandra_only(KKdata) #KJdata = vari_funcs.chandra_only(KJdata) #JKdata = vari_funcs.chandra_only(JKdata) #JJdata = vari_funcs.chandra_only(JJdata) #%% plot z distributions of the sets ### Jz = vari_funcs.get_z(JJdata) Kz = vari_funcs.get_z(KKdata) plt.figure() plt.hist([Jz, Kz], bins=25, histtype='step', label=['J Variables', 'K Variables']) plt.xlabel('z') plt.legend(loc='upper center') #%% plot M_star distributions of the sets ### Jmstar = JJdata['Mstar_z_p'][Jz < 6] Kmstar = KKdata['Mstar_z_p'][Kz < 6] plt.figure()
Jmask = np.isin(Jdata['ID'], Kdata['ID']) Kdata = Kdata[Kmask] Jdata = Jdata[Jmask] Kflux = Kflux[Kmask] Jflux = Jflux[Jmask] Kfluxerr = Kfluxerr[Kmask] Jfluxerr = Jfluxerr[Jmask] ### Normalise ### Kfluxnorm, Kfluxerrnorm = vari_funcs.flux_funcs.normalise_flux_and_errors( Kflux, Kfluxerr) Jfluxnorm, Jfluxerrnorm = vari_funcs.flux_funcs.normalise_flux_and_errors( Jflux, Jfluxerr) ### Find z for full tbdata ### z = vari_funcs.get_z(Kdata) #%% All points posvar = np.linspace(0, 2, 5000) Kmeanflux = np.nanmean(Kfluxnorm, axis=1) Jmeanflux = np.nanmean(Jfluxnorm, axis=1) ### Set up arrays for K selected ### allKout = np.array([]) allKouterr = np.array([]) allJout = np.array([]) allJouterr = np.array([]) Kbad = [] # array for IDs that do not have a match in the other bad KbadIDs = [] # array for IDs that do not have a match in the other bad for n in range(len(Kdata)): #loop over the selection band obnum = Kdata['ID'][n] #get DR11 number