Star

class src.binary_sed_fitting.Star(name, distance, e_distance, filters_to_drop=[], wavelength_range=[0, 1000000000], data=None, model=None, r_limits='blackbody', run_name='0', component='A', _TYPE='Star')

Class for working with individual stars and their SED fitting.

name

Name of the source.

Type:

str

distance

Distance to the source [pc].

Type:

float

e_distance

Error in the distance measurement [pc].

Type:

float

filters_to_drop

List of filters to be dropped before fitting the SED. Default is an empty list.

Type:

list, optional

wavelength_range

Minimum and maximum values of the filters to consider for fitting [Angstrom]. Default is [0, 1,000,000,000].

Type:

list, optional

r_limits

Limits for the radius. Default is ‘blackbody’.

blackbody : Radius range automatically calculated from blackbody fit

[r_min,r_max] : Radius is varied between the r_min and r_max given in solar radii

Type:

str, optional

model

Model to fit to the data.

Type:

Model, optional

data

Dataframe containing the observational data. It is cropped to the fitted filters based on filters_to_drop and wavelength_range.

Type:

pandas.DataFrame, optional

data_all

A copy of the original data with an added ‘fitted’ column indicating whether the filter is used.

Created by drop_filters(). Model flux, residuals, and statistical measures are added in Fitter.get_parameters_from_chi2_minimization() and Fitter.get_parameters_from_noisy_chi2_minimization().

Type:

pd.DataFrame

data_not_fitted

DataFrame containing only removed filters based on filters_to_drop and wavelength_range.

Type:

DataFrame

filters_to_drop_all

List of filters that are to be dropped based on filters_to_drop and wavelength_range.

Type:

array-like

N

The number of filters that are fitted.

Type:

int

N_Np

Number of data points minus the number of free parameters in the model.

Type:

float

sf_list

List of scaling factors (NOT in log space).

Type:

list

df_chi2

DataFrame with fitting parameters for all fits.

Type:

pd.DataFrame

df_chi2_trimmed

DataFrame with fitting parameters for the top fits after trimming (default: top 1000).

Type:

pd.DataFrame

df_chi2_noisy

DataFrame with best fitting parameters for each noisy iteration.

Type:

pd.DataFrame

chi2_r

Reduced chi^2 value indicating goodness of fit.

Type:

float

vgf2

Reduced chi^2 assuming minimum 2 percent error.

Type:

float

vgfb2

Reduced chi^2 assuming minimum 10 percent error.

Type:

float

<parameter>

The best fit parameters available in Star.df_chi2 (e.g., Star.chi2, Star.sf, Star.R, Star.L, Star.Te, Star.MH, Star.logg …).

Type:

float

chi2_median

Median of the chi^2 values from noisy fits.

Type:

float

chi2_r_median

Median of the reduced chi^2 values from noisy fits.

Type:

float

vgf2_median

Median of the vgf^2 values from noisy fits.

Type:

float

vgfb2_median

Median of the vgfb^2 values from noisy fits.

Type:

float

<parameter>_median

The median of fit parameter values available in Star.df_chi2_noisy (e.g. Star.sf_median, Star.R_median, Star.L_median, Star.Te_median, Star.MH_median, Star.logg_median, …).

Type:

float

<parameter>_error_lower

The 16th percentile error for fit parameters available in Star.df_chi2_noisy. (e.g. Star.sf_error_lower, Star.R_error_lower, Star.L_error_lower, Star.Te_error_lower, Star.MH_error_lower, Star.logg_error_lower, …).

Type:

float

<parameter>_error_upper

The 84th percentile error for fit parameters available in Star.df_chi2_noisy. (e.g. Star.sf_error_upper, Star.R_error_upper, Star.L_error_upper, Star.Te_error_upper, Star.MH_error_upper, Star.logg_error_upper, …).

Type:

float

Te_blackbody

Effective temperature from the blackbody fit [K].

Type:

float

log_sf_blackbody

