def query(self, skycoord, radius):     
     
     with warnings.catch_warnings():
         
         #Ignore all warnings, which are many from the conesearch module
         
         warnings.simplefilter('ignore')
         
         try:
             
             votable = conesearch.conesearch(skycoord, radius, 
                                             catalog_db=self.catalog,
                                             verb=3, verbose=True,
                                             cache=False)
         
         except VOSError as exc:
             
             print(exc.message)
             return None
     
     out = self.applyFormat(votable)
     
     #This is needed to avoid strange errors
     del votable
     
     return out
Beispiel #2
0
def getVizierObjects(ra, dec, radius):
    with data.conf.set_temp("remote_timeout", 60):
        try:
            search = conesearch(
                center=(ra, dec),
                radius=0.05,
                verb=3,
                catalog_db="http://vizier.u-strasbg.fr/viz-bin/votable/-A?-source=IPHAS2&-out.all&",
            )
        except:
            print ("Failed to retrieve any results from Vizier.")
    return search.to_table()
def getVizierObjects(ra, dec, radius):
    with data.conf.set_temp('remote_timeout', 60):
        try:
            search = conesearch(
                center=(ra, dec),
                radius=0.05,
                verb=3,
                catalog_db=
                "http://vizier.u-strasbg.fr/viz-bin/votable/-A?-source=IPHAS2&-out.all&"
            )
        except:
            print("Failed to retrieve any results from Vizier.")
    return search.to_table()
Beispiel #4
0
 def _retrievefullregion(self,center,FootPrints):
     """ Returns the full catlog region of size self.search_rad containing center and image FootPrints """
     for region in reversed(self.RetrievedData):
         if np.all(FootPrints.separation(region['center']) < self.search_rad): #All footprints inside region
             return region['table']
     else: # Not available in our cached data
         NewData = {'center':center}
         print('DOWNLOADING region around: {0}'.format(center))
         NewData['table'] = conesearch.conesearch(center,self.search_rad,catalog_db=self.catalog_db).to_table()
         self.RetrievedData.append(NewData)
         if len(self.RetrievedData) > self.MaxCacheLength: # Remove data from the top of list
             self.RetrievedData = self.RetrievedData[-self.MaxCacheLength:]
         return NewData
def getBrightStars(ra, dec, radius):
    print(ra, dec, radius)
    maglimit = 30

    # First look for a cached copy of this data
    filenameParts = args.filename.split('.')
    usnoCache = filenameParts[0] + "_usno_cache.fits"
    usnoCached = False
    if not args.ignorecache:
        print("Looking for a cached copy of the USNO catalogue:", usnoCache)
        if os.path.exists(usnoCache):
            usnoCached = True

    if usnoCached:
        brightStarsTable = Table.read(usnoCache)
    else:
        with data.conf.set_temp('remote_timeout', 60):
            try:
                usno = 'The USNO-A2.0 Catalogue (Monet+ 1998) 1'
                search = conesearch(center=(ra, dec),
                                    radius=radius,
                                    verb=3,
                                    cache=True,
                                    catalog_db=usno)
            except:
                print("Failed to retrieve any results from Vizier.")
                return None
            brightStarsTable = search.to_table()
            print("Found %d bright stars in %f degree radius." %
                  (len(brightStarsTable), radius))
            brightStarsTable.write(usnoCache, format='fits', overwrite=True)

    brightStarsArray = []

    for row in brightStarsTable:
        if row['Rmag'] < maglimit:
            star = {}
            star['ra'] = row['RAJ2000']
            star['dec'] = row['DEJ2000']
            star['Rmag'] = row['Rmag']
            x, y = wcsSolution.all_world2pix([star['ra']], [star['dec']], 1)
            star['x'] = x
            star['y'] = y
            brightStarsArray.append(star)
            if star['Rmag'] > 12:
                star['radius'] = 40 * math.exp((-star['Rmag'] + 12) / 4)
            else:
                star['radius'] = 40
    print("%d are brighter than R=%.1f" % (len(brightStarsArray), maglimit))
    return brightStarsArray
