Ejemplo n.º 1
0
def nearest_source(band, skypos, radius=0.01, maglimit=20.0, verbose=0, catalog="MCAT", retries=20):
    """Return targeting parameters for the nearest MCAT source to a position.
    """
    out = np.array(
        gQuery.getArray(
            gQuery.mcat_sources(band, skypos[0], skypos[1], radius, maglimit=maglimit), verbose=verbose, retries=retries
        )
    )
    if not len(out) and band == "FUV":
        if verbose:
            print "No nearby MCAT source found in FUV. Trying NUV..."
        band = "NUV"
        out = np.array(
            gQuery.getArray(
                gQuery.mcat_sources(band, skypos[0], skypos[1], radius, maglimit=maglimit),
                verbose=verbose,
                retries=retries,
            )
        )
    if not len(out) and band == "NUV":
        if verbose:
            print "No nearby MCAT source found. Using input sky position."
        return skypos[0], skypos[1], 0.01

    # dist=np.sqrt( (out[:,0]-skypos[0])**2 + (out[:,1]-skypos[1])**2)
    dist = angularSeparation(out[:, 0], out[:, 1], skypos[0], skypos[1])
    if verbose > 1:
        print "Finding nearest among " + str(len(dist)) + " nearby sources."
    # Note that this doesn't cope with multiple entries for the same source.
    s = out[np.where(dist == dist.min())][0]
    # RA, Dec, NUV mag, FUV mag, NUV fwhm, FUV fwhm
    return avg_sources(band, [s[0], s[1]], verbose=verbose, retries=retries)
Ejemplo n.º 2
0
def nearest_distinct_source(band,skypos,radius=0.1,maglimit=20.0,verbose=0,
                                                    catalog='MCAT',retries=20):
    """Return parameters for the nearest non-targeted source."""
    out = np.array(gQuery.getArray(gQuery.mcat_sources(band,skypos[0],skypos[1],radius,maglimit=maglimit),verbose=verbose,retries=retries))
    #dist=np.sqrt( (out[:,0]-skypos[0])**2 + (out[:,1]-skypos[1])**2)
    dist = angularSeparation(out[:,0],out[:,1],skypos[0],skypos[1])
    ix = np.where(dist>0.005)
    return np.array(out)[ix][np.where(dist[ix]==dist[ix].min())][0]
Ejemplo n.º 3
0
def avg_sources(band,skypos,radius=0.001,maglimit=20.0,verbose=0,
                                                    catalog='MCAT',retries=20):
	"""Return the mean position of sources within the search radius."""
	out = np.array(gQuery.getArray(gQuery.mcat_sources(band,skypos[0],
        skypos[1],radius,maglimit=maglimit),verbose=verbose,retries=retries))
	ix = np.where(out[:,-2]>0) if band=='NUV' else np.where(out[:,-1]>0)
	fwhm = out[ix,-2].mean() if band=='NUV' else out[ix,-1].mean()
	return out[ix,0].mean(),out[ix,1].mean(),round(fwhm,4)
Ejemplo n.º 4
0
def bg_sources(band,ra0,dec0,radius,maskdepth=20.0,maskradius=1.5,margin=0.001):
    sources = gQuery.getArray(gQuery.mcat_sources(band,ra0,dec0,radius+margin,
                                                      maglimit=maskdepth))
    try:
        return {'ra':np.float32(np.array(sources)[:,0]),
                'dec':np.float32(np.array(sources)[:,1]),
                'fwhm':np.float32(np.array(sources)[:,7:9]),
                'maskdepth':maskdepth,'maskradius':maskradius,
                'radius':radius}
    except IndexError:
        return {'ra':np.array([]),'dec':np.array([]),
                'fwhm':np.array([]),'maglimit':maskdepth,'radius':radius}
Ejemplo n.º 5
0
def mcat_skybg(band, skypos, radius, verbose=0, retries=20):
    """Estimate the sky background using the MCAT skybg for nearby sources."""
    # Setting maglimit to 30 so that it gets _everything_...
    sources = gQuery.getArray(gQuery.mcat_sources(band, skypos[0], skypos[1], radius, maglimit=30), retries=retries)

    # The MCAT reports skybg in photons/sec/sq.arcsec
    if band == "NUV":
        skybg = np.float32(np.array(sources)[:, 5]).mean()
    else:
        skybg = np.float32(np.array(sources)[:, 6]).mean()

        # And radius is in degrees
    return skybg * area(radius * 60.0 * 60.0)
