PSFs for the companions

The whole Cepheid project is focussed on the Cepheids PSF, fitting, subtracting etc. using LOCI and other complicated algorithms. However, in some cases, we also need a simple prescription of the PSF for "normal" stars, i.e. stars that are not saturated ant not insanly overexposed, so that we don't see the same number of structures in the wings that we do see for the Cepheids. In particualr, we need an analytic form of the PSF to fit the flux of any detected companions and similarly, we need a sample of "clean" stars that we can use for our fake-insert experiements to determine fit uncertianties and detection limits.

In this notebook, we stars from a list of hand-selected stars in the Cepheid images. I just clicked through the images in ds9, selecting all stars that had a flux in the central pixel > 200, are not visibly impacted by the Cepheid PSF (usually that means they are far away, but if a star is very bright, then it is OK if it's close to the diffraction spike as long as it's flux is much larger than the spike), are single and look circular (no unresolved binaries).

In this notebook, we load in that list and then perform additional filtering to get a set of clean PSF templates.


In [ ]:
import numpy as np

import astropy.units as u
from astropy.coordinates import SkyCoord
from astroquery.gaia import Gaia
from astropy import table
from astropy.table import Table
from astropy.wcs import WCS
from astropy.io import fits

from astropy.nddata import NDData
from photutils.psf import extract_stars

import sherpa
import sherpa.astro.models
import sherpa.data
import sherpa.fit

import matplotlib.pyplot as plt

%matplotlib inline

In [105]:
# On melkor, the datapath is hardocded in snapshot program
# but to run on my laptop, I need to put it here
datapath = 'data/'

In [106]:
prflist = [['ibg402010_drz.fits', 612, 209],
           ['ibg402010_drz.fits', 1007, 951],
           ['ibg402010_drz.fits', 64, 823],
           ['ibg403010_drz.fits', 597, 385],
           ['ibg405010_drz.fits', 340, 40],
           ['ibg406010_drz.fits', 424, 348],
           ['ibg412010_drz.fits', 439, 239],
           ['ibg415010_drz.fits', 676, 73],
           ['ibg416010_drz.fits', 444, 217],
           ['ibg417010_drz.fits', 587, 954],
           ['ibg418010_drz.fits', 113, 946],
           ['ibg418010_drz.fits', 160, 720],
           ['ibg418010_drz.fits', 113, 946],
           ['ibg418010_drz.fits', 917, 873],
           ['ibg419010_drz.fits', 675, 644],
           ['ibg422010_drz.fits', 896, 320],
           ['ibg425010_drz.fits', 647, 697],
           ['ibg426010_drz.fits', 997, 84],
           ['ibg426010_drz.fits', 385, 95],
           ['ibg428010_drz.fits', 356, 85],
           ['ibg428010_drz.fits', 889, 496],
           ['ibg429010_drz.fits', 803, 305],
           ['ibg432010_drz.fits', 153, 109],
           ['ibg434010_drz.fits', 876, 577],
           ['ibg436010_drz.fits', 342, 878],
           ['ibg437010_drz.fits', 873, 239],
           ['ibg438010_drz.fits', 41, 651],
           ['ibg438010_drz.fits', 417, 403],
           ['ibg440010_drz.fits', 212, 338],
           ['ibg440010_drz.fits', 297, 1018],
           ['ibg443010_drz.fits', 358, 289],
           ['ibg444010_drz.fits', 329, 347],
           ['ibg444010_drz.fits', 724, 725],
           ['ibg446010_drz.fits', 276, 501],
           ['ibg449010_drz.fits', 75, 775],
           ['ibg450010_drz.fits', 669, 272],
           ['ibg452010_drz.fits', 158, 558],
           ['ibg453010_drz.fits', 812, 847],
           ['ibg453010_drz.fits', 333, 189],
           ['ibg455010_drz.fits', 567, 650],
           ['ibg455010_drz.fits', 263, 444],
           ['ibg456010_drz.fits', 530, 696],
           ['ibg458010_drz.fits', 162, 807],
           ['ibg459010_drz.fits', 375, 168],
           ['ibg462010_drz.fits', 683, 641],
           ['ibg463010_drz.fits', 647, 971],
           ['ibg463010_drz.fits', 319, 873],
           ['ibg465010_drz.fits', 588, 723],
           ['ibg468010_drz.fits', 150, 509],
           ['ibg468010_drz.fits', 280, 136],
           ['ibg471010_drz.fits', 600, 685],
           ['ibg471010_drz.fits', 892, 511],
          ]

First, we turn to GAIA. While the current DR2 does not explicitly mark catalog entries as multiple systems or extended sources, we can just look at the error in RA and dec. For stars as bright as the ones we've chosen, those errors are typically i nthe range 0.05 milliarcsec. Anything larger than that indicates that the source is not a good point source, so we want to reject it.


In [ ]:
radius = u.Quantity(1.0, u.arcsec)
gaia = []

