Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metallicity Histories in Tabular SFH #87

Merged
merged 4 commits into from
Jul 11, 2017
Merged

Metallicity Histories in Tabular SFH #87

merged 4 commits into from
Jul 11, 2017

Conversation

bd-j
Copy link
Collaborator

@bd-j bd-j commented Jul 10, 2017

This PR adds support for metallicity histories in tabular SFHs through the zcontinuous=3 flag and the set_tabular_sfh() method.

Similar to the existing tabular SFH options (see #63) usage is

import numpy as np
import fsps
sps = fsps.StellarPopulation(zcontinuous=3)
sps.params['sfh'] = 3
age = np.linspace(1, 10, 50)
sfr = np.exp(-age/3.0)
z = age / age.max() * 0.019
sps.set_tabular_sfh(age, sfr, z)
wave, spec = sps.get_spectrum(tage=0)

Note that the zcontinuous=3 option must only be used for sfh=3, Otherwise an unrecoverable fortran error will occur. Furthermore nebular emission cannot be added when multi-metallicity tabular SFH is computed.

This PR also adds a script to the demo/ directory that shows how to successively turn on and use some of the StellarPopulation options. It also addresses a documentation typo (#82)

@bd-j
Copy link
Collaborator Author

bd-j commented Jul 11, 2017

For fun, here is the spectrum from the SFH in the default sfh.dat that ships with FSPS, computed with a single mass-weighted metallicity and including the full metallicity history. Produced using the code snippet below.

mass-weighted-z_vs_z-history sfh dat

import os
import numpy as np
import matplotlib.pyplot as pl
import fsps

fn = os.path.join(os.environ['SPS_HOME'], 'data/sfh.dat')
age, sfr, z = np.genfromtxt(fn, unpack=True, skip_header=0)

pop = fsps.StellarPopulation(zcontinuous=1)
pop.params['sfh'] = 3

pop.set_tabular_sfh(age, sfr)
# get mass weighted metallicity
mbin = np.gradient(age) * sfr
mwz = (z * mbin).sum() / mbin.sum()
pop.params['logzsol'] = np.log10(mwz/0.019)
w, spec_onez = pop.get_spectrum(tage=-99)

pop._zcontinuous = 3
pop.set_tabular_sfh(age, sfr, z)
w, spec_multiz = pop.get_spectrum(tage=-99)

fig, axes = pl.subplots(2, 1, sharex=True)
ax = axes[0]
ax.plot(w, spec_onez, label="$Z_{{mass-weighted}}$")
ax.plot(w, spec_multiz, label="$Z_{{history}}$")
ax.legend()
ax.set_ylabel('$f_\\nu$')
ax = axes[1]
ax.plot(w, (spec_onez/spec_multiz - 1) * 100)
ax.set_ylabel("% difference")
ax.set_ylim(-10, 40)
ax.set_xlabel('wavelength')
[a.set_xlim(1.1e3, 0.95e4) for a in axes.flat]

@bd-j bd-j merged commit 8361d60 into dfm:master Jul 11, 2017
@jrleja
Copy link
Contributor

jrleja commented Jul 13, 2017

I’m surprised by the large delta in the UV. I believe it would be smaller if instead the luminosity-weighted metallicities were set equal. I think most of the delta is because the youngest stars have a considerably lower metallicity in the “onez” model.

For comparison, here's a Z(t) versus constant-Z comparison I did, with a constant SFH. Z(t) was set by a closed-box evolution model with the following values:

0-100 Myr, Z = 1 Zsun
100-300 Myr, Z = 0.96 Zsun
300 Myr-1 Gyr, Z = 0.87 Zsun
1 Gyr - 3 Gyr, Z = 0.66 Zsun
3-6 Gyr, Z = 0.41 Zsun
6-13.6 Gyr, Z = 0.13 Zsun

while the constant-Z value was taken to be Zsun. Emission lines are included because I did this the slow way, by generating 6 different populations and summing them.

agez_test

@bd-j
Copy link
Collaborator Author

bd-j commented Jul 13, 2017

@jrleja I agree! Using the luminosity weighted metallicity would be a much fairer comparison and I expect it would show a much smaller UV difference.

@bd-j bd-j deleted the zdep_tabular branch August 7, 2017 13:34
@bd-j bd-j mentioned this pull request Aug 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants