def read_gaia(targetwcs): ''' *targetwcs* here should include margin ''' from legacypipe.gaiacat import GaiaCatalog gaia = GaiaCatalog().get_catalog_in_wcs(targetwcs) debug('Got', len(gaia), 'Gaia stars nearby') # DJS, [decam-chatter 5486] Solved! GAIA separation of point sources # from extended sources # Updated for Gaia DR2 by Eisenstein, # [decam-data 2770] Re: [desi-milkyway 639] GAIA in DECaLS DR7 # But shifted one mag to the right in G. gaia.G = gaia.phot_g_mean_mag gaia.pointsource = np.logical_or( (gaia.G <= 19.) * (gaia.astrometric_excess_noise < 10.**0.5), (gaia.G >= 19.) * (gaia.astrometric_excess_noise < 10.**(0.5 + 0.2 * (gaia.G - 19.)))) # in our catalog files, this is in float32; in the Gaia data model it's # a byte, with only values 3 and 31 in DR2. gaia.astrometric_params_solved = gaia.astrometric_params_solved.astype( np.uint8) # Gaia version? gaiaver = int(os.getenv('GAIA_CAT_VER', '1')) #print('Assuming Gaia catalog Data Release', gaiaver) gaia_release = 'G%i' % gaiaver gaia.ref_cat = np.array([gaia_release] * len(gaia)) gaia.ref_id = gaia.source_id gaia.pmra_ivar = 1. / gaia.pmra_error**2 gaia.pmdec_ivar = 1. / gaia.pmdec_error**2 gaia.parallax_ivar = 1. / gaia.parallax_error**2 # mas -> deg gaia.ra_ivar = 1. / (gaia.ra_error / 1000. / 3600.)**2 gaia.dec_ivar = 1. / (gaia.dec_error / 1000. / 3600.)**2 for c in [ 'ra_error', 'dec_error', 'parallax_error', 'pmra_error', 'pmdec_error' ]: gaia.delete_column(c) for c in [ 'pmra', 'pmdec', 'parallax', 'pmra_ivar', 'pmdec_ivar', 'parallax_ivar' ]: X = gaia.get(c) X[np.logical_not(np.isfinite(X))] = 0. # radius to consider affected by this star -- # FIXME -- want something more sophisticated here! # (also see tycho.radius below) # This is in degrees and the magic 0.262 (indeed the whole # relation) is from eyeballing a radius-vs-mag plot that was in # pixels; that is unrelated to the present targetwcs pixel scale. gaia.radius = np.minimum(1800., 150. * 2.5**( (11. - gaia.G) / 3.)) * 0.262 / 3600. gaia.delete_column('G') return gaia
def read_gaia(wcs, bands): ''' *wcs* here should include margin ''' from legacypipe.gaiacat import GaiaCatalog from legacypipe.survey import GaiaSource gaia = GaiaCatalog().get_catalog_in_wcs(wcs) debug('Got', len(gaia), 'Gaia stars nearby') gaia.G = gaia.phot_g_mean_mag # Sort by brightness (for reference-*.fits output table) gaia.cut(np.argsort(gaia.G)) # Gaia to DECam color transformations for stars color = gaia.phot_bp_mean_mag - gaia.phot_rp_mean_mag # From Rongpu, 2020-04-12 # no BP-RP color: use average color color[np.logical_not(np.isfinite(color))] = 1.4 # clip to reasonable range for the polynomial fit color = np.clip(color, -0.6, 4.1) for b, coeffs in [ ('g', [ -0.1178631039, 0.3650113495, 0.5608615360, -0.2850687702, -1.0243473939, 1.4378375491, 0.0679401731, -1.1713172509, 0.9107811975, -0.3374324004, 0.0683946390, -0.0073089582, 0.0003230170 ]), ('r', [ 0.1139078673, -0.2868955307, 0.0013196434, 0.1029151074, 0.1196710702, -0.3729031390, 0.1859874242, 0.1370162451, -0.1808580848, 0.0803219195, -0.0180218196, 0.0020584707, -0.0000953486 ]), ('z', [ 0.4811198057, -0.9990015041, 0.1403990019, 0.2150988888, -0.2917655866, 0.1326831887, -0.0259205004, 0.0018548776 ]) ]: mag = gaia.G.copy() for order, c in enumerate(coeffs): mag += c * color**order gaia.set('decam_mag_%s' % b, mag) del color # For possible future use: # BASS/MzLS: # coeffs = dict( # g = [-0.1299895823, 0.3120393968, 0.5989482686, 0.3125882487, # -1.9401592247, 1.1011670449, 2.0741304659, -3.3930306403, # 2.1857291197, -0.7674676232, 0.1542300648, -0.0167007725, # 0.0007573720], # r = [0.0901464643, -0.2463711147, 0.0094963025, -0.1187138789, # 0.4131107392, -0.1832183301, -0.6015486252, 0.9802538471, # -0.6613809948, 0.2426395251, -0.0505867727, 0.0056462458, # -0.0002625789], # z = [0.4862049092, -1.0278704657, 0.1220984456, 0.3000129189, # -0.3770662617, 0.1696090596, -0.0331679127, 0.0023867628]) # force this source to remain a point source? # Long history here, starting DJS, [decam-chatter 5486] Solved! GAIA separation # of point sources from extended sources # Updated for Gaia DR2 by Eisenstein, # [decam-data 2770] Re: [desi-milkyway 639] GAIA in DECaLS DR7 # And made far more restrictive following BGS feedback. gaia.pointsource = np.logical_or( (gaia.G <= 18.) * (gaia.astrometric_excess_noise < 10.**0.5), (gaia.G <= 13.)) # in our catalog files, this is in float32; in the Gaia data model it's # a byte, with only values 3 and 31 in DR2. gaia.astrometric_params_solved = gaia.astrometric_params_solved.astype( np.uint8) # Gaia version? gaiaver = int(os.getenv('GAIA_CAT_VER', '1')) gaia_release = 'G%i' % gaiaver gaia.ref_cat = np.array([gaia_release] * len(gaia)) gaia.ref_id = gaia.source_id gaia.pmra_ivar = 1. / gaia.pmra_error**2 gaia.pmdec_ivar = 1. / gaia.pmdec_error**2 gaia.parallax_ivar = 1. / gaia.parallax_error**2 # mas -> deg gaia.ra_ivar = 1. / (gaia.ra_error / 1000. / 3600.)**2 gaia.dec_ivar = 1. / (gaia.dec_error / 1000. / 3600.)**2 for c in [ 'ra_error', 'dec_error', 'parallax_error', 'pmra_error', 'pmdec_error' ]: gaia.delete_column(c) for c in [ 'pmra', 'pmdec', 'parallax', 'pmra_ivar', 'pmdec_ivar', 'parallax_ivar' ]: X = gaia.get(c) X[np.logical_not(np.isfinite(X))] = 0. # uniform name w/ Tycho-2 gaia.zguess = gaia.decam_mag_z gaia.mag = gaia.G # Take the brighter of G, z to expand masks around red stars. gaia.mask_mag = np.minimum(gaia.G, gaia.zguess + 1.) # radius to consider affected by this star, for MASKBITS gaia.radius = mask_radius_for_mag(gaia.mask_mag) # radius for keeping this source in the ref catalog # (eg, for halo subtraction) gaia.keep_radius = 4. * gaia.radius gaia.delete_column('G') gaia.isgaia = np.ones(len(gaia), bool) gaia.istycho = np.zeros(len(gaia), bool) gaia.isbright = (gaia.mask_mag < 13.) gaia.ismedium = (gaia.mask_mag < 16.) gaia.donotfit = np.zeros(len(gaia), bool) # NOTE, must initialize gaia.sources array this way, or else numpy # will try to be clever and create a 2-d array, because GaiaSource is # iterable. gaia.sources = np.empty(len(gaia), object) if bands is not None: for i, g in enumerate(gaia): gaia.sources[i] = GaiaSource.from_catalog(g, bands) return gaia