Logarithm of the scaling factor from the blackbody fit.

Type:

float

run_name

Name of the run. Default is ‘0’.

Type:

str, optional

component

Component identifier (should be either ‘A’, ‘B’ or ‘C’). Default is ‘A’.

Type:

str, optional

_minimising_param

Parameter used for minimization (Only ‘chi2’ is implemented).

Type:

str

_TYPE

Type of the source.

  • Default is ‘Star’ for single fits.

  • ‘System’ for multi-component fits.

Type:

str, optional

__init__(name, distance, e_distance, filters_to_drop=[], wavelength_range=[0, 1000000000], data=None, model=None, r_limits='blackbody', run_name='0', component='A', _TYPE='Star')

Initializes a Star object using name, distance, model_to_fit, etc.

Parameters:
  • name (str) – Name of the source.

  • distance (float) – Distance to the source in parsecs (pc).

  • e_distance (float) – Error in the distance measurement in parsecs (pc).

  • filters_to_drop (list, optional) – List of filters to be dropped before fitting the SED. Default is an empty list.

  • wavelength_range (list, optional) – Minimum and maximum values of the filters to consider for fitting. Default is [0, 1,000,000,000].

  • r_limits (str, optional) – Limits for the radius. Default is ‘blackbody’.

  • run_name (str, optional) – Name of the run. Default is ‘0’.

  • component (str, optional) – Component identifier (should be either ‘A’, ‘B’ or ‘C’). Default is ‘A’.

  • _TYPE (str, optional) – Type of the source. Default is ‘Star’.

  • data (pandas.DataFrame, optional) – Dataframe containing the observational data.

  • model (Model, optional) – Model to fit to the data.

Raises:

NotImplementedError – If ‘component’ is not ‘A’, ‘B’, or ‘C’.

Notes

Updates: Star.name, Star.distance, Star.e_distance, Star.filters_to_drop, Star.wavelength_range, Star.r_limits, Star.run_name, Star.component, Star._TYPE, Star.data, Star.model, Star.data_all, Star.filters_to_drop_all, Star.N, Star.sf_list

If data is provided, it will be sorted by wavelength and processed. If model is also provided, it will be configured with the processed data.

create_sf_list(r_limits)

Create list of scaling factors.

The limits on radius are either taken from the used (via r_limits parameter).

Or calculated automatically from blackbody fitting.

Parameters:

r_limits (str or list) – Limits for the radius. Can be ‘blackbody’ to use blackbody fitting results or a list of two values for radius limits.

Notes

Updates: Star.sf_list

drop_filters()

Drops unnecessary filters based on wavelength range.

Notes

Updates: Star.data_all, Star.filters_to_drop_all, Star.data, Star.N

This function updates self.data and self.data_not_fitted DataFrames by filtering out entries outside the specified wavelength range or with negative wavelengths.

The function also logs the filters that are fitted and not fitted.

fit_blackbody(p0=[5000.0, -20], plot=False, show_plot=True, folder=None)

Fits a blackbody model to the SED.

Parameters:
  • p0 (list, optional) – Initial guess for the blackbody model parameters. Default is [5000., -20].

  • plot (bool, optional) – Whether to plot the blackbody fit. Default is False.

  • show_plot (bool, optional) – Whether to show the plot. Default is True.

  • folder (str, optional) – Folder to save the plot. No plot is saved if folder is None.

Notes

Updates: Star.Te_blackbody, Star.log_sf_blackbody

fit_chi2(refit=True, _trim=1000, _minimising_param='chi2')

Fits the SED using a chi-squared minimization approach.

Parameters:
  • refit (bool, optional) –

    Whether to refit the model. Default is True.

    • if True : the fit is redone.

    • If False: If a previous fit is available, it is read. Otherwise a fresh fit is made.

  • _trim (int, optional) – Number of data points to trim for fitting. Default is 1000.

  • _minimising_param (str, optional) – Parameter used for minimizing (only ‘chi2’ supported as of now). Default is ‘chi2’.

