Giter Club home page Giter Club logo

Comments (9)

zpace avatar zpace commented on June 29, 2024

At some point, I was advised to avoid instantiating fsps.StellarPopulation more than once: the maintainers would be better equipped to answer precisely why, but I suspect it has to do with how these python bindings interface with the underlying fortran.

Try running your two code blocks as separate programs, write out the result for each, and compare them that way.

from python-fsps.

dptriani avatar dptriani commented on June 29, 2024

I have separated them but they still give different result

from python-fsps.

bd-j avatar bd-j commented on June 29, 2024

It's true that to be safe you want to have a single StellarPopulation object. But the issue here I think is more that the default SFH (used in your first sp object) is a single age simple stellar population (sfh=0). The tabular sp.sfr value is not actually well-defined for such an SFH (since it is a delta function at age=0) and so the sfr variable that you compute is filled with zeros and the resulting sfh=3 spectrum is garbage. I guess we could check for non-zero sfr inside set_tabular_sfh() to warn users about this.

What I'd do instead is

import fsps
import matplotlib.pyplot as pl

sps = fsps.StellarPopulation()

# get the spectrum via the intrinsic SFH convolutions
sps.params["sfh"] = 4  #delayed_exponential
sdss_bands = fsps.find_filter("sdss")
mags = sps.get_mags(bands=sdss_bands)
age = (10 ** sps.log_age) / 1e9
sfr = sps.sfr
wavelength, spectrum = sps.get_spectrum(tage=13.7)

# get the spectrum from a tabular version
sps.params["sfh"] = 3
sps.set_tabular_sfh(age, sfr)
wavelength, spectrum1 = sps.get_spectrum(tage=13.7)

# Plot the SFR
fig, axes = pl.subplots(2, 1)
axes[0].plot(age, sfr, '-o')
axes[0].set_xlabel('Age (Gyr)')
axes[0].set_ylabel('SFR (M$_\odot$/yr')
axes[1].plot(wavelength, spectrum, label="via sfh=4")
axes[1].plot(wavelength, spectrum1, label="via sfh=3")
axes[1].set_xlim(1e3, 1e4)
axes[1].set_xlabel('$\lambda (\AA)$')
axes[1].set_ylabel('$f_\nu (L_\odot/Hz)$')
axes[1].legend(loc=0)
pl.show()

In fact you will probably still notice (smaller) differences. I'm pretty sure this is because for sfh=1, 4, or 5 all the calculations are done exactly, taking into the account the true exponential dependence of the SFR between ssp ages, whereas for sfh=3 the SFH is assumed to be piecewise linear between the provided tabular age points, which becomes a poor approximation to the true SFH as the age resolution decreases. But it could be good to do some more testing of that.

from python-fsps.

dptriani avatar dptriani commented on June 29, 2024

Thanks a lot for the answer!

from python-fsps.

dptriani avatar dptriani commented on June 29, 2024

Hi, I want to clarify that the value of age given by log_age is the age of universe or lookback time?
I made several model with single burst with different tstart and the later tstart (the bigger number) give smaller stellar mass.
So say if I want to specify the burst to start 3Gyr ago, should I put 11 or 3 in the tstart?

from python-fsps.

bd-j avatar bd-j commented on June 29, 2024

Is this with sfh=3? I'm not sure how you'd do a burst that way. Also, by tstart do you mean the sf_start parameter? Or the tburst parameter? Both of those are only defined for sfh=1,4,5

from python-fsps.

dptriani avatar dptriani commented on June 29, 2024

for sfh=1, I change the tstart parameter

from python-fsps.

bd-j avatar bd-j commented on June 29, 2024

Yes, the times (sf_start, tburst, tage, log_age) are age of universe, not lookback time.

from python-fsps.

bd-j avatar bd-j commented on June 29, 2024

Just wanted to add a note here that the difference between the spectra obtained via SFH=3 and SFH=4 for delay-tau that I mentioned earlier in the thread was actually caused largely by an FSPS bug in tabular SFH calculations, now fixed by cconroy20/fsps#32

Remaining differences are much less than a percent for lambda > 1300 AA, and less than 5 percent blueward of that.

from python-fsps.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.