Beispiel #6
0
def getBrightStars(ra, dec, radius):
    print (ra, dec, radius)
    maglimit = 30

    # First look for a cached copy of this data
    filenameParts = args.filename.split(".")
    usnoCache = filenameParts[0] + "_usno_cache.fits"
    usnoCached = False
    if not args.ignorecache:
        print ("Looking for a cached copy of the USNO catalogue:", usnoCache)
        if os.path.exists(usnoCache):
            usnoCached = True

    if usnoCached:
        brightStarsTable = Table.read(usnoCache)
    else:
        with data.conf.set_temp("remote_timeout", 60):
            try:
                usno = "The USNO-A2.0 Catalogue (Monet+ 1998) 1"
                search = conesearch(center=(ra, dec), radius=radius, verb=3, cache=True, catalog_db=usno)
            except:
                print ("Failed to retrieve any results from Vizier.")
                return None
            brightStarsTable = search.to_table()
            print ("Found %d bright stars in %f degree radius." % (len(brightStarsTable), radius))
            brightStarsTable.write(usnoCache, format="fits", overwrite=True)

    brightStarsArray = []

    for row in brightStarsTable:
        if row["Rmag"] < maglimit:
            star = {}
            star["ra"] = row["RAJ2000"]
            star["dec"] = row["DEJ2000"]
            star["Rmag"] = row["Rmag"]
            x, y = wcsSolution.all_world2pix([star["ra"]], [star["dec"]], 1)
            star["x"] = x
            star["y"] = y
            brightStarsArray.append(star)
            if star["Rmag"] > 12:
                star["radius"] = 40 * math.exp((-star["Rmag"] + 12) / 4)
            else:
                star["radius"] = 40
    print ("%d are brighter than R=%.1f" % (len(brightStarsArray), maglimit))
    return brightStarsArray
Beispiel #7
0
        def get_refcat( self ):
                ra      = float(self.hd["CRVAL1"])
                dec     = float(self.hd["CRVAL2"])
                center  = SkyCoord(ra,dec,unit="degree")
                good_db = vos_catalog.get_remote_catalog_db('conesearch_good')
                if self.arm == "opt":
			#opt catalog
			conf.conesearch_dbname = 'conesearch_warn'
			#my_catname = "SDSS DR8 - Sloan Digital Sky Survey Data Release 8 2"
			my_catname = "The USNO-B1.0 Catalog (Monet+ 2003) 1"

                elif self.arm == "ira":
			#ira catalog
                        conf.conesearch_dbname = 'conesearch_warn'
                        my_catname = '2MASS All-Sky Catalog of Point Sources (Cutri+ 2003) 1'
                radius  = 0.13 * u.degree #0.294*2048/3600

                result  = conesearch.conesearch(center=center, radius=radius, catalog_db=my_catname)
                self.refcat     =  result.to_table()
Beispiel #8
0
def query2mass(ra, dec, fov2mass = fov/4*u.arcmin):
    """
    Inputs: RA and dec in degree decimal
    Output:     A table containing neighboring sources and the associated data 
                from the 2MASS PSC including the coordinates and the mags
    Sample usage: 
            result = query2mass(120,30) 
    Key columns: result['ra'], ['dec'], ['j_m'], ['h_m'],['k_m'], ['j_msigcom'], etc. 
    Check for None return
    This should be updated to work on Python 3.5"""
    # tmass_psc = 'Two Micron All Sky Survey (2MASS) 1' #Old Name
    # tmass_psc = '2MASS All-Sky Catalog of Point Sources (Cutri+ 2003)'
    tmass_psc = 'http://vizier.u-strasbg.fr/viz-bin/votable/-A?-out.all&-source=II/246/out&' #The catalog we're using
    c = SkyCoord(ra = ra*u.degree, dec = dec*u.degree) #make a SkyCoord object
    # res = conesearch.conesearch(c, fov*u.arcmin, catalog_db = tmass_psc, verbose = True)
    try: #conesearch doesn't work sometimes. Use this to handle exceptions
        res = conesearch.conesearch(c, fov2mass, catalog_db = tmass_psc, verbose = True)
        return res.array.data
    except VOSError:
        return None
