# ### Multiply all flux values in a yearstack by the correct constant ### #fluxcorrn = vari_funcs.psf_correct_mag(fluxn, fluxn, 'median') #fluxchancorrn = vari_funcs.psf_correct(fluxn, fluxchann, 'median') #sfluxcorrn = vari_funcs.psf_correct(fluxn, sfluxn, 'median') ### get error arrays and correct them ### fluxerrn = vari_funcs.magerr5_stacks(tbdata) fluxerrchan = vari_funcs.magerr5_stacks(chandata) sfluxerr = vari_funcs.magerr5_stacks(sdata) #fluxerrcorrn = vari_funcs.err_correct(fluxn, fluxerrn, fluxcorrn) fig = vari_funcs.flux_variability_plot(fluxn, fluxchann, 'mad', starflux=sfluxn, stars=True) #fig = vari_funcs.flux_variability_plot(fluxn, fluxchann, 'excess', # fluxerr = fluxerrn, starfluxerr = sfluxerr, # starflux=sfluxn, stars=True, # chanerr = fluxerrchan, # normalised=True) #fig.canvas.mpl_connect('pick_event', vari_funcs.onpick) # combined.close() chandra.close() stars.close()
return flux, fluxerr, tbdata ### Prep data ### flux, fluxerr, tbdata = prep_data(tbdata) fluxchan, chanerr, chandata = prep_data(chandata) sflux, serr, sdata = prep_data(sdata) ### reset X-ray column as messed up by stacking ### tbdata['X-ray'][tbdata['X-ray']==70] = False tbdata['X-ray'][tbdata['X-ray']==84] = True ### Check chisq plot looks correct ### fig,_ = vari_funcs.flux_variability_plot(flux, fluxchan, 'chisq', fluxerr=fluxerr, chanerr=chanerr, starflux=sflux, starfluxerr=serr, #normalised=True, stars=True, scale='log') fig.canvas.mpl_connect('pick_event', vari_funcs.onpickflux_2arcsec) #varydata = fits.open('variable_tables/no06_variables_chi30_2arcsec_DR11data_restframe.fits')[1].data #varydatalow = vari_funcs.flux_split(varydata, 'lower') varydatalow = fits.open('variable_tables/no06_variables_chi30_2arcsec_spec_DR11.fits')[1].data #varydatalow = vari_funcs.flux_split(varydata, 'lower') varyfluxlow, varyfluxerrlow, varydatalow = prep_data(varydatalow) varymeanlow = np.nanmean(varyfluxlow, axis=1) varychilow = vari_funcs.my_chisquare_err(varyfluxlow, varyfluxerrlow) plt.plot(varymeanlow, varychilow, 'kd', mfc='None')
### get error arrays and correct them ### #fluxerr = vari_funcs.fluxerr5_stacks_corr(tbdata2) #fluxerrchan = vari_funcs.fluxerr5_stacks_corr(chandata2) #sfluxerr = vari_funcs.fluxerr5_stacks_corr(sdata2) fluxerr = vari_funcs.fluxerr5_stacks(tbdata2) fluxerrchan = vari_funcs.fluxerr5_stacks(chandata2) sfluxerr = vari_funcs.fluxerr5_stacks(sdata2) fig, _ = vari_funcs.flux_variability_plot(flux, fluxchan, 'excess', fluxerr=fluxerr, flux2=fluxn, fluxerr2=fluxerrn, fluxchan2=fluxchann, chanerr2=fluxerrchann, comparison=True, starfluxerr=sfluxerr, starflux=sflux, stars=True, chanerr=fluxerrchan, normalised=True) 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 ### Bin 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, chanerr = fluxerrchan, normalised=True, scale='symlog') plt.text(5e2, 5e4, r'$\chi^{2} = \sum{\frac{( \,{x_{i} - \bar{x}})^{2} \,}{\sigma_{i}^{2}}}$') def my_chisquare(flux, char_var): fluxn = vari_funcs.normalise_flux(flux)
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) #plt.scatter(avgflux, sigma, marker='+') #plt.xscale('log') ##plt.yscale('log') #plt.xlabel('Mean Flux') #plt.ylabel('sigma') fig, _ = vari_funcs.flux_variability_plot(fluxn, fluxchann,
### Normalise arrays ### #fluxn = vari_funcs.normalise_flux(flux) #fluxchann = vari_funcs.normalise_flux(fluxchan) #sfluxn = vari_funcs.normalise_flux(sflux) # # #### Multiply all flux values in a yearstack by the correct constant ### #fluxcorrn = vari_funcs.psf_correct(fluxn, fluxn, 'median') #fluxchancorrn = vari_funcs.psf_correct(fluxn, fluxchann, 'median') #fluxcorr = vari_funcs.psf_correct(flux, flux, 'median') #fluxchancorr = vari_funcs.psf_correct(flux, fluxchan, 'median') fig, _ = vari_funcs.flux_variability_plot(flux, fluxchan, 'mad', starflux=sflux, stars=True) fig.canvas.mpl_connect('pick_event', vari_funcs.onpick) # Find outliers ### bins = np.array([13, 15]) bins = np.append(bins, np.arange(16, 24, 0.2)) bins = np.append(bins, [24, 25, 26]) #bins = 10**((30-bins)/2.5) #bins = np.flip(bins, axis=0) #outliers, tb, modz = vari_funcs.find_outliers(fluxn, tbdata, bins) #varys = tb[outliers] #varyflux = vari_funcs.mag5_stacks(varys) #varymad = median_absolute_deviation(varyflux, axis=1)
newallsmag = smag newallsmagerr = newsmagerr else: newallmag = np.vstack([newallmag, mag]) newallmagerr = np.vstack([newallmagerr, newmagerr]) newallchanmag = np.vstack([newallchanmag, chanmag]) newallchanmagerr = np.vstack([newallchanmagerr, newchanmagerr]) newallsmag = np.vstack([newallsmag, smag]) newallsmagerr = np.vstack([newallsmagerr, newsmagerr]) #%% plot excess variance with new arrays fig = vari_funcs.flux_variability_plot(newallmag, newallchanmag, 'excess', fluxerr=newallmagerr, starfluxerr=newallsmagerr, starflux=newallsmag, stars=True, chanerr=newallchanmagerr, normalised=True) #%% plot errchange with magnitude plt.figure() plt.scatter(bins[0:44], allerrchange) #%% save new magnitude and error arrays #np.save('chanmagorderedarray', newallchanmag) #np.save('channewmagerrarray', newallchanmagerr) #np.save('smagorderedarray', newallsmag) #np.save('snewmagerrarray', newallsmagerr) #corrections = np.array([bins[0:44], allerrchange])
#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 ### Multiply all flux values in a yearstack by the correct constant ### fluxcorrn = vari_funcs.psf_correct(fluxn, fluxn, 'mean') fluxchancorrn = vari_funcs.psf_correct(fluxn, fluxchann, 'mean') avgfluxcorrn = vari_funcs.psf_correct(fluxn, avgfluxperepochn, 'mean') ### Multiply all flux values in a yearstack by the star constant ### fluxscorrn = vari_funcs.psf_correct(sfluxn, fluxn, 'median') fluxchanscorrn = vari_funcs.psf_correct(sfluxn, fluxchann, 'median') avgfluxscorrn = vari_funcs.psf_correct(sfluxn, avgfluxperepochn, 'median') ### get error arrays and correct them ### fluxerrn = vari_funcs.fluxerr5_stacks_no06(tbdata) fluxerrcorrn = vari_funcs.err_correct(fluxn, fluxerrn, fluxcorrn) fluxerrscorr = vari_funcs.err_correct(fluxn, fluxerrn, fluxscorrn) fig = vari_funcs.flux_variability_plot(fluxcorrn, fluxchancorrn, 'mad', normalised=True) fig.canvas.mpl_connect('pick_event', vari_funcs.onpickchanonly)