Notes

Updates: Star._minimising_param

fit_noisy_chi2(total_iterations=100, refit=True, plot=False, _percentile_threshold=10)

Fits the SED using a chi-squared minimization approach. The SED is fitted total_iterations times using bootstrapping.

Parameters:
  • total_iterations (int, optional) – Number of iterations used for bootstrapping. Default is 100.

  • refit (bool, optional) –

    Whether to refit the model. Default is True.

    • if True : the fit is redone.

    • If False: If a previous fit is available, it is read. Otherwise a fresh fit is made.

  • _percentile_threshold (int, optional) – Percentile threshold used for setting up the extent of the noisy parameter grid. Default is 10.

  • plot (bool, optional) – Whether to plot the blackbody fit. Default is False.

plot(add_noisy_seds=False, show_plot=True, folder=None, FR_cutoff=0.5, _median=False)

Plot detailed properties of a single SED.

Parameters:
  • add_noisy_seds (bool, optional) – Whether to add noisy SEDs to the plot.

  • show_plot (bool, optional) – Whether to display the plot.

  • folder (str, optional) – Folder to save the plot. No plot is saved if folder is None.

  • FR_cutoff (float, optional) – Cutoff value for identifying data with fractional residual excess.

  • median (bool, optional) – Whether to use the median values for plotting.

Raises:

NotImplementedError – If component is other than ‘A’, ‘B’, and ‘C’.

Notes

This method plots various detailed properties of a single SED, including observed and fitted SEDs, fractional residuals, error weighted residuals, chi-squared values, HR diagram, and temperature-related distributions.

plot_blackbody_model(ax=None)

Plot the blackbody model spectrum.

Parameters:

