Hubble Source Catalog SWEEPS Proper Motion (CasJobs Version)

Contents

Hubble Source Catalog SWEEPS Proper Motion (CasJobs Version)#

2019 - 2022, Steve Lubow, Rick White, Trenton McKinney#

This notebook shows how to access the new proper motions available for the SWEEPS field in version 3.1 of the Hubble Source Catalog. Data tables in MAST CasJobs are queried from Python using the mastcasjobs module. Additional information is available on the SWEEPS Proper Motions help page.

Instructions:#

  • Complete the initialization steps described below.

  • Run the notebook to completion.

  • Modify and rerun any sections of the Table of Contents below.

Running the notebook from top to bottom takes about 7 minutes (depending on the speed of your computer).

Table of Contents#

  • Intialization

  • Properties of Full Catalog

    • Sky Coverage

    • Proper Motion Distributions

    • Visit Distribution

    • Time Coverage Distributions

    • Magnitude Distributions

    • Color Magnitude Diagram

    • Detection Positions

  • Good Photometric Objects

  • Science Applications

    • Proper Motions on the CMD

    • Proper Motions in Bulge Versus Disk

    • White Dwarfs

    • QSO Candidates

    • High Proper Motion Objects

    • HLA Cutout Images for Selected Objects

Initialization #

Install Python modules#

  1. This notebook requires the use of Python 3.

  2. Modules can be installed with conda, if using the Anaconda distribution of python, or with pip.

    • If you are using conda, do not install / update / remove a module with pip, that exists in a conda channel.

    • If a module is not available with conda, then it’s okay to install it with pip

  3. Install mastcasjobs and casjobs with pip:

pip install mastcasjobs

Set up your CasJobs account information#

You must have a MAST Casjobs account. Note that MAST Casjobs accounts are independent of SDSS Casjobs accounts.

For easy startup, you can optionally set the environment variables CASJOBS_USERID and/or CASJOBS_PW with your Casjobs account information. The Casjobs user ID and password are what you enter when logging into Casjobs.

This script prompts for your Casjobs user ID and password during initialization if the environment variables are not defined.

import astropy
import time
import sys
import os
import requests
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib.colors import LogNorm
from pathlib import Path

# check that version of mastcasjobs is new enough
# we are using some features not in version 0.0.1
from pkg_resources import get_distribution
from packaging.version import Version as V

assert V(get_distribution("mastcasjobs").version) >= V('0.0.2'), """
A newer version of mastcasjobs is required.
Update mastcasjobs to current version using this command:
pip install --upgrade git+git://github.com/rlwastro/mastcasjobs@master
"""

import mastcasjobs

from PIL import Image
from io import BytesIO

## For handling ordinary astropy Tables
from astropy.table import Table
from astropy.io import fits, ascii

from fastkde import fastKDE
from scipy.interpolate import RectBivariateSpline
from astropy.modeling import models, fitting

# There are a number of relatively unimportant warnings that 
# show up, so for now, suppress them:
import warnings
warnings.filterwarnings("ignore")

# set width for pprint
astropy.conf.max_width = 150
/tmp/ipykernel_2003/609964975.py:14: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import get_distribution
# set universal matplotlib parameters
plt.rcParams.update({'font.size': 16})
HSCContext = "HSCv3"

Set up Casjobs environment.

import getpass
if not os.environ.get('CASJOBS_USERID'):
    os.environ['CASJOBS_USERID'] = input('Enter Casjobs UserID:')
if not os.environ.get('CASJOBS_PW'):
    os.environ['CASJOBS_PW'] = getpass.getpass('Enter Casjobs password:')

Create table in MyDB with selected SWEEPS objects#

Note that the query restricts the sample to matches with at least 10 detections in each of F606W and F814W. This can be modified depending on the science goals.

This uses an existing MyDB.SWEEPS table if it already exists in your CasJobs account. If you want to change the query, either change the name of the output table or drop the table to force it to be recreated. Usually the query completes in about a minute, but if the database server is heavily loaded then it can take much longer.

DBtable = "SWEEPS"
jobs = mastcasjobs.MastCasJobs(context="MyDB")

try:
    print(f"Retrieving table MyDB.{DBtable} (if it exists)")
    tab = jobs.fast_table(DBtable, verbose=True)
except ValueError:
    print(f"Table MyDB.{DBtable} not found, running query to create it")

    # drop table if it already exists
    jobs.drop_table_if_exists(DBtable)

    # get main information
    query = f"""
        select a.ObjID,  RA=a.raMean, Dec=a.decMean, RAerr=a.raMeanErr, Decerr=a.decMeanErr,
            c.NumFilters, c.NumVisits,
            a_f606w=i1.MagMed,  a_f606w_n=i1.n, a_f606w_mad=i1.MagMAD,
            a_f814w=i2.MagMed, a_f814w_n=i2.n, a_f814w_mad=i2.MagMAD,
            bpm=a.pmLat, lpm=a.pmLon, bpmerr=a.pmLatErr, lpmerr=a.pmLonErr,
            pmdev=sqrt(pmLonDev*pmLonDev+pmLatDev*pmLatDev),
            yr=(a.epochMean - 47892)/365.25+1990, 
            dT=(a.epochEnd-a.epochStart)/365.25,
            yrStart=(a.epochStart - 47892)/365.25+1990,
            yrEnd=(a.epochEnd - 47892)/365.25+1990
        into mydb.{DBtable}
        from AstromProperMotions a join AstromSumMagAper2 i1 on 
             i1.ObjID=a.ObjID and i1.n >=10 and i1.filter ='F606W' and i1.detector='ACS/WFC'
         join AstromSumMagAper2 i2 on 
             i2.ObjID=a.ObjID and i2.n >=10 and i2.filter ='F814W' and i2.detector='ACS/WFC'
         join AstromSumPropMagAper2Cat c on a.ObjID=c.ObjID
    """

    t0 = time.time()
    jobid = jobs.submit(query, task_name="SWEEPS", context=HSCContext)
    print("jobid=", jobid)
    results = jobs.monitor(jobid)
    print(f"Completed in {(time.time()-t0):.1f} sec")
    print(results)

    # slower version using CasJobs output queue
    # tab = jobs.get_table(DBtable, verbose=False)
    
    # fast version using special MAST Casjobs service
    tab = jobs.fast_table(DBtable, verbose=True)
Retrieving table MyDB.SWEEPS (if it exists)
11.3 s: Retrieved 157.86MB table MyDB.SWEEPS
17.6 s: Converted to 443932 row table
tab
Table length=443932
ObjIDRADecRAerrDecerrNumFiltersNumVisitsa_f606wa_f606w_na_f606w_mada_f814wa_f814w_na_f814w_madbpmlpmbpmerrlpmerrpmdevyrdTyrStartyrEnd
int64float64float64float64float64int32int32float64int32float64float64int32float64float64float64float64float64float64float64float64float64float64
4000709002286269.7911379669984-29.2061561874114230.69648186245280990.273006233080014124722.127399444580078470.02160072326660156221.13010025024414470.01679992675781252.087558644949346-7.7382723294303710.388545822763860070.221156733689812372.8871545181336922013.300790214705811.3719145413717642003.43617966200852014.8080942033803
4000709002287269.7955922590832-29.2061516314949860.240202167603863430.1852481139121781624721.508499145507812470.02999877929687520.69930076599121470.023900985717773438-2.8930568503344967-0.78985838465552450.13165847900535780.124621856958779961.4746766326637852013.300790214705811.3719145413717642003.43617966200852014.8080942033803
4000709002288269.81608933789283-29.2061551966411950.30406841310206710.285040758620025624721.654399871826172470.0365009307861328120.85770034790039470.0171012878417968754.65866649193795-3.20988045803437850.139311721836511830.206480976047816261.95703573227134632013.300790214705811.3719145413717642003.43617966200852014.8080942033803
4000709002289269.8259694163096-29.206156688407510.35643254265220670.3954220029733366324719.79170036315918470.02820014953613281219.06909942626953470.019300460815429688-0.45662407290928664-2.09090500454338320.157581759523336530.27638812821949082.24152384993776852013.300790214705811.3719145413717642003.43617966200852014.8080942033803
4000709002290269.83486415728754-29.2061552669836430.162996398391985380.1406283940781183624620.566649436950684460.01594924926757812519.847750663757324460.0148010253906254.459275526783969-2.04336323443438860.178997279438553310.185035944688353961.00919709070525572013.51523827019923.00678224901781552011.80131195436252014.8080942033803
4000709002291269.83512411344606-29.20616352447980.182825831051080720.209350365068154124620.17770004272461460.02894973754882812519.489749908447266460.036399841308593754.090870144734149-8.0594731583940720.204463511521890520.262062125296961931.2930500270273292013.51523827019923.00678224901781552011.80131195436252014.8080942033803
4000709002292269.7964913295107-29.206187344833110.304911023972265270.2678449677785108624720.83639907836914470.0223999023437520.088300704956055470.02230072021484375-1.7001866534338244-5.9639674627591590.148141617998445470.19205176816533741.96717614892876542013.300790214705811.3719145413717642003.43617966200852014.8080942033803
4000709002293269.7872745304419-29.2062578288523371.3518855043600481.046061418947137824625.99174976348877460.085249900817871124.204350471496582460.05684947967529297-2.290436263458843-9.5968385596236270.7793734808164730.64853540325800878.5180455742088712013.320615015201611.3719145413717642003.43617966200852014.8080942033803
4000709002294269.80888716219647-29.2061891896260021.41345961187521031.251804780286295324725.465349197387695460.0810499191284179723.27630043029785470.0321006774902343754.381302303073221-4.7018558763948480.47844287930018571.02193637753253526.4696545651479532013.300790214705811.3719145413717642003.43617966200852014.8080942033803
..................................................................
4000946339500269.6899686412092-29.276978451867841.75817441277581680.935409107408077421023.770350456237793100.0608997344970703122.6496000289917100.037400245666503906-4.433870501660679-1.67011670319295422.29307144543402861.37664593465365684.2984304123552942013.90004365082272.19134921116230432012.49901610545182014.6903653166141
4000946380565269.71004704275265-29.2583186194187231.43372735707951641.47165523030859921123.99720001220703110.0373001098632812522.51849937438965110.0200004577636718751.6111158133637464-6.7456632868311521.96316916518413591.7202803635641434.4095240844353392013.90025407658032.30944127475487142012.49901610545182014.8084573802066
4000946404892269.67530078168915-29.2471627342426751.37639069491067261.613389460139535321224.929399490356445120.0292005538940429723.21535015106201120.06190013885498047-4.240018447223827-5.3013959214746952.32404892866457272.46465178107854675.0340409696458412013.37253173202112.04586304942736242012.3890313766822014.4348944261094
4000946417296269.7016328152704-29.2460704665937433.1308309826369583.18514411287760721125.600500106811523110.2341995239257812524.028099060058594110.25039863586425780.3265864932598421-6.4913946479921566.3967154596976412.57826528259230478.8294470986630282013.77311224404482.019486200362752012.67087911625122014.6903653166141
4000949430259269.722986295747-29.211971120172651.3619639637737381.15890561289665531524.502249717712402140.0661497116088867223.928850173950195140.0568504333496093754.745787093281551-3.41492243483594750.98752439816221490.60066867391504575.0810874604947742004.5674490817626.2125723619169572004.143782912162010.356355274077
4000949692413269.847657491686-29.2134644371428682.36780346719586682.022459781954067321024.422550201416016100.1117000579833984422.581549644470215100.02095031738281251.6834992526734194-14.4904675061560653.47406421445087954.4926563980115825.9461131883186352013.9553403396031.50985393087614852013.29824027250422014.8080942033803
4000949719295269.8230388680129-29.200721201818856.92562390115529252.4988461075181621025.977850914001465100.1077995300292968824.156999588012695100.03194999694824219-0.009307948981069264-9.2555808485828021.85811783298020821.524192442646531415.4735455528271032012.470060074062510.7687844081356622003.43617966200852014.2049640701443
4000979902333269.804403240861-29.1928132654553962.38599567764471271.39284851594804221025.71024990081787100.0653505325317382824.112099647521973100.054700851440429690.7550276872362829-4.77459070250673453.62576861309534771.4617815676884975.0650346984665922013.65899151197162.53086655097392082012.20402848387042014.7348950348442
4000979908546269.8156665822647-29.1898545163315260.91437485936164812.123819200708503721225.4466495513916120.1591005325317382823.336549758911133120.06319999694824219-7.2055855532918205-9.6832928336088782.6182646869419673.07248080976638835.2462673095450552013.83403361107031.60174311365878672013.20635108972152014.8080942033803
4000980227788269.7998513044728-29.197077719265191.84948598148885651.599149165537078421224.400450706481934120.1038999557495117222.93809986114502120.020649909973144530.15278595605010709-7.1721525185359610.6919345570902570.493731637979113745.76197440994000852012.656872142421411.3719145413717642003.43617966200852014.8080942033803

