Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Fornax Demo Notebooks

AGN Zoo: Comparison of AGN selected with different metrics

Learning Goals

By the end of this tutorial, you will:

Introduction

Active Galactic Nuclei (AGNs), some of the most powerful sources in the universe, emit a broad range of electromagnetic radiation, from radio waves to gamma rays. Consequently, there is a wide variety of AGN labels depending on the identification/selection scheme and the presence or absence of certain emissions (e.g., Radio loud/quiet, Quasars, Blazars, Seiferts, Changing looks). According to the unified model, this zoo of labels we see depend on a limited number of parameters, namely the viewing angle, the accretion rate, presence or lack of jets, and perhaps the properties of the host/environment (e.g., Padovani et al. 2017). Here, we collect archival photometry and labels from the literature to compare how some of these different labels/selection schemes compare.

We use manifold learning and dimensionality reduction to learn the distribution of AGN lightcurves observed with different facilities. We mostly focus on UMAP (Uniform Manifold Approximation and Projection, McInnes 2020) but also show SOM (Self organizing Map, Kohonen 1990) examples. The reduced 2D projections from these two unsupervised ML techniques reveal similarities and overlaps of different selection techniques. Coloring the projections with various statistical physical properties (e.g., mean brightness, fractional lightcurve variation) is informative of correlations of the selections technique with physics such as AGN variability. Using different parts of the EM in training (or in building the initial higher dimensional manifold) demonstrates how much information if any is in that part of the data for each labeling scheme, for example whether with ZTF optical light curves alone, we can identify sources with variability in WISE near IR bands. These techniques also have a potential for identifying targets of a specific class or characteristic for future follow up observations.

Runtime

As of 2024 September, this notebook takes about 3 minutes to run to completion on Fornax using a server with 16 GB RAM and 4 CPU.

Imports

Here are the libraries used in this network. They are also mostly mentioned in the requirements in case you don’t have them installed.

This cell will install them if needed:

1. Loading data

Here we load a parquet file of light curves generated using the light_curve_collector notebook in this same GitHub repo. With that light_curve_collector notebook, you can build your favorite sample from different sources in the literature and grab the data from archives of interest. This sample contains both spatial coordinates and categorical labels for each AGN. The labels are generated by a bitwise addition of a set of binary indicators. Each binary indicator corresponds to the AGN’s membership in various categories, such as being an SDSS_QSO or a WISE_Variable. For example, an AGN that is both an SDSS_QSO, a WISE_Variable, and also shows ‘Turn_on’ characteristics, would have a label calculated by combining these specific binary indicators using bitwise addition.

Downloading...
From (original): https://drive.google.com/uc?id=1gb2vWn0V2unstElGTTrHIIWIftHbXJvz
Fro
m (redirected): https://drive.google.com/uc?id=1gb2vWn0V2unstElGTTrHIIWIftHbXJvz&confirm=t&uuid=cc7d
dbc4-5d87-492e-8b80-03386d6c6f36
To: /home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/l
ight_curves/data/df_lc_020724.parquet.gzip
  0%|          | 0.00/243M [00:00<?, ?B/s]
  0%|          | 524k/243M [00:00<00:50, 4.83MB/s]
  1%|▏         | 3.15M/243M [00:00<00:14, 16.1MB/s]
  5%|▌         | 13.1M/243M [00:00<00:04, 49.6MB/s]
  9%|▉         | 21.5M/243M [00:00<00:03, 57.9MB/s]
 13%|█▎        | 32.5M/243M [00:00<00:02, 75.0MB/s]
 18%|█▊        | 44.6M/243M [00:00<00:02, 87.7MB/s]
 22%|██▏       | 53.5M/243M [00:00<00:02, 81.9MB/s]
 27%|██▋       | 65.5M/243M [00:00<00:01, 92.3MB/s]
 31%|███       | 75.0M/243M [00:00<00:01, 91.8MB/s]
 36%|███▌      | 86.5M/243M [00:01<00:01, 97.9MB/s]
 42%|████▏     | 101M/243M [00:01<00:01, 112MB/s]  
 49%|████▉     | 120M/243M [00:01<00:00, 134MB/s]
 58%|█████▊    | 141M/243M [00:01<00:00, 154MB/s]
 66%|██████▌   | 160M/243M [00:01<00:00, 168MB/s]
 73%|███████▎  | 178M/243M [00:01<00:00, 141MB/s]
 80%|███████▉  | 194M/243M [00:01<00:00, 146MB/s]
 87%|████████▋ | 212M/243M [00:01<00:00, 156MB/s]
 97%|█████████▋| 236M/243M [00:01<00:00, 177MB/s]
