def extract_flux(band, binlen, tbdata): ### first get the flux and error values for each stack binarr = range(binlen) shortflux = np.empty(len(binarr)) shortfluxerr = np.empty(len(binarr)) for n in binarr: seout = fits.open('SE_outputs_shortstacks/08B_' + str(band) + '_output_cam1_' + str(binlen) + 'bin_' + str(n) + '.fits')[1].data if band == 'J': seout = seout[seout['NUMBER'] == 13363] elif band == 'K': seout = seout[seout['NUMBER'] == 15100] elif band == 'H': seout = seout[seout['NUMBER'] == 11900] shortflux[n] = seout['FLUX_APER'][:, 4] shortfluxerr[n] = seout['FLUXERR_APER'][:, 4] ### Average non-flare flux ### if band == 'J': flux = vari_funcs.jflux5_stacks(tbdata).reshape(4) fluxerr = vari_funcs.jfluxerr5_stacks(tbdata).reshape(4) flux[3] = np.nan fluxerr[3] = np.nan elif band == 'K': flux = vari_funcs.flux5_stacks(tbdata).reshape(7) fluxerr = vari_funcs.fluxerr5_stacks(tbdata).reshape(7) flux[2] = np.nan fluxerr[2] = np.nan elif band == 'H': flux = vari_funcs.hflux5_stacks(tbdata).reshape(7) fluxerr = vari_funcs.hfluxerr5_stacks(tbdata).reshape(7) flux[2] = np.nan fluxerr[2] = np.nan meanflux = np.nanmean(flux) ### get flare flux ### flareflux = shortflux - meanflux #flux[0] ### Propogate errors ### errmeanflux = np.sqrt(np.nansum(np.square(fluxerr))) / binlen flarefluxerr = np.sqrt(np.square(shortfluxerr) + np.square(errmeanflux)) ### Convert to magnitudes ### if band == 'J': flaremag = 30 - 2.5 * np.log10(flareflux) + 0.91 elif band == 'H': flaremag = 30 - 2.5 * np.log10(flareflux) + 1.39 elif band == 'K': flaremag = 30 - 2.5 * np.log10(flareflux) + 1.85 flaremagerr = 1.086 / (flareflux / flarefluxerr) return flareflux, flarefluxerr, flaremag, flaremagerr
sfluxn = vari_funcs.flux5_stacks(sdata) ### remove values that are negative ### fluxn, tbdata = vari_funcs.semfluxlim(fluxn, tbdata) fluxchann, chandata = vari_funcs.semfluxlim(fluxchann, chandata) sfluxn, sdata = vari_funcs.semfluxlim(sfluxn, sdata) #fluxn, tbdata = vari_funcs.noneg(fluxn, tbdata) #fluxchann, chandata = vari_funcs.noneg(fluxchann, chandata) #sfluxn, sdata = vari_funcs.noneg(sfluxn, sdata) ### get error arrays and correct them ### #fluxerrn = vari_funcs.fluxerr5_stacks_corr(tbdata) #fluxerrchann = vari_funcs.fluxerr5_stacks_corr(chandata) #sfluxerrn = vari_funcs.fluxerr5_stacks_corr(sdata) fluxerrn = vari_funcs.fluxerr5_stacks(tbdata) fluxerrchann = vari_funcs.fluxerr5_stacks(chandata) sfluxerrn = vari_funcs.fluxerr5_stacks(sdata) # #### create an error array that is just the flux depths ### ## read in depths array #depths = np.load('fluxdepthsconv_PSF.npy') ## create empty arrays the correct shape #fluxerrn = np.zeros(np.shape(fluxn)) + depths[None,:] #fluxerrchann = np.zeros(np.shape(fluxchann)) + depths[None,:] #sfluxerrn = np.zeros(np.shape(sfluxn)) + depths[None,:] ### Open the fits files and get data ### tbdata2 = fits.open('mag_flux_tables/mag_flux_table_best.fits')[1].data chandata2 = fits.open('mag_flux_tables/xray_mag_flux_table_best.fits')[1].data sdata2 = fits.open('mag_flux_tables/stars_mag_flux_table.fits')[1].data
### Open the fits files and get data ### tbdata = fits.open('mag_flux_tables/mag_flux_table_best_1519match.fits')[1].data chandata = fits.open('mag_flux_tables/xray_mag_flux_table_best_1519match.fits')[1].data sdata = fits.open('mag_flux_tables/stars_mag_flux_table_1519match.fits')[1].data ## Create arrays of flux values ### fluxn = vari_funcs.flux5_stacks(tbdata) fluxchann = vari_funcs.flux5_stacks(chandata) sfluxn = vari_funcs.flux5_stacks(sdata) ### remove values that are negative ### fluxn, tbdata = vari_funcs.noneg(fluxn, tbdata) fluxchann, chandata = vari_funcs.noneg(fluxchann, chandata) sfluxn, sdata = vari_funcs.noneg(sfluxn, sdata) fluxerr = vari_funcs.fluxerr5_stacks(tbdata) fluxerrchan = vari_funcs.fluxerr5_stacks(chandata) sfluxerr = vari_funcs.fluxerr5_stacks(sdata) vari_funcs.flux_variability_plot(fluxn, fluxchann, 'var', starflux=sfluxn, stars=True, normalised=True, scale='symlog') #bins, medvar = vari_funcs.plot_median_line(fluxn, tbdata, statistic='var') bins, medvar = vari_funcs.plot_median_line_stars(fluxn, tbdata, sfluxn, sdata, statistic='var') # vari_funcs.flux_variability_plot(fluxn, fluxchann, 'chisq', fluxerr = fluxerr, starfluxerr = sfluxerr, starflux=sfluxn, stars=True,
chandata = fits.open( 'mag_flux_tables/xray_mag_flux_table_best_1519match.fits')[1].data sdata = fits.open( 'mag_flux_tables/stars_mag_flux_table_1519match.fits')[1].data ## Create arrays of flux values ### fluxn = vari_funcs.flux5_stacks(tbdata) fluxchann = vari_funcs.flux5_stacks(chandata) sfluxn = vari_funcs.flux5_stacks(sdata) ### remove values that are negative ### fluxn, tbdata = vari_funcs.noneg(fluxn, tbdata) fluxchann, chandata = vari_funcs.noneg(fluxchann, chandata) sfluxn, sdata = vari_funcs.noneg(sfluxn, sdata) fluxerr = vari_funcs.fluxerr5_stacks(tbdata) fluxerrchan = vari_funcs.fluxerr5_stacks(chandata) sfluxerr = vari_funcs.fluxerr5_stacks(sdata) fig = vari_funcs.flux_variability_plot(fluxn, fluxchann, 'mad', starflux=sfluxn, stars=True, normalised=True, scale='log') #fig = plt.figure(figsize=[9,6]) #avgflux = np.nanmean(fluxn, axis=1) #fluxnorm = vari_funcs.normalise_flux(fluxn) #sigma = np.std(fluxnorm, axis=1)
avgmag = np.nanmean(smag, axis=1) mask1 = avgmag > 15 mask2 = avgmag <= 19 ### Remove any variable stars from sample ### mad = median_absolute_deviation(sfluxn, axis=1) mask3 = mad < 0.01 ### Apply mask ### mask = mask1 * mask2 * mask3 mask = mask.astype('bool') sflux = sflux[mask] sfluxn = sfluxn[mask] sdata = sdata[mask] smag = smag[mask] sfluxerr = vari_funcs.fluxerr5_stacks(sdata) ### Generate a random interger to look at flux and FWHM curves of ### obnum = np.random.randint(0, 1599) obID = sdata['NUMBER_05B'][obnum] obflux = sflux[obnum, :] obfwhm = np.array([ sdata['FWHM_WORLD_05B'][obnum], sdata['FWHM_WORLD_06B'][obnum], sdata['FWHM_WORLD_07B'][obnum], sdata['FWHM_WORLD_08B'][obnum], sdata['FWHM_WORLD_09B'][obnum], sdata['FWHM_WORLD_10B'][obnum], sdata['FWHM_WORLD_11B'][obnum], sdata['FWHM_WORLD_12B'][obnum] ]) * 3600 obfr = np.array([ sdata['FLUX_RADIUS_05B'][obnum][1], sdata['FLUX_RADIUS_06B'][obnum][1], sdata['FLUX_RADIUS_07B'][obnum][1], sdata['FLUX_RADIUS_08B'][obnum][1], sdata['FLUX_RADIUS_09B'][obnum][1], sdata['FLUX_RADIUS_10B'][obnum][1],
### Bin data ### allerrchange = np.array([]) newallmag = np.array([]) newallmagerr = np.array([]) newallchanmag = np.array([]) newallchanmagerr = np.array([]) newallsmag = np.array([]) newallsmagerr = np.array([]) for n, binedge in enumerate(bins): print(binedge) if n == np.size(bins) - 1: break mag, bindata = vari_funcs.fluxbin(binedge, bins[n + 1], allmag, tbdata) #bindata magerr = vari_funcs.fluxerr5_stacks(bindata) #make error array meanflux = np.mean(mag, axis=1) mag, magerr = vari_funcs.normalise_flux_and_errors(mag, magerr) errchange, newmagerr = times_chi_err(mag, magerr) #find correction allerrchange = np.append(allerrchange, errchange) #create array of corrections ### Apply correction tp stars and X-ray ### chanmag, chanbin = vari_funcs.fluxbin(binedge, bins[n + 1], allchanmag, chandata) chanmagerr = vari_funcs.fluxerr5_stacks(chanbin) chanmeanmag = np.mean(chanmag, axis=1) chanmag, chanmagerr = vari_funcs.normalise_flux_and_errors( chanmag, chanmagerr)
avgfluxchanperepoch = np.mean(fluxchan, axis=0) #for non-stellar chandra savgfluxperepoch = np.median( sflux, axis=0) #median so randomly bright star shouldn't skew it ### Multiply all flux values in a yearstack by the correct constant ### fluxcorr = vari_funcs.psf_correct(flux, flux, 'mean') fluxchancorr = vari_funcs.psf_correct(flux, fluxchan, 'mean') avgfluxcorr = vari_funcs.psf_correct(flux, avgfluxperepoch, 'mean') ### Multiply all flux values in a yearstack by the star constant ### fluxscorr = vari_funcs.psf_correct(sflux, flux, 'median') fluxchanscorr = vari_funcs.psf_correct(sflux, fluxchan, 'median') avgfluxscorr = vari_funcs.psf_correct(sflux, avgfluxperepoch, 'median') ### get error arrays and correct them ### fluxerr = vari_funcs.fluxerr5_stacks(tbdata) fluxerrcorr = vari_funcs.err_correct(flux, fluxerr, fluxcorr) fluxerrscorr = vari_funcs.err_correct(flux, fluxerr, fluxscorr) ## Create arrays of flux values but without 06B ### fluxn = vari_funcs.flux5_stacks_no06(tbdata) fluxchann = vari_funcs.flux5_stacks_no06( chandata) # for chandra non-stellar objects #fluxpstar = vari_funcs.flux5_stacks(pstardata) # for chandra objects identified as stars sfluxn = vari_funcs.flux5_stacks_no06(sdata) ### Calculate the average flux for each year within each flux bin ### avgfluxperepochn = np.mean(fluxn, axis=0) #for UDS avgfluxchanperepochn = np.mean(fluxchann, axis=0) #for non-stellar chandra savgfluxperepochn = np.median( sfluxn, axis=0) #median so randomly bright star shouldn't skew it