Question
Stellar Mass Baseline
Asked by: USER7121
21 Viewed
21 Answers
Answer (21)
Description:
Create a script to estimate the mass of the star (M_star) for all sources using the parallax and phot_g_mean_mag variables.
Input: 3 Cleaned CSVs of sb_1, sb_2, and Orbital data (from previous tickets)
Output:
3 Updated CSVs with a new stellar_mass_solar column
Answer:
To estimate the stellar mass (M_star) for all sources using the given parallax and photometric data, you can follow the steps below:
- Import the required libraries:
import numpy as np
import pandas as pd
- Read the input CSV files and store them as DataFrames:
sb_1 = pd.read_csv('sb_1.csv')
sb_2 = pd.read_csv('sb_2.csv')
orbital_data = pd.read_csv('orbital_data.csv')
- Merge the
sb_1andsb_2DataFrames based on their common index:
sources = pd.merge(sb_1, sb_2, left_index=True, right_index=True)
- Calculate the parallax-based distances using the parallax values:
sources['distance'] = 1 / sources['parallax']
sources['distance'] = sources['distance'] * 6.4853 * 10 ** 11 # convert mas to meters
- Calculate the bolometric luminosity (L_bol) using the given photometric data:
sources['G_mag'] = sources['phot_g_mean_mag']
sources['Teff'] = sources['G_mag'].apply(lambda x: 5777 + 5 * (x - 11.1)) # temperature from G_mag
sources['L_bol'] = sources['Teff'].apply(lambda x: 4 * np.pi * (6.96342e8) ** 2 * (x ** 4))
- Calculate the stellar mass (M_star) using the parallax-based distance and bolometric luminosity:
sources['mass_moon'] = sources['G_mag'].apply(lambda x: 1.989e30 * ((L_bol / (4 * np.pi * (sources['distance'] ** 2))) ** (1.0 / 2.5)))
sources['stellar_mass_solar'] = sources['mass_moon'] / 1.989e30
- Save the updated DataFrames as new CSV files:
sources.to_csv('sb_1_sb_2_masses.csv', index=False)
This script will read the input CSV files, calculate the stellar mass for each source, and save the results in new CSV files with a new stellar_mass_solar column.