In [1]:
%matplotlib inline
%config InlineBackend.figure_formats=['svg']

import matplotlib
matplotlib.rcParams['figure.figsize'] = (9, 6)

In [2]:
import numpy as np
from matplotlib import pyplot as plt

from astropy import units as u
from astropy import coordinates as coord
from astropy.table import Column
from astroquery.vizier import Vizier


# “Crossmatching a catalogue of galaxies with bright stars base on their magnitude” or “Playing with indices”

## Excuse¶

We have a dense catalogue of galaxies in which we want to flag those that are near bright stars (because they may corrupt their magnitude). We want the flagging radius to be dependent on the r magnitude of the stars, with the prescription:

$$radius[arcsec] = \exp(-0.43 * r_{mag} + 8.4)$$

Don't worry, it's only an excuse to play with numpy array indices.

## Reminder: indexing with a list of indexes¶

Numpy arrays may be indexed with a list of integers corresponding to the indexes of the elements you want (see documentation).

In [3]:
number_names = np.array(['zero', 'one', 'two', 'three', 'four', 'five'])
print(number_names[[3, 0, 0, 1, 2, 5, 5, 4]])

['three' 'zero' 'zero' 'one' 'two' 'five' 'five' 'four']


## Getting the catalogues¶

We will use the SDSS9 catalogue as a dense catalogue of galaxies, and will use the Tycho-2 catalogue to get our stars. We get these catalogues directly from Vizier.

In [4]:
Vizier.ROW_LIMIT = -1  # If we don't do that, Vizier only send 50 rows.
region_center = coord.SkyCoord(34.8*u.deg, -4.4*u.deg)
sdss9, tycho2 = Vizier.query_region(region_center, width="40m", catalog=['sdss9', 'tycho2'])

In [5]:
plt.plot(sdss9['RAJ2000'], sdss9['DEJ2000'], "bo",
markeredgecolor='None', alpha=.5, label="SDSS9 galaxies")
plt.plot(tycho2['RAmdeg'], tycho2['DEmdeg'], "y*",
label="Tycho2 stars", markersize=14)
plt.xlabel("RA")
plt.ylabel("Dec")
plt.legend()

Out[5]:
<matplotlib.legend.Legend at 0x7f1ea40e82b0>