Closed cptkirkh closed 4 years ago
The code that you quoted is a Pandas function to read a csv file (which you don't have), and it won't read the Firefly FITS file. The code below will parse the Firefly FITS file and produce the needed csv file, which can be read in with Pandas.
I wrote this notebook as an exercise for a class, but I thought that extracting the spatially resolved stellar mass measurements from the Firefly catalog to be too time-consuming for class purposes. For the Marvin tutorials, I did not include the relevant csv file required to complete the tutorial (manga-8077-6104_mstar.csv
)---sorry! I'm going to add that file to the documentation because it makes this tutorial a lot simpler without extracting the map-level information from the Firefly file (which is also pretty large).
For your purposes, here is the script (called galaxy_spaxel_mstar.py
) that I used to generate manga-8077-6104_mstar.csv
from the Firefly fits file. The trick is matching the spaxel binids to create the 2D map.
"""
Write the spaxel stellar mass of a galaxy to csv.
Spaxel stellar masses come from the Firefly stellar population catalog
of Goddard et al. (2017).
Firefly VAC description:
http://www.sdss.org/dr14/manga/manga-data/manga-firefly-value-added-catalog/
Datamodel:
https://data.sdss.org/datamodel/files/MANGA_FIREFLY/FIREFLY_VER/manga_firefly-STELLARPOP.html
"""
import argparse
import os
from os.path import join
from astropy.io import fits
from marvin.tools.cube import Cube
import numpy as np
import pandas as pd
parser = argparse.ArgumentParser(description='Write resolved Mstar from Firefly stellar '
'population catalog for a single galaxy.')
parser.add_argument('plateifu', type=str)
args = parser.parse_args()
# args = parser.parse_args('8077-6104')
path_repo = os.path.split(os.path.abspath('.'))[0]
path_data = join(path_repo, 'data')
path_firefly = join(path_data, 'manga_firefly-v2_1_2-STELLARPOP.fits')
fin = fits.open(path_firefly)
plateifus = fin['GALAXY_INFO'].data['PLATEIFU']
# Ngal x Nybin x Nxbin x
# (binid,
# xmin [arcsec],
# xmax [arcsec],
# ymin [arcsec],
# ymax [arcsec],
# image size [units of spaxel number])
spaxel_binid = fin['SPAXEL_BINID'].data
# Ngal x Nbin x (Mstar, Mstar_err)
mstar_all = fin['STELLAR_MASS_VORONOI'].data
# Select galaxy and binids
ind1 = np.where(plateifus == args.plateifu)[0][0]
ind_binid = spaxel_binid[ind1, :, :, 0].astype(int)
# Create 2D stellar mass array
mstar = np.ones(ind_binid.shape) * np.nan
for row, inds in enumerate(ind_binid):
ind_nans = np.where(inds == -99)
mstar[row] = mstar_all[ind1, inds, 0]
mstar[row][ind_nans] = np.nan
# trim mstar to match size of DAP maps and write to csv
cube = Cube(args.plateifu)
len_x = int(cube.header['NAXIS1'])
df = pd.DataFrame(mstar[:len_x, :len_x])
fout = join(path_data, 'manga-{}_mstar.csv'.format(args.plateifu))
df.to_csv(fout, index=False)
print('\nWrote:', fout)
fin.close()
which I run as
python galaxy_spaxel_mstar.py 8077-6104
The manga-8077-6104_mstar.csv
file is now available on this build of the docs: https://sdss-marvin.readthedocs.io/en/bug-686-map-arith/tutorials/exercises.html
(which will be incorporated shortly into the docs going forward).
May I know how to adapt your code to the latest Firefly data (manga_firefly-v2_4_3.fits) ? Or is there any tutorial on matching the spaxel binids to create the 2D map? Thank you very much.
I just have a question about Spatially-Resolved Mass-Metallicity Relation jupyter notebook. How do you extract the stellar mass from the fits file?
import pandas as pd mstar = pd.read_csv(join(path_data, 'manga-{}_mstar.csv'.format(maps.plateifu)))
I see in hdu1 I see PHOTOMETRIC_MASS and then again in hdu11 I see Stellar Mass. Which of there do I pull and how? I am a new Astronomy student and kind ofo hung up on that. Thanks.