Getting Started#

[35]:
from GaiaAlertsPy import alert as gaap

import numpy as np
from astropy.stats import sigma_clip
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = "retina"
from matplotlib import rcParams
rcParams['savefig.dpi'] = 550
rcParams['font.size'] = 20
plt.rc('font', family='serif')

# fancy plotting
import seaborn as sns
pal = sns.color_palette('magma', 80)
hex_colors = pal.as_hex()

Query all Gaia Photometric Science Alerts to Date#

[6]:
table = gaap.all_sources() # query and download all Gaia Photometric Science Alerts
[5]:
table
[5]:
Table length=25708
NameDateRaDegDecDegAlertMagHistoricMagHistoricStdDevClassPublishedCommentTNSid
str9str19float64float64float64float64float64str14str19str130str10
Gaia24byo2024-07-21 08:45:07189.205866.8412818.44----unknown2024-07-24 21:12:16candidate SN near galaxy WISEA J123649.31+065027.9AT2024poq
Gaia24byn2024-07-21 00:34:3532.850646.7041218.3----unknown2024-07-24 21:11:26Apparently hostless transientAT2024knb
Gaia24bym2024-07-21 20:00:19211.39828-39.2031718.48----SN2024-07-24 21:10:36confirmed SN in galaxy IC 4367SN2024pfc
Gaia24byl2024-07-21 13:37:09233.02488-60.352518.7----unknown2024-07-24 21:09:46blue transient in the galactic planeAT2024qah
Gaia24byk2024-07-21 15:21:38172.1745242.5208318.8619.340.11QSO2024-07-24 21:08:56slow brightening in known QSOAT2024qag
Gaia24byj2024-07-21 05:07:3623.5668730.6116517.4717.970.15unknown2024-07-24 21:08:06Brightening in Gaia and GALEX sourceAT2020aafy
Gaia24byi2024-07-21 19:29:51248.02041-64.8837318.7219.480.21unknown2024-07-24 21:07:04Brightening of a Gaia and WISE sourceAT2024qaf
Gaia24byh2024-07-20 18:07:051.79692-19.9179418.9419.280.09unknown2024-07-24 11:49:06Brightening in Gaia and Wise sourceAT2024pzq
Gaia24byg2024-07-20 22:53:2729.2152542.5021717.4120.280.15unknown2024-07-24 11:43:542.5 mag brightening in candidate CV TCP J01565167+4230076AT2024moh
Gaia24byf2024-07-20 10:37:2638.239655.6628617.8819.130.59unknown2024-07-24 11:41:441.5 mag brightening in candidate CVAT2024pzp
.................................
Gaia14aaj2014-09-12 15:40:38187.702146.9698218.9819.560.1unknown2014-10-13 14:29:00----
Gaia14aai2014-08-30 11:57:3023.88339-20.4079619.1819.70.08unknown2014-10-13 14:29:00----
Gaia14aah2014-08-26 19:42:12210.4533754.513318.018.510.06unknown2014-10-13 14:29:00----
Gaia14aag2014-08-22 15:17:46219.1433544.6526117.7518.420.02unknown2014-10-13 14:29:00----
Gaia14aaf2014-08-17 21:35:53244.2538162.0068517.0518.060.19CV2014-10-13 14:29:00----
Gaia14aae2014-08-11 13:43:26242.8915663.1421716.0417.560.2CV2014-10-13 14:29:00----
Gaia14aad2014-08-08 01:17:01209.6812248.7009818.2818.850.02unknown2014-10-13 14:29:00----
Gaia14aac2014-08-02 07:19:24214.6674456.4695918.6819.550.05unknown2014-10-13 14:29:00----
Gaia14aab2014-07-27 19:10:29206.9101155.5487119.1120.00.1unknown2014-10-13 14:29:00----
Gaia14aaa2014-08-30 02:22:31200.2596145.5394317.3219.220.42SN Ia2014-09-12 09:00:00----

Sky Distribution of Alerts#

[6]:
plt.figure(figsize=(10,5))
_ = plt.hist2d(table['RaDeg'], table['DecDeg'], bins=(50, 50), cmap='Spectral_r')
plt.colorbar(label='# Sources')
plt.xlabel("RA [deg]")
plt.ylabel("DEC [deg]")
[6]:
Text(0, 0.5, 'DEC [deg]')
../_images/source_getting-started_6_1.png

Histogram of All Alert Magnitudes#

[11]:
plt.figure(figsize=(6,5))
_ = plt.hist(table['AlertMag'], histtype='stepfilled', color='teal', bins='scott', alpha=0.9)
plt.yscale('log')
plt.ylabel("Log (N)")
plt.xlabel("Alert $G_{mag}$ [mag]")
plt.minorticks_on()
../_images/source_getting-started_8_0.png

Getting Started with Alert Light Cuves#

In this short tutorial you will learn how to use GaiaAlertsPy and query the alert light curves. Once you query a Gaia Alerts, it will return a astropy.Table containing the epochal photometry.

[7]:
target_id = "Gaia22eoa"
alert_lc = gaap.GaiaAlert(target_id).query_lightcurve_alert()
[16]:
# view first 5 alerts
alert_lc[0:5]
[16]:
Table length=5
JDmag_Gmag_G_error
float64float64float64
2457107.455115740716.70.015068630569774477
2457131.131041666516.890.01568925719710279
2457268.40935185216.810.015420801849645116
2457298.716215277617.00.016077223994238388
2457319.640381944416.980.016004964926408682

The photometric uncertainties are calculated using the following equation and are valid for 13<G<21:

