Query Pan-STARRS DR2 catalog using CasJobs

This script shows how to query the Pan-STARRS DR2 catalog using a Python interface to Casjobs. The examples show how to do a simple cone search, how to manipulate the table of results, and how to get a light curve from the table of detections.

This relies on the mastcasjobs Python module. Follow the installation instructions given here: https://github.com/rlwastro/mastcasjobs.

You must have a MAST Casjobs account (see https://mastweb.stsci.edu/ps1casjobs to create one). Note that MAST Casjobs accounts are independent of SDSS Casjobs accounts.

For easy startup, set the CASJOBS_USERID and CASJOBS_PW environment variables with your Casjobs account information. These are the username and password you enter when logging into Casjobs.

This script prompts for your Casjobs username and password if the environment variables are not defined.

You can also specify your username and password directly in the MastCasJobs initialization using the username and password keyword parameters.

This notebook is available for download.

In [1]:
%matplotlib inline
import mastcasjobs
import requests

import os
import numpy as np
import matplotlib.pyplot as plt
import json

# get the WSID and password if not already defined
import getpass
if not os.environ.get('CASJOBS_USERID'):
    os.environ['CASJOBS_USERID'] = input('Enter Casjobs username:')
if not os.environ.get('CASJOBS_PW'):
    os.environ['CASJOBS_PW'] = getpass.getpass('Enter Casjobs password:')

Useful functions

Resolve names using MAST query. This uses the requests module to do the queries.

In [2]:
def mastQuery(request, json_return=False):
    """Perform a MAST query.

    Parameters
    ----------
    request (dictionary): The MAST request json object
    
    Returns the text response or (if json_return=True) the json response
    """
    
    url = "https://mast.stsci.edu/api/v0/invoke"

    # Encoding the request as a json string
    requestString = json.dumps(request)
    
    # make the query
    r = requests.post(url, data=dict(request=requestString))
    
    # raise exception on error
    r.raise_for_status()
    
    if json_return:
        return r.json()
    else:
        return r.text


def resolve(name):
    """Get the RA and Dec for an object using the MAST name resolver
    
    Parameters
    ----------
    name (str): Name of object

    Returns RA, Dec tuple with position"""

    resolverRequest = {'service':'Mast.Name.Lookup',
                       'params':{'input':name,
                                 'format':'json'
                                },
                      }
    resolvedObject = mastQuery(resolverRequest, json_return=True)
    # The resolver returns a variety of information about the resolved object, 
    # however for our purposes all we need are the RA and Dec
    try:
        objRa = resolvedObject['resolvedCoordinate'][0]['ra']
        objDec = resolvedObject['resolvedCoordinate'][0]['decl']
    except IndexError as e:
        raise ValueError("Unknown object '{}'".format(name))
    return (objRa, objDec)

Simple positional query

This searches the mean object catalog for objects within 50 arcsec of M87 (RA=187.706, Dec=12.391 in degrees). The fGetNearbyObjEq function returns a list of object IDs, and the subsequent joins extract information from the ObjectThin table (which has information on object positions and the number of available measurements) and the MeanObject table (which has information on photometry averaged over the multiple epochs of observation).

Note that the results are restricted to objects with nDetections>1, where nDetections is the total number of times the object was detected on the single-epoch images in any filter at any time. Objects with nDetections=1 tend to be artifacts, so this is a quick way to eliminate most spurious objects from the catalog.

This query runs in the interactive "quick" Casjobs queue, where the function pauses until the query is complete and returns the results as a CSV string. If one of these queries times out (which can happen if the database server is heavily loaded), try simply running it again. Often the same query will succeed the second time.

The more robust way to handle long-running queries is to run them in batch mode, but that requires waiting in the Casjobs queue if the system is busy.

The quick query returns the results as an astropy table. This table is easily manipulated to extract information on individual columns or rows.

In [3]:
query = """select o.objID, o.raMean, o.decMean,
o.nDetections, o.ng, o.nr, o.ni, o.nz, o.ny,
m.gMeanPSFMag, m.rMeanPSFMag, m.iMeanPSFMag, m.zMeanPSFMag, m.yMeanPSFMag
from fGetNearbyObjEq(187.706,12.391,50.0/60.0) nb
inner join ObjectThin o on o.objid=nb.objid and o.nDetections>1
inner join MeanObject m on o.objid=m.objid and o.uniquePspsOBid=m.uniquePspsOBid
"""

jobs = mastcasjobs.MastCasJobs(context="PanSTARRS_DR2")
tab = jobs.quick(query, task_name="python cone search")
tab
Out[3]:
Table length=45
objIDraMeandecMeannDetectionsngnrninznygMeanPSFMagrMeanPSFMagiMeanPSFMagzMeanPSFMagyMeanPSFMag
int64float64float64int64int64int64int64int64int64float64float64float64float64float64
122851876947049923187.6947602812.38281582123019.867418.592719.069218.1394-999.0
122851877008084336187.7008012512.37828064153255021.1629-999.018.754318.4389-999.0
122851877018527082187.7018316712.3805351452210020.3146-999.018.1687-999.0-999.0
122851877049294726187.7049523912.3785145272221019.030618.453718.5761-999.0-999.0
122851877062673559187.7062495612.3775483471230120.52118.906318.9627-999.018.1421
122851877090477761187.7090282412.381016152967115019.746817.746117.491517.6221-999.0
122851877096718451187.7096956412.3815862821010020.5734-999.0-999.0-999.0-999.0
122851877109888891187.7109880912.38200012200200-999.0-999.0-999.0-999.0-999.0
122851877115528846187.7113434112.3818190921100023.352417.3302-999.0-999.0-999.0
122851877124637737187.7124607712.3810060950910159719.324718.029617.798817.930417.5089
..........................................
122871877026011277187.7025378412.3923406262131216101116.941715.388615.329915.768116.9338
122871877062551436187.7062236512.39236505200002-999.0-999.0-999.0-999.015.1102
122871877063310741187.7063047212.39182315302010-999.014.4229-999.014.4249-999.0
122871877068858435187.7069158512.3982706273121018.659117.865117.777617.9392-999.0
122871877075050430187.7074791212.3915839200020-999.0-999.0-999.015.5752-999.0
122881876951360506187.6952922912.40011853200101-999.0-999.019.2936-999.017.7803
122881877085143466187.708499612.402404083791177318.826118.006817.766917.875117.6812
122881877095525205187.7095170312.40389466200200-999.0-999.018.8612-999.0-999.0
122881877105204765187.7104973112.4035168200200-999.0-999.019.1368-999.0-999.0
122881877112164157187.7112626212.40316813200200-999.0-999.019.0408-999.0-999.0

Get DR2 light curve for RR Lyrae star KQ UMa

This time we start with the object name, use the MAST name resolver (which relies on Simbad and NED) to convert the name to RA and Dec, and then query the PS1 DR2 mean object catalog at that position. This time we use the fGetNearestObjEq function to select just the object closest to the search position.

In [4]:
objname = 'KQ UMa'
ra, dec = resolve(objname)
radius = 1.0/60.0 # radius = 1 arcsec

query = """select o.objID, o.raMean, o.decMean,
o.nDetections, o.ng, o.nr, o.ni, o.nz, o.ny,
m.gMeanPSFMag, m.rMeanPSFMag, m.iMeanPSFMag, m.zMeanPSFMag, m.yMeanPSFMag
from fGetNearestObjEq({},{},{}) nb
inner join ObjectThin o on o.objid=nb.objid and o.nDetections>1
inner join MeanObject m on o.objid=m.objid and o.uniquePspsOBid=m.uniquePspsOBid
""".format(ra,dec,radius)

print(query)

jobs = mastcasjobs.MastCasJobs(context="PanSTARRS_DR2")
tab = jobs.quick(query, task_name="python cone search")
tab
select o.objID, o.raMean, o.decMean,
o.nDetections, o.ng, o.nr, o.ni, o.nz, o.ny,
m.gMeanPSFMag, m.rMeanPSFMag, m.iMeanPSFMag, m.zMeanPSFMag, m.yMeanPSFMag
from fGetNearestObjEq(139.33433,68.63514,0.016666666666666666) nb
inner join ObjectThin o on o.objid=nb.objid and o.nDetections>1
inner join MeanObject m on o.objid=m.objid and o.uniquePspsOBid=m.uniquePspsOBid

Out[4]:
Table length=1
objIDraMeandecMeannDetectionsngnrninznygMeanPSFMagrMeanPSFMagiMeanPSFMagzMeanPSFMagyMeanPSFMag
int64float64float64int64int64int64int64int64int64float64float64float64float64float64
190361393344112894139.3344497268.63506046681021131415.040214.55314.210914.281414.3041

Get the detection information

Extract all the objects with the same object ID from the Detection table, which contains all the individual measurements for this source. The results are joined to the Filter table to convert the filter numbers to names. The somewhat odd structure for the SQL (with the inner query in parentheses) ensures that the select by objID occurs before the match to the Filter table. If the SQL optimizer gets confused and does the join between Detection and Filter before selecting the subset of objects, the query is very slow!

In [5]:
objid = tab['objID'][0]
query = """select 
    objID, detectID, filter=f.filterType, obsTime, ra, dec,
    psfFlux, psfFluxErr, psfMajorFWHM, psfMinorFWHM, psfQfPerfect, 
    apFlux, apFluxErr, infoFlag, infoFlag2, infoFlag3
from (
    select * from Detection where objID={}
    ) d
join Filter f on d.filterID=f.filterID
order by d.filterID, obsTime
""".format(objid)

print(query)

dtab = jobs.quick(query, task_name="python detection search")
dtab
select 
    objID, detectID, filter=f.filterType, obsTime, ra, dec,
    psfFlux, psfFluxErr, psfMajorFWHM, psfMinorFWHM, psfQfPerfect, 
    apFlux, apFluxErr, infoFlag, infoFlag2, infoFlag3
from (
    select * from Detection where objID=190361393344112894
    ) d
join Filter f on d.filterID=f.filterID
order by d.filterID, obsTime

Out[5]:
Table length=66
objIDdetectIDfilterobsTimeradecpsfFluxpsfFluxErrpsfMajorFWHMpsfMinorFWHMpsfQfPerfectapFluxapFluxErrinfoFlaginfoFlag2infoFlag3
int64int64str1float64float64float64float64float64float64float64float64float64float64int64int64int64
190361393344112894153347716310000010g55634.477414139.334520768.635035770.008261921.14074e-051.881851.767340.9929160.008617051.14233e-05102760517128124782656
190361393344112894153348968310000008g55634.4899457139.3344882168.635061460.00773731.10268e-051.810311.605180.9984610.007921721.09406e-05102760517128124782656
190361393344112894232228791560000017g56423.2881719139.3344944168.635039520.003351987.26745e-061.602041.450480.9985890.003386587.2363e-06102760517128108038208
190361393344112894255559866370000015g56656.5989211139.3344459268.635045890.003729097.37688e-061.828311.686920.9991910.003721637.52088e-06102760517128124815424
190361393344112894262040070370000016g56721.4009635139.3344514868.635048070.0035767.22894e-061.605851.503960.9986050.003596037.43463e-061027605171287374912
190361393344112894262040708370000014g56721.4073411139.3344530468.635044060.003505547.14809e-061.624151.488270.9994870.003596247.43434e-061027605171287374912
190361393344112894264231864260000022g56743.3189045139.334443168.635044970.003438677.81574e-061.539571.47610.9990490.003612397.85237e-061027605171287374912
190361393344112894264232516260000024g56743.3254198139.3344451268.635052850.003474037.87789e-061.527511.433250.9993670.003603497.8686e-061027605171287374912
190361393344112894153441340410000012r55635.4136426139.3344717368.63505340.009787581.10843e-051.678791.56530.9985090.009907631.11231e-05102760517128124815424
190361393344112894153442549410000013r55635.4257356139.3344773268.635052790.00936211.1005e-051.347241.209520.4074960.009506791.09949e-0510276051716034880
................................................
190361393344112894183254354520000014y55933.5437238139.334453468.635059040.00793942.4924e-050.9592310.9014580.9968530.008030782.37126e-051027605171287374912
190361393344112894183255163520000015y55933.5518128139.3344423268.635056690.009155732.64422e-051.113310.953680.9971150.009145152.48501e-0510276051712874483776
190361393344112894191726725200000011y56018.2674345139.3344607968.635064030.008296462.59461e-051.073321.015630.9979240.008337592.33303e-051027605171287374912
190361393344112894191727369200000012y56018.2738664139.3344518968.635061520.008199962.55524e-051.095041.059140.9978190.008207532.3153e-051027605171287374912
190361393344112894229122569150000014y56392.2258719139.3344274268.635062340.007804222.57689e-051.028780.8931950.9986180.007772792.16455e-051027605171287374912
190361393344112894229123273150000011y56392.2329084139.3344459568.635057440.008035032.55974e-050.9418010.8887880.998050.008070372.2092e-051027605171287374912
190361393344112894264322648150000024y56744.2269452139.33445468.635058640.005404461.32146e-051.388291.34770.9989220.005498671.13527e-05102760517128124782656
190361393344112894265623008150000027y56757.2305455139.3344431968.635063750.006366141.60784e-050.8950410.8033650.8525160.004128591.01303e-0510276058112834880
190361393344112894287165374630000023y56972.6539243139.3344422668.635060870.006878172.79326e-051.536861.288130.9916470.006999142.16585e-051027605171287374912
190361393344112894287265116630000028y56973.6513438139.3344499168.635057590.006653772.7704e-051.856191.703970.998640.006631062.13156e-051027605171287342144

Plot the light curves

The psfFlux values from the Detection table are converted from Janskys to AB magnitudes. Measurements in the 5 different filters are plotted separately.

In [6]:
# convert flux in Jy to magnitudes
t = dtab['obsTime']
mag = -2.5*np.log10(dtab['psfFlux']) + 8.90
xlim = np.array([t.min(),t.max()])
xlim = xlim + np.array([-1,1])*0.02*(xlim[1]-xlim[0])

plt.rcParams.update({'font.size': 14})
plt.figure(1,(10,10))
for i, filter in enumerate("grizy"):
    plt.subplot(511+i)
    w = np.where(dtab['filter']==filter)
    plt.plot(t[w],mag[w],'-o')
    plt.ylabel(filter+' [mag]')
    plt.xlim(xlim)
    plt.gca().invert_yaxis()
    if i==0:
        plt.title(objname)
plt.xlabel('Time [MJD]')
plt.tight_layout()

Plot differences from the mean magnitudes in the initial search.

In [7]:
# convert flux in Jy to magnitudes
t = dtab['obsTime']
mag = -2.5*np.log10(dtab['psfFlux']) + 8.90
xlim = np.array([t.min(),t.max()])
xlim = xlim + np.array([-1,1])*0.02*(xlim[1]-xlim[0])

plt.rcParams.update({'font.size': 14})
plt.figure(1,(10,10))
for i, filter in enumerate("grizy"):
    plt.subplot(511+i)
    w = np.where(dtab['filter']==filter)
    magmean = tab[filter+'MeanPSFMag'][0]
    plt.plot(t[w],mag[w] - magmean,'-o')
    plt.ylabel('{} [mag - {:.2f}]'.format(filter,magmean))
    plt.xlim(xlim)
    plt.gca().invert_yaxis()
    if i==0:
        plt.title(objname)
plt.xlabel('Time [MJD]')
plt.tight_layout()

Identify bad data

There is one clearly bad $z$ magnitude with a very large difference. Select the bad point and look at it in more detail.

Note that indexing a table (or numpy array) with a logical expression selects just the rows where that expression is true.

In [8]:
dtab[ (dtab['filter']=='z') & (np.abs(mag-tab['zMeanPSFMag'][0]) > 2) ]
Out[8]:
Table length=1
objIDdetectIDfilterobsTimeradecpsfFluxpsfFluxErrpsfMajorFWHMpsfMinorFWHMpsfQfPerfectapFluxapFluxErrinfoFlaginfoFlag2infoFlag3
int64int64str1float64float64float64float64float64float64float64float64float64float64int64int64int64
190361393344112894183252627520000234z55933.5264577139.3348816868.635322730.0003179456.73008e-061.075371.01530.3229860.0002132172.36939e-0610276045312832768

From examining this table, it looks like psfQfPerfect is bad. This flag is the PSF-weighted fraction of unmasked pixels in the image (see the documentation for more details). Values near unity indicate good data that is not significantly affected by bad pixels.

Check all the psfQfPerfect values for the $z$ filter to see if this value really is unusual. The list of values below are sorted by magnitude. The bad point is the only value with psfQfPerfect < 0.95.

In [9]:
w = np.where(dtab['filter']=='z')
zdtab = dtab[w]
zdtab['mag'] = mag[w]
zdtab['dmag'] = zdtab['mag'] - tab['zMeanPSFMag'][0]
ii = np.argsort(-np.abs(zdtab['dmag']))
zdtab = zdtab[ii]
zdtab['objID','obsTime','mag','dmag','psfQfPerfect']
Out[9]:
Table length=13
objIDobsTimemagdmagpsfQfPerfect
int64float64float64float64float64
19036139334411289455933.526457717.644120000843743.3627200008437390.322986
19036139334411289456289.615934613.890659532156441-0.390740467843558650.997811
19036139334411289456289.624111213.916806313581588-0.364593686418411170.988369
19036139334411289456351.416848313.998972905236004-0.282427094763995970.999257
19036139334411289455281.252828514.5379146386864730.25651463868647360.99754
19036139334411289456351.42407614.032501974717418-0.248898025282581870.999187
19036139334411289455527.650891914.512118206878710.230718206878711030.997265
19036139334411289456648.567601914.056429712068542-0.224970287931457240.997982
19036139334411289455527.638146914.4651409733243030.183740973324303170.99738
19036139334411289455281.262515114.4285539422482680.147153942248268170.955584
19036139334411289455933.53451514.3076397658521160.0262397658521162920.997489
19036139334411289456019.296878214.27863588374898-0.00276411625102035430.997654
19036139334411289456019.303801414.2828912657662080.0014912657662087270.997338

Repeat the plot with bad psfQfPerfect values excluded

Do the plot again but exclude low psfQfPerfect values.

In [10]:
# convert flux in Jy to magnitudes
t = dtab['obsTime']
mag = -2.5*np.log10(dtab['psfFlux']) + 8.90
magmean = 0.0*mag
for filter in "grizy":
    magmean[dtab['filter']==filter] = tab[filter+'MeanPSFMag'][0]
dmag = mag - magmean
dmag1 = dmag[dtab['psfQfPerfect']>0.9]
# fix the x and y axis ranges
xlim = np.array([t.min(),t.max()])
xlim = xlim + np.array([-1,1])*0.02*(xlim[1]-xlim[0])
# flip axis direction for magnitude
ylim = np.array([dmag1.max(),dmag1.min()])
ylim = ylim + np.array([-1,1])*0.02*(ylim[1]-ylim[0])

plt.rcParams.update({'font.size': 14})
plt.figure(1,(10,10))
for i, filter in enumerate("grizy"):
    plt.subplot(511+i)
    w = np.where((dtab['filter']==filter) & (dtab['psfQfPerfect']>0.9))[0]
    plt.plot(t[w],dmag[w],'-o')
    plt.ylabel('{} [mag - {:.2f}]'.format(filter,magmean[w[0]]))
    plt.xlim(xlim)
    plt.ylim(ylim)
    if i==0:
        plt.title(objname)
plt.xlabel('Time [MJD]')
plt.tight_layout()

Plot versus the periodic phase instead of epoch

Plot versus phase using known RR Lyr period from Simbad (table J/AJ/132/1202/table4).

In [11]:
period = 0.48636
# convert flux in Jy to magnitudes
t = (dtab['obsTime'] % period) / period
mag = -2.5*np.log10(dtab['psfFlux']) + 8.90
magmean = 0.0*mag
for filter in "grizy":
    magmean[dtab['filter']==filter] = tab[filter+'MeanPSFMag'][0]
dmag = mag - magmean
dmag1 = dmag[dtab['psfQfPerfect']>0.9]
# fix the x and y axis ranges
xlim = np.array([t.min(),t.max()])
xlim = xlim + np.array([-1,1])*0.02*(xlim[1]-xlim[0])
# flip axis direction for magnitude
ylim = np.array([dmag1.max(),dmag1.min()])
ylim = ylim + np.array([-1,1])*0.02*(ylim[1]-ylim[0])

plt.rcParams.update({'font.size': 14})
plt.figure(1,(10,10))
for i, filter in enumerate("grizy"):
    plt.subplot(511+i)
    w = np.where((dtab['filter']==filter) & (dtab['psfQfPerfect']>0.9))[0]
    w = w[np.argsort(t[w])]
    plt.plot(t[w],dmag[w],'-o')
    plt.ylabel('{} [mag - {:.2f}]'.format(filter,magmean[w[0]]))
    plt.xlim(xlim)
    plt.ylim(ylim)
    if i==0:
        plt.title(objname)
plt.xlabel('Phase')
plt.tight_layout()

Repeat search using eclipsing binary KIC 2161623

From Villanova Kepler Eclipsing Binaries

In [12]:
objname = 'KIC 2161623'
ra, dec = resolve(objname)
radius = 1.0/60.0 # radius = 1 arcsec

query = """select o.objID, o.raMean, o.decMean,
o.nDetections, o.ng, o.nr, o.ni, o.nz, o.ny,
m.gMeanPSFMag, m.rMeanPSFMag, m.iMeanPSFMag, m.zMeanPSFMag, m.yMeanPSFMag
from fGetNearestObjEq({},{},{}) nb
inner join ObjectThin o on o.objid=nb.objid and o.nDetections>1
inner join MeanObject m on o.objid=m.objid and o.uniquePspsOBid=m.uniquePspsOBid
""".format(ra,dec,radius)

print(query)

jobs = mastcasjobs.MastCasJobs(context="PanSTARRS_DR2")
tab = jobs.quick(query, task_name="python cone search")
tab
select o.objID, o.raMean, o.decMean,
o.nDetections, o.ng, o.nr, o.ni, o.nz, o.ny,
m.gMeanPSFMag, m.rMeanPSFMag, m.iMeanPSFMag, m.zMeanPSFMag, m.yMeanPSFMag
from fGetNearestObjEq(291.744461,37.59102,0.016666666666666666) nb
inner join ObjectThin o on o.objid=nb.objid and o.nDetections>1
inner join MeanObject m on o.objid=m.objid and o.uniquePspsOBid=m.uniquePspsOBid

Out[12]:
Table length=1
objIDraMeandecMeannDetectionsngnrninznygMeanPSFMagrMeanPSFMagiMeanPSFMagzMeanPSFMagyMeanPSFMag
int64float64float64int64int64int64int64int64int64float64float64float64float64float64
153102917444859851291.7444645137.591000167101612151414.599814.282114.158714.200414.0672

Get the detection information

This time include the psfQfPerfect limit directly in the database query.

In [13]:
objid = tab['objID'][0]
query = """select 
    objID, detectID, filter=f.filterType, obsTime, ra, dec,
    psfFlux, psfFluxErr, psfMajorFWHM, psfMinorFWHM, psfQfPerfect, 
    apFlux, apFluxErr, infoFlag, infoFlag2, infoFlag3
from (
    select * from Detection where objID={}
    ) d
join Filter f on d.filterID=f.filterID
where psfQfPerfect>0.9
order by d.filterID, obsTime
""".format(objid)

print(query)

dtab = jobs.quick(query, task_name="python detection search")

# add magnitude and difference from mean
dtab['magmean'] = 0.0
for filter in "grizy":
    dtab['magmean'][dtab['filter']==filter] = tab[filter+'MeanPSFMag'][0]
dtab['mag'] = -2.5*np.log10(dtab['psfFlux']) + 8.90
dtab['dmag'] = dtab['mag']-dtab['magmean']
dtab
select 
    objID, detectID, filter=f.filterType, obsTime, ra, dec,
    psfFlux, psfFluxErr, psfMajorFWHM, psfMinorFWHM, psfQfPerfect, 
    apFlux, apFluxErr, infoFlag, infoFlag2, infoFlag3
from (
    select * from Detection where objID=153102917444859851
    ) d
join Filter f on d.filterID=f.filterID
where psfQfPerfect>0.9
order by d.filterID, obsTime

Out[13]:
Table length=45
objIDdetectIDfilterobsTimeradecpsfFluxpsfFluxErrpsfMajorFWHMpsfMinorFWHMpsfQfPerfectapFluxapFluxErrinfoFlaginfoFlag2infoFlag3magmeanmagdmag
int64int64str1float64float64float64float64float64float64float64float64float64float64int64int64int64float64float64float64
15310291744485985190150443710000088g55002.5047803291.7444639137.59100060.005010086.65687e-061.987441.812110.9994210.005174137.31225e-0610276051712812481542414.599814.6503883483652380.05058834836523829
15310291744485985190151959710000087g55002.5199475291.7444661137.591001560.004873346.48844e-061.984871.707930.9992340.005115427.27714e-0610276051712812481542414.599814.6804332199703220.08063321997032169
153102917444859851131534996560000129g55416.3502179291.7444608237.590996920.005256228.41646e-061.624031.578930.9985660.00529928.62578e-06102760517128737491214.599814.598316163992422-0.0014838360075781765
153102917444859851131536180650000138g55416.362065291.7444593737.590997330.005330288.62169e-061.320811.271860.9987570.005400828.91577e-0610276051712812481542414.599814.58312494213292-0.016675057867079346
153102917444859851204528930560000076g56146.2895546291.7444591437.590980730.005223998.43794e-061.333691.292110.9997580.005325068.88465e-06102760517128737491214.599814.6049941576962470.0051941576962466485
153102917444859851204530041560000085g56146.3006673291.7444648637.590976490.005235398.44281e-061.428831.226830.9646460.005324198.85594e-06102760517128737491214.599814.6026274021838770.0028274021838772256
153102917444859851241032265120000094g56511.322909291.7444565737.590997520.005286418.3427e-061.151231.107890.9987220.005374848.8135e-06102760517128737491214.599814.59209789291219-0.007702107087810717
153102917444859851241033321120000081g56511.3334693291.7444594537.590996430.005278898.31263e-061.078980.9873230.9952790.00533468.77771e-06102760517128737491214.599814.59364346902239-0.006156530977609265
15310291744485985191252543710000102r55013.5256677291.7444598537.590994540.007002438.7848e-061.901871.686890.9989620.007235139.82915e-06102760517128737491214.282114.2868780598010370.00477805980103696
153102917444859851131334556560000161r55414.3458067291.744462237.590998720.007148638.94809e-061.348021.239560.9978170.007153779.46631e-06102760517128737491214.282114.264442951598488-0.017657048401511943
.........................................................
153102917444859851159961616410000125y55700.6163536291.7444634637.590997680.008672862.66106e-050.7800350.6504660.9595020.008731062.5663e-05102760517128737491214.067214.054594160173803-0.012605839826196785
153102917444859851160460087410000136y55705.6010605291.7444637237.590996670.008389142.4518e-050.8922940.7857140.9974980.008507052.38093e-05102760517128737491214.067214.0907063948286750.02350639482867578
153102917444859851160461274410000134y55705.6129264291.7444647937.590994840.008463762.45964e-050.8435670.7193540.9821990.008459892.36938e-05102760517128737491214.067214.0810916501795480.01389165017954852
153102917444859851171734372010000127y55818.3439014291.7444641937.590999730.008995372.60801e-051.256050.9636240.9975090.008931252.37426e-051027605171285770656014.067214.014952421081372-0.05224757891862808
153102917444859851171735523010000129y55818.3554064291.7444605837.591002080.008938852.61524e-051.26840.9412590.9979290.008983012.38145e-051027605171284092934414.067214.02179587604703-0.04540412395297011
153102917444859851194462075640000160y56045.6209324291.744462737.590999140.009013122.46438e-051.411571.293440.9983750.009005782.28883e-051027605171285770656014.067214.01281211682762-0.05438788317237986
153102917444859851194462752640000158y56045.6277083291.7444598937.590997180.008816422.44413e-051.403771.198980.9995120.008887092.26963e-05102760517128737491214.067214.03676932228063-0.03043067771936947
153102917444859851213319324300000159y56234.1934155291.7444637337.59100090.008511512.42822e-051.045040.8496060.994970.008423522.41261e-05102760517128737491214.067214.0749834656833920.007783465683392166
153102917444859851213319880300000163y56234.1989869291.7444691537.591000790.008522162.36733e-051.038710.8439690.9949770.008332252.42534e-051027605171287448377614.067214.07362579090310.006425790903099582
153102917444859851245335559360000173y56554.3560604291.7444648837.590998740.008707051.611e-051.429061.389350.9596460.008868841.39697e-051027605171284092934414.067214.050322404022426-0.01687759597757399
In [14]:
t = dtab['obsTime']
dmag = dtab['dmag']
xlim = np.array([t.min(),t.max()])
xlim = xlim + np.array([-1,1])*0.02*(xlim[1]-xlim[0])
ylim = np.array([dmag.max(),dmag.min()])
ylim = ylim + np.array([-1,1])*0.02*(ylim[1]-ylim[0])

plt.rcParams.update({'font.size': 14})
plt.figure(1,(10,10))
for i, filter in enumerate("grizy"):
    plt.subplot(511+i)
    w = np.where(dtab['filter']==filter)[0]
    plt.plot(t[w],dmag[w],'-o')
    magmean = dtab['magmean'][w[0]]
    plt.ylabel('{} [mag - {:.2f}]'.format(filter,magmean))
    plt.xlim(xlim)
    plt.ylim(ylim)
    if i==0:
        plt.title(objname)
plt.xlabel('Time [MJD]')
plt.tight_layout()

Plot versus phase using known period

Eclipsing binaries basically vary by same amount in all filters since it is a geometrical effect, so combine the data into a single light curve. Wrap using known period and plot versus phase.

In [15]:
period = 2.2834698
bjd0 = 54999.599837
t = ((dtab['obsTime']-bjd0) % period) / period
dmag = dtab['dmag']
w = np.argsort(t)
t = t[w]
dmag = dmag[w]
xlim = np.array([t.min(),t.max()])
xlim = xlim + np.array([-1,1])*0.02*(xlim[1]-xlim[0])
ylim = np.array([dmag.max(),dmag.min()])
ylim = ylim + np.array([-1,1])*0.02*(ylim[1]-ylim[0])

plt.rcParams.update({'font.size': 14})
plt.figure(1,(10,6))
plt.plot(t,dmag,'-o')
plt.xlim(xlim)
plt.ylim(ylim)
plt.xlabel('Phase')
plt.ylabel('Delta magnitude from mean [mag]')
plt.title(objname)
plt.tight_layout()

Repeat search for another eclipsing binary KIC 8153568

In [16]:
objname = 'KIC 8153568'
ra, dec = resolve(objname)
radius = 1.0/60.0 # radius = 1 arcsec

query = """select o.objID, o.raMean, o.decMean,
o.nDetections, o.ng, o.nr, o.ni, o.nz, o.ny,
m.gMeanPSFMag, m.rMeanPSFMag, m.iMeanPSFMag, m.zMeanPSFMag, m.yMeanPSFMag
from fGetNearestObjEq({},{},{}) nb
inner join ObjectThin o on o.objid=nb.objid and o.nDetections>1
inner join MeanObject m on o.objid=m.objid and o.uniquePspsOBid=m.uniquePspsOBid
""".format(ra,dec,radius)

jobs = mastcasjobs.MastCasJobs(context="PanSTARRS_DR2")
tab = jobs.quick(query, task_name="python cone search")
tab
Out[16]:
Table length=1
objIDraMeandecMeannDetectionsngnrninznygMeanPSFMagrMeanPSFMagiMeanPSFMagzMeanPSFMagyMeanPSFMag
int64float64float64int64int64int64int64int64int64float64float64float64float64float64
160802869044447231286.9044440244.0054736988161531101615.182514.989914.890715.199914.8484
In [17]:
objid = tab['objID'][0]
query = """select 
    objID, detectID, filter=f.filterType, obsTime, ra, dec,
    psfFlux, psfFluxErr, psfMajorFWHM, psfMinorFWHM, psfQfPerfect, 
    apFlux, apFluxErr, infoFlag, infoFlag2, infoFlag3
from (
    select * from Detection where objID={}
    ) d
join Filter f on d.filterID=f.filterID
where psfQfPerfect>0.9
order by d.filterID, obsTime
""".format(objid)

dtab = jobs.quick(query, task_name="python detection search")

# add magnitude and difference from mean
dtab['magmean'] = 0.0
for filter in "grizy":
    dtab['magmean'][dtab['filter']==filter] = tab[filter+'MeanPSFMag'][0]
dtab['mag'] = -2.5*np.log10(dtab['psfFlux']) + 8.90
dtab['dmag'] = dtab['mag']-dtab['magmean']
dtab
Out[17]:
Table length=60
objIDdetectIDfilterobsTimeradecpsfFluxpsfFluxErrpsfMajorFWHMpsfMinorFWHMpsfQfPerfectapFluxapFluxErrinfoFlaginfoFlag2infoFlag3magmeanmagdmag
int64int64str1float64float64float64float64float64float64float64float64float64float64int64int64int64float64float64float64
16080286904444723191336429430000113g55014.3646518286.9044337444.005475750.0031095.98065e-061.781.238110.9983350.003124475.69291e-06102760517128737491215.182515.16844819489202-0.014051805107978765
16080286904444723191337480430000116g55014.3751566286.9044389444.005475020.003130566.00144e-061.669391.327730.9981970.003156135.71358e-0610276051712812481542415.182515.160944920386187-0.021555079613811756
160802869044447231126057565120000092g55361.57592286.9044531744.005474510.003095736.72312e-061.74981.624220.9988260.003100456.69387e-06102760517128737491215.182515.173092310398793-0.00940768960120586
160802869044447231126058741130000111g55361.587678286.9044515744.005480650.003028156.57752e-061.628391.525790.9983870.00310626.76425e-06102760517128737491215.182515.1970565394434590.01455653944345947
160802869044447231128744126310000284g55388.4415151286.904450244.005478910.0008064623.51444e-061.101320.9925010.9976310.0008104163.45294e-0610276051712812481542415.182516.633540228713331.45104022871333
160802869044447231128745341310000249g55388.4536712286.9044504344.005479360.0009817623.82737e-061.10851.074410.9974910.0009855843.78859e-0610276051712812481542415.182516.41998445419421.2374844541942007
160802869044447231164544841720000097g55746.4486739286.9044531544.005476460.003066556.32653e-061.328511.166930.998310.003047336.63894e-061027605171284092934415.182515.1833748744026880.0008748744026885191
160802869044447231164744408530000111g55748.4443394286.9044520744.005478350.003040576.5461e-061.371531.231930.9985440.003078286.69725e-06102760517128737491215.182515.1926124845225450.010112484522545984
160802869044447231164745526530000113g55748.4555151286.9044527544.00547970.003047286.57104e-061.275311.264240.9985190.003085646.71944e-06102760517128737491215.182515.19021909674720.0077190967472002825
160802869044447231235756984470000099g56458.5701018286.9044537844.005474560.003086676.74978e-061.565411.496550.90410.003092766.7849e-061027605171287448377615.182515.176274497593653-0.00622550240634645
.........................................................
160802869044447231281422935550000135z56915.2295351286.904444144.005471620.004052511.10757e-051.311431.133850.9995880.004052121.03719e-0510276051712812481542415.199914.880689762025602-0.3192102379743975
160802869044447231136027009120000145y55461.2702758286.9044550344.005478270.004297691.96242e-051.486521.389680.9986860.004233951.58905e-05102760517128737491214.848414.816912285364621-0.031487714635378694
160802869044447231136028204120000148y55461.2822322286.9044599444.005482290.004174612.0278e-051.765061.7130.9987050.004197361.56164e-05102760517128737491214.848414.8484602272529576.0227252957290034e-05
160802869044447231159959993400000147y55700.6001108286.9044469244.005480860.004009831.95314e-051.040480.8986510.9980290.003961771.71112e-051027605171284092934414.848414.8921850981421540.0437850981421537
160802869044447231159961165400000142y55700.611833286.9044446344.005480940.004096671.92559e-050.8760260.7410520.9988060.004039491.75641e-05102760517128737491214.848414.8689225461527830.02052254615278315
160802869044447231160459626400000159y55705.5964454286.904448944.00548110.003313431.64053e-051.01180.848480.9974650.003279931.48499e-0510276051712812481542414.848415.0993054998595560.2509054998595559
160802869044447231160460795400000171y55705.6081345286.9044468444.005479640.003211941.64645e-051.081210.9909370.9978730.00318011.44718e-0510276051712812481542414.848415.1330814401710430.2846814401710436
160802869044447231171023586640000136y55811.2360427286.904452544.005483570.00421441.82169e-050.7231510.6624750.99780.004252461.73593e-05102760517128734214414.848414.838160616795776-0.01023938320422424
160802869044447231171024776640000151y55811.2479472286.9044527644.005482270.004250271.862e-050.7636580.6921140.9977030.004313361.74107e-05102760517128734214414.848414.828958700882717-0.01944129911728254
160802869044447231245335002470000153y56554.3504901286.9044508544.005477840.004270931.24367e-051.463481.403940.9726070.004264339.76066e-06102760517128737491214.848414.823693866365545-0.02470613363445473
In [18]:
t = dtab['obsTime']
dmag = dtab['dmag']
xlim = np.array([t.min(),t.max()])
xlim = xlim + np.array([-1,1])*0.02*(xlim[1]-xlim[0])
ylim = np.array([dmag.max(),dmag.min()])
ylim = ylim + np.array([-1,1])*0.02*(ylim[1]-ylim[0])

plt.rcParams.update({'font.size': 14})
plt.figure(1,(10,10))
for i, filter in enumerate("grizy"):
    plt.subplot(511+i)
    w = np.where(dtab['filter']==filter)[0]
    plt.plot(t[w],dmag[w],'-o')
    magmean = dtab['magmean'][w[0]]
    plt.ylabel('{} [mag - {:.2f}]'.format(filter,magmean))
    plt.xlim(xlim)
    plt.ylim(ylim)
    if i==0:
        plt.title(objname)
plt.xlabel('Time [MJD]')
plt.tight_layout()

Eclipsing binaries basically vary by same amount in all filters since it is a geometrical effect, so combine the data into a single light curve.

Wrap using known period and plot versus phase. Plot two periods of the light curve this time.

This nice light curve appears to show a secondary eclipse.

In [19]:
period = 3.6071431
bjd0 = 54999.289794
t = ((dtab['obsTime']-bjd0) % period) / period
dmag = dtab['dmag']
w = np.argsort(t)
# extend to two periods
nw = len(w)
w = np.append(w,w)
t = t[w]
# add one to second period
t[-nw:] += 1
dmag = dmag[w]
xlim = [0,2.0]
ylim = np.array([dmag.max(),dmag.min()])
ylim = ylim + np.array([-1,1])*0.02*(ylim[1]-ylim[0])

plt.rcParams.update({'font.size': 14})
plt.figure(1,(12,6))
plt.plot(t,dmag,'-o')
plt.xlim(xlim)
plt.ylim(ylim)
plt.xlabel('Phase')
plt.ylabel('Delta magnitude from mean [mag]')
plt.title(objname)
plt.tight_layout()
In [ ]: