feat: Create blackbodies-and-integration.jl tutorial notebook#20
Conversation
|
Yea, I'm inclined to just inline it from Planck.jl ourselves since it's so short, and then just point folks to Korg.jl or SpectralFitting.jl if they want to do more advanced things like model fitting |
|
Yeah, probably doing it inline would also allow us to expose more of Julia in the tutorial |
|
Given the topic of this notebook it would seem appropriate to mention the existence of InitialMassFunctions.jl in a note or other admonishment in case people specifically want ready-to-use IMF implementations, see e.g. using InitialMassFunctions: Salpeter1955, pdf
using QuadGK: quadgk
using Test: @test
struct PowerLawPDF
γ::Float64
B::Float64
PowerLawPDF(γ, B = 1.0) = new(γ, B)
PowerLawPDF(; γ, B = 1.0) = new(γ, B)
end
(p::PowerLawPDF)(x) = x^p.γ / p.B
salpeter_unnormalized = PowerLawPDF(γ = -2.35)
B, _ = quadgk(salpeter_unnormalized, 0.01, 100.0)
salpeter = PowerLawPDF(salpeter_unnormalized.γ, B)
m_grid = logrange(10^-2, 10^2, length = 100)
# Compare integrals with InitialMassFunctions.jl
salpeter_imf = Salpeter1955(0.01, 100.0) # Normalized between 0.01 and 100.0 as above
@test quadgk(salpeter, 0.01, 0.6)[1] ≈ quadgk(x->pdf(salpeter_imf, x), 0.01, 0.6)[1] atol = 1e-5
@test quadgk(salpeter, 15.0, 100.0)[1] ≈ quadgk(x->pdf(salpeter_imf, x), 15.0, 100.0)[1] atol = 1e-5 |
|
Nice, thanks Chris! Will fold it in |
| PowerLawPDF(γ, B = 1.0) = new(γ, B) | ||
| PowerLawPDF(; γ, B = 1.0) = new(γ, B) |
There was a problem hiding this comment.
Would Base.@kwdef help us avoid these hoops? I added an example in the DQ notebook
|
I'm wondering if re-naming this tutorial to something more general like "Numerical integration with units" would be more appropriate since only the first half explicitly deals with blackbodies. I took a crack at reorganizing the sections in the DQ version |
|
Seems to me like the first part with the blackbody is mostly about units and second part is mostly about numerical integration. They overlap a little (integrating the blackbody with units and seeing the units are still preserved) but the IMF is a probability distribution so the unit focus is not as clear in that part. I am interested in the possibility of trying to connect these more intuitively -- you could start on the blackbody side and set up a simplified polytropic stellar interior model and solve for the steady-state surface temperature given a stellar mass (here you could do DiffEq + Unitful) and derive the relation between initial mass and surface temperature. Then you set up IMF as you already have; then you can convert the probability distribution of stellar masses (dN/dM_ini) to a distribution of stellar temperatures (dN/dT) or stellar luminosities (dN/dL) by integrating over the blackbodies. I might try throwing that idea into a language model sometime I have some spare time and see what comes out. |
|
Agreed, I think the connection of the IMF section to unit analysis doesn't really come in until the challenge problem where the learner is tasked with modifying the
Whoa, those ideas sound awesome! |
Since Planck.jl has been archived and Korg.jl doesn't support frequency, we need to rework the ordering and how the tutorial progresses.