Example binary fit

Fitting method

  • Read data

  • Create A component

  • Fit A component

  • Create a residual star (B)

  • Fit B component

  • Plot and save logs

Quick fit

import src.binary_sed_fitting as bsf
################################################################################
name        = 'WOCS2002'
file_name   = 'data/extinction_corrected_flux_files/%s.csv'%name
data        = bsf.load_data(file_name, mode='csv')
distance    = 831. # pc
e_distance  = 11.  # pc
################################################################################
model_name = 'kurucz'
limits = {'Te'   : [3500, 9000],
          'logg' : [   3,    5],
          'MH'   : [ 0.0,  0.0],
          'alpha': [ 0.0,  0.0]}
model_A = bsf.Model(model_name, limits=limits)

model_name = 'koester'
limits = {'Te'   : [5000,80000],
          'logg' : [ 6.5,  9.5]}
model_B = bsf.Model(model_name, limits=limits)
################################################################################
star_system = bsf.System(name=name,
                         distance=distance,
                         e_distance=e_distance,
                         data=data)
################################################################################
star_system.setup_A_component(model=model_A,
                              wavelength_range=[3000, 1_000_000_000],
                              r_limits='blackbody')

star_system.A.fit_chi2()
################################################################################
star_system.create_residual_star(component='B',
                                 model=model_B,
                                 wavelength_range=[0, 1_000_000_000],
                                 r_limits=[0.001,1.0])
star_system.B.fit_chi2()
################################################################################
star_system.plot()
22:38:37 ----- WARNING  ----- estimate_runtime
Calculating chi2: ETA ~ 0 s
22:38:38 ----- WARNING  ----- get_parameters_from_chi2_minimization
Based on chi2, I recommend removal of following filters: ['KPNO/Mosaic.I']; chi2=[105.36663391]
22:38:38 ----- WARNING  ----- estimate_runtime
Calculating chi2: ETA ~ 0 s
22:38:39 ----- WARNING  ----- get_parameters_from_chi2_minimization
Based on chi2, I recommend removal of following filters: ['KPNO/Mosaic.I']; chi2=[105.83209209]
_images/output_3_3.png

Advance options

  • Each component in a System can be accessed and processed as a seperate Star

  • 3rd component can be fitted by creating a residual star after fitting A and B components.

    • Potentially, any number of components can be fitted. But none of the plotting functions are designed to deal with more than 3.

  • System.Total

    • Star object representing the total fitted flux.

star_system.A.plot()

print(star_system.Total.data_all.head())
                      wavelength          flux         error  error_fraction  FilterID
Astrosat/UVIT.F148W  1481.000000  2.548070e-15  1.361179e-16        0.053420
Astrosat/UVIT.F154W  1541.000000  2.285731e-15  1.368403e-16        0.059867
Astrosat/UVIT.F169M  1608.000000  2.360782e-15  1.261129e-16        0.053420
GALEX/GALEX.NUV      2303.366368  3.296702e-15  8.677147e-17        0.026321
KPNO/Mosaic.B        4357.276538  9.309407e-14  6.130611e-15        0.065854

                     error_2percent  error_10percent  log_wavelength  FilterID
Astrosat/UVIT.F148W    1.361179e-16     2.548070e-16        3.170555
Astrosat/UVIT.F154W    1.368403e-16     2.285731e-16        3.187803
Astrosat/UVIT.F169M    1.261129e-16     2.360782e-16        3.206286
GALEX/GALEX.NUV        8.677147e-17     3.296702e-16        3.362363
KPNO/Mosaic.B          6.130611e-15     9.309407e-15        3.639215

                      log_flux  e_log_flux  fitted    model_flux  FilterID
Astrosat/UVIT.F148W -14.593789    0.023200    True  2.173278e-15
Astrosat/UVIT.F154W -14.640975    0.026000    True  2.444154e-15
Astrosat/UVIT.F169M -14.626944    0.023200    True  2.579711e-15
GALEX/GALEX.NUV     -14.481920    0.011431    True  7.706038e-15
KPNO/Mosaic.B       -13.031078    0.028600    True  9.911352e-14

                     residual_flux  fractional_residual        ewr  FilterID
Astrosat/UVIT.F148W   3.747922e-16             0.147089   2.753439
Astrosat/UVIT.F154W  -1.584237e-16            -0.069310  -1.157727
Astrosat/UVIT.F169M  -2.189290e-16            -0.092736  -1.735976
GALEX/GALEX.NUV      -4.409336e-15            -1.337499 -50.815509
KPNO/Mosaic.B        -6.019451e-15            -0.064660  -0.981868

                          chi2_i       vgf2_i     vgfb2_i
FilterID
Astrosat/UVIT.F148W     7.581426     7.581426    2.163507
Astrosat/UVIT.F154W     1.340331     1.340331    0.480386
Astrosat/UVIT.F169M     3.013612     3.013612    0.859993
GALEX/GALEX.NUV      2582.215946  2582.215946  178.890421
KPNO/Mosaic.B           0.964065     0.964065    0.418090
_images/output_12_1.png