-
-
Notifications
You must be signed in to change notification settings - Fork 2k
planck function addition #1480
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
planck function addition #1480
Conversation
|
@skendrew - just for information, if anyone requests any changes during review, you just need to commit the changes and push to the same branch, and the pull request will update. |
|
Quick comment for now - it looks like the changes in |
|
OK thanks and will do - to both comments. I haven't configured my editor properly yet on my new laptop!! |
|
@kendrew -- Would it be possible to have an option to return f_nu units instead of f_lambda units for the mid-IR through radio users out there? It's also easier to convert f_nu to AB mags. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify this block of code to:
try:
w = w.to(u.m, equivalencies=u.spectral())
except u.UnitsError:
raise InputParameterError("First parameter must be in wavelength or frequency units")
since the equivalency will take care of intepreting frequency or length in the right way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added wave number comprehension to u.spectral(), so you can now also input wavelengths as wave number.
|
@astrofrog, @skendrew -- on second thought, maybe that's just cluttering up the interface. After all, there is astropy.units.equivalencies.spectral_density. But it would be nice if this were called plank_lambda so users aren't always having to read the docs to remember which one it is. |
|
@skendrew - Thanks for the contribution! I've finally had a chance to review this, and I've left a few comments above - they are all fairly minor! Some are just a question of style or consistency with the rest of Astropy. The way we usually deal with comments like this is to implement each of them (sometimes one commit per main comment), push the new commits to the branch, then respond to the comments to say if a particular comment has been addressed (even just saying 'Done'). You may have to close on 'show outdated diff' in some cases as the comment may disappear if it is no longer relevant to the code in the pull request. |
|
@aconley - agreed, let's just stick to |
|
@skendrew - minor comments:
@aconley, @astrofrog: I'm not sure I like the suggestion of having One advantage of this is that the function will not return frequency units for a wavelength (i.e., length units), which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As expressed, this runs the risks of inaccuracies for very long wavelengths and warnings about overflow error for very small ones.
(e.g., I get an overflow warning for planck(1.*u.AA, 1e4*u.K), and results are less accurate for, e.g., planck(10.*u.m, 1.e10 * u.K). You might want to catch the overflow (since it is not actually physically meaningful); the inaccuracies would only seem to be an issue if people use float32 (note that this is possible with quantities).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an addendum, you should use np.expm1(value) rather than np.exp(value)-1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unproven, but maybe freq ** 3 will have performance improvement over lambda ** 5?
|
p.s. As an implementation of the above, one could have the individual |
|
@mhvk - Calling it blackbody is fine -- but I can't say I'm worried about anybody likely to be using astropy not immediately knowing the association between Max Planck and the blackbody formula! For my own personal convenience, I would prefer whatever_lambda and whatever_nu, because the standard in the mid-IR through mm is to work in f_nu as a function of wavelength, and so anybody working there will always have to mucking about with equivalencies. And odd convention, I know, but such is life. At least it isn't as bad as antennae temperature! |
|
I'm with @aconley - I don't think the unit of the input variable should determine whether it's f_nu or f_lambda, and in the mid-IR it is indeed common to use f_nu(lambda). My suggestion for now is to first implement comments about planck_lambda itself, then once the function is ready, it's easy to simply add a second one called planck_nu and then just adjust the formula. For the purpose of this pull request, let's maybe not worry too much about the underflow/overflow, and we can fix it in a subsequent pull request? |
|
@astrofrog, @aconley - I thought a bit more and agree that the individual functions are useful to have (also for speed-up in modelling), so good to go ahead. As long as we have a As for the name, yes, of course, most astronomers will understand As a final question: on second thought I also wondered whether one should convert the flux to some specific units at all, whether [W/m2/mu] or anything else; the beauty of quantities is that they represent the same physical quantity (in this case flux with wavelength units) no matter what the precise units. So, perhaps just remove For modelling, this would make it a little faster, as it is unlikely the data being modelled are in exactly those units, so the equivalent of (Also, since you convert wavelengths to [m] anyway, you do automatically get a readable output unit, [J / (m3 s)]) |
|
I just wanted to mention that I think a blackbody spectrum model would be a great addition. @nden @embray I think this is the first model where using quantities as parameters and possibly as inputs to I think this should be implemented as a class |
|
Sorry I missed this PR ealier. My comments below would be more useful then. Coincidentally, STScI Synthetic Photometry package (in development) also has similar Planck blackbody implementations. The default units are, of course, suited for Hubble Space Telescope. https://github.com/spacetelescope/pysynphot/blob/master/synphot/planck.py The magical flux units are defined in particularly Incidentally, I also implemented a Perhaps some of my work would be useful for this PR as well. I would certainly use the Astropy Planck function when it is available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temperature must be in Kelvin. If someone gives the value in Celcius or whatever that obscure unit Americans use that I cannot spell, temperature should be converted to Kelvin first.
|
I'd like to suggest we revisit our previous decision to implement this as a model. Clearly this would be a useful function regardless of |
|
@astrofrog, where would such functions reside in |
|
Not sure, but doesn't mean it can't be done :) Not utils though, that's for non astro utils (more infrastructure stuff) |
|
The units thing is something I'm working on almost as we speak. But I agree there's no reason it has to be implemented strictly within the Model framework. In fact I've been trying to design things so that basic functions can have any number of implementations outside the Model framework, and can be easily wrapped (possibly even swapping out implementations where one implementation is somehow better than another for some particular data). |
|
|
|
Scipy uses the very cryptic |
|
I don't really care what it's called, but I've said elsewhere (possibly even in this PR) that it would be good to have a module of general analytic functions and such. These would be used by some of the models in the modeling package in their |
|
A quick online search reveals that @eteq implemented some models back in 2010 at https://pythonhosted.org/Astropysics/coremods/models.html -- Any plans to port them to |
|
@pllim - yes definitely. They're mostly functions that can pretty much be imported wholesale into The only uncertainty is about the |
|
@eteq Not to get too far off topic, but there are no major changes that would significantly impact porting. Quantity support is on its way but again is not a major factor in implementation. |
|
@embray - I just meant that some of those models would be better if they used So I can try to port over all of those that make sense to include (some of them like gaussians and various polynomials are superceded by exostomg |
|
@eteq , is it feasible to move the models that need proper unit handling to |
|
@pllim - yeah, that might make sense for some of them. Will have to go through the list of models a bit more to decide for sure |
|
Merged in #3094 |
|
Thanks @skendrew and @pllim--it will be great to use these in the modeling framework once I've gotten Quantity working with models ^^; |
|
No prob! |
Added the planck() function to functional_models, and a corresponding test function test_planck() to test_models. The test compares the planck() output integrated over a range of wavelengths with the Stefan-Boltzmann law.