Hubble Source Catalog API Notebook#

2019 - 2022, Rick White, Trenton McKinney#

A new MAST interface supports queries to the current and previous versions of the Hubble Source Catalog. It allows searches of the summary table (with multi-filter mean photometry) and the detailed table (with all the multi-epoch measurements). It also has an associated API, which is used in this notebook.

This is based on HSC Use Case #3.

  • It searches the HSC for variable objects in the vicinity of dwarf galaxy IC 1613,

  • shows the positions of those objects in a color-magnitude diagram,

  • extracts light curves for an example object, and

  • displays cutout images from the Hubble observations that were used for the light curve measurements.

The whole process takes only 30 seconds to complete.

Another notebook generates a color-magnitude diagram for the Small Magellanic Cloud in only a couple of minutes. A more complex notebook that shows how to access the proper motion tables using the HSC API is also available.

Instructions:#

  • Complete the initialization steps described below.

  • Run the notebook.

Running the notebook from top to bottom takes about 30 seconds.

Table of Contents#

  • Initialization

  • Get metadata on available HSC columns

  • Find variable objects in IC 1613

    • Use MAST name resolver

    • Search HSC summary table

    • Plot variability index versus magnitude

    • Show variable objects in a color-magnitude diagram

  • Get HSC light curve for a variable

  • Extract HLA cutout images for the variable

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

import astropy
from astropy.coordinates import SkyCoord
import time
import sys
import os
import requests
import json
import numpy as np
import matplotlib.pyplot as plt

from pprint import pprint

from astropy.table import Table
import pandas as pd

from PIL import Image
from io import BytesIO, StringIO

# set width for pprint
astropy.conf.max_width = 150
/tmp/ipykernel_1978/236952991.py:14: DeprecationWarning: 
Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),
(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)
but was not found to be installed on your system.
If this would cause problems for you,
please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466
        
  import pandas as pd
# set universal matplotlib parameters
plt.rcParams.update({'font.size': 16})

MAST API functions#

  • Execute HSC searches and resolve names using MAST query.

  • Here we define several interrelated functions for retrieving information from the MAST API.

    • The hcvcone(ra, dec, radius [, keywords]) function searches the HCV catalog near a position.

    • The hcvsearch() function performs general non-positional queries.

    • The hcvmetadata() function gives information about the columns available in a table.

hscapiurl = "https://catalogs.mast.stsci.edu/api/v0.1/hsc"


def hsccone(ra, dec, radius, table="summary", release="v3", format="csv", magtype="magaper2",
            columns=None, baseurl=hscapiurl, verbose=False, **kw):
    """Do a cone search of the HSC catalog

    Parameters
    ----------
    ra (float): (degrees) J2000 Right Ascension
    dec (float): (degrees) J2000 Declination
    radius (float): (degrees) Search radius (<= 0.5 degrees)
    table (string): summary, detailed, propermotions, or sourcepositions
    release (string): v3 or v2
    magtype (string): magaper2 or magauto (only applies to summary table)
    format: csv, votable, json, table
    columns: list of column names to include (None means use defaults)
    baseurl: base URL for the request
    verbose: print info about request
    **kw: other parameters (e.g., 'numimages.gte':2)
    """

    data = kw.copy()
    data['ra'] = ra
    data['dec'] = dec
    data['radius'] = radius
    return hscsearch(table=table, release=release, format=format, magtype=magtype,
                     columns=columns, baseurl=baseurl, verbose=verbose, **data)