for i, p in enumerate(prflist):
    wcs = WCS(fits.getheader(datapath + p[0], 1))
    ra, dec = wcs.all_pix2world(p[1], p[2], 1)
    coord = SkyCoord(ra=ra, dec=dec, unit=(u.degree, u.degree), frame='icrs')
    j = Gaia.cone_search(coord, radius)
    r = j.get_results()
    r['i'] = i
    r['file'] = p[0]
    r['x'] = p[1]
    r['y'] = p[2]
    gaia.append(r)

In [147]:
gaiatab = table.vstack(gaia)
gaiatab


Out[147]:
Table length=52
solution_iddesignationsource_idrandom_indexref_epochrara_errordecdec_errorparallaxparallax_errorparallax_over_errorpmrapmra_errorpmdecpmdec_errorra_dec_corrra_parallax_corrra_pmra_corrra_pmdec_corrdec_parallax_corrdec_pmra_corrdec_pmdec_corrparallax_pmra_corrparallax_pmdec_corrpmra_pmdec_corrastrometric_n_obs_alastrometric_n_obs_acastrometric_n_good_obs_alastrometric_n_bad_obs_alastrometric_gof_alastrometric_chi2_alastrometric_excess_noiseastrometric_excess_noise_sigastrometric_params_solvedastrometric_primary_flagastrometric_weight_alastrometric_pseudo_colourastrometric_pseudo_colour_errormean_varpi_factor_alastrometric_matched_observationsvisibility_periods_usedastrometric_sigma5d_maxframe_rotator_object_typematched_observationsduplicated_sourcephot_g_n_obsphot_g_mean_fluxphot_g_mean_flux_errorphot_g_mean_flux_over_errorphot_g_mean_magphot_bp_n_obsphot_bp_mean_fluxphot_bp_mean_flux_errorphot_bp_mean_flux_over_errorphot_bp_mean_magphot_rp_n_obsphot_rp_mean_fluxphot_rp_mean_flux_errorphot_rp_mean_flux_over_errorphot_rp_mean_magphot_bp_rp_excess_factorphot_proc_modebp_rpbp_gg_rpradial_velocityradial_velocity_errorrv_nb_transitsrv_template_teffrv_template_loggrv_template_fe_hphot_variable_flaglbecl_lonecl_latpriam_flagsteff_valteff_percentile_lowerteff_percentile_uppera_g_vala_g_percentile_lowera_g_percentile_uppere_bp_min_rp_vale_bp_min_rp_percentile_lowere_bp_min_rp_percentile_upperflame_flagsradius_valradius_percentile_lowerradius_percentile_upperlum_vallum_percentile_lowerlum_percentile_upperdatalink_urlepoch_photometry_urldistifilexy
yrdegmasdegmasmasmasmas / yrmas / yrmas / yrmas / yrmas1 / mas21 / um1 / ummaselectron / selectron / smagelectron / selectron / smagelectron / selectron / smagmagmagmagkm / skm / sKlog(cm.s**-2)dexdegdegdegdegKKKmagmagmagmagmagmagRsunRsunRsunLsunLsunLsun
int64objectint64int64float64float64float64float64float64float64float64float32float64float64float64float64float32float32float32float32float32float32float32float32float32float32int32int32int32int32float32float32float64float64int16boolfloat32float64float64float32int16int16float32int32int16boolint32float64float64float32float32int32float64float64float32float32int32float64float64float32float32float32int16float32float32float32float64float64int32float32float32float32objectfloat64float64float64float64int64float32float32float32float32float32float32float32float32float32int64float32float32float32float32float32float32objectobjectfloat64int64str18int64int64
1635721458409799680Gaia DR2 42673976947822209284267397694782220928100691132015.5287.05414337640630.057088317752889691.29655402707989120.051389551919923880.138940642293070770.065804367784924522.1114197-3.59838063766835560.11716042079325267-4.8905813023992940.1060709894690015-0.022343619-0.168893040.10487678-0.008879941-0.18072510.020061811-0.009888715-0.142477480.093694230.102583319409316.1113224195.386730.275713039853371037.14466315885834131False9.2883141.3351547230241660.0128883082035654710.0105258971180.11141969011False9326397.8563572969135.62608108266079740.9714.63444474945.66907554983952.9607531597894293.3836616.115826834249.82197614091162.94872815050286210.1877313.4252741.484798302.69055181.48138141.2091703----0------NOT_AVAILABLE36.002315006993626-3.1393248964273917288.666110741745123.6374947199745371000013804.953232.33334116.15--------------------------https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+42673976947822209285.717718462157228e-050ibg402010_drz.fits612209
1635721458409799680Gaia DR2 426739779786153011242673977978615301121547304462015.5287.056201919762260.046362292940061261.30558080328004310.042663515658038630.439875240985087460.057452867547788547.65628-0.03406912563940030.08619414648821153-0.130074026058372730.07891623771749010.007196901-0.25851172-0.12912999-0.11048176-0.16287646-0.014983596-0.29061073-0.358228150.137323990.03011830511901181-1.318123193.7302250.00.031False12.1936651.54232026166104720.010813739232509549-0.0149581051490.08359324014False11610373.4578817371936.85868362198616751512.45615.648557134706.21870050999116.272631165748088289.210716.169708118492.39089514832849.510498153816116171.5270714.9393451.272344201.23036290.521151540.70921135----0------NOT_AVAILABLE36.011295334169304-3.1370197894472414288.6695939356842523.646185898338791000014956.04827.55123.0------------2001112.08414671.95048312.19657662.36089421.69585323.0259352https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+42673977978615301125.554558310901536e-051ibg402010_drz.fits1007951
1635721458409799680Gaia DR2 426739780220724032042673978022072403201604096432015.5287.06312492017080.062790165884824861.29770313574154630.056292099883493540.185419895804752540.075468530438585662.4569168-1.34426694002804380.1188039331733622-4.7947259710811880.109991795094576280.002861211-0.27345762-0.08577161-0.015550057-0.148873940.06181476-0.18904561-0.278482230.134790750.09167339113011305.6080427212.118440.279973587181138464.7262869151778631False6.1446161.27181471941154940.0140734399806360970.0273917241390.11210833013False11310518.6495321310789.041013437657451163.43715.633466111848.9811086083820.30545254947100691.0583617.1840571114116.51338485064573.58689353278075191.8346114.3876021.517827402.79645541.55059151.2458639----0------NOT_AVAILABLE36.00745699862537-3.1467805418239365288.675992266885423.6374907402226421000013984.9553384.54175.2852.67332.58692.78511.35421.2991.3943--------------https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+42673978022072403205.2456399467558675e-052ibg402010_drz.fits64823
1635721458409799680Gaia DR2 451414528824059251245141452882405925125034770762015.5284.562572846692260.03573477669957307617.3592608829180080.033818536779263441.94177169411213610.0413263098748513646.986332-8.5780470242242610.06918261978189656-19.8156924996225360.06900124150303860.303547230.308842240.1917494-0.496878740.104804076-0.47079226-0.15920201-0.088714935-0.43256380.320745922882882731510.116828575.96990.00.031True327.960571.60131002112700080.0080924895730084130.01111689534110.052393835040False286864914.33259538692066.0159765262288418.6387310.84593328506164.208444992313385.7149273078537.8137611.09065929651722.566326626813126.8039445452249.64822810.2267631.3387300.863896370.244726180.6191702----0------NOT_AVAILABLE49.203992286621376.361576046244109288.2242573511851439.881674788134051000015534.255343.35873.0------------2001113.30507872.93480563.54552279.231958.9466029.517298https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+45141452882405925125.430140004119451e-053ibg403010_drz.fits597385
1635721458409799680Gaia DR2 4204653582696321792420465358269632179215415883772015.5287.08072874387530.034123055600201714-7.4388115249932290.0314385907942151750.52497656721182150.0406495006499009612.914711-3.13684513998495040.06827634316586204-6.4616439904425950.064784979773883310.19042155-0.13420683-0.10429257-0.2281653-0.3976722-0.108046584-0.16972196-0.171311360.143856590.21545318141014010.99412566151.282470.0168239493632769240.02870315483540246831False24.5832921.50380669061065440.0080942534341737530.1043065716100.074163646017False14020828.41958508395310.8070833024518061927.293314.891725129234.83227351603513.312542666945497693.694115.4378161517254.50103701923647.55148248572876362.8593814.1696641.27178801.26815130.54609110.7220602----0------NOT_AVAILABLE28.195037652193527-7.122660425488573287.5461212005040514.9661099242416681000014822.42334676.855010.12------------2001112.65748432.46209672.82549453.44110132.8352314.0469713https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+42046535826963217920.000160364926799281444ibg405010_drz.fits34040
1635721458409799680Gaia DR2 4293157229319401344429315722931940134412371269832015.5287.998711351476740.055815771416569734.3545548665774440.060690413892750470.84112039810314140.0729093821235926311.536518-0.79901622149150680.12005427353455846-3.4777529788783110.114810868828601630.43088236-0.15945564-0.09287989-0.24851614-0.28786504-0.09328008-0.37288803-0.304011020.04841020.17831577194019316.621527346.84020.328669315342628676.90666426908085831False4.3923731.373235323835240.0113854819454737180.1381205322110.120994836024False2057379.12857257575610.111442987211259729.7799716.018353202419.42022100639466.8317898748336636.20163716.892111810614.54520827317499.24160532390825106.95660414.6971661.766328602.19494440.87375831.3211861----0------NOT_AVAILABLE39.155689752631986-2.571706365136609290.145586214450226.543798784446451020013908.33333554.04410.1074------------2001111.86366941.46370552.25380950.730127630.596990640.8632646https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+42931572293194013440.000229273505726893445ibg406010_drz.fits424348
1635721458409799680Gaia DR2 5250032958803803520525003295880380352015563120632015.5146.304729720663520.08834305644444834-62.506499792633280.061032816521145360.75580283475474760.087057896217317018.681611-1.1860903596894170.188767967976827687.519556751780670.11007068752303290.02603953-0.0788118240.373035850.0482944770.53390660.290246370.0360940360.42742390.0126150140.000469354561470144316.698502642.832640.4028176018853813514.01301441608208431False4.07395271.58112066598162480.016338388182469358-0.08727676417120.17905444018False13011617.86725392097762.743521701835625185.1644115.525551610002.744459187605961.387816329024410.40448515.351091415303.0026045252671122.184704121675813.63679514.2999782.17817501.0511122-0.174459461.2255716----0------NOT_AVAILABLE283.1956176266505-7.004838223567386197.06104399073968-66.310995067713341020115095.63334259.06938.0--------------------------https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+52500329588038035204.4399800305629967e-056ibg412010_drz.fits439239
1635721458409799680Gaia DR2 5125243573094348805125243573094348805277262622015.523.1858137423554960.0390773069207458463.588855963076580.033758440382355660.82760785631883820.04682012684928496517.6763273.1232821093348210.06537946267464514-2.76352046839984840.06057706639572152-0.090867750.049315803-0.644977870.043638587-0.18401924-0.032334838-0.33251184-0.0271292850.33237663-0.24104926298029620.06382555291.873960.00.031False8.068061.40747147762352930.009183929756177744-0.00386671234170.073954605042False3407109.1195877700424.1432223446837811715.843116.058826332317.12410424535039.961479964802425232.6084116.939014337484.56941831536722.87726472543002327.161915.0765031.378749301.86251160.8801880.98232365----0------NOT_AVAILABLE127.506019668974231.084537436128159451.6568842300780548.768991201530861000013933.753835.04167.17------------2001111.81949821.62137211.91440750.71420840.62453020.80388665https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+5125243573094348807.391511035611572e-057ibg415010_drz.fits67673
1635721458409799680Gaia DR2 589167530305308108858916753030530810885931677152015.5218.144520033602560.025061209713861655-56.888538726628890.0273275446014899950.83301342619305410.0384793350207638921.648333-14.7255577956006630.07049770206786848-13.1682995585485860.0655681221951057-0.28546858-0.29716880.070107960.028257990.241917040.0217192470.00042553246-0.140424680.0800764-0.1053762821202120-2.8555121153.618260.00.031False21.9596751.515875284497750.006732926738806168-0.001278540824120.07293663025False22018171.6628121535769.0434500614412752009.372815.039879237886.40079221064735.39004627920231222.8423515.6091912315647.1483716843369.3676848229735225.5682714.2758321.295068501.33335880.56931210.76404667----0------NOT_AVAILABLE316.447657340459673.3054373663063967236.24075637556598-39.3666770693121751000014713.33354529.55009.01.8691.55792.3990.9380.7651.1752001111.66383151.47320651.80162811.23090931.1002641.3615547https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+58916753030530810885.956787486076014e-058ibg416010_drz.fits444217
...............................................................................................................................................................................................................................................................................................................
1635721458409799680Gaia DR2 595277567527595392059527756752759539209474493132015.5260.69454672154650.05559592191460894-45.609481994185040.079459278988532510.186407293791094640.065802751734564032.8328192-0.347812617061401930.13106523342888687-1.02403011782050160.1372831257906937-0.71266860.5887337-0.875766040.73776007-0.846899570.84790224-0.9669742-0.76159590.83366066-0.858988518401840-0.34787613171.848620.00.031False59.4889531.43362561058922870.0071425557901905820.01970380521100.19893512024False18347661.9817746709912.7043793623251193751.618213.9929352115881.08352010467442.03070388616449377.8448214.8491882147180.48191903649458.376522702990165808.209913.0775141.323101.77167420.85625270.9154215----0------NOT_AVAILABLE343.5147290788381-5.218544007366134262.9726283607509-22.396942438000021000014313.53948.05100.00.8920.6461.05860.44220.33490.5067--------------https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+59527756752759539200.0001197109681320807342ibg458010_drz.fits162807
1635721458409799680Gaia DR2 5960623340819000192596062334081900019214053908212015.5264.402440316676630.05375550520809922-40.810315966063450.0551157339395500140.89302778431588730.064986033744141313.741841-0.397233812829229540.0957995031457435-1.8071751341533350.086625790805697840.32219106-0.19790635-0.29147652-0.16763341-0.63004070.09955567-0.6924464-0.16891520.5171978-0.0785814910501032-1.055346883.35530.00.031False19.6951031.51971311509284910.014438172543073170.250069831270.10056553015False8214579.41877673925232.34590995847981450.7345315.27901678463.329296155209693.810780913856912.19832515.532535612689.97819846542184.9317448295108268.619814.5032681.45090201.02926640.253519060.7757473----0------NOT_AVAILABLE349.03074862635185-4.861659933310241265.5614111117193-17.4572412457697651020015215.1754777.05875.0------------2001111.07198310.84471451.27765980.76585420.647309660.8843987https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+59606233408190001922.598187834155437e-0543ibg459010_drz.fits375168
1635721458409799680Gaia DR2 582446449370600806458244644937060080646414489782015.5229.936221757097060.038886033725138075-66.497322391098890.0573546864154760240.497657109238301640.086871112526227335.7286835-5.317368982632890.07912450352889475-11.5505576270180940.156378921041366940.1234316-0.152706-0.110236290.053018548-0.176879870.005130629-0.2740952-0.19280164-0.158055470.298531652550251410.961999576.879640.337468148616375148.3331582036833531False4.4872421.52835220549076770.01381595385576421-0.04248342729140.14563265035False2679010.58298040267817.833470754017974505.2624515.801483256300.979103253014143.8840776800255743.79205315.8528682610462.859432839557347.433465258334330.11471414.7127941.86046101.14007380.0513849261.0886889----0------NOT_AVAILABLE316.9747005740874-7.758076137319726248.29376358068902-46.051579458922811020015143.454259.07050.0--------------------------https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+58244644937060080643.964605484373755e-0544ibg462010_drz.fits683641
1635721458409799680Gaia DR2 582313435951111641658231343595111164169971452872015.5240.29479524315240.02829850900669221-63.771628079605240.0239597909298125270.52141223115793660.0361895518138698314.407811-1.1475358582217680.059757684984844475-2.2905867942000020.05011433320459020.20866424-0.1473213-0.32011235-0.23397575-0.19753623-0.21828333-0.3148712-0.00162858750.34072942-0.054091766280027460.91923606290.188020.00.031False14.8817231.55173719652188780.00675935549231866750.0886365932160.06248972034False24412139.08182840962812.572652085523924965.5148315.477901225849.65902911718325.97257573054567225.2244415.933561229387.83196987991148.68248370534864192.8379814.8305061.255242501.1030550.455659870.64739513----0------NOT_AVAILABLE322.1328204321316-8.220217431288875252.83501757522552-42.09195303143151000014993.514897.05165.767------------2001111.86569231.74334031.93995481.94983711.63502532.264649https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+58231343595111164164.6861309094096466e-0545ibg463010_drz.fits647971
1635721458409799680Gaia DR2 5823134359511110912582313435951111091211533129062015.5240.301796759482270.026908767478029828-63.7737879207895160.0230168762541323320.115621111119706440.033467689765947083.4547086-3.47977119043654830.04935822898060123-7.403125422241760.0525106640590882540.23048162-0.16340527-0.38838762-0.29327878-0.07476394-0.26467973-0.250121030.0083279890.161731470.0277695930102983-1.4845914257.898380.00.031False14.7318481.49648729428189740.0063777218364834330.0425935150.057793505037False30312164.0462386636397.8114600940134981557.205215.475671245228.20142192120143.63160211422086119.8260316.0555082510661.78753759692231.636627243421263337.0077214.6923451.306307811.3631630.579836850.78332615----0------NOT_AVAILABLE322.13371732037155-8.223884998079843252.83981059869495-42.09321347605921000024698.60354499.04958.0--------------------------https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+58231343595111109124.572382456575388e-0546ibg463010_drz.fits319873
1635721458409799680Gaia DR2 582422665560082291258242266556008229127707201672015.5232.712152171041880.013041263066323389-65.600344939078130.0207747293087952620.70594021568421130.0285926540794040124.689566-1.11818660925131130.02526954894433926-3.4144521407428290.0611473085669882250.3302901-0.143877970.078183880.17965876-0.0302376650.132568630.099835835-0.11796496-0.041441050.47839668412040754.9845233559.714660.080864397664765541.696213279611599831False31.267251.6158065379788880.0047411941314265060.01615087147150.06733032054True32830367.70455949862713.1444737148056372310.30214.4823362617525.501347226516157.75801833516383111.09103414.7422122622288.156256691145258.128909158663686.3450613.8917351.311052600.85047720.259876250.59060097----0------NOT_AVAILABLE318.4233121919155-7.643720992394395249.34251124010024-44.813705578380041000015602.5435406.086520.66651.00650.59271.48850.5370.3050.78972001111.65705611.22327361.7796832.43730522.1949132.6796975https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+58242266556008229123.8462285510881896e-0547ibg465010_drz.fits588723
1635721458409799680Gaia DR2 1857884212368260480185788421236826048014226101712015.5312.87150315959440.0193608657414190428.2529398109502240.0275959055169221060.311849797052534960.027856674170943611.194797-3.9082451259035650.04467228228987131-4.7771837612060830.045855615151432710.161927090.25038552-0.49934924-0.159655320.14846069-0.19252902-0.7140625-0.13351433-0.0518950970.0007824007261026012.614486317.944730.01.2585344472030546e-1531False34.7991831.60627699162746640.0053782701501735460.1805409830140.057226535031False23327635.68894999556511.5909100887937412384.255414.584692415691.71681289369762.52262582271788250.9766114.8622122418651.8738430829750.29850963332606370.8235814.0851141.242726100.777098660.27752210.49957657----0------NOT_AVAILABLE72.13644772004507-10.152926994389833326.0150829640456343.71699916009841000015954.0255767.46360.0------------2001113.13403152.74669483.34013911.1210048.66558513.576424https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+18578842123682604800.0001015680093628216648ibg468010_drz.fits150509
1635721458409799680Gaia DR2 185788414365865305618578841436586530561371001732015.5312.87333913261140.03371692077808350528.2489043827149580.073026138646913440.095660699138129620.052558260227818241.8200887-8.7266610726385160.08550798990872921-8.422966613150390.120203035719398180.212609680.023875665-0.4643983-0.22906968-0.15089582-0.26446488-0.84109640.0153049230.21713930.1219614126102601-0.6611762239.717760.00.031False7.58471971.55138386150569780.0104939184945967950.1757024430140.13662814031False2526462.4984646486595.8185338358825551110.674716.162365283538.776324970476738.2017537600611792.6338716.479256275191.29828906402834.62583674721388149.9255715.473731.350882301.00552560.316890720.6886349----0------NOT_AVAILABLE72.1342602028306-10.156703736890876326.015067241049943.712651731104461000015306.1155086.85611.25--------------------------https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+18578841436586530560.0001021754043754379949ibg468010_drz.fits280136
1635721458409799680Gaia DR2 2027951173407534080202795117340753408011496176172015.5297.879814695648860.01992607859876536427.458670013218860.0239325366874268840.40278791231293060.02978928938295648613.521233-0.67319724727183460.04863033732103339-4.7194006842161820.051542394658151760.00236178280.19798510.132075820.0239358080.0231528920.04123365-0.007402360.018274905-0.078107820.033859983257025529.803941538.431640.185446448618008967.931443482783568531False20.3904421.59264885797916040.00581117325904962-0.001136570530150.0551355035True24257974.31632514443598.41081495432029589.1051613.7802761333116.68198458256406.29782306712381.5083914.0512711344774.867184444636872.374654935973751.3252713.1343351.343552700.91693690.270995140.64594173----0------NOT_AVAILABLE63.946077180250240.32036522491066616307.7340547134449547.311890877164391000015575.05343.36145.0------------2001114.0573553.3395584.4168614.32716411.75163516.902693https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+20279511734075340805.056117746763301e-0550ibg471010_drz.fits600685
1635721458409799680Gaia DR2 202795117343513804820279511734351380484398474182015.5297.883497918865150.01448403270361554927.460491058892750.021937524376961911.0805920053124240.0249179625280032343.365986-1.0755233745589190.034066745207752464-2.17559647003802860.04468272744554217-0.1156833840.107232176-0.13373041-0.033907898-0.12625602-0.021507736-0.30998373-0.191208320.00018605622-0.0927967928702861-2.5995471223.196780.00.031False36.470911.5244091747744010.0050791007188620190.0244297433170.05107364036False25627906.44231642725615.610802897605451787.636614.5741042412490.51082207104333.251580591219906375.636615.1099382422862.10818245410354.36098276643936420.5609713.8641291.266826401.24580860.535833360.70997524----0------NOT_AVAILABLE63.9493126243199940.31848641043989334307.7394270761946647.31274534954951000014885.66654750.60555026.7363------------2001111.44399151.36408081.52726481.0703341.00748351.1331844https://gea.esac.esa.int/data-server/datalink/links?ID=Gaia+DR2+20279511734351380484.913469810283974e-0551ibg471010_drz.fits892511