Properties of Full Catalog #

Sky Coverage #

fig, ax = plt.subplots(figsize=(12, 10))
ax.scatter('RA', 'Dec', data=tab, s=1, alpha=0.1)
ax.set(xlabel='RA', ylabel='Dec', title=f'{len(tab)} stars in SWEEPS')
ax.invert_xaxis()
../../../_images/7eff0474f3af7416039fa855dddcf8bdf52848647f3119177acee64df171e57d.png

Proper Motion Histograms #

Proper motion histograms for lon and lat#

bin = 0.2
hrange = (-20, 20)
bincount = int((hrange[1]-hrange[0])/bin + 0.5) + 1

fig, ax = plt.subplots(figsize=(12, 10))
for col, label in zip(['lpm', 'bpm'], ['Longitude', 'Latitude']):
    ax.hist(col, data=tab, range=hrange, bins=bincount, label=label, histtype='step', linewidth=2)
ax.set(xlabel='Proper motion [mas/yr]', ylabel=f'Number [in {bin:.2} mas bins]', title=f'{len(tab):,} stars in SWEEPS')
_ = ax.legend()
../../../_images/6584e496fc32dddc81587d80c411db413463896131fcdf1332339504b0e91547.png

Proper motion error cumulative histogram for lon and lat#

bin = 0.01
hrange = (0, 2)
bincount = int((hrange[1]-hrange[0])/bin + 0.5) + 1

fig, ax = plt.subplots(figsize=(12, 10))
for col, label in zip(['lpmerr', 'bpmerr'], ['Longitude Error', 'Latitude Error']):
    ax.hist(col, data=tab, range=hrange, bins=bincount, label=label, histtype='step', cumulative=1, linewidth=2)
ax.set(xlabel='Proper motion error [mas/yr]', ylabel=f'Cumulative number [in {bin:0.2} mas bins]', title=f'{len(tab):,} stars in SWEEPS')
_ = ax.legend(loc='upper left')
../../../_images/14b46e2e4117be872466ce5b7b0d2f18be0c6dd9df5b35bf14035394eeeb349a.png

Proper motion error log histogram for lon and lat#

bin = 0.01
hrange = (0, 6)
bincount = int((hrange[1]-hrange[0])/bin + 0.5) + 1

fig, ax = plt.subplots(figsize=(12, 10))
for col, label in zip(['lpmerr', 'bpmerr'], ['Longitude Error', 'Latitude Error']):
    ax.hist(col, data=tab, range=hrange, bins=bincount, label=label, histtype='step', linewidth=2)
ax.set(xlabel='Proper motion error [mas/yr]', ylabel=f'Number [in {bin:0.2} mas bins]', title=f'{len(tab):,} stars in SWEEPS', yscale='log')
_ = ax.legend(loc='upper right')
../../../_images/639039dcff53dcbf050ef38c40d1a09f8339ada475fd73d6d64f086bd95cc56d.png

Proper motion error as a function of dT#

Exclude objects with dT near zero, and to improve the plotting add a bit of random noise to spread out the quanitized time values.

# restrict to sources with dT > 1 year
dtmin = 1.0
w = np.where(tab['dT'] > dtmin)[0]
if ('rw' not in locals()) or len(rw) != len(w):
    rw = np.random.random(len(w))

x = np.array(tab['dT'][w]) + 0.5*(rw-0.5)
y = np.log(np.array(tab['lpmerr'][w]))

# Calculate the point density
t0 = time.time()
myPDF, axes = fastKDE.pdf(x.flatten(), y.flatten(), numPoints=2**9+1)
print("kde took {:.1f} sec".format(time.time()-t0))

# interpolate to get z values at points
finterp = RectBivariateSpline(axes[1], axes[0], myPDF)
z = finterp(y, x, grid=False)

# Sort the points by density, so that the densest points are plotted last
idx = z.argsort()
xs, ys, zs = x[idx], y[idx], z[idx]

# select a random subset of points in the most crowded regions to speed up plotting
wran = np.where(np.random.random(len(zs))*zs < 0.05)[0]
print("Plotting {} of {} points".format(len(wran), len(zs)))
xs = xs[wran]
ys = ys[wran]
zs = zs[wran]
kde took 1.6 sec
Plotting 170107 of 442682 points
fig, ax = plt.subplots(figsize=(12, 10))
sc = ax.scatter(xs, np.exp(ys), c=zs, s=2, edgecolors='none', cmap='plasma')
ax.set(xlabel='Date range [yr]', ylabel='Proper motion error [mas/yr]',
       title=f'{len(tab):,} stars in SWEEPS\nLongitude PM error', yscale='log')
_ = fig.colorbar(sc, ax=ax)
../../../_images/0a35b9fb1913900ea97a69b93ada2fadf008d9c566b9f1fca4699801ebadbc61.png

Proper motion error log histogram for lon and lat#

Divide sample into points with \(<6\) years of data and points with more than 6 years of data.

bin = 0.01
hrange = (0, 6)
bincount = int((hrange[1]-hrange[0])/bin + 0.5) + 1

tsplit = 6
dmaglim = 0.05

wmag = np.where((tab['a_f606w_mad'] < dmaglim) & (tab['a_f814w_mad'] < dmaglim))[0]
w1 = wmag[tab['dT'][wmag] <= tsplit]
w2 = wmag[tab['dT'][wmag] > tsplit]
fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(12, 12), sharey=True, tight_layout=True)

for ax, w in zip([ax1, ax2], [w1, w2]):
    for col, label in zip(['lpmerr', 'bpmerr'], ['Longitude Error', 'Latitude Error']):
        data = tab[w]
        ax.hist(col, data=data, range=hrange, bins=bincount, label=label, histtype='step', linewidth=2)
        
ax1.set(xlabel='Proper motion error [mas/yr]', ylabel=f'Number [in {bin:0.2} mas bins]',
        title=f'{len(w1):,} stars in SWEEPS with dT < {tsplit} yrs, dmag < {dmaglim}', yscale='log')
ax2.set(xlabel='Proper motion error [mas/yr]', ylabel=f'Number [in {bin:0.2} mas bins]',
        title=f'{len(w2):,} stars in SWEEPS with dT > {tsplit} yrs, dmag < {dmaglim}', yscale='log')

ax1.legend()
ax2.legend()
<matplotlib.legend.Legend at 0x7f70bbb56910>
../../../_images/552f7a4ca8e7e202b966c976faf501869794a4f41788a61a9b4d8da739f57337.png

Number of Visits Histogram #

bin = 1
hrange = (0, 130)
bincount = int((hrange[1]-hrange[0])/bin + 0.5) + 1

fig, ax = plt.subplots(figsize=(12, 10))
ax.hist('NumVisits', data=tab, range=hrange, bins=bincount, label='Number of visits ', histtype='step', linewidth=2)
ax.set(xlabel='Number of visits', ylabel='Number of objects', title=f'{len(tab):,} stars in SWEEPS')
_ = ax.margins(x=0)
../../../_images/9e1c8f657a91139c6db5541cec043c702fa7f50bcdd8770b0b79f2a318cf5bcb.png

Time Histograms #

First plot histogram of observation dates.

bin = 1
hrange = (2000, 2020)
bincount = int((hrange[1]-hrange[0])/bin + 0.5) + 1

fig, ax = plt.subplots(figsize=(12, 10))
ax.hist('yr', data=tab, range=hrange, bins=bincount, label='year ', histtype='step', linewidth=2)
ax.set(xlabel='mean detection epoch (year)', ylabel='Number of objects', title=f'{len(tab):,} stars in SWEEPS')
ax.set_xticks(ticks=range(2000, 2021, 2))
_ = ax.margins(x=0)
../../../_images/6a986b202c8a7a0d96a5d4f98d01fe1bc72bacdbd108c012295b03d66d416e5f.png

Then plot histogram of observation duration for the objects.

bin = 0.25
hrange = (0, 15)
bincount = int((hrange[1]-hrange[0])/bin + 0.5) + 1

fig, ax = plt.subplots(figsize=(12, 10))
ax.hist('dT', data=tab, range=hrange, bins=bincount, label='year ', histtype='step', linewidth=2)
_ = ax.set(xlabel='time span (years)', ylabel='Number of objects', title=f'{len(tab):,} stars in SWEEPS', yscale='log')
../../../_images/6a7ec14c6cc4aa1ad512782110756fa0e6bc43dcac078ce0bf7f13c6f2d9737b.png

Magnitude Histograms #

Aper2 magnitude histograms for F606W and F814W#

bin = 0.025
hrange = (16, 28)
bincount = int((hrange[1]-hrange[0])/bin + 0.5) + 1

fig, ax = plt.subplots(figsize=(12, 10))
for col, label in zip(['a_f606w', 'a_f814w'], ['F606W', 'F814W']):
    ax.hist(col, data=tab, range=hrange, bins=bincount, label=label, histtype='step', linewidth=2)
ax.set(xlabel='magnitude', ylabel=f'Number [in {bin:0.2} mas bins]', title=f'{len(tab):,} stars in SWEEPS')
_ = ax.legend(loc='upper right')
../../../_images/2b700b638ec16b05addf0669bf3cb0415cc24e53b4596c3e1a68b80fb38ffadf.png

Aper2 magnitude error histograms for F606W and F814W#

bin = 0.001
hrange = (0, 0.2)
bincount = int((hrange[1]-hrange[0])/bin + 0.5) + 1

fig, ax = plt.subplots(figsize=(12, 10))
for col, label in zip(['a_f606w_mad', 'a_f814w_mad'], ['F606W', 'F814W']):
    ax.hist(col, data=tab, range=hrange, bins=bincount, label=label, histtype='step', linewidth=2)
ax.set(xlabel='magnitude error (median absolute deviation)', ylabel=f'Number of stars[in {bin:0.2} magnitude bins]',
       title=f'{len(tab):,} stars in SWEEPS')
_ = ax.legend(loc='upper right')
../../../_images/333195b712cf9ec5ab9d54532aa990df6b46211f2d41fb01aa34c52e174fd7e1.png

Color-Magnitude Diagram #

Color-magnitude diagram#

Plot the color-magnitude diagram for the ~440k points retrieved from the database. This uses fastkde to compute the kernel density estimate for the crowded plot, which is very fast. See https://pypi.org/project/fastkde/ for instructions – or just do
pip install fastkde

f606w = tab['a_f606w']
f814w = tab['a_f814w']
RminusI = f606w-f814w