def hscsearch(table="summary", release="v3", magtype="magaper2", format="csv",
              columns=None, baseurl=hscapiurl, verbose=False, **kw):
    """Do a general search of the HSC catalog (possibly without ra/dec/radius)

    Parameters
    ----------
    table (string): summary, detailed, propermotions, or sourcepositions
    release (string): v3 or v2
    magtype (string): magaper2 or magauto (only applies to summary table)
    format: csv, votable, json, table
    columns: list of column names to include (None means use defaults)
    baseurl: base URL for the request
    verbose: print info about request
    **kw: other parameters (e.g., 'numimages.gte':2).  Note this is required!
    """

    data = kw.copy()
    if not data:
        raise ValueError("You must specify some parameters for search")
    if format not in ("csv", "votable", "json", 'table'):
        raise ValueError("Bad value for format")
    if format == "table":
        rformat = "csv"
    else:
        rformat = format
    url = f"{cat2url(table, release, magtype, baseurl=baseurl)}.{rformat}"
    if columns:
        # check that column values are legal
        # create a dictionary to speed this up
        dcols = {}
        for col in hscmetadata(table, release, magtype)['name']:
            dcols[col.lower()] = 1
        badcols = []
        for col in columns:
            if col.lower().strip() not in dcols:
                badcols.append(col)
        if badcols:
            raise ValueError(f"Some columns not found in table: {', '.join(badcols)}")
        # two different ways to specify a list of column values in the API
        # data['columns'] = columns
        data['columns'] = f"[{','.join(columns)}]"

    # either get or post works
    # r = requests.post(url, data=data)
    r = requests.get(url, params=data)

    if verbose:
        print(r.url)
    r.raise_for_status()
    if format == "json":
        return r.json()
    elif format == "table":
        # use pandas to work around bug in Windows for ascii.read
        return Table.from_pandas(pd.read_csv(StringIO(r.text)))
    else:
        return r.text


def hscmetadata(table="summary", release="v3", magtype="magaper2", baseurl=hscapiurl):
    """Return metadata for the specified catalog and table
    
    Parameters
    ----------
    table (string): summary, detailed, propermotions, or sourcepositions
    release (string): v3 or v2
    magtype (string): magaper2 or magauto (only applies to summary table)
    baseurl: base URL for the request
    
    Returns an astropy table with columns name, type, description
    """
    url = f"{cat2url(table, release, magtype, baseurl=baseurl)}/metadata"
    r = requests.get(url)
    r.raise_for_status()
    v = r.json()
    # convert to astropy table
    tab = Table(rows=[(x['name'], x['type'], x['description']) for x in v],
                names=('name', 'type', 'description'))
    return tab


def cat2url(table="summary", release="v3", magtype="magaper2", baseurl=hscapiurl):
    """Return URL for the specified catalog and table
    
    Parameters
    ----------
    table (string): summary, detailed, propermotions, or sourcepositions
    release (string): v3 or v2
    magtype (string): magaper2 or magauto (only applies to summary table)
    baseurl: base URL for the request
    
    Returns a string with the base URL for this request
    """
    checklegal(table, release, magtype)
    if table == "summary":
        url = f"{baseurl}/{release}/{table}/{magtype}"
    else:
        url = f"{baseurl}/{release}/{table}"
    return url


def checklegal(table, release, magtype):
    """Checks if this combination of table, release and magtype is acceptable
    
    Raises a ValueError exception if there is problem
    """
    
    releaselist = ("v2", "v3")
    if release not in releaselist:
        raise ValueError(f"Bad value for release (must be one of {', '.join(releaselist)})")
    if release == "v2":
        tablelist = ("summary", "detailed")
    else:
        tablelist = ("summary", "detailed", "propermotions", "sourcepositions")
    if table not in tablelist:
        raise ValueError(f"Bad value for table (for {release} must be one of {', '.join(tablelist)})")
    if table == "summary":
        magtypelist = ("magaper2", "magauto")
        if magtype not in magtypelist:
            raise ValueError(f"Bad value for magtype (must be one of {', '.join(magtypelist)})")

Get metadata on available columns #

The metadata query returns information on the columns in the table. It works for any of the tables in the API (summary, detailed, propermotions, sourcepositions).

Note that the summary table has a huge number of columns! Each of the 133 filter/detector combinations has 3 columns with the magnitude, median absolute deviation (MAD, a robust measure of the scatter among the measurements), and the number of independent measurements in the filter. The filter name includes a prefix for the detector (A=ACS/WFC, W3=WFC3/UVIS or WFC3/IR, W2=WFPC2) followed by the standard name of the filter. So for instance all three instruments have an F814W filter, so there are columns for A_F814W, W3_F814W, and W2_F814W.

meta = hscmetadata("summary")
print(len(meta), "columns in summary")
filterlist = meta['name'][19::3].tolist()
print(len(filterlist), "filters")
pprint(filterlist, compact=True)
meta[:19]
418 columns in summary
133 filters
['W3_BLANK', 'W2_F122M', 'W2_F160BN15', 'W2_F160BW', 'W2_F170W', 'W2_F185W',
 'W3_F200LP', 'W3_F218W', 'W2_F218W', 'W3_F225W', 'W3_FQ232N', 'W3_FQ243N',
 'W2_F255W', 'W3_F275W', 'W3_F280N', 'W3_G280', 'W2_F300W', 'W3_F300X',
 'W3_F336W', 'W2_F336W', 'W3_F343N', 'W2_F343N', 'W3_F350LP', 'W3_F373N',
 'W2_F375N', 'W3_FQ378N', 'W2_F380W', 'W3_FQ387N', 'W3_F390M', 'W2_F390N',
 'W3_F390W', 'W3_F395N', 'W3_F410M', 'W2_F410M', 'W3_FQ422M', 'A_F435W',
 'W3_FQ436N', 'W3_FQ437N', 'W2_F437N', 'W3_F438W', 'W2_F439W', 'W2_F450W',
 'W3_F467M', 'W2_F467M', 'W3_F469N', 'W2_F469N', 'A_F475W', 'W3_F475W',
 'W3_F475X', 'W3_F487N', 'W2_F487N', 'W3_FQ492N', 'A_F502N', 'W3_F502N',
 'W2_F502N', 'W3_FQ508N', 'W3_F547M', 'W2_F547M', 'A_F550M', 'A_F555W',
 'W3_F555W', 'W2_F555W', 'W2_F569W', 'W3_FQ575N', 'W2_F588N', 'W3_F600LP',
 'A_F606W', 'W3_F606W', 'W2_F606W', 'W3_FQ619N', 'W3_F621M', 'W2_F622W',
 'A_F625W', 'W3_F625W', 'W3_F631N', 'W2_F631N', 'W3_FQ634N', 'W3_F645N',
 'W3_F656N', 'W2_F656N', 'W3_F657N', 'A_F658N', 'W3_F658N', 'W2_F658N',
 'A_F660N', 'W3_F665N', 'W3_F665N_F6', 'W3_FQ672N', 'W3_F673N', 'W2_F673N',
 'W3_FQ674N', 'W2_F675W', 'W3_F680N', 'W3_F689M', 'W2_F702W', 'W3_FQ727N',
 'W3_FQ750N', 'W3_F763M', 'A_F775W', 'W3_F775W', 'W2_F785LP', 'W2_F791W',
 'A_F814W', 'W3_F814W', 'W2_F814W', 'W3_F845M', 'A_F850LP', 'W3_F850LP',
 'W2_F850LP', 'W3_FQ889N', 'W3_FQ906N', 'W3_FQ924N', 'W3_FQ937N', 'W3_F953N',
 'W2_F953N', 'W3_F098M', 'W3_G102', 'W2_F1042M', 'W3_F105W', 'W3_F110W',
 'W3_F125W', 'W3_F126N', 'W3_F127M', 'W3_F128N', 'W3_F130N', 'W3_F132N',
 'W3_F139M', 'W3_F140W', 'W3_G141', 'W3_F153M', 'W3_F160W', 'W3_F164N',
 'W3_F167N']
Table length=19
nametypedescription
str16str5str163
MatchIDlongidentifier for the match
MatchRAfloatright ascension coordinate of the match position
MatchDecfloatdeclination coordinate of the match position
DSigmafloatstandard deviation of source positions in match
AbsCorrcharindicator of whether the match contains sources that are aligned to a standard catalog
NumFiltersintnumber of filters in match with sources detected in the aper2 aperture
NumVisitsintnumber of visits in match with sources detected in the aper2 aperture
NumImagesintnumber of Hubble Legacy Archive single filter, visit-combined (level 2) images in match with sources detected in the aper2 aperture
StartTimecharearliest start time of exposures in match with sources detected in the aper2 aperture
StopTimecharlatest stop time of exposures in match with sources detected in the aper2 aperture
StartMJDfloatmodified Julian date (MJD) for earliest start time of exposures in match with sources detected in the aper2 aperture
StopMJDfloatmodified Julian date (MJD) for latest stop time of exposures in match with sources detected in the aper2 aperture
TargetNamecharname of a target for an exposure in match
CIfloataverage normalized concentration index for sources detected in the aper2 aperture within the match
CI_Sigmafloatstandard deviation of normalized concentration index values for sources detected in the aper2 aperture within the match
KronRadiusfloataverage Kron radius for sources detected in the aper2 aperture within the match
KronRadius_Sigmafloatstandard deviation of Kron radius values for sources detected in the aper2 aperture within the match
Extinctionfloatextinction, obtained from the NASA/IPAC Extragalactic Database (NED), along the line of sight to the match position
SpectrumFlagcharY/N indicator of whether there is a spectrum in the Hubble Legacy Archive for this match. If the value is Y, then there is an entry in table SpecCat for the match.

Find variable objects in the dwarf irregular galaxy IC 1613 #

This is based on HSC Use Case #3, which shows an example of selecting objects from the HSC in portal. This is simple to do using the HSC API.

Use astropy name resolver to get position of IC 1613 #

target = 'IC 1613'
coord_ic1613 = SkyCoord.from_name(target)

ra_ic1613 = coord_ic1613.ra.degree
dec_ic1613 = coord_ic1613.dec.degree
print(f'ra: {ra_ic1613}\ndec: {dec_ic1613}')
ra: 16.2016962
dec: 2.1194959

Select objects with enough measurements to determine variability #

This searches the summary table for objects within 0.5 degrees of the galaxy center that have at least 10 measurements in both ACS F475W and F814W.

# save typing a quoted list of columns
columns = """MatchID,MatchRA,MatchDec,NumFilters,NumVisits,NumImages,StartMJD,StopMJD,
    A_F475W, A_F475W_N, A_F475W_MAD,
    A_F814W, A_F814W_N, A_F814W_MAD""".split(",")
columns = [x.strip() for x in columns]
columns = [x for x in columns if x and not x.startswith('#')]

constraints = {'A_F475W_N.gte': 10, 'A_F814W_N.gte': 10}

t0 = time.time()
tab = hsccone(ra_ic1613, dec_ic1613, 0.5, table="summary", release='v3', columns=columns, verbose=True, format="table", **constraints)
print(f"{(time.time()-t0):.1f} s: retrieved data and converted to {len(tab)}-row astropy table")

# clean up the output format
tab['A_F475W'].format = "{:.3f}"
tab['A_F475W_MAD'].format = "{:.3f}"
tab['A_F814W'].format = "{:.3f}"
tab['A_F814W_MAD'].format = "{:.3f}"
tab['MatchRA'].format = "{:.6f}"
tab['MatchDec'].format = "{:.6f}"
tab['StartMJD'].format = "{:.5f}"
tab['StopMJD'].format = "{:.5f}"
tab
https://catalogs.mast.stsci.edu/api/v0.1/hsc/v3/summary/magaper2.csv?A_F475W_N.gte=10&A_F814W_N.gte=10&ra=16.2016962&dec=2.1194959&radius=0.5&columns=%5BMatchID%2CMatchRA%2CMatchDec%2CNumFilters%2CNumVisits%2CNumImages%2CStartMJD%2CStopMJD%2CA_F475W%2CA_F475W_N%2CA_F475W_MAD%2CA_F814W%2CA_F814W_N%2CA_F814W_MAD%5D
7.9 s: retrieved data and converted to 18666-row astropy table
Table length=18666
MatchIDMatchRAMatchDecNumFiltersNumVisitsNumImagesStartMJDStopMJDA_F475WA_F475W_NA_F475W_MADA_F814WA_F814W_NA_F814W_MAD
int64float64float64int64int64int64float64float64float64int64float64float64int64float64
2247601216.1083492.1652143142653965.2915357009.8626225.178120.01124.248120.014
2262777316.1122302.1366542122353965.2915353967.7194126.884110.01326.258120.042
2263983916.1101402.1762442122453965.2915353967.7194125.630120.02326.109120.031
2264569216.1214122.1728893142653965.2915357009.8626224.598120.00624.216120.016
2280898816.1375932.1533943142653965.2915357009.8626223.740120.01424.259120.018
2296348316.1409532.1433752122453965.2915353967.7194125.648120.02526.167120.096
2296363516.1200672.1315403142653965.2915357009.8626226.597120.04925.852120.058
2296381216.1199742.1462803142653965.2915357009.8626224.825120.00324.183120.010
2191923916.1172762.1795062122353965.2915353967.7194126.803110.06126.012120.055
2191974216.1384862.1534473142653965.2915357009.8626225.369120.01524.655120.016
..........................................
3125531616.1134062.1440543142653965.2915357009.8626225.347120.02024.605120.019
3125670116.1325052.1854732122453965.2915353967.7194125.074120.02524.374120.014
3125794116.1073942.1288152122453965.2915353967.7194123.420120.06423.009120.087
9134099416.1268042.1780312122353965.2915353967.7194126.199120.02726.708110.082
9134418216.1091382.1368502122453965.2915353967.7194124.832120.01525.547120.025
9147739216.1167512.1355082122253965.2915353967.7194126.820100.03726.174120.044
9104895616.1165142.1529072122353965.2915353967.7194126.521120.04026.595110.076
9105026116.1127142.1506043142653965.2915357009.8626225.362120.02124.617120.025
9204584016.1352012.1842032122453965.2915353967.7194125.341120.13725.249120.089
9205072616.1055392.1525153142653965.2915357009.8626225.199120.01425.496120.046

Plot object positions on the sky#

We mark the galaxy center as well. Note that this field is in the outskirts of IC 1613. The 0.5 search radius (which is the maximum allowed in the API) allows finding these objects.

fig, ax = plt.subplots(figsize=(10, 10))
ax.plot('MatchRA', 'MatchDec', 'bo', markersize=1, data=tab, label=f'{len(tab)} HSC measurements')
ax.plot(ra_ic1613, dec_ic1613, 'rx', label=target, markersize=10)
ax.set(xlabel='RA [deg]', ylabel='Dec [deg]', aspect='equal')
ax.invert_xaxis()
_ = ax.legend(loc='best')
../../../_images/3829e9c2d7c3b335b54a51e76b0b483a1f5d0dee10cc3e62ae91293500a8b8df.png

Plot MAD variability index versus magnitude in F475W #

The median absolute deviation is measured among the ~12 magnitude measurements in the catalog. Some scatter is expected from noise (which increases for fainter objects). Objects with MAD values that are high are likely to be variable.

Select variable objects that are not too faint.

wvar = np.where((tab['A_F475W_MAD'] > 0.1) & (tab['A_F475W'] < 24) & (tab['A_F475W'] > 21))[0]

fig, ax = plt.subplots(figsize=(10, 10))
ax.plot('A_F475W', 'A_F475W_MAD', 'bo', markersize=2, alpha=0.1, data=tab,
        label=f'{len(tab)} HSC measurements near {target}')
ax.plot('A_F475W', 'A_F475W_MAD', 'ro', markersize=5, data=tab[wvar],
        label=f'{len(wvar)} variable candidates')
ax.set(xlabel='A_F475W [mag]', ylabel='A_F475W_MAD [mag]')
_ = ax.legend(loc='best')
../../../_images/3894b59ea155f5fbc6a90f095edbf3dad009b6561a051d0aaf469fa59496c177.png

Check positions of variable objects in a color-magnitude diagram #

Note that these objects are generally located in the Cepheid instability strip.

b_minus_i = tab['A_F475W'] - tab['A_F814W']

fig, ax = plt.subplots(figsize=(10, 10))
ax.plot(b_minus_i, tab['A_F475W'], 'bo', markersize=2, alpha=0.1,
        label=f'{len(tab)} HSC measurements near {target}')
ax.plot(b_minus_i[wvar], tab['A_F475W'][wvar], 'ro', markersize=5,
        label=f'{len(wvar)} variable candidates')
ax.set(xlabel='A_F475W - A_F814W [mag]', ylabel='A_F475W [mag]')
ax.invert_yaxis()
_ = ax.legend(loc='best')
../../../_images/a00f18ca26416a51a6d52aab20c45552e126ff5546f1c3509889527cb5efb74c.png

Query the API for the light curve for one of the objects #

Select the most variable object as an example.

