import matplotlib

# matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

plt.switch_backend('agg')
import matplotlib as mpl
import matplotlib.colors as mplc

# in ps1 virtual env, unforked version of ezgal does not work due to py2 stuff:
# pip install git+git://github.com/boada/easyGalaxy
import ezgal
import os

import src.globals as glo

# Bower, Lucey & Ellis 1992; Ellis et al. 1997; De Propris et al. 1999;
# Lin et al. 2006). We adopt a model consistent with these find-
# ings. Specifically, our star formation model is an exponentially
# decaying starburst at redshift z = 3 with a Chabrier initial mass
# function (IMF) and a decay time of 0.4 Gyr (Bruzual & Charlot
# 2003, hereafter BC03). We introduce tilt in the RS by using six
# different models, each with a different metallicity (Kodama &
# Arimoto 1997) adjusted to follow the luminosity–metallicity re-
# lation observed in Coma (Poggianti et al. 2001).


# sfh = exp_0.4
# Specifies an exponentially decaying burst of star formation with a
# timescale of 0.4 Gyrs

# met = ?
# zf = 3
# tau = 0.4
# imf = chab (Chabrier)
# modelset = bc03

# All filenames contain information on the model set, SFH, IMF,
# and metallicity. The naming convention is:

# {modelset}_{sfh}_z_{met}_{imf}.fits

# load an EzGal model file
# name = 'bc03_exp_0.5_z_0.02_chab.model'
# name = 'ezgal_model.txt'
name = 'bc03_burst_0.1_z_0.02_chab.model'
# foo = os.path.join(glo.dir_external, 'ezgal_web', name)
foo = os.path.join(glo.DIR_EXTERNAL, 'ezgal', name)
model = ezgal.model(foo)

filters = ['galex_fuv', 'galex_nuv', 'acs_f435w', 'acs_f475w',
                     'acs_f555w', 'acs_f606w', 'acs_f625w', 'acs_f775w',
                     'acs_f814w', 'acs_f850lp', 'wfc3_f218w', 'wfc3_f225w',
                     'wfc3_f275w', 'wfc3_f438w', 'wfc3_f475w', 'wfc3_f555w',
                     'wfc3_f606w', 'wfc3_f625w', 'wfc3_f775w', 'wfc3_f814w',
                     'wfc3_f850lp', 'wfc3_f105w', 'wfc3_f110w', 'wfc3_f125w',
                     'wfc3_f140w', 'wfc3_f160w', 'wfc3_f127m', 'wfc3_f139m',
                     'wfc3_f153m', 'wfpc2_f450w', 'wfpc2_f555w', 'wfpc2_f606w',
                     'wfpc2_f675w', 'wfpc2_f814w', 'ch1', 'ch2', 'ch3', 'ch4', 'j',
                     'h', 'ks', 'sloan_u', 'sloan_g', 'sloan_r', 'sloan_i',
                     'sloan_z', 'wise_ch1', 'wise_ch2', '4star_j', '4star_h',
                     '4star_ks', '4star_m_j1', '4star_m_j2', '4star_m_j3',
                     '4star_m_hshort', '4star_m_hlong', 'ukidss_y', 'ukidss_j',
                     'ukidss_h', 'ukidss_k']

map(model.add_filter, filters)

foobar = model.get_absolute_mags(zf=3, zs=np.arange(0.3, 1.5, 0.01) )

# get a grid of redshifts out to the desired formation redshift
zf = 3
zs = model.get_zs(zf)

# plot mass-to-light ratio evolution versus redshift for three filters
plt.plot(zs, model.get_rest_ml_ratios(zf, filters='sloan_i', zs=zs), 'k-',
         label='Sloan i')
plt.plot(zs, model.get_rest_ml_ratios(zf, filters='ks', zs=zs), 'r--',
         label='2MASS Ks')
plt.plot(zs, model.get_rest_ml_ratios(zf, filters='ch2', zs=zs), 'b:',
         label='IRAC ch2')

# and set labels for the plot
plt.xlabel('z')
plt.ylabel('M/L Ratio')

# how about a legend?
plt.legend()

# all done
plt.savefig('foo.png')

import matplotlib

# matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

plt.switch_backend('agg')
import matplotlib as mpl
import matplotlib.colors as mplc

# in ps1 virtual env, unforked version of ezgal does not work due to py2 stuff:
# pip install git+git://github.com/boada/easyGalaxy
import ezgal
import os

import src.globals as glo

# Bower, Lucey & Ellis 1992; Ellis et al. 1997; De Propris et al. 1999;
# Lin et al. 2006). We adopt a model consistent with these find-
# ings. Specifically, our star formation model is an exponentially
# decaying starburst at redshift z = 3 with a Chabrier initial mass
# function (IMF) and a decay time of 0.4 Gyr (Bruzual & Charlot
# 2003, hereafter BC03). We introduce tilt in the RS by using six
# different models, each with a different metallicity (Kodama &
# Arimoto 1997) adjusted to follow the luminosity–metallicity re-
# lation observed in Coma (Poggianti et al. 2001).


