An Application to a Simulated Galaxy

This notebook gives an example of how to use AstroLink for exploration of astrophysical data.

First, we need to set up for our analysis…

[1]:
# Uncomment for interactive plots
#%matplotlib widget

# Comment for interactive plots
%matplotlib inline
[2]:
# Imports
import numpy as np
from astrolink import AstroLink
import matplotlib.pyplot as plt
from scipy.stats import beta

… and then we need some data:

[3]:
P = np.load('../data/newhalo_young.npy')
print(P.shape, P.dtype)
(200359, 8) float32

P is a simulated galaxy expressed a numpy array consisting of 200359 points in 8 dimensions. Specifically, it is the ‘newhalo_young’ galaxy from Galaxia (originally from the Johnston et al. (2008) simulations) and the points represent stellar particles. The 8 dimensions (in the order that they appear within P) are; the three Cartesian spatial coordinates (x, y, z: in kpc); the three corresponding Cartesian velocities (vx, vy, vz: in km/s); and two elemental abundances ([Fe/H], [\(\alpha\)/Fe]: unitless).

What does the galaxy look like?

[4]:
# Plot the positions in space
fig, ax = plt.subplots(figsize=(12, 12), subplot_kw={'projection': '3d'})
ax.scatter(*P[:, :3].T, s=0.1, facecolors='k', edgecolors='k', alpha=0.1)
ax.set_aspect('equal')
ax.set_title('Positions of the stars')
ax.set_xlabel('x (kpc)')
ax.set_ylabel('y (kpc)')
ax.set_zlabel('z (kpc)')
[4]:
Text(0.5, 0, 'z (kpc)')
_images/simulated_galaxy_demo_8_1.png
[5]:
# Plot the velocity distribution
fig, ax = plt.subplots(figsize=(12, 12), subplot_kw={'projection': '3d'})
ax.scatter(*P[:, 3:6].T, s=0.1, facecolors='k', edgecolors='k', alpha=0.1)
ax.set_aspect('equal')
ax.set_title('Velocities of the stars')
ax.set_xlabel(r'$v_x$ (km/s)')
ax.set_ylabel(r'$v_y$ (km/s)')
ax.set_zlabel(r'$v_z$ (km/s)')
[5]:
Text(0.5, 0, '$v_z$ (km/s)')
_images/simulated_galaxy_demo_9_1.png
[6]:
# Plot the [alpha/Fe] versus [Fe/H] plane
fig, ax = plt.subplots(figsize=(12, 12))
ax.scatter(*P[:, 6:].T, s=0.1, facecolors='k', edgecolors='k', alpha=0.5)
ax.set_aspect('equal')
ax.set_title(r'The [$\alpha$/Fe] versus [Fe/H] plane of the stars')
ax.set_xlabel('[Fe/H]')
ax.set_ylabel(r'[$\alpha$/Fe]')
[6]:
Text(0, 0.5, '[$\\alpha$/Fe]')
_images/simulated_galaxy_demo_10_1.png

So we can clearly see that there is structure within the halo. So how do we find that structure?

Changing the clusters

Having observed the ordered-density plot, the prominence distribution (and fitted model), and the clusters that AstroLink has found from the data, you may wish to adjust the output.

If you wish to adjust whether the data is rescaled before clustering or not, you can change the adaptive attribute (adaptive = 1 by default, meaning that each feature is rescaled to have unit variance) and re-run AstroLink. For example;

c.adaptive = 0
c.run()

If you wish to adjust the resolution of the clustering structure (i.e. how smooth the estimated density field is and thereby how sensitive AstroLink is to fine-structure), you can change the k_den attribute (k_den = 20 by default) and re-run AstroLink. For example;

c.k_den = 30
c.run()

If you wish to adjust how well-connected the clustering structure is (i.e. the meaning of ‘local’ when finding structure), you can change the k_link attribute (k_link = ‘auto’ by default, meaning that is calculated from the k_den parameter and the dimensionality of the input data set) and re-run AstroLink. For example;

c.k_link = 10
c.run()

Changing any of the above attributes requires re-running AstroLink, however the following attributes can be changed without needing to re-run the entire algorithm and instead only needing to (re-)run the extract_clusters() method.

If you wish to adjust the style of the clustering hierarchy, you can change the h_style attribute (h_style = 1 by default) and run the extract_clusters() method. For example;

c.h_style = 0
c.extract_clusters()

If you wish to adjust the lower statistical significance threshold of the clusters, you can change the S attribute (S = ‘auto’ by default, meaning that it is calculated to best separate noise and clusters according to the prominence model fit) and run the extract_clusters() method. For example;

c.S = 5
c.extract_clusters()

Of course, these parameters can all be specified when initialising the AstroLink object. For example;

c = AstroLink(P, adaptive = 0, k_den = 30, k_link = 10, h_style = 0, S = 5)

Further analysis

To do further analysis on the clustering output, the user may wish to know which points (with respect to the order in which they appear within the input data) belong to the clusters that AstroLink has found. These sets can be constructed from the ordering and clusters attributes.

cluster_members = [clusterer.ordering[clst[0]:clst[1]] for clst in clusterer.clusters]