100%|██████████| 243M/243M [00:02<00:00, 120MB/s]

Loading...

1.1 What is in this sample

To effectively undertake machine learning (ML) in addressing a specific question, it’s imperative to have a clear understanding of the data we’ll be utilizing. This understanding aids in selecting the appropriate ML approach and, critically, allows for informed and necessary data preprocessing. For example whether a normalization is needed, and what band to choose for normalization.

<Figure size 800x800 with 1 Axes>

In this particular example, the largest subsamples of AGNs, all with a criteria on redshift (z<1), are from the optical spectra by the SDSS quasar sample DR16Q, the value added SDSS spectra from SPIDERS, and a subset of AGNs selected in MIR WISE bands based on their variability (csv in data folder credit RChary). We also include some smaller samples from the literature to see where they sit compared to the rest of the population and if they are localized on the 2D projection. These include the Changing Look AGNs from the literature (e.g., LaMassa et al. 2015, Lyu et al. 2022, Hon et al. 2022), a sample which showed variability in Galex UV images (Wasleske et al. 2022), a sample of variable sources identified in optical Palomar observations (Baldassare et al. 2020), and the optically variable AGNs in the COSMOS field from a three year program on the VLT(De Cicco et al. 2019). We also include 30 Tidal Disruption Event coordinates identified from ZTF light curves Hammerstein et al. (2022).

<Figure size 2000x400 with 1 Axes>

The histogram shows the number of lightcurves which ended up in the multi-index data frame from each of the archive calls in different wavebands/filters.

/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/.tox/py313-buildhtml/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:3860: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/.tox/py313-buildhtml/lib/python3.13/site-packages/numpy/_core/_methods.py:144: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/.tox/py313-buildhtml/lib/python3.13/site-packages/numpy/_core/_methods.py:222: RuntimeWarning: Degrees of freedom <= 0 for slice
  ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/.tox/py313-buildhtml/lib/python3.13/site-packages/numpy/_core/_methods.py:180: RuntimeWarning: invalid value encountered in divide
  arrmean = um.true_divide(arrmean, div, out=arrmean,
/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/.tox/py313-buildhtml/lib/python3.13/site-packages/numpy/_core/_methods.py:214: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
<Figure size 2000x400 with 1 Axes>

While from the histogram plot we see which bands have the highest number of observed lightcurves, what might matter more in finding/selecting variability or changing look in lightcurves is the cadence and the average baseline of observations. For instance, Panstarrs has a large number of lightcurve detections in our sample, but from the figure above we see that the average number of visits and the baseline for those observations are considerably less than ZTF. WISE also shows the longest baseline of observations which is suitable to finding longer term variability in objects.

2. Preprocess data for ML (ZTF bands)

We first look at this sample only in ZTF bands which have the largest number of visits. We start by unifying the time grid of the light curves so oobjects with different start time or number of observations can be compared. We do this by interpolation to a new grid. The choice of the grid resolution and baseline is strictly dependent on the input data, in this case ZTF, to preserve as much as possible all the information from the observations. The unify_lc, or unify_lc_gp functions do the unification of the lightcurve arrays. For details please see the codes. The time arrays are chosen based on the average duration of observations, with ZTF and WISE covering 1600, 4000 days respectively. We note that we disregard the time of observation of each source, by subtracting the initial time from the array and bringing all lightcurves to the same footing. This has to be taken into account if it influences the science of interest. We then interoplate the time arrays with linear or Gaussian Process regression (unift_lc/ unify_lc_gp respectively). We also remove from the sample objects with less than 5 datapoints in their light curve. We measure basic statistics and combine the tree observed ZTF bands into one longer array as input to dimensionailty reduction after deciding on normalization. We also do a shuffling of the sample to be sure that the separations of different classes by ML are not simply due to the order they are seen in training (in case it is not done by the ML routine itself).

Loading...
<Figure size 1500x500 with 1 Axes>
<Figure size 1500x500 with 1 Axes>
<Figure size 1500x500 with 1 Axes>
<Figure size 1500x500 with 1 Axes>
<Figure size 1500x500 with 1 Axes>
/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/light_curves/code_src/AGNzoo_functions.py:290: RuntimeWarning: invalid value encountered in sqrt
  fvar = (np.sqrt(varf - deltaf)) / meanf

The combination of the tree bands into one longer arrays in order of increasing wavelength, can be seen as providing both the SED shape as well as variability in each from the light curve. Figure below demonstrates this as well as our normalization choice. We normalize the data in ZTF R band as it has a higher average numbe of visits compared to G and I band. We remove outliers before measuring the mean and max of the light curve and normalizing by it. This normalization can be skipped if one is mearly interested in comparing brightnesses of the data in this sample, but as dependence on flux is strong to look for variability and compare shapes of light curves a normalization helps.

<Figure size 1800x400 with 3 Axes>

3. Learn the Manifold

Now we can train a UMAP with the processed data vectors above. Different choices for the number of neighbors, minimum distance and metric can be made and a parameter space can be explored. We show here our preferred combination given this data. We choose manhattan distance (also called the L1 distance) as it is optimal for the kind of grid we interpolated on, for instance we want the distance to not change if there are observations missing. Another metric appropriate for our purpose in time domain analysis is Dynamic Time Warping (DTW), which is insensitive to a shift in time. This is helpful as we interpolate the observations onto a grid starting from time 0 and when discussing variability we care less about when it happens and more about whether and how strong it happened. As the measurement of the DTW distance takes longer compared to the other metrics we show examples here with manhattan and only show one example exploring the parameter space including a DTW metric in the last cell of this notebook.

/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/.tox/py313-buildhtml/lib/python3.13/site-packages/umap/umap_.py:1952: UserWarning: n_jobs value 1 overridden to 1 by setting random_state. Use no seed for parallelism.
  warn(
<Figure size 1800x600 with 5 Axes>

The left panel is colorcoded by the origin of the sample. The middle panel shows the sum of mean brightnesses in three bands (arbitrary unit) demonstrating that after normalization we see no correlation with brightness. The panel on the right is color coded by a statistical measure of variability (i.e. the fractional variation see here). As with the plotting above it is not easy to see all the data points and correlations in the next two cells measure probability of belonging to each original sample as well as the mean statistical property on an interpolated grid on this reduced 2D projected surface.

<Figure size 1200x400 with 4 Axes>

3.1 Sample comparison on the UMAP

/tmp/ipykernel_3628/3793995111.py:10: RuntimeWarning: invalid value encountered in divide
  prob = hist_per_cluster / hist
<Figure size 1500x1200 with 23 Axes>

Figure above shows how with ZTF light curves alone we can separate some of these AGN samples, where they have overlaps. We can do a similar exercise with other dimensionality reduction techniques. Below we show two SOMs one with normalized and another with no normalization. The advantage of Umaps to SOMs is that in practice you may change the parameters to separate classes of vastly different data points, as distance is preserved on a umap. On a SOM however only topology of higher dimensions is preserved and not distance hence, the change on the 2d grid does not need to be smooth and from one cell to next there might be larg jumps. On the other hand, an advantage of the SOM is that by definition it has a grid and no need for a posterior interpolation (as we did above) is needed to map more data or to measure probabilities, etc.

3.2 Reduced dimensions on a SOM grid

/tmp/ipykernel_3628/2599028209.py:53: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
  plt.tight_layout()
<Figure size 1200x900 with 13 Axes>

The above SOMs are colored by the mean fractional variation of the lightcurves in all bands (a measure of AGN variability). The crosses are different samples mapped to the trained SOM to see if they are distinguishable on a normalized lightcurve som.

/tmp/ipykernel_3628/1301010532.py:49: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
  plt.tight_layout()
<Figure size 1200x900 with 13 Axes>
/tmp/ipykernel_3628/2695913503.py:31: UserWarning: Tight layout not applied. tight_layout cannot make Axes width small enough to accommodate all Axes decorations
  plt.tight_layout()
<Figure size 1200x1200 with 223 Axes>

skipping the normalization of lightcurves, further separates turn on/off CLAGNs when looking at ZTF lightcurves only.

4. Repeating the above, this time with ZTF + WISE manifold

Loading...
<Figure size 1500x500 with 1 Axes>
<Figure size 1500x500 with 1 Axes>
<Figure size 1500x500 with 1 Axes>
/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/light_curves/code_src/AGNzoo_functions.py:290: RuntimeWarning: invalid value encountered in sqrt
  fvar = (np.sqrt(varf - deltaf)) / meanf
/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/.tox/py313-buildhtml/lib/python3.13/site-packages/umap/umap_.py:1952: UserWarning: n_jobs value 1 overridden to 1 by setting random_state. Use no seed for parallelism.
  warn(
<Figure size 1800x600 with 5 Axes>
/tmp/ipykernel_3628/3793995111.py:10: RuntimeWarning: invalid value encountered in divide
  prob = hist_per_cluster / hist
<Figure size 1500x1200 with 23 Axes>

5. Wise bands alone

Loading...
<Figure size 1500x500 with 1 Axes>
/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/light_curves/code_src/AGNzoo_functions.py:290: RuntimeWarning: invalid value encountered in sqrt
  fvar = (np.sqrt(varf - deltaf)) / meanf
/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/.tox/py313-buildhtml/lib/python3.13/site-packages/umap/umap_.py:1952: UserWarning: n_jobs value 1 overridden to 1 by setting random_state. Use no seed for parallelism.
  warn(
<Figure size 1800x600 with 5 Axes>
/tmp/ipykernel_3628/3463858432.py:10: RuntimeWarning: invalid value encountered in divide
  prob = hist_per_cluster / hist
<Figure size 1500x1200 with 23 Axes>

6. UMAP with different metrics/distances on ZTF+WISE

DTW takes a bit longer compared to other metrics, so it is commented out in the cell below.

/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/.tox/py313-buildhtml/lib/python3.13/site-packages/umap/umap_.py:1952: UserWarning: n_jobs value 1 overridden to 1 by setting random_state. Use no seed for parallelism.
  warn(
/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/.tox/py313-buildhtml/lib/python3.13/site-packages/umap/umap_.py:1952: UserWarning: n_jobs value 1 overridden to 1 by setting random_state. Use no seed for parallelism.
  warn(
/home/runner/work/fornax-demo-notebooks/fornax-demo-notebooks/.tox/py313-buildhtml/lib/python3.13/site-packages/umap/umap_.py:1952: UserWarning: n_jobs value 1 overridden to 1 by setting random_state. Use no seed for parallelism.
  warn(
(np.float64(-3.8178215265274047), np.float64(10.599652791023255), np.float64(2.8609209060668945), np.float64(11.284222602844238))
<Figure size 1200x1000 with 3 Axes>

About this notebook

Acknowledgements

References

References
  1. Hammerstein, E., van Velzen, S., Gezari, S., Cenko, S. B., Yao, Y., Ward, C., Frederick, S., Villanueva, N., Somalwar, J. J., Graham, M. J., Kulkarni, S. R., Stern, D., Andreoni, I., Bellm, E. C., Dekany, R., Dhawan, S., Drake, A. J., Fremling, C., Gatkine, P., … Yan, L. (2022). The Final Season Reimagined: 30 Tidal Disruption Events from the ZTF-I Survey. The Astrophysical Journal, 942(1), 9. 10.3847/1538-4357/aca283