Exemple #1
0
 def toStar(self, sourcerec, magfield):
     data = {}
     data.update(dict(sourcerec.items()))
     try:
         mag = float(sourcerec[magfield])
     except:
         mag = 0.0
         
     # Make sure we have at least these Ginga standard fields defined
     d = { 'name':         sourcerec.id,
           'ra_deg':       float(sourcerec.ra),
           'dec_deg':      float(sourcerec.dec),
           'mag':          mag,
           'preference':   0.0,
           'priority':     0,
           'description':  'fake magnitude' }
     data.update(d)
     data['ra'] = wcs.raDegToString(data['ra_deg'])
     data['dec'] = wcs.decDegToString(data['dec_deg'])
     return Catalog.Star(**data)
Exemple #2
0
    def search(self, **params):
        self.logger.debug("search params=%s" % (str(params)))
        url = self.base_url % params

        data = self.fetch(url, filepath=None)
        data = data.decode("utf8")

        lines = data.split('\n')
        offset = 0
        while offset < len(lines):
            line = lines[offset].strip()
            print line
            offset += 1
            if line.startswith('-'):
                break
        self.logger.debug("offset=%d" % (offset))

        results = []
        table = [lines[offset-2]]
        
        for line in lines[offset:]:
            line = line.strip()
            #print ">>>", line
            if (len(line) == 0) or line.startswith('#'):
                continue
            elts = line.split()
            if (len(elts) < 3):
                continue
            table.append(line)

            try:
                name = elts[self.index['name']]
                ra = elts[self.index['ra']]
                dec = elts[self.index['dec']]
                mag = float(elts[self.index['mag']])
                #print name

                if (self.format == 'deg') or 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 ra/dec via EQUINOX change if catalog EQUINOX is
                # not the same as our default one (2000)
                if cmp(self.equinox, 2000.0) != 0:
                    ra_deg, dec_deg = wcs.eqToEq2000(ra_deg, dec_deg,
                                                     self.equinox)
                
                ra_txt = wcs.raDegToString(ra_deg, format='%02d:%02d:%06.3f')
                dec_txt = wcs.decDegToString(dec_deg,
                                               format='%s%02d:%02d:%05.2f')
                self.logger.debug("STAR %s AT ra=%s dec=%s mag=%f" % (
                    name, ra_txt, dec_txt, mag))

                results.append(Star(name=name, ra_deg=ra_deg, dec_deg=dec_deg,
                                    ra=ra_txt, dec=dec_txt, mag=mag,
                                    flag=0, description=''))

            except Exception, e:
                print str(e)
                self.logger.error("Error parsing catalog query results: %s" % (
                    str(e)))
Exemple #3
0
    def search(self, **params):
        self.logger.debug("search params=%s" % (str(params)))
        url = self.base_url % params

        data = self.fetch(url, filepath=None)

        lines = data.split('\n')
        offset = 0
        while offset < len(lines):
            line = lines[offset].strip()
            print line
            offset += 1
            if line.startswith('-'):
                break
        print "offset=%d" % (offset)

        print "iterating data"
        results = []
        table = [lines[offset - 2]]

        for line in lines[offset:]:
            line = line.strip()
            #print ">>>", line
            if (len(line) == 0) or line.startswith('#'):
                continue
            elts = line.split()
            if (len(elts) < 3):
                continue
            table.append(line)

            try:
                name = elts[self.index['name']]
                ra = elts[self.index['ra']]
                dec = elts[self.index['dec']]
                mag = float(elts[self.index['mag']])
                #print name

                if (self.format == 'deg') or 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 ra/dec via EQUINOX change if catalog EQUINOX is
                # not the same as our default one (2000)
                if cmp(self.equinox, 2000.0) != 0:
                    ra_deg, dec_deg = wcs.eqToEq2000(ra_deg, dec_deg,
                                                     self.equinox)

                ra_txt = wcs.raDegToString(ra_deg, format='%02d:%02d:%06.3f')
                dec_txt = wcs.decDegToString(dec_deg,
                                             format='%s%02d:%02d:%05.2f')
                print "STAR %s AT ra=%s dec=%s mag=%f" % (name, ra_txt,
                                                          dec_txt, mag)

                results.append(
                    Star(name=name,
                         ra_deg=ra_deg,
                         dec_deg=dec_deg,
                         ra=ra_txt,
                         dec=dec_txt,
                         mag=mag,
                         flag=0,
                         description=''))

            except Exception, e:
                print str(e)
                self.logger.error("Error parsing catalog query results: %s" %
                                  (str(e)))