# Calculate the point density
w = np.where((RminusI > -1) & (RminusI < 4))[0]
x = np.array(RminusI[w])
y = np.array(f606w[w])
t0 = time.time()
myPDF, axes = fastKDE.pdf(x, y, numPoints=2**10+1)
print("kde took {:.1f} sec".format(time.time()-t0))

# interpolate to get z values at points
finterp = RectBivariateSpline(axes[1], axes[0], myPDF)
z = finterp(y, x, grid=False)

# Sort the points by density, so that the densest points are plotted last
idx = z.argsort()
xs, ys, zs = x[idx], y[idx], z[idx]

# select a random subset of points in the most crowded regions to speed up plotting
wran = np.where(np.random.random(len(zs))*zs < 0.05)[0]
print(f"Plotting {len(wran)} of {len(zs)} points")
xs = xs[wran]
ys = ys[wran]
zs = zs[wran]
kde took 1.8 sec
Plotting 147298 of 443502 points
fig, ax = plt.subplots(figsize=(12, 10))
sc = ax.scatter(xs, ys, c=zs, s=2, edgecolors='none', cmap='plasma')
ax.set(xlabel='A_F606W - A_F814W', ylabel='A_F606W', title=f'{len(x):,} stars in SWEEPS')
ax.invert_yaxis()
fig.colorbar(sc, ax=ax)
<matplotlib.colorbar.Colorbar at 0x7f70e567c2d0>
../../../_images/e2588c3a6284b71f34b228fb6b5e0259909f71bf3fa87b1d5f41c8dd6648d18e.png

Detection Positions #

Define a function to plot the PM fit for an object.

# define function
def positions(Obj, jobs=None):
    """
    input parameter Obj is the value of the ObjID 
    optional jobs parameter re-uses casjobs jobs variable
    output plots change in (lon, lat) as a function of time
    overplots proper motion fit
    provides number of objects and magnitude/color information
    """
    if not jobs:
        jobs = mastcasjobs.MastCasJobs(context=HSCContext)

    # execute these as "system" queries so they don't fill up your Casjobs history

    # get the measured positions as a function of time
    query = f"""SELECT dT, dLon, dLat 
        from AstromSourcePositions where ObjID={Obj}
        order by dT
        """
    pos = jobs.quick(query, context=HSCContext, task_name="SWEEPS/Microlensing", astropy=True, system=True)
    
    # get the PM fit parameters
    query = f"""SELECT pmlon, pmlonerr, pmlat, pmlaterr
        from AstromProperMotions where ObjID={Obj}
        """
    pm = jobs.quick(query, context=HSCContext, task_name="SWEEPS/Microlensing", astropy=True, system=True)
    
    lpm = pm['pmlon'][0]
    bpm = pm['pmlat'][0]
    
    # get the intercept for the proper motion fit referenced to the start time
    # time between mean epoch and zero (ref) epoch (years)

    # get median magnitudes and colors for labeling
    query = f"""SELECT a_f606w=i1.MagMed, a_f606_m_f814w=i1.MagMed-i2.MagMed
        from AstromSumMagAper2 i1 
        join AstromSumMagAper2 i2 on i1.ObjID=i2.ObjID 
        where i1.ObjID={Obj} and i1.filter='f606w' and i2.filter='f814w' 
        """
    phot = jobs.quick(query, context=HSCContext, task_name="SWEEPS/Microlensing", astropy=True, system=True)
    f606w = phot['a_f606w'][0]
    f606wmf814w = phot['a_f606_m_f814w'][0]

    x = pos['dT']
    # xpm = np.linspace(0, max(x), 10)
    xpm = np.array([x.min(), x.max()])
        
    y1 = pos['dLon']
    ypm1 = lpm*xpm
    
    y2 = pos['dLat']
    ypm2 = bpm*xpm

    # plot figure
    fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(6, 3), tight_layout=True)
    
    ax1.scatter(x, y1, s=10)
    ax1.plot(xpm, ypm1, '-r')
    
    ax2.scatter(x, y2, s=10)
    ax2.plot(xpm, ypm2, '-r')
    
    ax1.set_xlabel('dT (yrs)', fontsize=10)
    ax1.set_ylabel('dLon (mas)', fontsize=10)
    ax2.set_xlabel('dT (yrs)', fontsize=10)
    ax2.set_ylabel('dLat (mas)', fontsize=10)
    
    fig.suptitle(f"ObjID {Obj}"
                 f"\n{len(x)} detections, (lpm, bpm) = ({lpm:.1f}, {bpm:.1f}) mas/yr"
                 f"\n(f606w, f606w-f814w) = ({f606w:.1f}, {f606wmf814w:.1f})", size=10)
    
    plt.show()
    plt.close()

Plot positions of objects that are detected in more than 90 visits with a median absolute deviation from the fit of less than 1.5 mas and proper motion error less than 1.0 mas/yr.

n = tab['NumVisits']
dev = tab['pmdev']
objid = tab['ObjID']
lpmerr0 = np.array(tab['lpmerr'])
bpmerr0 = np.array(tab['bpmerr'])
wi = np.where((dev < 1.5) & (n > 90) & (np.sqrt(bpmerr0**2+lpmerr0**2) < 1.0))[0]
print(f"Plotting {len(wi)} objects")
for o in objid[wi]:
    positions(o, jobs=jobs)
Plotting 21 objects
../../../_images/ea9a0ee837255d590baf0ae5957554f9492c886755dc9fec67a25004c0e87653.png ../../../_images/61a7b21360753385c503efc141b2836e6b4b9d6aef17977fa9ed96dcea145fd6.png ../../../_images/e5c581bc0ddd8debe47e159262bd408c21711ee14ab0b85578479330ee020773.png ../../../_images/1768f64790ade5a91a5ee56f5aba3530a06cfe37fd8798bf5d739c117bf14c26.png ../../../_images/b8b3ec4d2b2a92af1d6be7102ee206610cad71af6cdd32858eeafe16852f25d6.png ../../../_images/acc63d29e8ce7e02a0f7351a1412efd5191d05497674c54cae944936db21332e.png ../../../_images/be95fee43b1ffd856bf6c34948afe004abd20d7f51498cd8e505ac4097c91878.png ../../../_images/dbfde35ed6368a814319dffbb734067a86ac638cb2a33d661a526aae7d063873.png ../../../_images/dda1edd59713847f89207d10a7b24aede18365dd73770250c11aceb058a37b4c.png ../../../_images/6ea89a15fa39b7a04df9563ec4a6f3966a83fe36d7ceedc3ecbe64ca4d52a707.png ../../../_images/6b3d53f3561c624597301bb70e1973a6afc0f4b5d50f93043762169ca5457df1.png ../../../_images/cd47824504798203188b31b367a0d1add984a616bb122a37c3034e58ad08837f.png ../../../_images/f08c9045561bce7fcbceedfb7a7dc232d262ef53a010065ba038df0db7ec0a00.png ../../../_images/5e23f36558b51b7d0004c850f9c364ec65e4ee9865ba7b3bdb7c0b374605d478.png ../../../_images/9d0af576f4f7592aeeea3e2a54f4dcc18b34cac853918ea14bb77d3d1c4a53e5.png ../../../_images/8d8a9275ab8075087038a837373e82d2efe8c8568e1cec79dc0bc4c75ca955ef.png ../../../_images/ac8b2f6685e78c4ffac54f4c7363fef5b2a34e333608e8ba23c25f48a54bf337.png ../../../_images/f3d3b0f7edf9f1b4b041d829dc5c6ab4c0e5f8399d53ebbd3746290cc369aa48.png ../../../_images/024d57564bce735e7adaad56b9640843614d4345e79e675039b7fbccda1c2fc1.png ../../../_images/d2fc074b2dc476c826d152531a654d7766a516f6240318755a93209309626ce9.png ../../../_images/866e96ef2e6b6ca30a2493838c4b76b3fb4d7b06e58b1594b6b9fc779f4bcb3a.png

Good Photometric Objects #

Look at photometric error distribution to pick out good photometry objects as a function of magnitude #

The photometric error is mainly a function of magnitude. We make a cut slightly above the typical error to exclude objects that have poor photometry. (In the SWEEPS field, that most often is the result of blending and crowding.)

f606w = tab['a_f606w']
f814w = tab['a_f814w']
RminusI = f606w-f814w

w = np.where((RminusI > -1) & (RminusI < 4))[0]
f606w_mad = tab['a_f606w_mad']
f814w_mad = tab['a_f814w_mad']

t0 = time.time()
# Calculate the point density
x1 = np.array(f606w[w])
y1 = np.array(f606w_mad[w])
y1log = np.log(y1)
myPDF1, axes1 = fastKDE.pdf(x1, y1log, numPoints=2**10+1)
finterp = RectBivariateSpline(axes1[1], axes1[0], myPDF1)
z1 = finterp(y1log, x1, grid=False)
# Sort the points by density, so that the densest points are plotted last
idx = z1.argsort()
xs1, ys1, zs1 = x1[idx], y1[idx], z1[idx]

# select a random subset of points in the most crowded regions to speed up plotting
wran = np.where(np.random.random(len(zs1))*zs1 < 0.05)[0]
print(f"Plotting {len(wran)} of {len(zs1)} points")
xs1 = xs1[wran]
ys1 = ys1[wran]
zs1 = zs1[wran]

x2 = np.array(f814w[w])
y2 = np.array(f814w_mad[w])
y2log = np.log(y2)
myPDF2, axes2 = fastKDE.pdf(x2, y2log, numPoints=2**10+1)
finterp = RectBivariateSpline(axes2[1], axes2[0], myPDF2)
z2 = finterp(y2log, x2, grid=False)
idx = z2.argsort()
xs2, ys2, zs2 = x2[idx], y2[idx], z2[idx]
print(f"{(time.time()-t0):.1f} s: completed kde")

# select a random subset of points in the most crowded regions to speed up plotting
wran = np.where(np.random.random(len(zs2))*zs2 < 0.05)[0]
print(f"Plotting {len(wran)} of {len(zs2)} points")
xs2 = xs2[wran]
ys2 = ys2[wran]
zs2 = zs2[wran]

xr = (18, 27)
xx = np.arange(501)*(xr[1]-xr[0])/500.0 + xr[0]
xcut1 = 24.2
xnorm1 = 0.03
xcut2 = 23.0
xnorm2 = 0.03

# only plot a subset of the points to speed things up
qsel = 3
xs1 = xs1[::qsel]
ys1 = ys1[::qsel]
zs1 = zs1[::qsel]
xs2 = xs2[::qsel]
ys2 = ys2[::qsel]
zs2 = zs2[::qsel]
Plotting 274288 of 443502 points
4.4 s: completed kde
Plotting 250981 of 443502 points
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(15, 8), tight_layout=True)

ax1.scatter(xs1, ys1, c=zs1, s=2, edgecolors='none', cmap='plasma')
ax1.plot(xx, xnorm1 * (1. + 10.**(0.4*(xx-xcut1))), linewidth=2.0,
         label=f'${xnorm1:.2f} (1+10^{{0.4(M-{xcut1:.1f})}})$')

ax2.scatter(xs2, ys2, c=zs2, s=2, edgecolors='none', cmap='plasma')
ax2.plot(xx, xnorm2 * (1. + 10.**(0.4*(xx-xcut2))), linewidth=2.0,
         label=f'${xnorm2:.2f} (1+10^{{0.4(M-{xcut2:.1f})}})$')

ax1.legend(loc='upper left')
ax2.legend(loc='upper left')

ax1.set(xlabel='F606W', ylabel='F606W_MAD', yscale='log')
ax2.set(xlabel='F814W', ylabel='F814W_MAD', yscale='log')
[Text(0.5, 0, 'F814W'), Text(0, 0.5, 'F814W_MAD'), None]
../../../_images/cd2a11468eb15bc6945ed471a40b7dafe11c66ca2dd50fd344292efdf9ea0d6d.png