# sfh = exp_0.4
# Specifies an exponentially decaying burst of star formation with a
# timescale of 0.4 Gyrs

# met = ?
# zf = 3
# tau = 0.4
# imf = chab (Chabrier)
# modelset = bc03

# All filenames contain information on the model set, SFH, IMF,
# and metallicity. The naming convention is:

# {modelset}_{sfh}_z_{met}_{imf}.fits

# load an EzGal model file
# name = 'bc03_exp_0.5_z_0.02_chab.model'
# name = 'ezgal_model.txt'
name = 'bc03_burst_0.1_z_0.02_chab.model'
# foo = os.path.join(glo.dir_external, 'ezgal_web', name)
foo = os.path.join(glo.DIR_EXTERNAL, 'ezgal', name)
model = ezgal.model(foo)

filters = ['galex_fuv', 'galex_nuv', 'acs_f435w', 'acs_f475w',
                     'acs_f555w', 'acs_f606w', 'acs_f625w', 'acs_f775w',
                     'acs_f814w', 'acs_f850lp', 'wfc3_f218w', 'wfc3_f225w',
                     'wfc3_f275w', 'wfc3_f438w', 'wfc3_f475w', 'wfc3_f555w',
                     'wfc3_f606w', 'wfc3_f625w', 'wfc3_f775w', 'wfc3_f814w',
                     'wfc3_f850lp', 'wfc3_f105w', 'wfc3_f110w', 'wfc3_f125w',
                     'wfc3_f140w', 'wfc3_f160w', 'wfc3_f127m', 'wfc3_f139m',
                     'wfc3_f153m', 'wfpc2_f450w', 'wfpc2_f555w', 'wfpc2_f606w',
                     'wfpc2_f675w', 'wfpc2_f814w', 'ch1', 'ch2', 'ch3', 'ch4', 'j',
                     'h', 'ks', 'sloan_u', 'sloan_g', 'sloan_r', 'sloan_i',
                     'sloan_z', 'wise_ch1', 'wise_ch2', '4star_j', '4star_h',
                     '4star_ks', '4star_m_j1', '4star_m_j2', '4star_m_j3',
                     '4star_m_hshort', '4star_m_hlong', 'ukidss_y', 'ukidss_j',
                     'ukidss_h', 'ukidss_k']

map(model.add_filter, filters)

foobar = model.get_absolute_mags(zf=3, zs=np.arange(0.3, 1.5, 0.01) )

# get a grid of redshifts out to the desired formation redshift
zf = 3
zs = model.get_zs(zf)

# plot mass-to-light ratio evolution versus redshift for three filters
plt.plot(zs, model.get_rest_ml_ratios(zf, filters='sloan_i', zs=zs), 'k-',
         label='Sloan i')
plt.plot(zs, model.get_rest_ml_ratios(zf, filters='ks', zs=zs), 'r--',
         label='2MASS Ks')
plt.plot(zs, model.get_rest_ml_ratios(zf, filters='ch2', zs=zs), 'b:',
         label='IRAC ch2')

# and set labels for the plot
plt.xlabel('z')
plt.ylabel('M/L Ratio')

# how about a legend?
plt.legend()

# all done
plt.savefig('foo.png')

# matplotlib.use('TkAgg') # in ps1 virtual env, unforked version of ezgal does not work due to py2 stuff: # pip install git+git://github.com/boada/easyGalaxy # Bower, Lucey & Ellis 1992; Ellis et al. 1997; De Propris et al. 1999; # Lin et al. 2006). We adopt a model consistent with these find- # ings. Specifically, our star formation model is an exponentially # decaying starburst at redshift z = 3 with a Chabrier initial mass # function (IMF) and a decay time of 0.4 Gyr (Bruzual & Charlot # 2003, hereafter BC03). We introduce tilt in the RS by using six # different models, each with a different metallicity (Kodama & # Arimoto 1997) adjusted to follow the luminosity–metallicity re- # lation observed in Coma (Poggianti et al. 2001). # sfh = exp_0.4 # Specifies an exponentially decaying burst of star formation with a # timescale of 0.4 Gyrs # met = ? # zf = 3 # tau = 0.4 # imf = chab (Chabrier) # modelset = bc03 # All filenames contain information on the model set, SFH, IMF, # and metallicity. The naming convention is: # {modelset}_{sfh}_z_{met}_{imf}.fits # load an EzGal model file # name = 'bc03_exp_0.5_z_0.02_chab.model' # name = 'ezgal_model.txt' # foo = os.path.join(glo.dir_external, 'ezgal_web', name) # get a grid of redshifts out to the desired formation redshift # plot mass-to-light ratio evolution versus redshift for three filters # and set labels for the plot # how about a legend? # all done