def z_split_max_likely(tbdata): posvar = np.linspace(0, 2, 5000) ### Remove edges ### tbdata = vari_funcs.remove_edges(tbdata) ### Split by z ### tbhigh, tblow = z_split(tbdata) ### Get luminosity and flux ### tbhigh, highL, highfluxnorm, higherrnorm = get_luminosity_and_flux(tbhigh) tblow, lowL, lowfluxnorm, lowerrnorm = get_luminosity_and_flux(tblow) ### Get sig values ### numobs = np.shape(highfluxnorm)[0] meanflux = np.nanmean(highfluxnorm, axis=1) highout = np.array([ vari_funcs.maximum_likelihood(highfluxnorm[n, :], higherrnorm[n, :], meanflux[n], posvar, n=n, printn=100) for n in range(numobs) ]) numobs = np.shape(lowfluxnorm)[0] meanflux = np.nanmean(lowfluxnorm, axis=1) lowout = np.array([ vari_funcs.maximum_likelihood(lowfluxnorm[n, :], lowerrnorm[n, :], meanflux[n], posvar, n=n, printn=100) for n in range(numobs) ]) return highL, highout, lowL, lowout, tbdata
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 run_max_likely(tbdata): posvar = np.linspace(0,2,5000) ### Remove edges ### tbdata = vari_funcs.remove_edges(tbdata) ### Get luminosity and flux ### tbdata, L, fluxnorm, fluxerrnorm= get_luminosity_and_flux(tbdata) ### 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 L, out, tbdata
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
from scipy import stats import vari_funcs #my module to help run code neatly #from scipy.stats import chisquare #plt.close('all') #close any open plots ### Open the fits files and get data ### tbdata = fits.open( 'mag_flux_tables/mag_flux_table_best_extra_clean_no06.fits')[1].data chandata = fits.open( 'mag_flux_tables/xray_mag_flux_table_best_extra_clean_no06.fits')[1].data sdata = fits.open( 'mag_flux_tables/stars_mag_flux_table_extra_clean_no06.fits')[1].data sigtb = Table.read('sigma_tables/quad_epoch_sigma_table_extra_clean_no06.fits') ### Remove edges ### tbdata = vari_funcs.remove_edges(tbdata) chandata = vari_funcs.remove_edges(chandata) sdata = vari_funcs.remove_edges(sdata) #### Limit to Chandra region ### #tbdata = vari_funcs.chandra_only(tbdata) #chandata = vari_funcs.chandra_only(chandata) #sdata = vari_funcs.chandra_only(sdata) ## Create arrays of flux values ### flux = vari_funcs.flux5_stacks(tbdata) fluxchan = vari_funcs.flux5_stacks(chandata) sflux = vari_funcs.flux5_stacks(sdata) ### remove values that are negative ### flux, tbdata = vari_funcs.noneg(flux, tbdata)
### create ensemble arrays ### enflux, enfluxerr, enL = make_ensemble(tbdata, L, binedge, fluxnorm, fluxerrnorm) ### Get ensemble maximum likelihood ### sig, sigerr, meanL = get_ensemble_sig(enflux, enfluxerr, enL, posvar) #### get errors ### xerr = find_err_values(binedge, sortedL, meanL) return tbdata, meanL, xerr, sig, sigerr #%% remove edges and split by z ### tbdata = vari_funcs.remove_edges(tbdata) #fullxray = vari_funcs.remove_edges(fullxray) tb1, tb2, tb3, tb4, tb5 = z_split(tbdata) #fullhigh, fulllow = z_split(fullxray) #%% run function ### tb1, meanL1, xerr1, sig1, sigerr1 = get_ensemble_data(tb1) tb2, meanL2, xerr2, sig2, sigerr2 = get_ensemble_data(tb2) tb3, meanL3, xerr3, sig3, sigerr3 = get_ensemble_data(tb3) tb4, meanL4, xerr4, sig4, sigerr4 = get_ensemble_data(tb4) tb5, meanL5, xerr5, sig5, sigerr5 = get_ensemble_data(tb5) #%% run plot ### plt.figure(figsize=[12,7]) #plt.subplot(121)
from astropy.io import fits #for handling fits from astropy.table import Table #for handling tables 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') plt.style.use('dark_background') ### Get fits files ### chandata = fits.open('variable_tables/no06_variables_chi30_2arcsec_chandata_DR11data_restframe.fits')[1].data xmmdata = fits.open('variable_tables/no06_variables_chi30_2arcsec_xmmdata_DR11data_restframe.fits')[1].data tbdata = fits.open('variable_tables/no06_variables_chi30_2arcsec_DR11data_restframe.fits')[1].data ### Remove edges ### tbdata = vari_funcs.remove_edges(tbdata) chandata = vari_funcs.remove_edges(chandata) xmmdata = vari_funcs.remove_edges(xmmdata) nontb = tbdata[~tbdata['X-ray']] #xtb = tbdata[tbdata['X-ray']] ### Get positions ### nonRA = nontb['ALPHA_J2000'] nonDec = nontb['DELTA_J2000'] #xRA = xtb['ALPHA_J2000'] #xDec = xtb['DELTA_J2000'] chanRA = chandata['ALPHA_J2000'] chanDec = chandata['DELTA_J2000'] xmmRA = xmmdata['ALPHA_J2000'] xmmDec = xmmdata['DELTA_J2000']
return binedge def combine_Xray(binedge, xmmenflux, xmmenfluxerr, xmmenL, chanenflux, chanenfluxerr, chanenL): enflux = {} enfluxerr = {} enL = {} for m, enmin in enumerate(binedge): enflux[m] = np.vstack([xmmenflux[m],chanenflux[m]]) enfluxerr[m] = np.vstack([xmmenfluxerr[m],chanenfluxerr[m]]) enL[m] = np.append(xmmenL[m],chanenL[m]) return enflux, enfluxerr, enL #%% remove edges ### tbdata = vari_funcs.remove_edges(tbdata) chandata = vari_funcs.remove_edges(chandata) xmmdata = vari_funcs.remove_edges(xmmdata) fullxray = vari_funcs.remove_edges(fullxray) #%% get_luminosity_and_flux ### tbdata, L, fluxnorm, fluxerrnorm= get_luminosity_and_flux(tbdata) chandata, chanL, chanfluxnorm, chanerrnorm= get_luminosity_and_flux(chandata) xmmdata, xmmL, xmmfluxnorm, xmmerrnorm = get_luminosity_and_flux(xmmdata, xmm=True) fullxray, fullL, fullfluxnorm, fullerrnorm= get_luminosity_and_flux(fullxray) #%% Split into bins according to nir luminosity ### ### Join xmm and chan arrays ### xrayL = np.append(xmmL, chanL)