\[\begin{equation} \sigma_{mag_{G}} = 3.43779 - (G/1.13759) + (G/3.44123)^2 - (G/6.51996)^3 + (G/11.45922)^4 \end{equation}\]

For more information please see Gaia Early Data Release 3. Gaia photometric science alerts.

Let’s plot the light curve of this interesting Young Stellar Object:

[8]:
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(10,5))
ax.errorbar(alert_lc['JD']-2.45e6, alert_lc['mag_G'], alert_lc['mag_G_error'], fmt='o', capsize=1, color='seagreen',
label='Gaia-G')
ax.legend()
ax.set_ylim(ax.set_ylim()[::-1])
ax.set_xlabel("Julian Date - 2.45e6 [days]")
ax.set_ylabel("Magnitude")
plt.minorticks_on()
../_images/source_getting-started_14_0.png

Accessing the BP-RP Low-Res. Spectra#

For the moment we suggest that the spectra for each band is summed and the zero-point for each filter to be applied when converting from the raw ADU to the AB magnitude system. Further investigation will examine the calibration between standard stars and calibrating the ADU spectra to more reliable zero-point estimations and other systematics.

Warning – this is a very crude estimate to convert the BP/RP spectra to BP/RP magnitudes. More tutorials and methods for calibration will come soon!

Let’s first fetch all the BP/RP photometry:

[9]:
# Now we can even query the BP_RP information
color_lc = gaap.GaiaAlert(target_id).query_bprp_history()
[11]:
color_lc[0:5]
[11]:
Table length=5
DateJDAverage Mag.orderbprpName
str19float64float64int64float64[60]float64[60]str9
2015-03-25 22:55:222457107.4616.700.0 .. 14.00.019 .. -2.419Gaia22eoa
2015-04-18 15:08:422457131.1316.8911.2061 .. -0.20610.2057 .. -5.2057Gaia22eoa
2015-09-02 21:49:292457268.4116.8121.9246 .. -2.32460.5859 .. -1.3859Gaia22eoa
2015-10-03 05:11:222457298.7217.032.9471 .. -0.54710.238 .. -3.038Gaia22eoa
2015-10-24 03:22:102457319.6416.984-1.6875 .. 8.0875-1.029 .. -4.771Gaia22eoa

Now we can estimate a very approximate magnitude for each bp/rp spectrum using the instrumental zero-point values:

[29]:
# Instrumental zero-point values
zp_BP, zp_RP = 25.3514, 24.7619 # Table 5.2 (https://gea.esac.esa.int/archive/documentation/GDR2/Data_processing/chap_cu5pho/sec_cu5pho_calibr/ssec_cu5pho_calibr_extern.html)

bp_mag, rp_mag = [], []
for _lc in color_lc:
    bp0, rp0 = _lc['bp'], _lc['rp']

    # Count only positive ADU counts & apply 5-sigma clip (see Hodgkin et al. 2021; Section 3.6)
    bp, rp = sigma_clip(bp0[bp0>0], sigma=5), sigma_clip(rp0[rp0>0], sigma=5)

    # Convert total flux to magnitudes
    bp_mag.append(-2.5*np.log10(bp.sum()) + zp_BP)
    rp_mag.append(-2.5*np.log10(rp.sum()) + zp_RP)

Time Series BP RP Spectra#

Alternatively, we can also fetch the raw ADU spectra that are reported on the GSA website. Same drill as before. These spectra are not calibrated - however some crude clolors can be extracted if you know the SED if your soruce.

Supposed we wanted to see the overall change in the low-res BP/RP spectra as a function of time and Gaia G magnitude. We can make a nice visualization combining the epochal BP/RP spectra including the average G band magnitude. From the plot below, we can see how for this particular souce that its spectrum is mostly red!

Please see the epochal BP/RP tutorial for more details!

[36]:
plt.figure(figsize=(8, 7))

# Plotting each color light curve
for i, c in enumerate(color_lc):
    offset = i * 20
    color = hex_colors[i % len(hex_colors)]

    # Plot BP and RP light curves with offset
    plt.step(range(0, 60), c['bp'] + offset, color=color, alpha=0.9, lw=2)
    plt.step(range(60, 120), c['rp'] + offset, color=color, alpha=0.9, lw=2)

    # Annotate with average magnitude every third curve
    if i % 3 == 0:
        plt.text(130, np.min(c['rp']) + offset, f"Gmag = {c['Average Mag.']:.2f}", fontsize=9, color=color, weight='bold')

# Labels and grid
plt.ylabel("ADU + Const.")
plt.xlabel("Pixels (Pseudo-Wavelength)")
plt.minorticks_on()
plt.grid(which='both', linestyle='--', alpha=0.2)

plt.tight_layout()
../_images/source_getting-started_22_0.png

Using the extrapolated BP/RP colors we can now plot the BP and RP light curves to see if our object of interest has any color evolution:

[33]:
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(10,5))
ax.errorbar(alert_lc['JD'], alert_lc['mag_G'], alert_lc['mag_G_error'], fmt='.', capsize=1, color='seagreen',
label='Gaia-G')
ax.scatter(color_lc['JD'], bp_mag, color='mediumpurple', label='BP')
ax.scatter(color_lc['JD'], rp_mag, color='crimson', label='RP')
ax.legend()
ax.set_ylim(ax.set_ylim()[::-1])
ax.set_xlabel("Julian Date")
ax.set_ylabel("Apparent Mag.")
[33]:
Text(0, 0.5, 'Apparent Mag.')
../_images/source_getting-started_24_1.png