In [148]:
# Select only those stars that are likely good single point sources
gaiatab = gaiatab[(gaiatab['ra_error'] < 0.1) & (gaiatab['dec_error'] < 0.1)]

Next, we load all remaining sources.


In [149]:
# -1 because the above positions are measured in ds9, which counts from (1,1)   
# while the python code counts from (0,0)                                       
stars621 = extract_stars([NDData(fits.open(datapath + row['file'])[1].data) for row in gaiatab],
                         [Table({'x': [row['x'] - 1], 'y': [row['y'] - 1]}) for row in gaiatab],
                         size=25)
stars845 = extract_stars([NDData(fits.open(datapath + row['file'].replace('10_', '20_'))[1].data) 
                          for row in gaiatab],
                         [Table({'x': [row['x'] - 1], 'y': [row['y'] - 1]}) for row in gaiatab],
                         size=25)

In [150]:
def sherpa_phot(psf, data):
    # Set sensible starting values
    # Use hasattr so I can use the same function for e.g. Gauss2D if I want to try that
    if hasattr(psf, 'alpha') and not psf.alpha.frozen:
        psf.alpha = 2
    if hasattr(psf, 'r0') and not psf.r0.frozen:
        psf.r0 = 2
    psf.ampl = np.max(s.data)
    x, y = np.indices(data.shape)
    dpsf = sherpa.data.Data2D('', x.flatten(), y.flatten(), data.flatten())
    fpsf = sherpa.fit.Fit(dpsf, psf, stat=sherpa.stats.LeastSq())
    fpsf.fit()
    return data - psf(x.flatten(), y.flatten()).reshape(data.shape)