Define function to apply noise cut and plot color-magnitude diagram with cut#

Note that we reduce the R-I range to 0-3 here because there are very few objects left bluer than R-I = 0 or redder than R-I = 3.

def noisecut(tab, factor=1.0):
    """Return boolean array with noise cut in f606w and f814w using model
    factor is normalization factor to use (>1 means allow more noise)
    """
    f606w = tab['a_f606w']
    f814w = tab['a_f814w']
    f606w_mad = tab['a_f606w_mad']
    f814w_mad = tab['a_f814w_mad']
    
    # noise model computed above
    xcut_f606w = 24.2
    xnorm_f606w = 0.03 * factor
    xcut_f814w = 23.0
    xnorm_f814w = 0.03 * factor
    return ((f606w_mad < xnorm_f606w*(1+10.0**(0.4*(f606w-xcut_f606w))))
            & (f814w_mad < xnorm_f814w*(1+10.0**(0.4*(f814w-xcut_f814w)))))
# low-noise objects
good = noisecut(tab, factor=1.0)

# Calculate the point density
w = np.where((RminusI > 0) & (RminusI < 3) & good)[0]
x = np.array(RminusI[w])
y = np.array(f606w[w])
t0 = time.time()
myPDF, axes = fastKDE.pdf(x, y, numPoints=2**10+1)
print(f"kde took {(time.time()-t0):.1f} sec")

# interpolate to get z values at points
finterp = RectBivariateSpline(axes[1], axes[0], myPDF)
z = finterp(y, x, grid=False)

# Sort the points by density, so that the densest points are plotted last
idx = z.argsort()
xs, ys, zs = x[idx], y[idx], z[idx]

# select a random subset of points in the most crowded regions to speed up plotting
wran = np.where(np.random.random(len(zs))*zs < 0.075)[0]
print(f"Plotting {len(wran)} of {len(zs)} points")
xs = xs[wran]
ys = ys[wran]
zs = zs[wran]
kde took 1.5 sec
Plotting 129587 of 333525 points
fig, ax = plt.subplots(figsize=(12, 10))

sc = ax.scatter(xs, ys, c=zs, s=2, edgecolors='none', cmap='plasma')
ax.set(xlabel='A_F606W - A_F814W', ylabel='A_F606W',
       title=f'{len(x):,} stars in SWEEPS', xlim=(-1, 4), ylim=(27.5, 17.5))
_ = fig.colorbar(sc, ax=ax)
../../../_images/23c8635b52b86b1011f21907a2d61a70a1f32b89642dda7610d48f4e4a161d2d.png

Science Applications #

Proper Motions of Good Objects #

Average proper motion in color-magnitude bins#

# good defined above
f606w = tab['a_f606w']
f814w = tab['a_f814w']
RminusI = f606w-f814w
w = np.where((RminusI > 0) & (RminusI < 3) & good)[0]
lpm = np.array(tab['lpm'][w])
bpm = np.array(tab['bpm'][w])
x = np.array(RminusI[w])
y = np.array(f606w[w])

nbins = 50
count2d, yedge, xedge = np.histogram2d(y, x, bins=nbins)
lpm_sum = np.histogram2d(y, x, bins=nbins, weights=lpm-lpm.mean())[0]
bpm_sum = np.histogram2d(y, x, bins=nbins, weights=bpm-bpm.mean())[0]
lpm_sumsq = np.histogram2d(y, x, bins=nbins, weights=(lpm-lpm.mean())**2)[0]
bpm_sumsq = np.histogram2d(y, x, bins=nbins, weights=(bpm-bpm.mean())**2)[0]

ccount = count2d.clip(1) 
lpm_mean = lpm_sum/ccount
bpm_mean = bpm_sum/ccount
lpm_rms = np.sqrt(lpm_sumsq/ccount-lpm_mean**2)
bpm_rms = np.sqrt(bpm_sumsq/ccount-bpm_mean**2)
lpm_msigma = lpm_rms/np.sqrt(ccount)
bpm_msigma = bpm_rms/np.sqrt(ccount)

ww = np.where(count2d > 100)
yy, xx = np.mgrid[:nbins, :nbins]
xx = (0.5*(xedge[1:]+xedge[:-1]))[xx]
yy = (0.5*(yedge[1:]+yedge[:-1]))[yy]
fig, ax = plt.subplots(figsize=(12, 10))

Q = ax.quiver(xx[ww], yy[ww], lpm_mean[ww], bpm_mean[ww], color='red', width=0.0015)
qlength = 5
ax.quiverkey(Q, 0.8, 0.97, qlength, f'{qlength} mas/yr', coordinates='axes', labelpos='W')
ax.invert_yaxis()
_ = ax.set(xlabel='A_F606W - A_F814W', ylabel='A_F606W',
           xlim=(xedge[0], xedge[-1]), ylim=(yedge[-1], yedge[0]))
../../../_images/47b8ccb3cf20dde7e1dbe76f068bc4c04e4cb2abe9b53f211b440a6fa669e084.png

RMS in longitude PM as a function of color/magnitude#

Mean longitude PM as image#

fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(20, 6), tight_layout=True, sharey=True)

# plot ax1
p1 = ax1.scatter(xs, ys, c=zs, s=2, edgecolors='none', cmap='plasma')
ax1.set(xlabel='A_F606W - A_F814W', ylabel='A_F606W',
        title=f'Color-magnitude\n{len(x):,} stars in SWEEPS')
ax1.set(xlim=(xedge[0], xedge[-1]), ylim=(yedge[0], yedge[-1]))
ax1.invert_yaxis()
fig.colorbar(p1, ax=ax1)

# plot ax2
mask = (lpm_msigma <= 1.0) & (count2d > 10)
im2 = (lpm_mean+lpm.mean())*mask
im2[~mask] = np.nan
vmax = np.nanmax(np.abs(im2))

p2 = ax2.imshow(im2, cmap='RdYlGn', aspect="auto", origin="lower",
                extent=(xedge[0], xedge[-1], yedge[0], yedge[-1]))
ax2.set(xlabel='A_F606W - A_F814W',
        title='Mean Longitude PM\n$\\sigma(\\mathrm{PM}) \\leq 1$ and $N > 10$')
ax2.set(xlim=(xedge[0], xedge[-1]), ylim=(yedge[0], yedge[-1]))
ax2.invert_yaxis()
cb2 = fig.colorbar(p2, ax=ax2)
cb2.ax.set_ylabel('mas/yr', rotation=270, labelpad=15)

# plat ax3
im3 = lpm_rms*(count2d > 10)

p3 = ax3.imshow(im3, cmap='magma', aspect="auto", origin="lower",
                extent=(xedge[0], xedge[-1], yedge[0], yedge[-1]),
                norm=LogNorm(vmin=im3[im3 > 0].min(), vmax=im3.max()))
ax3.set(xlabel='A_F606W - A_F814W',
        title='RMS in Longitude PM\nN > 10')
ax3.set(xlim=(xedge[0], xedge[-1]), ylim=(yedge[0], yedge[-1]))
ax3.invert_yaxis()
cb3 = fig.colorbar(p3, ax=ax3)
_ = cb3.ax.set_ylabel('mas/yr', rotation=270)
../../../_images/1eae4673dab1b8569469f8e46c022ba759226dbe4016734ffcaff238510f66bd.png

Mean latitude PM as image#

fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(20, 6), tight_layout=True, sharey=True)

# plot ax1
p1 = ax1.scatter(xs, ys, c=zs, s=2, edgecolors='none', cmap='plasma')
ax1.set(xlabel='A_F606W - A_F814W', ylabel='A_F606W',
        title=f'Color-magnitude\n{len(x):,} stars in SWEEPS')
ax1.set(xlim=(xedge[0], xedge[-1]), ylim=(yedge[0], yedge[-1]))
ax1.invert_yaxis()
fig.colorbar(p1, ax=ax1)

# plot ax2
mask = (bpm_msigma <= 1.0) & (count2d > 10)
im2 = (bpm_mean+bpm.mean())*mask
im2[~mask] = np.nan
vmax = np.nanmax(np.abs(im2))

p2 = ax2.imshow(im2, cmap='RdYlGn', aspect="auto", origin="lower",
                extent=(xedge[0], xedge[-1], yedge[0], yedge[-1]))
ax2.set(xlabel='A_F606W - A_F814W',
        title='Mean Latitude PM\n$\\sigma(\\mathrm{PM}) \\leq 1$ and $N > 10$')
ax2.set(xlim=(xedge[0], xedge[-1]), ylim=(yedge[0], yedge[-1]))
ax2.invert_yaxis()
cb2 = fig.colorbar(p2, ax=ax2)
cb2.ax.set_ylabel('mas/yr', rotation=270, labelpad=15)

# plot ax3
im3 = bpm_rms*(count2d > 10)

p3 = ax3.imshow(im3, cmap='magma', aspect="auto", origin="lower",
                extent=(xedge[0], xedge[-1], yedge[0], yedge[-1]),
                norm=LogNorm(vmin=im3[im3 > 0].min(), vmax=im3.max()))
ax3.set(xlabel='A_F606W - A_F814W',
        title='RMS in Latitude PM\nN > 10')
ax3.set(xlim=(xedge[0], xedge[-1]), ylim=(yedge[0], yedge[-1]))
ax3.invert_yaxis()
cb3 = fig.colorbar(p3, ax=ax3)
_ = cb3.ax.set_ylabel('mas/yr', rotation=270)
../../../_images/c6b09e3319d05d6c053ac54ff0af121b60adbcfe50cd2503d5a2304cd908dcf3.png

Proper Motions in Bulge and Disk #

Fit a smooth function to the main ridgeline of color-magnitude diagram#

Fit the R-I vs R values, but force the function to increase montonically with R. We use a log transform of the y coordinate to help.

# locate ridge line
iridgex = np.argmax(myPDF, axis=1)
pdfx = myPDF[np.arange(len(iridgex), dtype=int), iridgex]
# pdfx = myPDF.max(axis=1)
wx = np.where(pdfx > 0.1)[0]
iridgex = iridgex[wx]
# use weighted sum of 2*hw+1 points around peak
hw = 10
pridgex = 0.0
pdenom = 0.0
for k in range(-hw, hw+1):
    wt = myPDF[wx, iridgex+k]
    pridgex = pridgex + k*wt
    pdenom = pdenom + wt
pridgex = iridgex + pridgex/pdenom
ridgex = np.interp(pridgex, np.arange(len(axes[0])), axes[0])

# Fit the data using a polynomial model
x0 = axes[1][wx].min()
x1 = axes[1][wx].max()
p_init = models.Polynomial1D(9)
fit_p = fitting.LinearLSQFitter()
xx = (axes[1][wx]-x0)/(x1-x0)
yoff = 0.65
yy = np.log(ridgex - yoff)
p = fit_p(p_init, xx, yy)

# define useful functions for the ridge line


def ridge_color(f606w, function=p, yoff=yoff, x0=x0, x1=x1):
    """Return R-I position of ridge line as a function of f606w magnitude
    
    function, yoff, x0, x1 are from polynomial fit above
    """
    return yoff + np.exp(p((f606w-x0)/(x1-x0)))


# calculate grid of function values for approximate inversion
rxgrid = axes[1][wx]
rygrid = ridge_color(rxgrid)
color_domain = [rygrid[0], rygrid[-1]]
mag_domain = [axes[1][wx[0]], axes[1][wx[-1]]]
print(f"color_domain {color_domain}")
print(f"mag_domain   {mag_domain}")