Ejemplo n.º 6
0
def get_mags(band,ra0,dec0,radius,maglimit,mode='coadd',
                   zpmag={'NUV':20.08,'FUV':18.82},verbose=0):
    """Given RA, Dec and search radius, searches the coadd MCAT for sources.
    Returns a dict() which contains magnitudes for all of the APER settings.
    Note: Visit mode returns a lot more sources, more slowly than coadd mode
    given the same search parameters. You should probably use smaller search
    radii in visit mode. If you're just trying to find unique sources in a
    large region, use coadd mode and then pass the result through the
    parse_unique_sources() function contained in this module.
    """
    zpf,zpn = zpmag['FUV'],zpmag['NUV']
    if mode=='coadd':
        out =np.array(gQuery.getArray(
                  gQuery.mcat_sources(band,ra0,dec0,radius,maglimit=maglimit),
                  verbose=verbose))
        if not len(out):
            print "Warning: No sources found!"
            return 0
        return {'ra':out[:,0],'dec':out[:,1],
                'FUV':{'mag':out[:,3],1:out[:,9]+zpf,2:out[:,10]+zpf,
                       3:out[:,11]+zpf,4:out[:,12]+zpf,5:out[:,13]+zpf,
                       6:out[:,14],7:out[:,15]+zpf},
                'NUV':{'mag':out[:,2],1:out[:,16]+zpn,2:out[:,17]+zpn,
                       3:out[:,18]+zpn,4:out[:,19]+zpn,5:out[:,20]+zpn,
                       6:out[:,21]+zpn,7:out[:,22]+zpn}}
    elif mode=='visit':
        out = np.array(gQuery.getArray(
                       gQuery.mcat_visit_sources(ra0,dec0,radius),
                       verbose=verbose))
        # NOTE: For runtime considerations, mcat_visit_sources() does not
        # make any slices on time or maglimit, so we need to do it here.
        ix = np.where((out[:,2 if band=='NUV' else 3]<maglimit) &
                                           (out[:,2 if band=='NUV' else 3]>0))
        return {'ra':out[:,0][ix],'dec':out[:,1][ix],
                'NUV':{'mag':out[:,2][ix],'expt':out[:,8][ix],
                1:out[:,18][ix]+zpn,2:out[:,19][ix]+zpn,3:out[:,20][ix]+zpn,
                4:out[:,21][ix]+zpn,5:out[:,22][ix]+zpn,6:out[:,23][ix]+zpn,
                7:out[:,24][ix]+zpn},
                'FUV':{'mag':out[:,3][ix],'expt':out[:,9][ix],
                1:out[:,11][ix]+zpf,2:out[:,12][ix]+zpf,3:out[:,13][ix]+zpf,
                4:out[:,14][ix]+zpf,5:out[:,15][ix]+zpf,6:out[:,16][ix]+zpf,
                7:out[:,17][ix]+zpf}}
    else:
        print "mode must be in [coadd,visit]"
        return
Ejemplo n.º 7
0
 def test_mcat_sources(self):
     band = self.NUV
     bandflag = 1 if band=='NUV' else 2
     query = (str(self.baseURL)+
         'select ra, dec, nuv_mag, fuv_mag, fov_radius, nuv_skybg, fuv_skybg,'
         ' nuv_fwhm_world, fuv_fwhm_world, fuv_mag_aper_1, fuv_mag_aper_2,'
         ' fuv_mag_aper_3, fuv_mag_aper_4, fuv_mag_aper_5, fuv_mag_aper_6,'
         ' fuv_mag_aper_7, nuv_mag_aper_1, nuv_mag_aper_2, nuv_mag_aper_3,'
         ' nuv_mag_aper_4, nuv_mag_aper_5, nuv_mag_aper_6, nuv_mag_aper_7'
         ' fuv_magerr_aper_1, fuv_magerr_aper_2, fuv_magerr_aper_3,'
         ' fuv_magerr_aper_4, fuv_magerr_aper_5, fuv_magerr_aper_6,'
         ' fuv_magerr_aper_7, nuv_magerr_aper_1, nuv_magerr_aper_2,'
         ' nuv_magerr_aper_3, nuv_magerr_aper_4, nuv_magerr_aper_5,'
         ' nuv_magerr_aper_6, nuv_magerr_aper_7'
         ' from '+str(self.MCATDB)+'.photoobjall as p inner join '+str(self.MCATDB)+
         '.photoextract as pe on p.photoextractid=pe.photoextractid inner join '+
         str(self.MCATDB)+'.fgetnearbyobjeq('+repr(float(self.ra0))+', '+
         repr(float(self.dec0))+', '+
         str(self.radius*60.)+') as nb on p.objid=nb.objid and (band=3 or band='+
         str(bandflag)+') and '+str(band)+'_mag<'+str(self.maglimit)+
         str(self.formatURL))
     self.assertEqual(gq.mcat_sources(self.NUV,self.ra0,self.dec0,self.radius,maglimit=self.maglimit),query)
Ejemplo n.º 8
0
 def test_mcat_sources(self):
     self.assertEqual(gq.mcat_sources(self.NUV,self.ra0,self.dec0,self.radius,maglimit=self.maglimit),'http://masttest.stsci.edu/portal/Mashup/MashupQuery.asmx/GalexPhotonListQueryTest?query=select ra, dec, nuv_mag, fuv_mag, fov_radius, nuv_skybg, fuv_skybg, nuv_fwhm_world, fuv_fwhm_world, fuv_mag_aper_1, fuv_mag_aper_2, fuv_mag_aper_3, fuv_mag_aper_4, fuv_mag_aper_5, fuv_mag_aper_6, fuv_mag_aper_7, nuv_mag_aper_1, nuv_mag_aper_2, nuv_mag_aper_3, nuv_mag_aper_4, nuv_mag_aper_5, nuv_mag_aper_6, nuv_mag_aper_7 fuv_magerr_aper_1, fuv_magerr_aper_2, fuv_magerr_aper_3, fuv_magerr_aper_4, fuv_magerr_aper_5, fuv_magerr_aper_6, fuv_magerr_aper_7, nuv_magerr_aper_1, nuv_magerr_aper_2, nuv_magerr_aper_3, nuv_magerr_aper_4, nuv_magerr_aper_5, nuv_magerr_aper_6, nuv_magerr_aper_7 from Gr6plus7.dbo.photoobjall as p inner join Gr6plus7.dbo.photoextract as pe on p.photoextractid=pe.photoextractid inner join Gr6plus7.dbo.fgetnearbyobjeq(176.919525856, 0.255696872807, 0.24) as nb on p.objid=nb.objid and (band=3 or band=1) and NUV_mag<30.0&format=json&timeout={}')