Esempio n. 1
0
def test_propermotions(db):
    # Tests against the ProperMotions table

    # There should be no entries in the ProperMotions table without both mu_ra and mu_dec
    t = db.query(db.ProperMotions.c.source).\
        filter(or_(db.ProperMotions.c.mu_ra.is_(None),
                   db.ProperMotions.c.mu_dec.is_(None))).\
        astropy()
    if len(t) > 0:
        print('\nEntries found without proper motion values')
        print(t)
    assert len(t) == 0
Esempio n. 2
0
def test_photometry(db):
    # Tests for Photometry table

    # Check that no negative magnitudes have been provided,
    # nor any that are larger than 99 (if missing/limits, just use None)
    t = db.query(db.Photometry). \
        filter(or_(db.Photometry.c.magnitude < 0,
                   db.Photometry.c.magnitude >= 99)). \
        astropy()
    if len(t) > 0:
        print('\nInvalid magnitudes present')
        print(t)
    assert len(t) == 0
Esempio n. 3
0
def test_coordinates(db):
    # Verify that all sources have valid coordinates
    t = db.query(db.Sources.c.source, db.Sources.c.ra,
                 db.Sources.c.dec).filter(
                     or_(db.Sources.c.ra.is_(None),
                         db.Sources.c.ra < 0, db.Sources.c.ra > 360,
                         db.Sources.c.dec.is_(None), db.Sources.c.dec < -90,
                         db.Sources.c.dec > 90)).astropy()

    if len(t) > 0:
        print(f'\n{len(t)} Sources failed coordinate checks')
        print(t)

    assert len(t) == 0, f'{len(t)} Sources failed coordinate checks'
Esempio n. 4
0
def test_propermotions(db):
    # Tests against the ProperMotions table

    # There should be no entries in the ProperMotions table without both mu_ra and mu_dec
    t = db.query(db.ProperMotions.c.source).\
        filter(or_(db.ProperMotions.c.mu_ra.is_(None),
                   db.ProperMotions.c.mu_dec.is_(None))).\
        astropy()
    if len(t) > 0:
        print('\nEntries found without proper motion values')
        print(t)
    assert len(t) == 0

    # While there may be many proper motion measurements for a single source,
    # there should be only one marked as adopted
    t = db.query(db.ProperMotions.c.source,
                 func.sum(db.ProperMotions.c.adopted).label('adopted_counts')). \
        group_by(db.ProperMotions.c.source). \
        having(func.sum(db.ProperMotions.c.adopted) > 1). \
        astropy()
    if len(t) > 0:
        print("\nProper Motion measurements with incorrect 'adopted' labels")
        print(t)
    assert len(t) == 0
Esempio n. 5
0
# Query and sort sources by declination
db.query(db.Sources.c.source).order_by(db.Sources.c.dec).all()

# Query for join Sources and Publications and return just several of the columns
results = db.query(db.Sources.c.source, db.Sources.c.reference, db.Publications.c.name)\
            .join(db.Publications, db.Sources.c.reference == db.Publications.c.name)\
            .all()
print(results)

# Query with AND
db.query(db.Sources).filter(and_(db.Sources.c.dec > 0,
                                 db.Sources.c.ra > 200)).all()

# Query with OR
db.query(db.Sources).filter(or_(db.Sources.c.dec < 0,
                                db.Sources.c.ra > 200)).all()

# Update a row
stmt = db.Sources.update()\
         .where(db.Sources.c.source == '2MASS J13571237+1428398')\
         .values(shortname='1357+1428')
db.engine.execute(stmt)

# Testing foreign key updates
stmt = db.Publications.update()\
         .where(db.Publications.c.name == 'Cutr12')\
         .values(name='FAKEREF')
db.engine.execute(stmt)
db.query(db.Publications).filter(db.Publications.c.name == 'FAKEREF').all()
results = db.query(
    db.Photometry).filter(db.Photometry.c.reference == 'FAKEREF').all()