Beispiel #9
0
    def search(self, **params):
        """For compatibility with generic star catalog search.
        """

        self.logger.debug("search params=%s" % (str(params)))
        ra, dec = params['ra'], params['dec']
        if not (':' in ra):
            # Assume RA and DEC are in degrees
            ra_deg = float(ra)
            dec_deg = float(dec)
        else:
            # Assume RA and DEC are in standard string notation
            ra_deg = wcs.hmsStrToDeg(ra)
            dec_deg = wcs.dmsStrToDeg(dec)

        # Convert to degrees for search radius
        radius_deg = float(params['r']) / 60.0
        #radius_deg = float(params['r'])

        # Note requires astropy 3.x+
        c = coordinates.SkyCoord(ra_deg * units.degree,
                                 dec_deg * units.degree,
                                 frame='icrs')
        self.logger.info("Querying catalog: %s" % (self.full_name))
        time_start = time.time()
        results = conesearch.conesearch(c, radius_deg * units.degree,
                                        catalog_db=self.full_name)
        time_elapsed = time.time() - time_start

        numsources = results.array.size
        self.logger.info("Found %d sources in %.2f sec" % (
            numsources, time_elapsed))

        # Scan the returned fields to find ones we need to extract
        # particulars from (ra, dec, id, magnitude)
        mags = []
        ext = {}
        fields = results.array.dtype.names
        for name in fields:
            ucd = results.get_field_by_id(name).ucd
            ucd = str(ucd).lower()
            if ucd == 'id_main':
                ext['id'] = name
            elif ucd == 'pos_eq_ra_main':
                ext['ra'] = name
            elif ucd == 'pos_eq_dec_main':
                ext['dec'] = name
            if ('phot_' in ucd) or ('phot.' in ucd):
                mags.append(name)
        self.logger.debug("possible magnitude fields: %s" % str(mags))
        if len(mags) > 0:
            magfield = mags[0]
        else:
            magfield = None

        # prepare the result list
        starlist = []
        arr = results.array
        for i in range(numsources):
            source = dict(zip(fields, arr[i]))
            starlist.append(self.toStar(source, ext, magfield))

        # metadata about the list
        columns = [('Name', 'name'),
                   ('RA', 'ra'),
                   ('DEC', 'dec'),
                   ('Mag', 'mag'),
                   ('Preference', 'preference'),
                   ('Priority', 'priority'),
                   ('Description', 'description'),
                   ]
        # Append extra columns returned by search to table header
        # TODO: what if not all sources have same record structure?
        # is this possible with VO?
        cols = list(fields)
        cols.remove(ext['ra'])
        cols.remove(ext['dec'])
        cols.remove(ext['id'])
        columns.extend(zip(cols, cols))

        # which column is the likely one to color source circles
        colorCode = 'Mag'

        info = Bunch.Bunch(columns=columns, color=colorCode)
        return starlist, info
Beispiel #10
0
def analyse():
    completed = 0
    textOutput.append("Analysing...")
    textOutput.append(
        "-----------------------------------------------------------------------------"
    )

    for field in header:
        textOutput.append(
            str(field) + ":  \t " + str(header[field]) + "\t //" +
            str(header.comments[field]))
        completed += 0.5
        progress.setValue(completed)
        time.sleep(0.02)

    textOutput.append(
        "-----------------------------------------------------------------------------"
    )
    canvas.plotFitLog()
    completed += 5
    progress.setValue(completed)
    time.sleep(1)

    hist.plotHist(10000)
    completed += 5
    progress.setValue(completed)

    hist.plotHist(159999)
    completed += 5
    progress.setValue(completed)

    textOutput.append(str('Min:') + str(np.min(image_data)))
    textOutput.append(str('Max:') + str(np.max(image_data)))
    textOutput.append(str('Mean:') + str(np.mean(image_data)))
    textOutput.append(str('Stdev:') + str(np.std(image_data)))

    mean, median, std = sigma_clipped_stats(image_data, sigma=3.0, iters=5)
    noiseLevel = mean

    completed = 45
    progress.setValue(completed)

    #canvas.plotApertures()

    mean, median, std = sigma_clipped_stats(image_data, sigma=3.0, iters=5)
    daofind = DAOStarFinder(fwhm=3.0, threshold=5. * std)
    sources = daofind(image_data - median)

    completed = 47
    progress.setValue(completed)

    canvas.addPicture()
    pix_coords = []
    for point in sources:
        pix_coords.append((point['xcentroid'], point['ycentroid']))
    w = WCS(hdu.header)
    world_coords = w.wcs_pix2world(pix_coords, 0)
    sky_coords = coordinates.SkyCoord(world_coords * u.deg, frame='fk4')
    sr = 0.2 * u.degree
    num = 0

    completed = 50
    progress.setValue(completed)
    res = []
    with warnings.catch_warnings():
        warnings.simplefilter('ignore')

    for cord in sky_coords:
        canvas.plotPoint(pix_coords[num][0], pix_coords[num][1], 'red')
        if (completed < 99):
            completed += 1
            progress.setValue(completed)
            time.sleep(0.3)
            completed += 1
            progress.setValue(completed)
        textOutput.append(
            "-----------------------------------------------------------------------------"
        )
        textOutput.append('Found star #' + str(num + 1))
        textOutput.append('Constelation name: ' + cord.get_constellation())
        textOutput.append(str(cord))
        result = conesearch.conesearch(
            cord,
            sr,
            catalog_db=
            'The HST Guide Star Catalog, Version 1.2 (Lasker+ 1996) 1')
        res.append(result)
        textOutput.append('Number of stars from Catalogue: ' +
                          str(len(result.array.data)))
        textOutput.append(str(result.array.dtype.names))
        textOutput.append(
            str(result.array.data[result.array.data['Pmag'].argmax()]))
        textOutput.append("My mag: " + str(sources[num]['mag']) +
                          " Catalog mag: " +
                          str(result.array.data['Pmag'].max()))
        canvas.plotPoint(pix_coords[num][0], pix_coords[num][1], 'lightgreen')
        num = num + 1

    num = 0
    for cord in sky_coords:
        x = int(pix_coords[num][1])
        y = int(pix_coords[num][0])
        peak = image_data[x][y]
        if (getMyMagnitude(image_data, x, y, peak) == 71437):
            mags.append((getMyMagnitude(image_data, x, y, peak),
                         0.5 + res[num].array.data['Pmag'].max()))
        elif (getMyMagnitude(image_data, x, y, peak) == 10200):
            mags.append(
                (getMyMagnitude(image_data, x, y,
                                peak), -1 + res[num].array.data['Pmag'].max()))
        else:
            mags.append(
                (getMyMagnitude(image_data, x, y,
                                peak), res[num].array.data['Pmag'].max()))
        print("Peak: " + str(peak) + " " + str(x) + " " + str(y) +
              " My mag: " + str(getMyMagnitude(image_data, x, y, peak)) +
              " Catalog mag: " + str(res[num].array.data['Pmag'].max()))
        num = num + 1
    magsorted = sorted(mags, key=lambda x: x[0])
    plt.plot([x[0] for x in magsorted], [x[1] for x in magsorted])
    plt.show()
    completed = 100
    progress.setValue(completed)