def ridge_mag(RminusI, xgrid=rxgrid, ygrid=rygrid):
    """Return f606w position of ridge line as a function of R-I color
    
    Uses simple linear interpolation to get approximate value
    """
    f606w = np.interp(RminusI, ygrid, xgrid)
    f606w[(RminusI < ygrid[0]) | (RminusI > ygrid[-1])] = np.nan
    return f606w
color_domain [0.6883374859498668, 2.156051675824816]
mag_domain   [19.356585323810577, 26.480549454689026]

Plot the results to check that they look reasonable.

ridgexf = yoff + np.exp(p(xx))

fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(12, 6), tight_layout=True)

ax1.plot(axes[1][wx], ridgex, 'bo')
ax1.plot(axes[1][wx], ridgexf, color='red')
ax1.set(xlabel='R', ylabel='R-I')

# check the derivative plot to see if it stays positive
deriv = (np.exp(p(xx)) * 
         models.Polynomial1D.horner(xx, (p.parameters * np.arange(len(p.parameters)))[1:]))

ax2.semilogy(axes[1][wx], np.exp(p(xx)) *
             models.Polynomial1D.horner(xx, (p.parameters * np.arange(len(p.parameters)))[1:]), color='red')
_ = ax2.set(xlabel='R', ylabel='Fit derivative', title=f'Min deriv {deriv.min():.6f}')
../../../_images/5248b4699e101eaa59566f08f99c77fb0ff1ecbe97dbfb81ce1f2f02bd155343.png

Plot the ridgeline on the CMD#

fig, ax = plt.subplots(figsize=(12, 10))

sc = ax.scatter(xs, ys, c=zs, s=2, edgecolors='none', cmap='plasma')

# overplot ridge line
ax.plot(ridge_color(axes[1][wx]), axes[1][wx], color='red')
ax.plot(axes[0], ridge_mag(axes[0]), color='green')

ax.set(xlabel='A_F606W - A_F814W', ylabel='A_F606W',
       title=f'Color-magnitude\n{len(x):,} stars in SWEEPS',
       xlim=(xedge[0], xedge[-1]), ylim=(yedge[0], yedge[-1]))
ax.invert_yaxis()
_ = fig.colorbar(sc, ax=ax)
../../../_images/c4f48bcdf29bfd5196f0885d136573417894a80306080c59cae91ad1197b4ba0.png

Binned distribution of PM(Long) vs magnitude offset from ridge line#

yloc = ridge_mag(x)
x1 = x[np.isfinite(yloc)]
wy = np.where((axes[0] >= x1.min()) & (axes[0] <= x1.max()))[0]
ridgey = ridge_mag(axes[0][wy])

# Weighted histogram
dmagmin = -2.0
dmagmax = 1.0
xmax = axes[0][wy[-1]]
# xmin = axes[0][wy[0]]
xmin = 1.0
wsel = np.where((y-yloc >= dmagmin) & (y-yloc <= dmagmax) & (x >= xmin) & (x <= xmax))[0]

x2 = y[wsel]-yloc[wsel]
y2 = lpm[wsel]-lpm.mean()
hrange = (dmagmin, dmagmax)
hbins = 50
count1d, xedge1d = np.histogram(x2, range=hrange, bins=hbins)
lpm_sum1d = np.histogram(x2, range=hrange, bins=hbins, weights=y2)[0]
lpm_sumsq1d = np.histogram(x2, range=hrange, bins=hbins, weights=y2**2)[0]

ccount1d = count1d.clip(1)
lpm_mean1d = lpm_sum1d/ccount1d
lpm_rms1d = np.sqrt(lpm_sumsq1d/ccount1d-lpm_mean1d**2)
lpm_msigma1d = lpm_rms1d/np.sqrt(ccount1d)
lpm_mean1d += lpm.mean()

x1d = 0.5*(xedge1d[1:]+xedge1d[:-1])

xboundary = np.hstack((axes[0][wy], axes[0][wy[::-1]]))
yboundary = np.hstack((ridgey+dmagmax, ridgey[::-1]+dmagmin))
wb = np.where((xboundary >= xmin) & (xboundary <= xmax))
xboundary = xboundary[wb]
yboundary = yboundary[wb]
print(xboundary[0], yboundary[0], xboundary[-1], yboundary[-1])
print(xboundary.shape, yboundary.shape)
xboundary = np.append(xboundary, xboundary[0])
yboundary = np.append(yboundary, yboundary[0])

# don't plot huge error points
wp = np.where(lpm_msigma1d < 1)
1.0020693112164736 23.784969024110392 1.0020693112164736 20.784969024110392
(394,) (394,)
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(14, 7), tight_layout=True)

ax1.scatter(xs, ys, c=zs, s=2, edgecolors='none', cmap='plasma')
ax1.plot(xboundary, yboundary, color='red')
ax1.set(xlabel='R - I (A_F606W - A_F814W)', ylabel='R (A_F606W)',
        title=f'Color-magnitude\n{len(x):,} stars in SWEEPS',
        xlim=(xedge[0], xedge[-1]), ylim=(yedge[0], yedge[-1]))
ax1.invert_yaxis()

ax2.errorbar(x1d[wp], lpm_mean1d[wp], xerr=(xedge1d[1]-xedge1d[0])/2.0, yerr=lpm_msigma1d[wp], linestyle='')
ax2.set(xlabel='Distance from ridge line [R mag]', ylabel='Mean Longitude PM [mas/yr]',
        title=f'{len(x2):,} stars in SWEEPS\n1-sigma error bars on mean PM')
ax2.invert_xaxis()
../../../_images/ba49f0022f23f6aa2a9e70908d90d19e6ebd054c5dbed5a7b160789baa8051d4.png

Reproduce Figure 1 from Calamida et al. 2014#

image

w = np.where((RminusI > 0) & (RminusI < 3) & good)[0]

# Calculate the point density
x = np.array(RminusI[w])
y = np.array(f606w[w])
myPDF, axes = fastKDE.pdf(x, y, numPoints=2**10+1)
finterp = RectBivariateSpline(axes[1], axes[0], myPDF)
z = finterp(y, x, grid=False)
idx = z.argsort()
xs, ys, zs = x[idx], y[idx], z[idx]

# select a random subset of points in the most crowded regions to speed up plotting
wran = np.where(np.random.random(len(zs))*zs < 0.1)[0]
print(f"Plotting {len(wran)} of {len(zs)} points")
xs = xs[wran]
ys = ys[wran]
zs = zs[wran]

# locate ridge line in magnitude as a function of color
xloc = ridge_color(y)
ridgex = ridge_color(axes[1][wx])

# locate ridge line in color as function of magnitude
yloc = ridge_mag(x)
x1 = x[np.isfinite(yloc)]
wy = np.where((axes[0] >= x1.min()) & (axes[0] <= x1.max()))[0]
ridgey = ridge_mag(axes[0][wy])

# low-noise objects
print(f"Selected {len(w):,} low-noise objects")

# red objects
ylim = yloc - 1.5 - (yloc - 25.0).clip(0)/(1+10.0**(-0.4*(yloc-26.0)))
wred = np.where((y < 25) & (y > 19.5) & (y < ylim) & (x-xloc > 0.35))[0]
# wred = np.where((y<25) & (y > 19.5) & ((y-yloc) < -1.5)
#                   & (x-xloc > 0.3))[0]
#                   & (x > 1.1) & (x < 2.5) & (x-xloc > 0.2))[0]
print(f"Selected {len(wred):,} red objects")
# main sequence objects
wmain = np.where((y > 21) & (y < 22.4) & (np.abs(x-xloc) < 0.1))[0]
print(f"Initially selected {len(wmain):,} MS objects")
# sort by distance from ridge and select the closest
wmain = wmain[np.argsort(np.abs(x[wmain]-xloc[wmain]))]
wmain = wmain[:len(wred)]
print(f"Selected {len(wmain):,} MS objects closest to ridge")
Plotting 156300 of 333525 points
Selected 333,525 low-noise objects
Selected 2,797 red objects
Initially selected 59,605 MS objects
Selected 2,797 MS objects closest to ridge
fig = plt.figure(figsize=(12, 8), tight_layout=True)
gs = gridspec.GridSpec(2, 2, width_ratios=[2, 1])