In [151]:
beta2d = sherpa.astro.models.Beta2D()
beta2d.xpos = stars621[0].data.shape[0] / 2
beta2d.ypos = stars621[0].data.shape[1] / 2
beta2d.alpha = 2
beta2d.alpha.frozen = True

results = []

for i, s in enumerate(stars621):
    out = sherpa_phot(beta2d, s.data)
    results.append([p.val for p in beta2d.pars])
res621 = Table(rows=results, names = [p.name for p in beta2d.pars])

In [152]:
results = []

for i, s in enumerate(stars845):
    out = sherpa_phot(beta2d, s.data)
    results.append([p.val for p in beta2d.pars])
res845 = Table(rows=results, names = [p.name for p in beta2d.pars])

Since the (x,y) positions are just picked by hand in ds9, they might be off by a pixel or two. However, for the fake insertion technique later, we want sources that are reasonably centered in the extracted sub-images. Thus, in the first round, we fit the (x,y) values, calculate the difference and then adjust the input (x,y) in our catalog.


In [153]:
plt.plot(res621['xpos'])
plt.plot(res845['xpos'])
plt.plot(res621['ypos'])
plt.plot(res845['ypos'])


Out[153]:
[<matplotlib.lines.Line2D at 0x1209e03d0>]

In [154]:
# Note how (x, y) -> (y, x) because of the ordering of the indices
# I don't want to find out exactly where that happens, just make make this line look better.
# I just chekc that it works (see below) and that's all that I need here.
gaiatab['x'] = gaiatab['x'] - np.rint(12.5 - res621['ypos'])
gaiatab['y'] = gaiatab['y'] - np.rint(12.5 - res621['xpos'])

