Пример #1
0
def _xmatch(session, edge):
    """Join photometric measurements of two overlapping catalogs in the
    given bandpass.
    """
    from_cstar = aliased(CatalogStar)
    to_cstar = aliased(CatalogStar)
    from_cat = aliased(Catalog)
    to_cat = aliased(Catalog)
    from_obs = aliased(Observation)
    to_obs = aliased(Observation)
    from_bp = aliased(Bandpass)
    to_bp = aliased(Bandpass)

    overlap_polygon = _make_q3c_polygon(_get_overlap_polygon(session, edge))
    q = (
        session.query(from_obs.mag, from_obs.mag_err, to_obs.mag, to_obs.mag_err)
        .join(to_cstar, to_cat.catalog_stars)
        .join(from_cstar, from_cat.catalog_stars)
        .filter(to_cat.id == edge.to_id)
        .filter(from_cat.id == edge.from_id)
        .filter(func.q3c_poly_query(to_cstar.ra, to_cstar.dec, overlap_polygon))
        .filter(func.q3c_join(to_cstar.ra, to_cstar.dec, from_cstar.ra, from_cstar.dec, 1.0 / 3600.0))
        .join(from_obs, from_cstar.observations)
        .join(to_obs, to_cstar.observations)
        .join(from_bp, from_obs.bandpass)
        .filter(from_bp.id == edge.bandpass_id)
        .join(to_bp, to_obs.bandpass)
        .filter(to_bp.id == edge.bandpass_id)
    )
    dt = np.dtype([("from_mag", float), ("from_mag_err", float), ("to_mag", float), ("to_mag_err", float)])
    data = np.array(q.all(), np.dtype(dt))
    return data
Пример #2
0
 def sources_contained(self):
     """Query the database and return all `Sources` contained by the
     polygon of this object"""
     from .source import Source
     return DBSession().query(Source) \
         .filter(func.q3c_poly_query(Source.ra,
                                     Source.dec,
                                     self.poly))
Пример #3
0
    def images(self, type=CalibratableImage):

        candidates = DBSession().query(type).filter(
            func.q3c_radial_query(
                type.ra, type.dec, self.ra, self.dec,
                0.64)).filter(func.q3c_poly_query(self.ra, self.dec,
                                                  type.poly))

        return candidates.all()
Пример #4
0
def load_photometry(fieldname, tile, radec_poly,
                    use_vega, disable_intercal,
                    server='marvin'):
    """Load WIRCam photometry from Starplex, converted to AB mag."""
    instrument = "wircam"

    connect_to_server(server)
    session = Session()

    mag1obs = aliased(Observation)
    mag2obs = aliased(Observation)
    bp1 = aliased(Bandpass)
    bp2 = aliased(Bandpass)

    catalog = session.query(Catalog).\
        filter(Catalog.name == fieldname).\
        filter(Catalog.instrument == instrument).\
        one()
    q = session.query(CatalogStar.cfrac, mag1obs.mag, mag2obs.mag_err,
                      mag2obs.mag, mag2obs.mag_err).\
        join(mag1obs, CatalogStar.observations).\
        join(mag2obs, CatalogStar.observations).\
        join(Catalog).\
        filter(Catalog.name == fieldname).\
        filter(Catalog.instrument == instrument).\
        join(bp1, mag1obs.bandpass).\
        filter(bp1.name == "J").\
        join(bp2, mag2obs.bandpass).\
        filter(bp2.name == "Ks").\
        filter(func.q3c_poly_query(CatalogStar.ra,
                                   CatalogStar.dec,
                                   np.array(radec_poly).flatten().tolist()))
    dt = [('cfrac', np.float), ('J', np.float), ('J_err', np.float),
            ('Ks', np.float), ('Ks_err', np.float)]
    data = np.array(q.all(), dtype=np.dtype(dt))

    # Apply the intercal ZP correction
    if not disable_intercal:
        if 'intercal' in catalog.meta:
            for band in ['J', 'Ks']:
                if band in catalog.meta['intercal']:
                    data[band] += catalog.meta['intercal'][band]['zp']

    # Convert to AB
    if not use_vega:
        data['J'] = wircam_vega_to_ab(data['J'], "J")
        data['Ks'] = wircam_vega_to_ab(data['Ks'], "Ks")

    log.info("Field {0} {2} {3:d} has {1:d} stars".
        format(fieldname, data.shape[0], instrument, tile))
    session.close()
    if len(data) == 0:
        raise NoDataError
    return data
Пример #5
0
    def unphotometered_images(self):
        subq = DBSession().query(
            ForcedPhotometry.id, ForcedPhotometry.image_id).filter(
                ForcedPhotometry.source_id == self.id).subquery()

        q = DBSession().query(SingleEpochSubtraction).filter(
            func.q3c_radial_query(
                SingleEpochSubtraction.ra, SingleEpochSubtraction.dec, self.ra,
                self.dec, 0.64)).filter(
                    func.q3c_poly_query(
                        self.ra, self.dec,
                        SingleEpochSubtraction.poly)).outerjoin(
                            subq, subq.c.image_id == SingleEpochSubtraction.id
                        ).filter(subq.c.id == None)

        return q.all()
Пример #6
0
def _xmatch(session, edge):
    """Join photometric measurements of two overlapping catalogs in the
    given bandpass.
    """
    from_cstar = aliased(CatalogStar)
    to_cstar = aliased(CatalogStar)
    from_cat = aliased(Catalog)
    to_cat = aliased(Catalog)
    from_obs = aliased(Observation)
    to_obs = aliased(Observation)
    from_bp = aliased(Bandpass)
    to_bp = aliased(Bandpass)

    overlap_polygon = _make_q3c_polygon(_get_overlap_polygon(session, edge))
    q = session.query(from_obs.mag,
                      from_obs.mag_err,
                      to_obs.mag,
                      to_obs.mag_err).\
        join(to_cstar, to_cat.catalog_stars).\
        join(from_cstar, from_cat.catalog_stars).\
        filter(to_cat.id == edge.to_id).\
        filter(from_cat.id == edge.from_id).\
        filter(func.q3c_poly_query(to_cstar.ra,
                                   to_cstar.dec,
                                   overlap_polygon)).\
        filter(func.q3c_join(to_cstar.ra,
                             to_cstar.dec,
                             from_cstar.ra,
                             from_cstar.dec,
                             1. / 3600.)).\
        join(from_obs, from_cstar.observations).\
        join(to_obs, to_cstar.observations).\
        join(from_bp, from_obs.bandpass).\
        filter(from_bp.id == edge.bandpass_id).\
        join(to_bp, to_obs.bandpass).\
        filter(to_bp.id == edge.bandpass_id)
    dt = np.dtype([('from_mag', float), ('from_mag_err', float),
                   ('to_mag', float), ('to_mag_err', float)])
    data = np.array(q.all(), np.dtype(dt))
    return data