Coverage for ZTF

We shall make four coverage plots: Equatorial/Galactic and filter-r/filter-g. The area of each blob is the number of candidates found in that field.

In [1]:
import mysql.connector
import numpy as np

from astropy.table import Table
import astropy.coordinates as coord
import astropy.units as u

import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline

Query the database. Ask if you want the settings. For some reason the natural join returned empty set, so I used inner join.

In [2]:
import settings
msl = mysql.connector.connect(\
            user    =settings.DB_USER, \
            password=settings.DB_PASS, \
            host    =settings.DB_HOST, \
cursor = msl.cursor(buffered=True, dictionary=True)
query = 'select candidates.field,fid,fields.ra,fields.decl,glong,glat,count(*) as n '
query += 'from candidates inner join fields on candidates.field=fields.field  '
query += 'where nid=531 '
query += 'group by candidates.field,fid'
n = cursor.rowcount
Make an astropy table, sort out the radians, then make one of the 4 plots.
In [3]:
def makeplot(fid, longname, longlist, latname, latlist, nlist):
    slist = np.array(nlist, dtype=np.float32)
    slist = 200*np.sqrt(slist/np.amax(slist))
    t = Table([np.array(longlist), np.array(latlist)], names=(longname, latname))
    long = coord.Angle(t[longname]*
    long = long.wrap_at(180*
    lat  = coord.Angle(t[latname]*
    fig = plt.figure(figsize=(10,7))
    ax = fig.add_subplot(111, projection="mollweide")
    filter = 'g'
    if fid == 1: filter = 'r'
    plt.title('Coverage %s,%s in filter %s with %d fields' \
              % (longname, latname, filter, len(longlist)))
    ax.scatter(long.radian, lat.radian, s=slist, c=filter)

Extract lists of coordinates from the database cursor.

In [4]:
ralist = [[],[]]
delist = [[],[]]
gglist = [[],[]]
gtlist = [[],[]]
nlist  = [[],[]]
i = 0
for row in cursor:
    fid = row['fid']-1

Make plots in equatorial (RA/Dec)

In [5]:
for fid in range(2):
    makeplot(fid, 'RA', ralist[fid], 'Dec', delist[fid], nlist[fid])
Make plots in galactic (Glong/Glat)
In [6]:
for fid in range(2):
    makeplot(fid, 'Glong', gglist[fid], 'Glat', gtlist[fid], nlist[fid])
/opt/lsst-3.6/python/miniconda3-4.3.21/lib/python3.6/site-packages/matplotlib/projections/ RuntimeWarning: invalid value encountered in arcsin
  theta = np.arcsin(y / np.sqrt(2))