In [155]:
# Now extract it again
# -1 because the above positions are measured in ds9, which counts from (1,1)   
# while the python code counts from (0,0)                                       
stars621 = extract_stars([NDData(fits.open(datapath + row['file'])[1].data) for row in gaiatab],
                         [Table({'x': [row['x'] - 1], 'y': [row['y'] - 1]}) for row in gaiatab],
                         size=25)
stars845 = extract_stars([NDData(fits.open(datapath + row['file'].replace('10_', '20_'))[1].data) 
                          for row in gaiatab],
                         [Table({'x': [row['x'] - 1], 'y': [row['y'] - 1]}) for row in gaiatab],
                         size=25)

In [188]:
# fit it again
results = []

for i, s in enumerate(stars621):
    beta2d.xpos = 12.5
    beta2d.ypos = 12.5
    out = sherpa_phot(beta2d, s.data)
    results.append([p.val for p in beta2d.pars])
res621 = Table(rows=results, names = [p.name for p in beta2d.pars])

results = []

for i, s in enumerate(stars845):
    beta2d.xpos = 12.5
    beta2d.ypos = 12.5
    out = sherpa_phot(beta2d, s.data)
    results.append([p.val for p in beta2d.pars])
res845 = Table(rows=results, names = [p.name for p in beta2d.pars])

In [158]:
# Check its centered
plt.plot(res621['xpos'])
plt.plot(res845['xpos'])
plt.plot(res621['ypos'])
plt.plot(res845['ypos'])


Out[158]:
[<matplotlib.lines.Line2D at 0x120a190d0>]

Look at fit results with alpha and r0 free


In [183]:
beta2d.alpha.frozen = False
results = []

for i, s in enumerate(stars621):
    beta2d.xpos = 12.5
    beta2d.ypos = 12.5
    out = sherpa_phot(beta2d, s.data)
    results.append([p.val for p in beta2d.pars])
res621ar = Table(rows=results, names = [p.name for p in beta2d.pars])

results = []

for i, s in enumerate(stars845):
    beta2d.xpos = 12.5
    beta2d.ypos = 12.5
    out = sherpa_phot(beta2d, s.data)
    results.append([p.val for p in beta2d.pars])
res845ar = Table(rows=results, names = [p.name for p in beta2d.pars])

In [185]:
plt.scatter(res621ar['alpha'], res621ar['r0'], c=gaiatab['parallax'])
plt.colorbar()


Out[185]:
<matplotlib.colorbar.Colorbar at 0x1219f1e50>

In [186]:
plt.scatter(res845ar['alpha'], res845ar['r0'], c=gaiatab['parallax'])
plt.colorbar()