ax1 = fig.add_subplot(gs[:, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[1, 1])

# plot ax1
ax1.scatter(xs, ys, c=zs, s=2, cmap='plasma', edgecolors='none')
ax1.scatter(x[wred], y[wred], c='red', s=2, edgecolors='none')
ax1.scatter(x[wmain], y[wmain], c='blue', s=2, edgecolors='none')
ax1.set(xlabel='F606W-F814W [mag]', ylabel='F606W [mag]', title=f'{len(x):,} stars in SWEEPS',
        xlim=(0, 3), ylim=(18, 27.5))
ax1.invert_yaxis()

# plot ax2
lrange = (-20, 5)
brange = (-12.5, 12.5)

# MS and red points in random order
wsel = w[np.append(wmain, wred)]
colors = np.array(['blue']*len(wsel))
colors[len(wmain):] = 'red'
irs = np.argsort(np.random.random(len(wsel)))
wsel = wsel[irs]
colors = colors[irs]

masks = [w, wsel]
sizes = [0.1, 2]
colors2 = ['darkgray', colors]

for mask, color, size in zip(masks, colors2, sizes):
    ax2.scatter('lpm', 'bpm', data=tab[mask], c=color, s=size)

ax2.set(ylabel='Latitude PM [mas/yr]', xlim=lrange, ylim=brange)

# plot ax3
bins = 0.5
bincount = int((lrange[1]-lrange[0])/bins + 0.5) + 1

masks = [w[wmain], w[wred]]
labels = ['MS', 'Red']
colors = ['b', 'r']

for mask, label, color in zip(masks, labels, colors):
    ax3.hist('lpm', data=tab[mask], range=lrange, bins=bincount, label=label, color=color, histtype='step')

ax3.set(xlabel='Longitude PM [mas/yr]', ylabel=f'Number [in {bins:.2} mas bins]')
_ = ax3.legend(loc='upper left')
../../../_images/1ec9247f7db107f58155d0e521cc28ab1919b0833847ab749373ff1919aad886.png

Mean and median proper motions of bulge stars compared with SgrA*#

(-6.379 \(\pm\) 0.026, -0.202 \(\pm\) 0.019) mas/yr Reid and Brunthaler (2004)

lpmmain = np.mean(tab['lpm'][w[wmain]])
bpmmain = np.mean(tab['bpm'][w[wmain]])

norm = 1.0/np.sqrt(len(tab['lpm'][w[wmain]]))
print("Bulge stars mean PM longitude {:.2f} +- {:.3f} latitude {:.2f} +- {:.3f}".format(
    np.mean(tab['lpm'][w[wmain]]), norm*np.std(tab['lpm'][w[wmain]]),
    np.mean(tab['bpm'][w[wmain]]), norm*np.std(tab['bpm'][w[wmain]])
    ))

norm = 1.2533/np.sqrt(len(tab['lpm'][w[wmain]]))
print("Bulge stars median PM longitude {:.2f} +- {:.3f} latitude {:.2f} +- {:.3f}".format(
    np.median(tab['lpm'][w[wmain]]), norm*np.std(tab['lpm'][w[wmain]]),
    np.median(tab['bpm'][w[wmain]]), norm*np.std(tab['bpm'][w[wmain]])
    ))
Bulge stars mean PM longitude -6.31 +- 0.059 latitude -0.13 +- 0.053
Bulge stars median PM longitude -6.45 +- 0.074 latitude -0.13 +- 0.067

White Dwarfs #

w = np.where((RminusI > 0) & (RminusI < 3) & good)[0]

wwd = np.where((RminusI < 0.7)
               & (RminusI > 0) 
               & (f606w > 22.5) 
               & good 
               & (tab['lpm'] < 5) 
               & (tab['lpm'] > -20))[0]
xwd = np.array(RminusI[wwd])
ywd = np.array(f606w[wwd])

# Calculate the point density
x = np.array(RminusI[w])
y = np.array(f606w[w])

myPDF, axes = fastKDE.pdf(x, y, numPoints=2**10+1)
finterp = RectBivariateSpline(axes[1], axes[0], myPDF)
z = finterp(y, x, grid=False)
idx = z.argsort()
xs, ys, zs = x[idx], y[idx], z[idx]

# select a random subset of points in the most crowded regions to speed up plotting
wran = np.where(np.random.random(len(zs))*zs < 0.1)[0]
print(f"Plotting {len(wran)} of {len(zs)} points")
xs = xs[wran]
ys = ys[wran]
zs = zs[wran]

# locate ridge line in magnitude as a function of color
xloc = ridge_color(y)
ridgex = ridge_color(axes[1][wx])

# locate ridge line in color as function of magnitude
yloc = ridge_mag(x)
x1 = x[np.isfinite(yloc)]
wy = np.where((axes[0] >= x1.min()) & (axes[0] <= x1.max()))[0]
ridgey = ridge_mag(axes[0][wy])

# low-noise objects
print(f"Selected {len(w):,} low-noise objects")

# red objects
ylim = yloc - 1.5 - (yloc - 25.0).clip(0)/(1+10.0**(-0.4*(yloc-26.0)))
wred = np.where((y < 25) & (y > 19.5) & (y < ylim) & (x-xloc > 0.35))[0]
# wred = np.where((y < 25) & (y > 19.5) & ((y-yloc) < -1.5)
#                   & (x-xloc > 0.3))[0]
#                   & (x > 1.1) & (x < 2.5) & (x-xloc > 0.2))[0]
print("Selected {:,} red objects".format(len(wred)))
# main sequence objects
wmain = np.where((y > 21) & (y < 22.4) & (np.abs(x-xloc) < 0.1))[0]
print("Initially selected {:,} MS objects".format(len(wmain)))
# sort by distance from ridge and select the closest
wmain = wmain[np.argsort(np.abs(x[wmain]-xloc[wmain]))]
wmain = wmain[:len(wred)]
print(f"Selected {len(wmain):,} MS objects closest to ridge")
Plotting 156180 of 333525 points
Selected 333,525 low-noise objects
Selected 2,797 red objects
Initially selected 59,605 MS objects
Selected 2,797 MS objects closest to ridge
fig = plt.figure(figsize=(12, 8), tight_layout=True)
gs = gridspec.GridSpec(2, 2, width_ratios=[2, 1])

ax1 = fig.add_subplot(gs[:, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[1, 1])

# plot ax1
ax1.scatter(xs, ys, c=zs, s=2, cmap='plasma', edgecolors='none')
ax1.scatter(x[wred], y[wred], c='red', s=2, edgecolors='none')
ax1.scatter(x[wmain], y[wmain], c='blue', s=2, edgecolors='none')
ax1.scatter(xwd, ywd, c='green', s=10, edgecolors='none')
ax1.set(xlabel='F606W-F814W [mag]', ylabel='F606W [mag]',
        title=f'{len(x):,} stars in SWEEPS', xlim=(0, 3), ylim=(18, 27.5))
ax1.invert_yaxis()

# plot ax2
lrange = (-20, 5)
brange = (-12.5, 12.5)

# MS and red points in random order
wsel = w[np.append(wmain, wred)]
colors = np.array(['blue']*len(wsel))
colors[len(wmain):] = 'red'
irs = np.argsort(np.random.random(len(wsel)))
wsel = wsel[irs]
colors = colors[irs]

masks = [w, wsel, wwd]
sizes = [0.1, 2, 2]
colors2 = ['darkgray', colors, 'green']

for mask, color, size in zip(masks, colors2, sizes):
    ax2.scatter('lpm', 'bpm', data=tab[mask], c=color, s=size)

ax2.set(ylabel='Latitude PM [mas/yr]', xlim=lrange, ylim=brange)

# plot ax3
bins = 0.5
bincount = int((lrange[1]-lrange[0])/bins + 0.5) + 1

masks = [wwd, w[wmain], w[wred]]
labels = ['WD', 'MS', 'Red']
colors = ['g', 'b', 'r']

for mask, label, color in zip(masks, labels, colors):
    ax3.hist('lpm', data=tab[mask], range=lrange, bins=bincount, label=label, color=color, histtype='step')

ax3.set(xlabel='Longitude PM [mas/yr]', ylabel=f'Number [in {bins:.2} mas bins]')
_ = ax3.legend(loc='upper left')
../../../_images/a57296477c78c8d303aaaac8baebd05d0fc4e39b1a6aea06ef751525c8289dff.png

White dwarf mean PM and uncertainity#

norm = 1.0/np.sqrt(len(tab['lpm'][wwd]))
print("WD PM mean +- stdev longitude {:.2f} +- {:.3f} latitude {:.2f} +- {:.3f}".format(
    np.mean(tab['lpm'][wwd]), norm*np.std(tab['lpm'][wwd]),
    np.mean(tab['bpm'][wwd]), norm*np.std(tab['bpm'][wwd])
    ))
WD PM mean +- stdev longitude -5.60 +- 0.152 latitude -0.03 +- 0.245

WDs generally closer to bulge (MS) PM distribution#

bins = 0.5
bincount = int((lrange[1]-lrange[0])/bins + 0.5) + 1

masks = [wwd, w[wmain], w[wred]]
labels = ['WD', 'MS', 'Red']
colors = ['g', 'b', 'r']

fig, ax = plt.subplots(figsize=(8, 6))

for mask, label, color in zip(masks, labels, colors):
    ax.hist('lpm', data=tab[mask], range=lrange, bins=bincount, label=label, color=color, histtype='step', density=True, cumulative=1)
    
ax.set(xlabel='Longitude PM [mas/yr]', ylabel='Cumulative fraction')
_ = ax.legend(loc='upper left')
../../../_images/d99c3dec5a4d0598d7e45146a04aa343ece5a81cc567dda7aa1c5bb028335bd7.png

Look for quasar candidates (low PM blue stars) #

Note this includes all objects, not just “good” objects with low mag noise, because quasars might be variable too.

wqso1 = np.where((RminusI < 0.5)
                 & (np.sqrt(tab['bpm']**2+tab['lpm']**2) < 1.0)
                 & (tab['NumFilters'] > 2))[0]
wqso1 = wqso1[np.argsort(f606w[wqso1])]
tab[wqso1]
Table length=14
ObjIDRADecRAerrDecerrNumFiltersNumVisitsa_f606wa_f606w_na_f606w_mada_f814wa_f814w_na_f814w_madbpmlpmbpmerrlpmerrpmdevyrdTyrStartyrEnd
int64float64float64float64float64int32int32float64int32float64float64int32float64float64float64float64float64float64float64float64float64float64
4000710313439269.74005171773325-29.1960324733696620.62659640476711190.8430363739939153139418.632399559020996740.0441493988037109418.75860023498535770.22760009765625-0.27295919570065810.09336852951614050.120074967796713130.193544431979997666.6645611028851392010.410458098704312.1389362929372312003.4367273590012015.5756636519384
4000710257520269.76634477578085-29.2233101667974570.70106072268639690.9635875312674559149618.71660041809082750.0379009246826171918.785300254821777740.45225048065185547-0.579616612423514-0.0041956748645314320.12862608053011320.226135156132128127.0797343733470172010.450586592934812.1389362929372312003.4367273590012015.5756636519384
4000710307965269.7417955221381-29.1985938594320160.92059357282046350.8518786138892231149418.73979949951172730.0638999938964843818.865349769592285760.200050354003906250.3782536664095988-0.36868955902233850.21250729952998930.173450479126670947.67323066072039952010.48587754622912.1389362929372312003.4367273590012015.5756636519384
4000710352240269.7337926320315-29.181394875452980.69463568140069660.906134226177322447918.78339958190918740.02304935455322265618.512550354003906740.27725028991699220.63371794604432230.297155837378090540.150632729427004340.200701984422958786.7381081223247512009.773737000133711.3711852081716672003.4367273590012014.8079125671727
4000710347699269.7783405856686-29.179119311166470.411557788323881730.484193362005322648118.839149475097656760.033950805664062518.898500442504883730.23670005798339844-0.116781003128475530.64992525647767450.0848778177748430.110360525762329693.79050728910901662009.760042142227111.3711852081716672003.4367273590012014.8079125671727
4000710305789269.7500895465239-29.1997069628762741.23779853402990740.9596173093379398139518.883800506591797760.01639938354492187518.647899627685547750.104499816894531250.76136088973964420.060728015679124810.144585196792062830.3078910876643928.6696086746168462010.451318818121812.1389362929372312003.4367273590012015.5756636519384
4000710287023269.73049137354224-29.2087865146858370.58867814142106730.8187862653505924139319.005799293518066700.1794986724853515619.03809928894043770.4453010559082031-0.027042326411294833-0.106561818017951920.113687594145356840.185473848934728326.0600193408506422010.409980814181812.1389362929372312003.4367273590012015.5756636519384
4000711198572269.7837898799627-29.1710583461873870.242890611463202840.378799458135692845620.384400367736816520.03075027465820312520.409199714660645540.018199920654296875-0.39276687371980523-0.26149912803296160.071572579772810260.069548523746184072.63978326440014982008.052253504512210.9976219052332842003.4367273590012014.4343492642342
4000711114267269.77699533206413-29.2130203399329034.241370555135963.939764673878310843523.104300498962402320.03829956054687523.02050018310547330.07789993286132812-0.8306962177406612-0.068584987281524040.92216223248728991.349666416366427418.9259942776495722005.554219435558512.1364001366899472003.4367273590012015.573127495691
4000710335454269.7613531455845-29.1872063610708647.4742973298759631.483136231049532837723.993050575256348760.0631999969482421924.481599807739258790.20109939575195312-0.54231856855157350.70604156118027321.46469300447186380.818374901008934844.5428643744239852009.979332637238311.3711852081716672003.4367273590012014.8079125671727
4000710273567269.7541240409338-29.215787960244744.7482141647964491.694094522863292437824.544499397277832760.0755500793457031224.190000534057617780.12094974517822266-0.06045787883823814-0.296998397160966930.93281897176258610.578092189093136828.4006901952327272009.689665799419811.3413992910292122003.4367273590012014.7781266500303
4000710273213269.762844233717-29.2159930735964582.84914127596411462.158951117635643535825.248699188232422570.07260131835937525.19580078125570.114398956298828120.58745325924043080.39619888781943280.57457023306250710.489268627804960217.0350228161346032008.657572905504111.3711852081716672003.4367273590012014.8079125671727
4000710327380269.7667196275462-29.1898039056530221.49756615770321074.658478945843615535325.343299865722656520.0939502716064453125.171499252319336350.27519989013671875-0.59257648522096910.35109846224308780.400360430563875550.96311017225164223.3949711231211242008.199840995264811.3413992910292122003.4367273590012014.7781266500303
4000710296308269.7744892710409-29.204392434039083.85543709725692542.264390319511768337825.49880027770996750.0967006683349609425.095499992370605780.112750053405761720.189753023786942140.171716606536581270.71736161335096080.644308755073237427.1842846412212932009.57501534738411.3717329051641372003.43617966200852014.8079125671727
fig, ax = plt.subplots(figsize=(10, 10))
ax.scatter(xs, ys, c=zs, s=2, edgecolors='none', cmap='plasma')
ax.plot(RminusI[wqso1], f606w[wqso1], 'rs', markersize=10, fillstyle='none')
ax.set(xlim=(xedge[0], xedge[-1]), ylim=(yedge[0], yedge[-1]))
ax.set(xlabel='R - I (A_F606W - A_F814W)', ylabel='R (A_F606W)',
       title=f'{len(x):,} stars in SWEEPS\n{len(wqso1)} low PM blue stars with NumFilters$\\geq3$')
ax.invert_yaxis()
../../../_images/a5c71fa2eba6b0bc013b4da17d208f4c714cdd4bb83286a5ad48c09d0b7332fe.png
objid = tab['ObjID']
print(f"Plotting {len(wqso1)} objects")
for o in objid[wqso1]:
    positions(o, jobs=jobs)
Plotting 14 objects
../../../_images/18c5aa067d896b275b23f44e602fc5cddbdbf9a625fc3f3a6d1dfdb9d4ec354d.png ../../../_images/4a7903d5d3c5312844178542aefba3a9b93074ffafb537b206f06877eb780b96.png ../../../_images/1658e199b645c413fd8979956fc51f849387e9e68bbde9b80b3d480287da2720.png ../../../_images/e9986e123c86177da0b255e5e1c943e7e582490a19ab4db2e2c55a7392661002.png ../../../_images/051950d4778ef4b97c1ed885adc8925171ae56de176949fe47c896896c1d354a.png ../../../_images/7e899b312a4031f8b093caa98b645e0ed0aebfb5e13fea0815c19bddb370d012.png ../../../_images/6cf601295741f64dd81363b19e1b5070f8a29c068b746c31d130cdd4d6ecfae4.png ../../../_images/9fa410f73ab105050266c60eb81ef2fdbd0af4e996d6f8d902844e535d1a4063.png ../../../_images/5d3173277268c37a05eb4a52de365f9fc14bbc4ece8f977241344a45a76243a6.png ../../../_images/471fb731eb39bbf5770d0048e7af46bbb7e27e64bf0798a9e2573c70db9c97f5.png ../../../_images/99fd27df88d5cbb35c0f40308c336f3896c614ec20775af7a6e5baa2e4b8f4ec.png ../../../_images/3ba798df5d022b93469fd9f0c7b4e4f6054b99aa67c75b4ccc096045d38d8a45.png ../../../_images/fa08d9bc14b6f8c4c152699f45f017a8ea103d3a1badef6594672a5ff3818ece.png ../../../_images/85227c013b5d12382922404bbe86d8f4e87958dacce31a4c720aa4c6eaabd4ac.png

Try again with different criteria on proper motion fit quality#

wqso2 = np.where((RminusI < 0.5)
                 & (np.sqrt(tab['bpm']**2+tab['lpm']**2) < 2.0)
                 & (np.sqrt(tab['bpmerr']**2+tab['lpmerr']**2) < 2.0)
                 & (tab['pmdev'] < 4.0))[0]
wqso2 = wqso2[np.argsort(f606w[wqso2])]
tab[wqso2]
Table length=10
ObjIDRADecRAerrDecerrNumFiltersNumVisitsa_f606wa_f606w_na_f606w_mada_f814wa_f814w_na_f814w_madbpmlpmbpmerrlpmerrpmdevyrdTyrStartyrEnd
int64float64float64float64float64int32int32float64int32float64float64int32float64float64float64float64float64float64float64float64float64float64
4000710347699269.7783405856686-29.179119311166470.411557788323881730.484193362005322648118.839149475097656760.033950805664062518.898500442504883730.23670005798339844-0.116781003128475530.64992525647767450.0848778177748430.110360525762329693.79050728910901662009.760042142227111.3711852081716672003.4367273590012014.8079125671727
4000711253077269.6915378419676-29.240201450193220.47048817337398590.527016297536424224618.8927001953125450.01090049743652343818.636449813842773420.1782999038696289-1.7408991354864214-0.59470771026326410.36131623059721120.74823452127072992.96134036189064352013.50340094293923.006781202524872011.80167617768172014.8084573802066
4000711347522269.70065127433986-29.2320349526647440.458137394606503550.97255062095775424318.917999267578125430.02580070495605468818.648849487304688380.28500080108642580.5245222694829835-0.90253215714022780.53318792314672771.13299016246126933.73078094247710322013.46489691614353.006781202524872011.80167617768172014.8084573802066
4000709025473269.82873131529516-29.195122574848120.54113639375424790.692045030767130524618.92685031890869440.012649536132812518.75755023956299420.38874912261962890.8548976473145768-1.15783376955440320.28769067083577350.433552708535085933.4563402628410352013.31542570356511.3719145413717642003.43617966200852014.8080942033803
4000710279756269.7207706977463-29.2123085559488870.413744843922597470.4883003181612267127018.977749824523926540.02824974060058593818.614700317382812550.35890007019042970.033714894109117335-1.6007022288058330.090524207329567410.090737501394596063.6197013826943342009.67976228942312.1389362929372312003.4367273590012015.5756636519384
4000711345953269.71277619272627-29.231306080124010.47321918364871311.004685668423822324619.01865005493164460.01224994659423828118.701799392700195390.15010070800781250.349685603051353271.91399348040913870.72542488495716681.08618790828335833.7553155526457392013.50340094293923.006781202524872011.80167617768172014.8084573802066
4000709014231269.8069522092499-29.200219944064810.38345216597794820.54906701179173724719.06329917907715460.03770065307617187518.564849853515625460.0460500717163085941.0342947783087193-1.42792407655898760.155265468888894280.368898475427276552.00174138195950762013.300790214705811.3719145413717642003.43617966200852014.8080942033803
4000710326758269.75587447129374-29.1899951880466380.399232380202015570.37137690294128917139519.077000617980957760.02159976959228515619.024099349975586770.26650047302246094-1.1141957269870415-0.86749835590098590.099480220588749970.064240536257315773.0978789147166582010.451318818121512.1389362929372312003.4367273590012015.5756636519384
4000711198572269.7837898799627-29.1710583461873870.242890611463202840.378799458135692845620.384400367736816520.03075027465820312520.409199714660645540.018199920654296875-0.39276687371980523-0.26149912803296160.071572579772810260.069548523746184072.63978326440014982008.052253504512210.9976219052332842003.4367273590012014.4343492642342
4000724763944269.7747901164537-29.265234033836870.433776731714064060.447421664711086624622.25380039215088460.0594997406005859421.910449981689453460.0336999893188476561.1821223347200740.140849289910045030.59608815874312850.42645224887957963.36392085386135162013.5031453570163.006781709597822011.8014940660382014.8082757756358
fig, ax = plt.subplots(figsize=(10, 10))
ax.scatter(xs, ys, c=zs, s=2, edgecolors='none', cmap='plasma')
ax.plot(RminusI[wqso2], f606w[wqso2], 'rs', markersize=10, fillstyle='none')
ax.set(xlabel='R - I (A_F606W - A_F814W)', ylabel='R (A_F606W)',
       xlim=(xedge[0], xedge[-1]), ylim=(yedge[0], yedge[-1]),
       title=f'{len(x):,} stars in SWEEPS\n{len(wqso2)} low PM blue stars\nwith NumFilters$\\geq3$')
ax.invert_yaxis()
../../../_images/2cc47c77673b98f53cd66496a028d5616499f8152e24b715ad73349974cf99b2.png
objid = tab['ObjID']
print(f"Plotting {len(wqso2)} objects")
for o in objid[wqso2]:
    positions(o, jobs=jobs)
Plotting 10 objects
../../../_images/051950d4778ef4b97c1ed885adc8925171ae56de176949fe47c896896c1d354a.png ../../../_images/8c4e0a73bab75946e41ca3c461c89dd394c985a32b650309b4bbe38e444aed33.png ../../../_images/58cccc1e919b237115aa128626cba2d30c18e6edf4d48437f5058bfcd3d745d5.png ../../../_images/b384f03a5b8f6e0d65f23a22f80fa4c03373cbcd498a439ec6b81d489a19c02e.png ../../../_images/f79f6b6ef078bdbf706239303e56cbb439bae13261f459925271d915183461f6.png ../../../_images/d7fb6188c6cf017c12b37c6bbfaaa8c1c57387a7f612478724c805babe08333d.png ../../../_images/c331abedad3c438e91d3c1b59ef97e9434250968d53dff08f65fcd30db862192.png ../../../_images/97af01444cf658c4c366303159b5aecbbf411dc9f41c8d9476e7ff7a6849c0a4.png ../../../_images/9fa410f73ab105050266c60eb81ef2fdbd0af4e996d6f8d902844e535d1a4063.png ../../../_images/6676bf38c3eace31144c8b677a778df663dc3f4b465fade6e2b406bbddd30134.png

High Proper Motion Objects #

Get a list of objects with high, accurately measured proper motions. Proper motions are measured relative to the main sequence sample (Galactic center approximately).

f606w = tab['a_f606w']
f814w = tab['a_f814w']
RminusI = f606w-f814w
lpm0 = np.array(tab['lpm'])
bpm0 = np.array(tab['bpm'])
lpmerr0 = np.array(tab['lpmerr'])
bpmerr0 = np.array(tab['bpmerr'])
pmtot0 = np.sqrt((bpm0-bpmmain)**2+(lpm0-lpmmain)**2)
pmerr0 = np.sqrt(bpmerr0**2+lpmerr0**2)

# sort samples by decreasing PM
wpml = np.where((pmtot0 > 12) & (pmtot0 < 15) & (pmerr0 < 1.0) & good)[0]
wpml = wpml[np.argsort(-pmtot0[wpml])]
xpml = np.array(RminusI[wpml])
ypml = np.array(f606w[wpml])

wpmh = np.where((pmtot0 > 15) & (pmerr0 < 1.0) & good)[0]
wpmh = wpmh[np.argsort(-pmtot0[wpmh])]
xpmh = np.array(RminusI[wpmh])
ypmh = np.array(f606w[wpmh])

# Calculate the point density
w = np.where((RminusI > -1) & (RminusI < 4) & good)[0]
x = np.array(RminusI[w])
y = np.array(f606w[w])
t0 = time.time()
myPDF, axes = fastKDE.pdf(x, y, numPoints=2**10+1)
print(f"kde took {(time.time()-t0):.1f} sec")

# interpolate to get z values at points
finterp = RectBivariateSpline(axes[1], axes[0], myPDF)
z = finterp(y, x, grid=False)

# Sort the points by density, so that the densest points are plotted last
idx = z.argsort()
xs, ys, zs = x[idx], y[idx], z[idx]

# select a random subset of points in the most crowded regions to speed up plotting
wran = np.where(np.random.random(len(zs))*zs < 0.05)[0]
print(f"Plotting {len(wran)} of {len(zs)} points")
xs = xs[wran]
ys = ys[wran]
zs = zs[wran]
kde took 1.4 sec
Plotting 99090 of 333743 points
fig, ax = plt.subplots(figsize=(12, 10))

ax.scatter(xs, ys, c=zs, s=2, edgecolors='none', cmap='plasma')
ax.scatter(xpml, ypml, s=40, c="green", marker="^", label='10 mas/yr < PM < 15 mas/yr')
ax.scatter(xpmh, ypmh, s=80, c="red", marker="^", label='15 mas/yr < PM')

ax.set(xlabel='A_F606W - A_F814W', ylabel='A_F606W',
       title=f'High proper motions relative to mean of main sequence sample (bulge)\n{len(x):,} stars in SWEEPS')

ax.invert_yaxis()
ax.legend()
<matplotlib.legend.Legend at 0x7f70e194b6d0>
../../../_images/2b5bf3f95629d4afcca48a356b7db126ea6b3d8b926ebb4b59a731ac3cc4db75.png
print(f"Plotting {len(wpmh)} objects")
for o in tab["ObjID"][wpmh]:
    positions(o, jobs=jobs)
Plotting 34 objects
../../../_images/29fa0895cc01b94a6b52f9361a3c9ae374a5200a942dd3205483932f74745ee1.png ../../../_images/1aa498e6b56f0dfe7a232a830e8f8eac489649357acf64cf3696bcbbea89c0e7.png ../../../_images/510927f2a85112875f68a68ef50d61090f2f7ebd80b093fdc21dafdab597f696.png ../../../_images/c71cd2b040ebf5434e398fd1f7335093dd7b43d56d4a7ab426f025d81fee54da.png ../../../_images/5294d637c1b179fdb8baf9f551ab7afc5c9a7fa8be1052c20046b30c5032de9d.png ../../../_images/eee59b7328761d2f4df92718c1f8ae038b7b3dfcf2eccfd085316b8121407f56.png ../../../_images/5457ce9a462ee1a7d43ba9c0e60322b3d6c8eb71f69bbad8b99d4407360add38.png ../../../_images/4bcac12067ce5f7248ff6c036e91945b52ebd9e5385e120f7a37df452308d023.png ../../../_images/1e507fb0f06e7121ad245d638e1507bfd2d394df990c0d17193296539f1202bf.png ../../../_images/7ca1d51c32a732aeb6c1542039686f28d998d80ed01ede5ce95449099f487571.png ../../../_images/e2de6ae2ad682df585efec4b54cd7d0ab52c40cdab7c53537750c3663ff2e9af.png ../../../_images/70af1a6f8559d7f303e546f13a33caff354b9e655895ea98f5d371c6a20c3455.png ../../../_images/53c65399db03571e040fa0e1241e27a8a589673ec7fe8815b4a4c766c056d277.png ../../../_images/c52a6da39a9c327f4e8a7a5ffedece9e16f12dca4a43a41cfe3e2d3e3caf91d8.png ../../../_images/450304d5f431be625d58b4aca51eabd918b5f2f035bb5892aaa0186d44f6ff08.png ../../../_images/d3dffccac64e7f4b0565082647cce2fd26bc53fcb18c8a4586e60d2c4dbf1c5f.png ../../../_images/4e5f754e0cef9fe7d15d5652f7327316b1715fbf1fcbfe82d90bd76681fbf63d.png ../../../_images/7790826386967248d9a4788ca7115d20f6084e32213b4bfd4b0310b7845f1404.png ../../../_images/48f7c32c8ed1cd61e30d01cd68ca44eedd6c8cb41437499149000bddf2a2d33e.png ../../../_images/ee8954522bf7084f01dded502a1b90dbcda54791407e8afcb46635a61f130aa0.png ../../../_images/1557fd0bd3984b31fb082d7ae33acc58ee6d907c9ff7f3ae124436805670ba28.png ../../../_images/86a1ddddfc22948c56980a0b7277295bacc9f9f2199d39abc6f256f4103f47bb.png ../../../_images/f931dae2a5837d80ca28b73aaca153ad07ecdba96d0c07d5b7796c2bcfc37983.png ../../../_images/f6635411f15bc215fbce3f0f3f5def2f67756a7a9385364a363855c85ab33cb8.png ../../../_images/f969567e82081583b0acaaada419ebf96b79e3b1d6ccfa7a73015cbd4396a3ee.png ../../../_images/0790c43e0f19b1cdd2428aabdabbce126e0f9a61dc3027b7e3c68bf10a40ac3f.png ../../../_images/f9e32c08cea23ae60832618e509cbddb26d5315cbeaf6a69db120ce369fbfa97.png ../../../_images/7cd638e2b61fa89e6349d9f4490521ea2bfdacbf6047b801f320d4091d0abbfe.png ../../../_images/bf974b40b624def0eae145ee8504d6375c72c3dcd6e9d033e330adaaee4d9445.png ../../../_images/7e510a70fcddc6e74500b5591b88ef6cd91d6d08476a88b3c6d9eb04341d0dec.png ../../../_images/a63fad87db4589a7262d6bf9eb23e40b4117e0881efdc6478df76173fb7c35a5.png ../../../_images/e8b841c9a65abea093536b134b21ecaa483958c9f6549e9137f84fefedbb68be.png ../../../_images/b28c242959b3f6f229d5ca51238cb8975d62b80a595c7c296dd79e3ca8549f2b.png ../../../_images/632f72e8cde813dc2609f390ed36d8a0c89346838c0d6f5aea98609e47e52fef.png

Very red high proper motion objects#

wpmred =  np.where((pmtot0 > 12) & (pmerr0 < 1.0) & (RminusI > 2.6) & good)[0]
print(f"Plotting {len(wpmred)} objects")
for o in tab["ObjID"][wpmred]:
    positions(o, jobs=jobs)
Plotting 4 objects
../../../_images/1aa498e6b56f0dfe7a232a830e8f8eac489649357acf64cf3696bcbbea89c0e7.png ../../../_images/d3dffccac64e7f4b0565082647cce2fd26bc53fcb18c8a4586e60d2c4dbf1c5f.png ../../../_images/3ce0afb4d2ee77c792dec35b96100d97c230fa821a927e1e2936e593fbf51907.png ../../../_images/ec50fc9fa5b0f2d1c5f4b2a23eaee77c038d53c2e66dd35c623d292d3b8d2e38.png

Very blue high proper motion objects#

wpmblue =  np.where((pmtot0 > 8) & (pmerr0 < 1.0) & (RminusI < 0.5) & good)[0]
print(f"Plotting {len(wpmblue)} objects")
for o in tab["ObjID"][wpmblue]:
    positions(o, jobs=jobs)
Plotting 12 objects
../../../_images/5f6076397581fd769e9b08776a303bc433e04767efba51af267a9fa887b9975a.png ../../../_images/3db8b8f101d0fc1d3e69252385af2abab333f1a8a663ed584e67bce55e755756.png ../../../_images/7790826386967248d9a4788ca7115d20f6084e32213b4bfd4b0310b7845f1404.png ../../../_images/e2549c5f1afb12e3845b35a03edb085c3d0a801dfa5612e7577004410710aa7e.png ../../../_images/14f688603af57884d0da2000391e4da96488a483566208d1cf0753fcdb9e2661.png ../../../_images/721ea1d2466e80a729d3d9a6f2de2f7465a5904583cb7faf5d5b2bad778bb2b2.png ../../../_images/53dcce64818e5d0776039f5673103f4dff13454ec8d3b22f1bc9d123282c6cca.png ../../../_images/81ce0a6fce3f920b2c97b3cb5cb41e4478dbf07c2b49169898a393ea0c2fc36a.png ../../../_images/765edb9ecbbf75c4d1f708850ee36b26e2200681e59c898413afe7334a2a6f1a.png ../../../_images/05658e2f8d350d93fd0c900e2602414826a47636907168cb4701fe948e585af7.png ../../../_images/9aadd16bb11b93b292233807cd05fa77fa099d9096c4bfe7c0bf1af2a219a78b.png ../../../_images/251b3f6b63df1cb0e5768ada5376d6e26fb3e0e56b49b7dd99f133235c109a5e.png

Get HLA cutout images for selected objects #

Get HLA color cutout images for the high-PM objects. The query_hla function gets a table of all the color images that are available at a given position using the f814w+f606w filters. The get_image function reads a single cutout image (as a JPEG color image) and returns a PIL image object.

See the documentation on HLA VO services and the fitscut image cutout service for more information on the web services being used.

def query_hla(ra, dec, size=0.0, imagetype="color", inst="ACS", format="image/jpeg",
              spectral_elt=("f814w", "f606w"), autoscale=95.0, asinh=1, naxis=33):
    # convert a list of filters to a comma-separated string
    if not isinstance(spectral_elt, str):
        spectral_elt = ",".join(spectral_elt)
    siapurl = (f"https://hla.stsci.edu/cgi-bin/hlaSIAP.cgi?"
               f"pos={ra},{dec}&size={size}&imagetype={imagetype}&inst={inst}"
               f"&format={format}&spectral_elt={spectral_elt}"
               f"&autoscale={autoscale}&asinh={asinh}"
               f"&naxis={naxis}")
    votable = Table.read(siapurl, format="votable")
    return votable


def get_image(url):
    """Get image from a URL"""
    r = requests.get(url)
    im = Image.open(BytesIO(r.content))
    return im
# display earliest and latest images side-by-side
# wsel = wpmred
# wsel = wpmblue
# top 10 highest PM objects
wsel = wpmh[:10]
nim = len(wsel)
icols = 1        # objects per row
ncols = 2*icols  # two images for each object
nrows = (nim+icols-1)//icols

imsize = 33
xcross = np.array([-1, 1, 0, 0, 0])*2 + imsize/2
ycross = np.array([0, 0, 0, -1, 1])*2 + imsize/2

# selected data from tab
sd = tab[['RA', 'Dec', 'ObjID']][wsel]

# create the figure
fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(12, (12/ncols)*nrows))

# iterate each observation, and each set of axes for the first and last image
for (ax1, ax2), obj in zip(axes, sd):
    
    # get the image urls and observation datetime
    hlatab = query_hla(obj["RA"], obj["Dec"], naxis=imsize)[['URL', 'StartTime']]
    # sort the data by the observation datetime, and get the first and last observation url
    (url1, time1), (url2, time2) = hlatab[np.argsort(hlatab['StartTime'])][[0, -1]]
    
    # get the images
    im1 = get_image(url1)
    im2 = get_image(url2)
    
    # plot the images
    ax1.imshow(im1, origin="upper")
    ax2.imshow(im2, origin="upper")
    
    # plot the center
    ax1.plot(xcross, ycross, 'g')
    ax2.plot(xcross, ycross, 'g')
    
    # labels and titles
    ax1.set(ylabel=f'ObjID {obj["ObjID"]}', title=time1)
    ax2.set_title(time2)
../../../_images/e18a32238cb2e66430a3a78ee81b92e786868cac027c42b86c74c4fc601b1bbe.png

Look at the entire collection of images for the highest PM object#

i = wpmh[0]

# selected data
sd = tab['ObjID', 'RA', 'Dec', 'a_f606w', 'a_f814w', 'bpm', 'lpm', 'yr', 'dT'][i]
display(sd)

imsize = 33
# get the URL and StartTime data
hlatab = query_hla(sd['RA'], sd['Dec'], naxis=imsize)[['URL', 'StartTime']]
# sort the data
hlatab = hlatab[np.argsort(hlatab['StartTime'])]

nim = len(hlatab)
ncols = 8
nrows = (nim+ncols-1)//ncols

xcross = np.array([-1, 1, 0, 0, 0])*2 + imsize/2
ycross = np.array([0, 0, 0, -1, 1])*2 + imsize/2
Row index=208405
ObjIDRADeca_f606wa_f814wbpmlpmyrdT
int64float64float64float64float64float64float64float64float64
4000711121911269.7367256594695-29.20969991911761820.6727504730224618.963199615478516-18.43788346257518-36.801459330875692004.1942381434012.749260607770275
# get the images: takes about 90 seconds for 77 images
images = [get_image(url) for url in hlatab['URL']]
# create the figure
fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(20, (20/ncols)*nrows), tight_layout=True)
# flatten the axes for easy iteration and zipping
axes = axes.flat

plt.rcParams.update({"font.size": 11})
for ax, time1, img in zip(axes, hlatab['StartTime'], images):
    # plot image
    ax.imshow(img, origin="upper")
    # plot the center
    ax.plot(xcross, ycross, 'g')
    # set the title
    ax.set_title(time1)
    
# remove the last 3 unused axes
for ax in axes[nim:]:
    ax.remove()

_ = fig.suptitle(f"ObjectID: {sd['ObjID']}\nRA: {sd['RA']:0.2f} Dec: {sd['Dec']:0.2f}\nObservations: {nim}", y=1, fontsize=14)
../../../_images/f74af5363134bf733665a7c1da4e924729b974a38eaacbb9a9570e45c94da21e.png