wvar = wvar[np.argsort(-tab['A_F475W_MAD'][wvar])]
iselect = wvar[0]
print(f"MatchID {tab['MatchID'][iselect]} B = {tab['A_F475W'][iselect]:.3f} B-I = {b_minus_i[iselect]:.3f}")
tab[wvar]
MatchID 80189155 B = 22.451 B-I = 0.450
Table length=29
MatchIDMatchRAMatchDecNumFiltersNumVisitsNumImagesStartMJDStopMJDA_F475WA_F475W_NA_F475W_MADA_F814WA_F814W_NA_F814W_MAD
int64float64float64int64int64int64float64float64float64int64float64float64int64float64
8018915516.1407402.1552883142653965.2915357009.8626222.451120.29422.001120.198
820048816.1447722.1523383142653965.2915357009.8626222.202120.26021.768120.188
6601267816.1351342.1547403142653965.2915357009.8626222.559120.25322.101120.192
6307852616.1055132.1555803142653965.2915357009.8626223.317120.22722.897120.138
8990986216.1171802.1688103142653965.2915357009.8626222.733120.22422.545120.099
9211935816.1365632.1828172122453965.2915353967.7194123.347120.21323.234120.131
6698056416.1256112.1352873142653965.2915357009.8626222.732120.19422.365120.138
9572235616.1330302.1756383142653965.2915357009.8626223.359120.18022.921120.129
6835608316.0957092.1474602122453965.2915353967.7194123.378120.17622.981120.109
4578661016.1213752.1338533142653965.2915357009.8626222.901120.17422.557120.131
..........................................
6979010916.1412842.1528813142653965.2915357009.8626222.635120.13322.138120.071
10043722816.1113102.1609083142653965.2915357009.8626223.382120.12322.914120.070
3085511116.1059252.1576033142653965.2915357009.8626222.781120.11722.698120.056
7021746816.1071422.1781613142653965.2915357009.8626223.804120.11623.428120.116
951069816.1379632.1410273142653965.2915357009.8626223.343120.11423.101120.080
1331738016.1183222.1528173142653965.2915357009.8626223.599120.10923.169120.091
1724089916.1396672.1535973142653965.2915357009.8626222.761120.10522.195120.073
10554598616.1443362.1562623142653965.2915357009.8626223.160120.10422.941120.138
6671616616.1322602.1635123142653965.2915357009.8626223.075120.10422.864120.075
6375565016.0953562.1373382122453965.2915353967.7194122.729120.10322.442120.062

Get column metadata for detailed observation table (which has time-dependent magnitudes).

meta = hscmetadata("detailed")
print(len(meta), "columns in detailed")
pprint(meta['name'].tolist(), compact=True)
39 columns in detailed
['CatID', 'MatchID', 'MemID', 'SourceID', 'ImageID', 'Det', 'MatchRA',
 'MatchDec', 'SourceRA', 'SourceDec', 'D', 'DSigma', 'AbsCorr', 'XImage',
 'YImage', 'ImageName', 'Instrument', 'Mode', 'Detector', 'Aperture',
 'ExposureTime', 'StartTime', 'StopTime', 'StartMJD', 'StopMJD', 'WaveLength',
 'Filter', 'TargetName', 'FluxAper2', 'MagAper2', 'MagAuto', 'PropID', 'CI',
 'KronRadius', 'Flags', 'HTMID', 'X', 'Y', 'Z']

Get separate light curves for F475W and F814W from the detailed table#

columns = """MatchID,SourceID,StartMJD,Detector,Filter,MagAper2,Flags,ImageName""".split(",")
columns = [x.strip() for x in columns]
columns = [x for x in columns if x and not x.startswith('#')]

constraints = {'MatchID': tab['MatchID'][iselect], 'Detector': 'ACS/WFC'}
t0 = time.time()
f475 = hscsearch(table="detailed", release='v3', columns=columns, Filter='F475W', format="table", **constraints)
f814 = hscsearch(table="detailed", release='v3', columns=columns, Filter='F814W', format="table", **constraints)
print(f"{time.time()-t0:.1f} s: retrieved data and converted to {len(f475)} (F475W) and {len(f814)} (F814W) row astropy tables")

f475.sort('StartMJD')
f814.sort('StartMJD')
f475['MagAper2'].format = "{:.3f}"
f475['StartMJD'].format = "{:.5f}"
f814['MagAper2'].format = "{:.3f}"
f814['StartMJD'].format = "{:.5f}"