ax (matplotlib.axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

plot_chi2(ax=None, color='C1', ls='--', median=False)

Plot the chi-squared values.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

  • color (str, optional) – Color of the plot. Default is ‘C1’.

  • ls (str, optional) – Linestyle of the plot. Default is ‘-‘.

  • median (bool, optional) – Whether to use the median values. Default is False.

plot_ewr(ax=None, deviation_cutoff=None, color='C1', ls='--', median=False)

Plot the Error Weighted Residual.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

  • deviation_cutoff (float, optional) – Cutoff value for deviation in EWR.

  • color (str, optional) – Color of the plot. Default is ‘C1’.

  • ls (str, optional) – Linestyle of the plot. Default is ‘-‘.

  • median (bool, optional) – Whether to use the median values. Default is False.

plot_fractional_residual(ax=None, FR_cutoff=None, color='C1', ls='--', median=False)

Plot the fractional residuals.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

  • FR_cutoff (float, optional) – Cutoff value for identifying data with fractional residual excess.

  • color (str, optional) – Color of the plot. Default is ‘C1’.

  • ls (str, optional) – Linestyle of the plot. Default is ‘-‘.

  • median (bool, optional) – Whether to use the median values. Default is False.

plot_hrd(ax=None, color='C1', median=False, cax=None)

Plot the Hertzsprung-Russell Diagram (HRD).

Parameters:
  • ax (matplotlib.axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

  • color (str, optional) – Color of the plot.

  • median (bool, optional) – Whether to use the median values.

  • cax (matplotlib.axes, optional) – Matplotlib axes for the colorbar.

plot_noisy_seds(ax=None, color='C1', ls='--')

Plot the noisy SEDs.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

  • color (str, optional) – Color of the plot. Default is ‘C1’.

  • ls (str, optional) – Linestyle of the plot. Default is ‘–‘.

plot_public(median=False, add_noisy_seds=False, ax=None, FR_cutoff=0.5, show_plot=True, folder=None)

Plot a simplified version of various properties of a single SED for public view.

Parameters:
  • median (bool, optional) – Whether to use the median values.

  • add_noisy_seds (bool, optional) – Whether to add noisy SEDs to the plot.

  • ax (matplotlib.axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

  • FR_cutoff (float, optional) – Cutoff value for identifying data with fractional residual excess.

  • show_plot (bool, optional) – Whether to display the plot.

  • folder (str, optional) – Folder to save the plot. No plot is saved if folder is None.

Raises:

NotImplementedError – If component is other than ‘A’, ‘B’, and ‘C’.

plot_residual(ax=None, color='C1', ls='--', median=False)

Plot the residuals.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

  • color (str, optional) – Color of the plot. Default is ‘C1’.

  • ls (str, optional) – Linestyle of the plot. Default is ‘–‘.

  • median (bool, optional) – Whether to use the median values. Default is False.

plot_sed_fitted(ax=None, color='C1', ls='--', median=False)

Plot the fitted SED.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

  • color (str, optional) – Color of the plot. Default is ‘C1’.

  • ls (str, optional) – Linestyle of the plot. Default is ‘–‘.

  • median (bool, optional) – Whether to use the median values. Default is False.

plot_sed_obs(ax=None)

Plot the observed SED.

Parameters:

ax (matplotlib.axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

plot_sed_skeleton_detailed()

Initialize and return the skeleton for detailed SED plots.

Returns:

  • fig (matplotlib.figure.Figure) – Matplotlib figure object.

  • ax (np.ndarray) – Matplotlib axes array.

plot_sed_skeleton_public()

Initialize and return the skeleton for public SED plots.

Returns:

  • fig (matplotlib.figure.Figure) – Matplotlib figure object.

  • ax (np.ndarray) – Matplotlib axes array.

plot_temperature_chi2(ax=None, color='C1', median=False, cax=None)

Plot the Temperature-Chi-squared distribution.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

  • color (str, optional) – Color of the plot. Default is ‘C1’.

  • median (bool, optional) – Whether to use the median values. Default is False.

  • cax (matplotlib.axes.Axes, optional) – Matplotlib axes for the colorbar.

plot_temperature_radius(ax=None, color='C1', median=False, cax=None)

Plot the Temperature-Radius distribution.

Parameters:
  • ax (matplotlib.axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

  • color (str, optional) – Color of the plot.

  • median (bool, optional) – Whether to use the median values.

  • cax (matplotlib.axes, optional) – Matplotlib axes for the colorbar.

plot_temperature_vgfb2(ax=None, color='C1', median=False, cax=None)

Plot the Temperature-vgf_b^2 distribution.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – Matplotlib axes to plot on. If None, a new subplot is created.

  • color (str, optional) – Color of the plot. Default is ‘C1’.

  • median (bool, optional) – Whether to use the median values. (Not supported for vgfb2)

  • cax (matplotlib.axes.Axes, optional) – Matplotlib axes for the colorbar.

Raises:

NotImplementedError – If median mode is True (not supported for vgfb2).

process_data()

Process the data by validating the data and calculating necessary parameters.

Raises:

ValueError – If duplicate filters are found in the data.

Notes

Updates: Star.data, Star.data_all

The method includes several steps to clean and preprocess the data before fitting:

  • Ensures no duplicate filters are present in the data.

  • Filters with zero errors are replaced with a value calculated as 110% of the maximum error fraction.

  • Errors are adjusted to ensure a minimum error fraction of 2% for VGF and 10% for VGFB calculations.

  • Logarithmic values of wavelength and flux are computed to facilitate fitting.

save_summary()

Save a summary of the current state of the instance to a log file.

Notes

  • Logs the current state of the instance into a CSV file (‘data/log_single_fitting.csv’) for future reference.

  • If the log file does not exist, it creates a new one. Otherwise, it appends to the existing log file.

  • Uses the Star._reduce_Star() method to create a reduced copy of the instance suitable for saving.

update_xylimits_detailed(ax)

Update the x and y limits for public SED plots.

Parameters:

ax (np.ndarray) – Matplotlib axes array.

update_xylimits_public(ax)

Update the x and y limits for public SED plots.

Parameters:

ax (np.ndarray) – Matplotlib axes array.