Exemplo n.º 1
0
def load_photometry(fieldname, instrument, band1, band2, server="marvin"):
    """Get photometry from starplex."""
    connect_to_server(server, echo=True)
    session = Session()
    # potentially a factor 10 speed gain with this
    # session.execute('SET ENABLE_NESTLOOP TO FALSE')
    mag1obs = aliased(Observation)
    mag2obs = aliased(Observation)
    bp1 = aliased(Bandpass)
    bp2 = aliased(Bandpass)
    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 == band1)\
            .join(bp2, mag2obs.bandpass)\
            .filter(bp2.name == band2)
    dt = [('cfrac', np.float), ('m1', np.float), ('e1', np.float),
            ('m2', np.float), ('e2', np.float)]
    data = np.array(q.all(), dtype=np.dtype(dt))
    log.info("Field {0} {2} has {1:d} stars".
        format(fieldname, data.shape[0], instrument))
    # session.execute('SET ENABLE_NESTLOOP TO TRUE')
    session.close()
    if len(data) == 0:
        raise NoDataError
    return data
def main():
    connect_to_server("marvin", echo=True)
    session = Session()

    catalogs = session.query(Catalog)
    for catalog in catalogs:
        catalog.metajson = catalog.meta
    session.commit()
Exemplo n.º 3
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
Exemplo n.º 4
0
def load_photometry(fieldname,
                    use_vega=False,
                    apply_intercal=False,
                    server='marvin'):
    """Load WIRCam photometry from Starplex, converted to AB mag.

    Filter out MW stars with a rudimentary J-Ks > 0.9 (Vega) color cut.
    """
    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, CatalogStar.ra, CatalogStar.dec,
                      mag1obs.mag, mag1obs.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")
    dt = [('cfrac', np.float), ('ra', np.float), ('dec', 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))

    # Filter out MW stars
    # FIXME rudimentary
    # Using Vega Mag here!
    sel = np.where((data['J'] - data['Ks']) > 0.9)[0]
    data = data[sel]

    # Apply the intercal ZP correction
    if apply_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} has {1:d} stars".format(fieldname, data.shape[0],
                                                    instrument))
    session.close()
    if len(data) == 0:
        raise NoDataError
    return data
Exemplo n.º 5
0
def load_photometry(fieldname,
                    use_vega=False, apply_intercal=False,
                    server='marvin'):
    """Load WIRCam photometry from Starplex, converted to AB mag.

    Filter out MW stars with a rudimentary J-Ks > 0.9 (Vega) color cut.
    """
    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, CatalogStar.ra, CatalogStar.dec,
                      mag1obs.mag, mag1obs.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")
    dt = [('cfrac', np.float), ('ra', np.float), ('dec', 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))

    # Filter out MW stars
    # FIXME rudimentary
    # Using Vega Mag here!
    sel = np.where((data['J'] - data['Ks']) > 0.9)[0]
    data = data[sel]

    # Apply the intercal ZP correction
    if apply_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} has {1:d} stars".
             format(fieldname, data.shape[0], instrument))
    session.close()
    if len(data) == 0:
        raise NoDataError
    return data