# Path: dist/astro-smpy-0.1.dev/smpy/dust.py
# def Calzetti(ta_grid, wave, Av):
#     Att = np.ones(np.append(ta_grid.shape, len(wave)))
#     k = np.zeros_like(wave.value)
# 
#     w0 = [wave <= 1200 * u.AA]
#     w1 = [wave < 6300 * u.AA]
#     w2 = [wave >= 6300 * u.AA]
#     w_u = wave.to(u.um).value
# 
#     x1 = np.argmin(np.abs(wave - 1200 * u.AA))
#     x2 = np.argmin(np.abs(wave - 1250 * u.AA))
# 
#     k[w2] = 2.659 * (-1.857 + 1.040 / w_u[w2])
#     k[w1] = 2.659 * (-2.156 + (1.509 / w_u[w1]) - (0.198 / w_u[w1] ** 2) + (0.011 / w_u[w1] ** 3))
#     k[w0] = k[x1] + ((wave[w0] - 1200. * u.AA) * (k[x1] - k[x2]) / (wave[x1] - wave[x2]))
# 
#     k += 4.05
#     k[k < 0.] = 0.
# 
#     tv = Av * k / 4.05
#     Att *= np.power(10, -0.4 * tv)
#     return Att
# 
# Path: dist/astro-smpy-0.1.dev/smpy/sfh.py
# def exponential(t, tau):
#     """ Exponential star formation history
# 
#     """
#     sfh = np.exp(-1 * t / tau) / np.abs(tau)
#     return sfh


import numpy as np
import copy
import os
import sys
import h5py
import types
import glob
import data
from scipy.interpolate import griddata
from scipy.spatial import Delaunay
from astropy import units as u
from astropy import constants as c
from astropy import cosmology as cos
from astropy.utils.console import ProgressBar
from .dust import Calzetti
from .sfh import exponential
from .misc import tau_madau
        
        self.wave = self.SSP.wave_arr[0]
        self.iw = self.SSP.iw_arr[0]
        self.sed_arr = self.SSP.sed_arr
        
        if hasattr(self.SSP, 'strm_arr') and hasattr(self.SSP, 'rmtm_arr'):
            self.strm_arr = np.array(self.SSP.strm_arr)
            self.rmtm_arr = np.array(self.SSP.rmtm_arr)
        
        self.iseds = np.array(self.SSP.iseds)
        
        # Find closest match for each tg value in ta - set tg to these values
        
        nebular = np.loadtxt(data_path+'/nebular_emission.dat', skiprows=1)
        self.neb_cont = nebular[:, 1]
        self.neb_hlines = nebular[:, 2]
        self.neb_metal = nebular[:, 3:]
        self.neb_wave = nebular[:, 0]
        
        if None not in (age, sfh, dust, metal_ind):
            if f_esc == None:
                self.build(age, sfh, dust, metal_ind, sfh_law=sfh_law,
                           dust_model=dust_model,
                           neb_cont=neb_cont, neb_met=neb_met)
            
            else:
                self.build(age, sfh, dust, metal_ind,
                           f_esc, sfh_law, dust_model, neb_cont, neb_met)
    
    def build(self, age, sfh, dust, metal, fesc = 1.,

# Path: dist/astro-smpy-0.1.dev/smpy/dust.py
# def Calzetti(ta_grid, wave, Av):
#     Att = np.ones(np.append(ta_grid.shape, len(wave)))
#     k = np.zeros_like(wave.value)
# 
#     w0 = [wave <= 1200 * u.AA]
#     w1 = [wave < 6300 * u.AA]
#     w2 = [wave >= 6300 * u.AA]
#     w_u = wave.to(u.um).value
# 
#     x1 = np.argmin(np.abs(wave - 1200 * u.AA))
#     x2 = np.argmin(np.abs(wave - 1250 * u.AA))
# 
#     k[w2] = 2.659 * (-1.857 + 1.040 / w_u[w2])
#     k[w1] = 2.659 * (-2.156 + (1.509 / w_u[w1]) - (0.198 / w_u[w1] ** 2) + (0.011 / w_u[w1] ** 3))
#     k[w0] = k[x1] + ((wave[w0] - 1200. * u.AA) * (k[x1] - k[x2]) / (wave[x1] - wave[x2]))
# 
#     k += 4.05
#     k[k < 0.] = 0.
# 
#     tv = Av * k / 4.05
#     Att *= np.power(10, -0.4 * tv)
#     return Att
# 
# Path: dist/astro-smpy-0.1.dev/smpy/sfh.py
# def exponential(t, tau):
#     """ Exponential star formation history
# 
#     """
#     sfh = np.exp(-1 * t / tau) / np.abs(tau)
#     return sfh


# Path: dist/astro-smpy-0.1.dev/smpy/smpy.py
import numpy as np
import copy
import os
import sys
import h5py
import types
import glob
import data
from scipy.interpolate import griddata
from scipy.spatial import Delaunay
from astropy import units as u
from astropy import constants as c
from astropy import cosmology as cos
from astropy.utils.console import ProgressBar
from .dust import Calzetti
from .sfh import exponential
from .misc import tau_madau

        
        self.wave = self.SSP.wave_arr[0]
        self.iw = self.SSP.iw_arr[0]
        self.sed_arr = self.SSP.sed_arr
        
        if hasattr(self.SSP, 'strm_arr') and hasattr(self.SSP, 'rmtm_arr'):
            self.strm_arr = np.array(self.SSP.strm_arr)
            self.rmtm_arr = np.array(self.SSP.rmtm_arr)
        
        self.iseds = np.array(self.SSP.iseds)
        
        # Find closest match for each tg value in ta - set tg to these values
        
        nebular = np.loadtxt(data_path+'/nebular_emission.dat', skiprows=1)
        self.neb_cont = nebular[:, 1]
        self.neb_hlines = nebular[:, 2]
        self.neb_metal = nebular[:, 3:]
        self.neb_wave = nebular[:, 0]
        
        if None not in (age, sfh, dust, metal_ind):
            if f_esc == None:
                self.build(age, sfh, dust, metal_ind, sfh_law=sfh_law,
                           dust_model=dust_model,
                           neb_cont=neb_cont, neb_met=neb_met)
            
            else:
                self.build(age, sfh, dust, metal_ind,
                           f_esc, sfh_law, dust_model, neb_cont, neb_met)
    
    def build(self, age, sfh, dust, metal, fesc = 1.,

              sfh_law = exponential, dust_model = Calzetti,