%matplotlib inline
%reload_ext autoreload
%autoreload 2

import os 
import h5py
import numpy as np
import astropy.units as units

from isoclassify import DATADIR
from isoclassify.direct import classify as classify_direct
from isoclassify.extinction import query_dustmodel_coords

"""
Explanation: Direct method example
An example use of isoclassify's direct method. Prefered use is through the command-line interface (see README).
End of explanation
"""


fn = os.path.join(DATADIR,'bcgrid.h5')
bcmodel = h5py.File(fn,'r', driver='core', backing_store=False)

"""
Explanation: Bolometric corrections model
Load the BC model.
End of explanation
"""


x = classify_direct.obsdata()
x.addcoords(292.0826387546914, 37.05987401545169)

"""
Explanation: Reddening maps
We first initialise the observational data and give it some arbitrary coordinates.
End of explanation
"""


dustmap = 'green19'
dustmodel, ext = query_dustmodel_coords(x.ra, x.dec, dustmap)

"""
Explanation: We then specify the reddening (dust) map to use. Here, we choose Green et al. (2019), a.k.a. Bayestar19 (see here for more information).
If we don't want to use a reddening map, isoclassify fits for Av. In this case specify dustmap = 'none'. Alternatively, if you want to assume no reddening, use dustmap = 'zero'. In both cases, the Cardelli et al. (1989) reddening law is assumed.
End of explanation
"""


# SPECTROSCOPY 
# [Teff, logg, FeH] and [sigma_Teff, sigma_logg, sigma_FeH] 
x.addspec([5777.,4.44,0.0],[60.,0.07,0.04])

# PARALLAX
x.addplx(0.07,0.007)

# 2MASS PHOTOMETRY
x.addjhk([4.38,4.04,4.00],[0.03,0.03,0.03])

# MAGNITUDE
# To use for the distance modulus
x.addmag([4.38],[0.03])

"""
Explanation: Observational data
We add some observational data for the star.
End of explanation
"""


paras = classify_direct.stparas(x, bcmodel=bcmodel, dustmodel=dustmodel, band='jmag', ext=ext, plot=1)

"""
Explanation: Fit
We perform the fit using isoclassify's direct method and the inputs described above.
End of explanation
"""