f475
0.5 s: retrieved data and converted to 12 (F475W) and 12 (F814W) row astropy tables
Table length=12
MatchIDSourceIDStartMJDDetectorFilterMagAper2FlagsImageName
int64int64float64str7str5float64int64str26
80189155400099906230553965.29153ACS/WFCF475W22.1920hst_10505_07_acs_wfc_f475w
80189155400099288800153965.42473ACS/WFCF475W22.2460hst_10505_08_acs_wfc_f475w
80189155400109511696253965.55794ACS/WFCF475W22.3760hst_10505_09_acs_wfc_f475w
80189155400092268073553965.69115ACS/WFCF475W22.5520hst_10505_10_acs_wfc_f475w
80189155400104227614553966.29057ACS/WFCF475W22.7050hst_10505_11_acs_wfc_f475w
80189155400122522139053966.42377ACS/WFCF475W22.8020hst_10505_12_acs_wfc_f475w
80189155400089576071953966.55698ACS/WFCF475W22.7790hst_10505_13_acs_wfc_f475w
80189155400081431786353966.69019ACS/WFCF475W22.8010hst_10505_14_acs_wfc_f475w
80189155400083092964353967.22301ACS/WFCF475W22.5260hst_10505_15_acs_wfc_f475w
80189155400085917111553967.35622ACS/WFCF475W21.5220hst_10505_16_acs_wfc_f475w
80189155400116287008253967.48942ACS/WFCF475W21.4490hst_10505_17_acs_wfc_f475w
80189155400092659285653967.62263ACS/WFCF475W21.7690hst_10505_18_acs_wfc_f475w

Plot the light curves#

The light curves appear well-behaved and are closely correlated in the two filters.

fig, ax = plt.subplots(figsize=(10, 6), tight_layout=True)

ax.plot('StartMJD', 'MagAper2', 'bo', data=f475, label='ACS/WFC F475W')
ax.plot('StartMJD', 'MagAper2', 'ro', data=f814, label='ACS/WFC F814W')

ax.set(xlabel='MJD [days]', ylabel='[mag]')
ax.invert_yaxis()
ax.legend()
<matplotlib.legend.Legend at 0x7f4a8abbdc90>
../../../_images/651ff04e77c270a7227b3eed8280fcc4e4ac4bcf9780d41770a591552b612f06.png

Extract HLA cutout images for the F475W images #

Get HLA F475W cutout images for the example variable. The get_hla_cutout function reads a single cutout image (as a JPEG grayscale image) and returns a PIL image object. See the documentation on the fitscut image cutout service for more information on the web service being used.

Examination of the images can be useful to identified cosmic-ray contamination and other possible image artifacts. In this case, no issues are seen, so the light curve is likely to be reliable.

def get_hla_cutout(imagename, ra, dec, size=33, autoscale=99.5, asinh=1, zoom=1):
    
    """Get JPEG cutout for an image"""
    
    url = "https://hla.stsci.edu/cgi-bin/fitscut.cgi"
    r = requests.get(url, params=dict(ra=ra, dec=dec, size=size, format="jpeg",
                                      red=imagename, autoscale=autoscale, asinh=asinh, zoom=zoom))
    im = Image.open(BytesIO(r.content))
    return im
# sort images by magnitude from faintest to brightest
isort = np.argsort(-f475['MagAper2'])

imagename = f475['ImageName'][isort]
mag = f475['MagAper2'][isort]
mjd = f475['StartMJD'][isort]

nim = len(imagename)
ncols = 4 # images per row
nrows = (nim+ncols-1)//ncols

imsize = 15
mra = tab['MatchRA'][iselect]
mdec = tab['MatchDec'][iselect]
# download list of images; might take a minute
images = [get_hla_cutout(imagename[k], mra, mdec, size=imsize) for k in range(nim)]
plt.rcParams.update({"font.size": 11})
fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(15, (15/ncols)*nrows), tight_layout=True)

axes = axes.flat

for i, (ax, img) in enumerate(zip(axes, images)):
    ax.imshow(img, origin="upper", cmap="gray")
    ax.set_title(f'{mjd[i]:.5f} f475w={mag[i]:.3f}')
../../../_images/5041e199154e35982ecc505a6447be8b4d0005e046a05a601ce1515d2e9d10a5.png