Out[186]:
<matplotlib.colorbar.Colorbar at 0xb2e70b3d0>

Look at fit results when alpha is frozen

Even if the alpha is frozen to a differnet value then what I will ultimately use to fit the LOCI subtracted data, it's close enough. The goal here is to remove source that obviously have a different PSF shape, e.g. because they are unresolved binaries or background sources or something.


In [198]:
out = plt.hist([res621['r0'], res845['r0']], bins=np.arange(1., 2.51, .05))



In [224]:
ind = (np.abs(res621['r0'] - 1.65) < .4) & (np.abs(res845['r0'] - 1.6) < 0.4)

In [226]:
ind.sum(), len(res621)


Out[226]:
(42, 47)

In [204]:
out = plt.hist([res621['ampl'][ind], res845['ampl'][ind]], bins=20, range=[0,2000])



In [202]:
plt.scatter(res621['ampl'], res845['ampl'], c=ind)


Out[202]:
<matplotlib.collections.PathCollection at 0xb7d0d5450>

In [203]:
plt.scatter(res621['ampl'] / res845['ampl'], res845['r0'], c=gaiatab['parallax'])
plt.colorbar()


Out[203]:
<matplotlib.colorbar.Colorbar at 0xb2e300310>

In [177]:
psf_621 = sherpa.astro.models.Beta2D()
psf_621.alpha = 2.2
psf_621.r0 = 1.7