Beispiel #11
0
def myconesearch(ra, dec, sr, catname="SDSS DR8 - Sloan Digital Sky Survey Data Release 8 2"):
    try:
        response = conesearch.conesearch(ra, dec, sr, catalog_db=catname)
    except VOSError:
        return None
    return response.array    
Beispiel #12
0
        if os.path.exists(dr2Filename):
            cached = True

    if not cached:
        for index, yCentre in enumerate(
                numpy.arange(height / 4, height, height / 4)):
            print(yCentre)
            imageCentre = [width / 2, yCentre]
            ra, dec = wcsSolution.all_pix2world([imageCentre], 1)[0]
            print(index, imageCentre, ra, dec)
            with data.conf.set_temp('remote_timeout', 60):
                try:
                    search = conesearch(
                        center=(ra, dec),
                        radius=0.1,
                        verb=3,
                        catalog_db=
                        "http://vizier.u-strasbg.fr/viz-bin/votable/-A?-source=IPHAS2&-out.all&"
                    )
                except:
                    print("Failed to retrieve any results from Vizier.")
            dr2nearbyTemp = search.to_table()
            if index == 0:
                dr2nearby = dr2nearbyTemp
            else:
                print("Table was %d rows. Additional data is %d rows." %
                      (len(dr2nearby), len(dr2nearbyTemp)))
                dr2nearbyWhole = vstack([dr2nearby, dr2nearbyTemp])
                dr2nearby = dr2nearbyWhole
                print("New table is %d rows." % len(dr2nearby))
            print(dr2nearby)
Beispiel #13
0
        t[columns_print].pprint(max_lines=-1, max_width=-1)

#########
# (N)avigate the image -- plot rings and everything on it
#########

    if (inp == 'N'): # Navigate the image -- plot rings and everything on it
        
# Now look up positions of stars in this field, from a star catalog

        w = WCS(t['Filename'][i])                  # Look up the WCS coordinates for this frame

        center  = w.wcs.crval  # degrees
        name_cat = 'The HST Guide Star Catalog, Version 1.1 (Lasker+ 1992) 1'
        print 'got 1'
        stars = conesearch.conesearch(w.wcs.crval, 0.3, cache=False, catalog_db = name_cat)
        print 'got 2'
        ra_stars  = np.array(stars.array['RAJ2000'])*d2r # Convert to radians
        print 'got 3'
        dec_stars = np.array(stars.array['DEJ2000'])*d2r # Convert to radians
        table_stars = Table(stars.array.data)

# Get an array of points along the ring

        ra_ring, dec_ring = get_jring_points_radec(et)                    # Return as radians              
        x_ring, y_ring    = w.wcs_world2pix(ra_ring*r2d, dec_ring*r2d, 0) # Convert to pixels
        
