Skip to content

feat: Create blackbodies-and-integration.jl tutorial notebook#20

Draft
abhro wants to merge 5 commits into
mainfrom
integration
Draft

feat: Create blackbodies-and-integration.jl tutorial notebook#20
abhro wants to merge 5 commits into
mainfrom
integration

Conversation

@abhro
Copy link
Copy Markdown
Member

@abhro abhro commented May 11, 2026

Since Planck.jl has been archived and Korg.jl doesn't support frequency, we need to rework the ordering and how the tutorial progresses.

@icweaver
Copy link
Copy Markdown
Member

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

@abhro
Copy link
Copy Markdown
Member Author

abhro commented May 12, 2026

Yeah, probably doing it inline would also allow us to expose more of Julia in the tutorial

@cgarling
Copy link
Copy Markdown
Member

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

@icweaver
Copy link
Copy Markdown
Member

Nice, thanks Chris! Will fold it in

Comment on lines +224 to +225
PowerLawPDF(γ, B = 1.0) = new(γ, B)
PowerLawPDF(; γ, B = 1.0) = new(γ, B)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would Base.@kwdef help us avoid these hoops? I added an example in the DQ notebook

@icweaver
Copy link
Copy Markdown
Member

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

@cgarling
Copy link
Copy Markdown
Member

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.

@icweaver
Copy link
Copy Markdown
Member

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 PowerLawPDF strict to use units. I actually want to try this myself because I have a feeling we will hit some gaps that we could potentially upstream, e.g., JuliaPhysics/DynamicQuantities.jl#40

I am interested in the possibility of trying to connect these more intuitively

Whoa, those ideas sound awesome!

@icweaver icweaver mentioned this pull request May 15, 2026
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.

3 participants