psf_845 = sherpa.astro.models.Beta2D()
psf_845.alpha = 2
psf_845.r0 = 1.625

for this_psf in [psf_621, psf_845]:
    # Set starting values
    this_psf.xpos = 12.5
    this_psf.ypos = 12.5
    # Freeze psf values
    this_psf.alpha.frozen = True
    this_psf.r0.frozen = True

In [181]:
data = stars845[5].data
plt.plot(data[12, :])

psf_845.ampl = np.max(data)
x, y = np.indices(data.shape)
dpsf = sherpa.data.Data2D('', x.flatten(), y.flatten(), data.flatten())
fpsf = sherpa.fit.Fit(dpsf, psf_845, stat=sherpa.stats.LeastSq())
fpsf.fit()
plt.plot(psf_845(x.flatten(), y.flatten()).reshape(data.shape)[12, :])


Out[181]:
[<matplotlib.lines.Line2D at 0xb7e0d19d0>]

Select the PSF stars

These stars have the following cuts applied:

  • Look good in GAIA
  • Have typical r0 fit results (for fixed alpha)
  • pick the brightest of those

In [217]:
bright = (res621['ampl'] > 400) & (res845['ampl'] > 400)

In [227]:
(ind & bright).sum()


Out[227]:
23

In [228]:
x, y = np.indices(stars621[0].data.shape)

fig, axes = plt.subplots(nrows=4, ncols=15, figsize=(35,12))

for j, s in enumerate((ind & bright).nonzero()[0][:15]):
    for i, stars in enumerate([stars621, stars845]):
        image = stars[s].data
        imout = axes[2 * i][j].imshow(image)
        #axes[0][j].set_title(prftestlist[j][0])
        plt.colorbar(imout, ax = axes[2 * i][j])
        thispsf = [psf_621, psf_845][i]
        photout = sherpa_phot(thispsf, image)
        imout = axes[2 * i + 1][j].imshow(photout)
        axes[2 * i + 1][j].set_title("residual")
        plt.colorbar(imout, ax = axes[2 * i + 1][j])



In [229]:
len(gaiatab), len(bright)


Out[229]:
(47, 47)

In [234]:
for row in gaiatab[ind & bright]:
    print("['{}', {:3.0f}, {:3.0f}],".format(row['file'], row['x'], row['y']))


['ibg405010_drz.fits', 340,  38],
['ibg416010_drz.fits', 443, 215],
['ibg418010_drz.fits', 112, 945],
['ibg418010_drz.fits', 112, 945],
['ibg422010_drz.fits', 895, 319],
['ibg426010_drz.fits', 385,  93],
['ibg436010_drz.fits', 342, 877],
['ibg438010_drz.fits', 416, 401],
['ibg440010_drz.fits', 211, 337],
['ibg443010_drz.fits', 359, 288],
['ibg444010_drz.fits', 328, 345],
['ibg444010_drz.fits', 725, 723],
['ibg446010_drz.fits', 276, 500],
['ibg453010_drz.fits', 812, 845],
['ibg453010_drz.fits', 333, 188],
['ibg455010_drz.fits', 263, 444],
['ibg456010_drz.fits', 529, 696],
['ibg458010_drz.fits', 161, 806],
['ibg459010_drz.fits', 374, 166],
['ibg465010_drz.fits', 588, 723],
['ibg468010_drz.fits', 150, 508],
['ibg471010_drz.fits', 600, 685],
['ibg471010_drz.fits', 892, 511],

The output of this notebook is this list of good PSF stars in the form of a python list with filename, x, and y of the position. The cleanest form of using this woudl be to write it out to a datatable. Any function that needs PSFs could than load any version of that table that we want. However, the way the code is currently written, this list is simply copied into the source code of detection.py in the snapshotprogram code. It's a little hacky, but it serves the same purpose and I really don't see why I should spend time ot clean this up right now. If I were to do a similar program again, I might use a different approach anyway.


In [ ]: