PS1 star/galaxy and distance analysis

First import matplotlib and numpy

In [5]:
import mysql.connector
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

Connect to database (ask for the settings).

Then run the query on

  • sgscore1 (star/galaxy parameter for nearest PS1 source, and
  • distpsnr1 (distance of nearest PS1 source)

Query excludes the value sgscore1=0.5, meaning NaN

And we use the standard criterion for "good" candidates.

In [6]:
from ztf import settings
msl = mysql.connector.connect(\
            user    =settings.DB_USER, \
            password=settings.DB_PASS, \
            host    =settings.DB_HOST, \
            database='ztf')
cursor = msl.cursor(buffered=True, dictionary=True)
query = 'SELECT sgscore1,distpsnr1 from objects where '
query += 'sgscore1 > 0.0 and sgscore1 <> 0.5 '
query += 'and ncandgp > 4'
cursor.execute(query)
n = cursor.rowcount
print ('found %d objects' % n)
found 175887 objects

Maybe there is a more direct way to do this ....

In [7]:
sglist = []
distlist = []
i = 0
for row in cursor:
    sglist.append(row['sgscore1'])
    distlist.append(row['distpsnr1'])
cursor.close()
Out[7]:
True

Make a histogram of sgscore1

In [8]:
hist, bins = np.histogram(sglist, bins=30)
width = 0.7 * (bins[1] - bins[0])
center = (bins[:-1] + bins[1:]) / 2
plt.bar(center, hist, align='center', width=width)
plt.yscale('log')
plt.show()

Make a scatter plot of sgscore1 (horizontal), and distpsnr1 (vertical)

In [10]:
plt.figure(figsize=(12,6))
plt.scatter(sglist, distlist, s=1, edgecolor='')
plt.ylim((0.0, 5.0))
plt.show()