def get_avg_flux(tbdata): flux = vari_funcs.flux1_stacks(tbdata) flux = vari_funcs.normalise_flux(flux) return np.nanmedian(flux, axis=0)
mag = sdata['MAG_APER_' + sem][:, 4] mask1 = mag > 15 #removes saturated mask2 = mag < 20 #removes very faint stars mask = mask1 * mask2 tempsdata = sdata[mask] avgFWHM[n] = np.median(tempsdata[colnames]) #* 3600 avgflux[n] = np.median(tempsdata['FLUX_APER_' + sem][:, 4]) if sem == '10B': psf[sem] = fits.getdata('PSFs/small_' + sem + '_K_PSF.fits') else: psf[sem] = fits.getdata('PSFs/matched_' + sem + '_K_PSF.fits') # psf[sem] = fits.open('PSFs/small_'+sem+'_K_PSF.fits')[0].data ## get flux curve flux = vari_funcs.flux5_stacks(tempsdata) flux = vari_funcs.normalise_flux(flux) ### Find maximum FWHM as this is what all the others willl become ### aimind = np.argmax(avgFWHM) aimsem = semesters[aimind] aimpsf = psf[aimsem] ### Convert FWHM into a sigma ### sigmaold = np.array([FWHM2sigma(fwhm, const) for fwhm in avgFWHM]) sigmabroad = sigmaold[aimind] plt.figure(4) plt.imshow(np.log(psf['10B'])) #plt.imshow(psf['10B']) phot = {} flux = {}
def my_chisquare(flux, char_var): fluxn = vari_funcs.normalise_flux(flux) meanflux = np.nanmean(fluxn, axis=1) top = np.square(fluxn-meanflux[:,None]) chi = np.nansum(top/char_var, axis=1) return chi
plt.figure(3,figsize=[8,8]) plt.plot(meanflux, chisq, 'b+',zorder=2) plt.plot(meanchan, chisqchan, 'ro', zorder=3, mfc='None', markersize=10) plt.plot(meansflux, schisq, 'm*', zorder=1, mfc='None', markersize=10) plt.yscale('log') plt.xscale('log') plt.ylabel('Chi Squared') plt.xlabel('Mean Flux') plt.title('1st iteration') plt.text(5e2, 1e3, r'$\chi^{2} = \sum{\frac{( \,{x_{i} - \bar{x}})^{2} \,}{\sigma_{noise}^{2}}}$') ### remove any with chisq > 70 ### newgflux = flux[chisq<50,:] newsflux = sflux[schisq<50,:] newflux = np.vstack((newgflux, newsflux)) newfluxn = vari_funcs.normalise_flux(newflux) vary = np.var(newfluxn, axis=1, ddof=1) newmedvar[n] = np.nanmedian(vary) newchisq = my_chisquare(flux, newmedvar[n]) newchisqchan = my_chisquare(fluxchan, newmedvar[n]) newschisq = my_chisquare(sflux, newmedvar[n]) ### plot new ### plt.figure(4, figsize=[8,8]) plt.plot(meanflux, newchisq, 'b+',zorder=2) plt.plot(meanchan, newchisqchan, 'ro', zorder=3, mfc='None', markersize=10) plt.plot(meansflux, newschisq, 'm*', zorder=1, mfc='None', markersize=10) plt.yscale('log') plt.xscale('log') plt.ylabel('Chi Squared')
#varymad = median_absolute_deviation(varyflux, axis=1) #varymean = np.mean(varyflux, axis=1) #plt.figure(1) #plt.plot(varymean, varymad, 'md', mfc='none', markersize=10) outliers2, tb2, modz2 = vari_funcs.find_outliers(flux, tbdata, bins, threshold=5) tb2['X-ray'][tb2['X-ray'] == 70] = False tb2['X-ray'][tb2['X-ray'] == 84] = True ### Find plotting values for the new flux table ### flux2 = vari_funcs.flux5_stacks(tb2) flux2, tb2 = vari_funcs.noneg(flux2, tb2) avgfluxperob2 = np.nanmean(flux2, axis=1) #for UDS flux2 = vari_funcs.normalise_flux(flux2) vary2 = median_absolute_deviation(flux2, axis=1) ### create table of varying ### magmask = avgfluxperob2 < 10**((30 - 21) / 2.5) outliers2 = outliers2 * magmask varydata = tb2[outliers2] #cols = fits.ColDefs(varydata) #hdu = fits.BinTableHDU.from_columns(cols) #hdu.writeto('variable_tables/variable_mag_flux_table_with06B_mag21.fits') varyfluxcorr = flux2[outliers2] varymadcorr = vary2[outliers2] varymeancorr = avgfluxperob2[outliers2] varymodz = modz2[outliers2] #plt.plot(varymeancorr, varymadcorr, 'kd', mfc='none', markersize=10)
from photutils import CircularAperture, aperture_photometry hdr08B = fits.getheader('Images/UDS_08B_K.fits') # random year (same in all) const = -hdr08B['CD1_1'] # constant that defines unit conversion for FWHM semesters = ['05B', '06B', '07B', '08B', '09B', '10B', '11B', '12B'] ### get data and create flux and errors array ### sdata = fits.open('mag_flux_tables/stars_mag_flux_table.fits')[1].data sflux = vari_funcs.flux5_stacks(sdata) smag = vari_funcs.mag5_stacks(sdata) sflux, sdata = vari_funcs.noneg(sflux, sdata) smag = vari_funcs.mag5_stacks(sdata) ### set up normalised flux ### sfluxn = np.copy(sflux) sfluxn = vari_funcs.normalise_flux(sfluxn) ### Limit to same magnitude range as PSFS ### 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]