MaStar Tutorials

Python Tutorial

This Python tutorial provides basic examples of how to view the MaStar catalog and spectral data. This tutorial assumes you are using Python 3 and have the Astropy package installed.

Using the mastarall file

First, import the necessary packages:

import astropy.io.fits as fits
import numpy as np
import matplotlib.pyplot as plt

The mastarall file contains important summary info about each star in the catalog. We can load in the catalog with

mastarall = fits.open(dir + 'mastarall-v3_1_1-v1_7_7.fits')

where “dir” is the path to the directory where you’ve stored the mastarall file.

To look at the header information of the fits file and identify which extension to use, type

mastarall.info()

We are interested in the "GOODVISITS" extension, so we will be using extension 2. For a full description of the different extensions, see the catalog documentation.

To learn what information this extension contains, list all of the column names using:

mastarall[2].data.names

To import your stellar parameter file of choice, go to this link. For this example we will be using the median parameters - 'mastar-goodvisits_v3_1_1-v1_7_7-params-median.fits'. We load in the parameters with

params = fits.open(dir + 'mastar-goodvisits_v3_1_1-v1_7_7-params-median.fits')[1].data
teff, logg, feh = params['teff'], params['logg'], params['feh']
valid = params['valid']   #used to remove stars with that aren't valid

Let’s select all K stars from this catalog with effective temperatures (from input catalog) between 3700 and 5200K (note not all stars have valid input stellar parameters) and print the number of stars found:

ksel = np.where((teff > 3700) & (teff < 5200) & (valid == 1))
print(len(mastarall[2].data[ksel]))   #how many spectra are selected

We can use this selector to examine other properties of these stars, such as their surface gravity distribution, e.g.,

plt.hist(logg[ksel])
plt.title("log g")
plt.show()

Or alternatively you can put the K stars into their own structure including all parameters from the mastarall structure.

kstars = fits.open(dir + 'mastar-goodvisits_v3_1_1-v1_7_7-params-median.fits')[1].data[ksel]
plt.hist(kstars["logg"])
plt.title("log g")
plt.show()

Plotting a MaStar spectrum

Let’s plot the spectrum for the first of our K stars selected above. We first need to find its MaNGA ID:

print(kstars[0]["MANGAID"])

Next we will load in the spectra file described here:

goodspec = fits.open(dir+'mastar-goodspec-v3_1_1-v1_7_7.fits')[1].data

Cross-reference the MaNGA ID from the mastarall file with the goodspec file to isolate the spectra we're interested in. Note that most stars are observed multiple times, so this may return more than one spectra:

visits = goodspec["MANGAID"] == kstars[0]["MANGAID"]
wl = goodspec[visits]["WAVE"][0]
flux = goodspec[visits]["FLUX"][0]

Now let’s plot the spectrum. Note that this hasn't been de-reddened and that E(B-V) values can be found in here:

plt.plot(wl,flux)
plt.ylabel("flux (1e-17 erg/s/cm$^2$/Angstrom")
plt.xlabel("wavelength (Angstroms)")
plt.show()
The spectrum for one MaStar K star
The spectrum for one MaStar K star

Plotting a Gaia Colour Magnitude Diagram (CMD)

We can use the extinction corrected Gaia colours in this file to plot a CMD of MaStar stars, coloured by their parameters. We will use the atmosphere parameters already opened in the first example.
Firstly, download the file and open it to get the Gaia colour index and absolute magnitude.

photom = fits.open(dir + 'mastarall-gaia-extcorr-v3_1_1-v1_7_7.fits')[1].data
bprp_gaia, g_mag = photom['BP_RP'], photom['PHOT_G_MEAN_MAG']   #photometry
clean_match = photom['GAIA_CLEANMATCH']          #mask of clean matched to Gaia
mask = np.where((valid == 1)&(clean_match == 1))   #mask of the valid params and Gaia clean match

Now plot the CMD:

plt.scatter(bprp_gaia[mask], g_mag[mask], c=teff[mask], cmap='rainbow_r')
plt.gca().invert_yaxis()
plt.xlabel('$G_{BP}-G_{RP})
plt.ylabel('$M_{G})
cbar = plt.colorbar(pad=0)
cbar.set_alpha(1)
cbar.set_label('T$_{eff}/10^4$ [K]')
cbar.ax.invert_yaxis()
cbar.draw_all()
plt.show()

IDL Tutorial

This IDL tutorial provides basic examples of how to view the MaStar catalog and spectral data. This tutorial assumes you are using at least IDL 7.1 and have the IDL Astronomy User's Library installed.

Using the mastarall file

The mastarall file contains important summary info about each star in the catalog. We can load in the catalog with

mastar = mrdfits(dir + 'mastarall-v2_4_3-v1_0_2.fits','GOODSTARS',hdr)

where "dir" is the path to the directory where you've stored the mastarall file. Here, we have read in the GOODSTARS extension. For a full description of the different extensions, see the catalog documentation.

To see the contents of the catalog, type

help,mastar,/str

Let's select all K stars from this catalog with effective temperatures (from input catalog) between 3700 and 5200 K (note not all stars have valid input stellar parameters) and print the number of stars found:

ksel = where(mastar.input_teff ge 3700 and mastar.input_teff lt 5200,count)
print,count

We can use this selector to examine other properties of these stars, such as their surface gravity distribution, e.g.,

plothist,mastar[ksel].input_logg,xtitle='log g'

Or alternatively you can put the K stars into their own IDL structure including all parameters from the mastar structure.

kstars = mastar[ksel]
plothist,kstars.input_logg,xtitle='log g'

Plotting a MaStar spectrum

Let's plot the spectrum for the first of our K stars selected above. We first need to find its MaNGA ID:

print,kstars[0].mangaid

Next we will load in the spectra file described here:

goodspec = mrdfits(dir+"mastar-goodspec-v2_4_3-v1_0_2.fits.gz",1,hdr2)

Cross-reference the MaNGA ID from the mastarall file with the goodspec file to isolate the spectra we're interested in. In this case, the star was observed multiple times, so we will plot the first visit:

visits = where(strtrim(goodspec.MANGAID,2) eq strtrim(kstars[0].MANGAID,2))
wl = goodspec[visits[0]].WAVE
flux = goodspec[visits[0]].FLUX

Now let's plot the spectrum:

plot,wl,flux,xtitle='wavelength (Angstroms)',ytitle='flux (1e-17 erg/s/cm^2/Angstrom',/xsty,font=0
The spectrum for one MaStar K star
The spectrum for one MaStar K star