# Look up velocity of NH, for stellar aberration
        
        et = t['ET'][i]
        abcorr = 'LT+S'
Beispiel #14
0
    def search(self, **params):
        """For compatibility with generic star catalog search.
        """

        self.logger.debug("search params=%s" % (str(params)))
        ra, dec = params['ra'], params['dec']
        if not (':' in ra):
            # Assume RA and DEC are in degrees
            ra_deg = float(ra)
            dec_deg = float(dec)
        else:
            # Assume RA and DEC are in standard string notation
            ra_deg = wcs.hmsStrToDeg(ra)
            dec_deg = wcs.dmsStrToDeg(dec)

        # Convert to degrees for search radius
        radius_deg = float(params['r']) / 60.0
        #radius_deg = float(params['r'])

        c = coordinates.ICRSCoordinates(ra_deg,
                                        dec_deg,
                                        unit=(units.degree, units.degree))
        self.logger.info("Querying catalog: %s" % (self.full_name))
        time_start = time.time()
        results = conesearch.conesearch(c,
                                        radius_deg * units.degree,
                                        catalog_db=self.full_name)
        time_elapsed = time.time() - time_start

        numsources = results.array.size
        self.logger.info("Found %d sources in %.2f sec" %
                         (numsources, time_elapsed))

        # Scan the returned fields to find ones we need to extract
        # particulars from (ra, dec, id, magnitude)
        mags = []
        ext = {}
        fields = results.array.dtype.names
        for name in fields:
            ucd = results.get_field_by_id(name).ucd
            ucd = str(ucd).lower()
            if ucd == 'id_main':
                ext['id'] = name
            elif ucd == 'pos_eq_ra_main':
                ext['ra'] = name
            elif ucd == 'pos_eq_dec_main':
                ext['dec'] = name
            if ('phot_' in ucd) or ('phot.' in ucd):
                mags.append(name)
        self.logger.debug("possible magnitude fields: %s" % str(mags))
        if len(mags) > 0:
            magfield = mags[0]
        else:
            magfield = None

        # prepare the result list
        starlist = []
        arr = results.array
        for i in range(numsources):
            source = dict(zip(fields, arr[i]))
            starlist.append(self.toStar(source, ext, magfield))

        # metadata about the list
        columns = [
            ('Name', 'name'),
            ('RA', 'ra'),
            ('DEC', 'dec'),
            ('Mag', 'mag'),
            ('Preference', 'preference'),
            ('Priority', 'priority'),
            ('Description', 'description'),
        ]
        # Append extra columns returned by search to table header
        # TODO: what if not all sources have same record structure?
        # is this possible with VO?
        cols = list(fields)
        cols.remove(ext['ra'])
        cols.remove(ext['dec'])
        cols.remove(ext['id'])
        columns.extend(zip(cols, cols))

        # which column is the likely one to color source circles
        colorCode = 'Mag'

        info = Bunch.Bunch(columns=columns, color=colorCode)
        return starlist, info
Beispiel #15
0
    if not args.ignorecache:
        print ("Looking for a cached copy of the DR2 catalogue:", dr2Filename)
        if os.path.exists(dr2Filename):
            cached = True

    if not cached:
        for index, yCentre in enumerate(numpy.arange(height / 4, height, height / 4)):
            print (yCentre)
            imageCentre = [width / 2, yCentre]
            ra, dec = wcsSolution.all_pix2world([imageCentre], 1)[0]
            print (index, imageCentre, ra, dec)
            with data.conf.set_temp("remote_timeout", 60):
                try:
                    search = conesearch(
                        center=(ra, dec),
                        radius=0.1,
                        verb=3,
                        catalog_db="http://vizier.u-strasbg.fr/viz-bin/votable/-A?-source=IPHAS2&-out.all&",
                    )
                except:
                    print ("Failed to retrieve any results from Vizier.")
            dr2nearbyTemp = search.to_table()
            if index == 0:
                dr2nearby = dr2nearbyTemp
            else:
                print ("Table was %d rows. Additional data is %d rows." % (len(dr2nearby), len(dr2nearbyTemp)))
                dr2nearbyWhole = vstack([dr2nearby, dr2nearbyTemp])
                dr2nearby = dr2nearbyWhole
                print ("New table is %d rows." % len(dr2nearby))
            print (dr2nearby)

        radius = 0.05
Beispiel #16
0
def myconesearch(ra, dec, sr, catname="SDSS DR8 - Sloan Digital Sky Survey Data Release 8 2"):
    response = conesearch.conesearch(4*15, +50, 0.01, catalog_db=catname)
    return response.array