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

Implement mass-metallicity relations #58

Merged
merged 82 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
f31cca0
Add new MZR doc page
cgarling Nov 17, 2024
57096a5
Continue working on MZR derivation
cgarling Nov 21, 2024
8a785d7
More MZR derivations
cgarling Nov 22, 2024
31d37fc
More explanation in linear AMR fg!
cgarling Nov 22, 2024
74cb1ce
Continue MZR derivation
cgarling Nov 24, 2024
6022238
continuing derivation
cgarling Nov 28, 2024
cdb1559
Add `tups_to_mat` to convert tuples to matrix
cgarling Dec 1, 2024
feb474c
Add general derivation for MZR model parameters
cgarling Dec 1, 2024
a896fb6
Add `StatsBase` to test environment
cgarling Dec 2, 2024
e315966
Begin adding MZR functionality from notebook
cgarling Dec 2, 2024
e0390b9
Add docs for the new MZR functions
cgarling Dec 2, 2024
d9bb629
Remove `T_max` from `calculate_coeffs` arguments
cgarling Dec 2, 2024
83a5a69
Start adding tests for `fg_mzr!`
cgarling Dec 2, 2024
b5c4cbb
Support arbitrary `logAge` in `fg_mzr!`
cgarling Dec 3, 2024
07f91bf
Change `npar` to `nparams` and add method
cgarling Dec 4, 2024
4367537
Add methods for transformations
cgarling Dec 4, 2024
692aefd
Fitting function `fit_sfh` with Optim.jl working
cgarling Dec 4, 2024
02852a0
Fix treatment of fixed parameters
cgarling Dec 4, 2024
b20821d
Add `invH`, `mzr`, and `disp` fields to return
cgarling Dec 5, 2024
29f0650
Add `BFGSResult` type for return from fitting
cgarling Dec 5, 2024
e1695ae
Fix `exptransform` doctest
cgarling Dec 6, 2024
7a7d2f8
Remove old `MZR_old.md` doc file
cgarling Dec 6, 2024
8264c80
Reorganize `mzr_test.jl` and test `BFGSResult`
cgarling Dec 6, 2024
224e6b3
Fix sampling of fixed variables in `BFGSResult`
cgarling Dec 7, 2024
0e43418
Add `CompositeBFGSResult` type
cgarling Dec 10, 2024
241bf9a
Add HMC sampling code
cgarling Dec 10, 2024
beb3bab
Remove old HMC code with warmup
cgarling Dec 10, 2024
b488fb3
Remove old return statements from `fit_sfh`
cgarling Dec 10, 2024
1a01ef2
many things sorry
cgarling Dec 10, 2024
f76d19a
Use `@turbo` in `exptransform_samples!`
cgarling Dec 12, 2024
08f7aeb
Revert `@turbo` use in `exptransform_samples!`
cgarling Dec 15, 2024
87b4d00
Add `cum_sfr_quantiles`
cgarling Dec 15, 2024
1bb49db
Only fit free variables -- fix sampling methods
cgarling Dec 16, 2024
d2866f7
Change `MZROptimizer` to `HierarchicalOptimizer`
cgarling Dec 16, 2024
96cdbec
Move `fg_mzr!` to `fg!` to support generic AMR
cgarling Dec 16, 2024
9a8e73d
Move code to generic locations
cgarling Dec 16, 2024
72036a8
Allow `fit_sfh` to use `AbstractMetallicityModel`
cgarling Dec 16, 2024
82a31b5
Consolidate MZR code
cgarling Dec 16, 2024
9ea7439
Add docstring for `fg!` internal function
cgarling Dec 16, 2024
c1f9712
Correct treatment of `F` and `G` in `fg!`
cgarling Dec 16, 2024
0941ef3
Document `variables` argument
cgarling Dec 16, 2024
b7f0306
Document `kws...` passthrough in `fit_sfh`
cgarling Dec 16, 2024
8b94c0d
Functioning `LinearAMR` generic implementation
cgarling Dec 18, 2024
b08c244
Add `LogarithmicAMR` along with tests
cgarling Dec 18, 2024
b630dea
Add `dZ_dMH`
cgarling Dec 19, 2024
59b121b
Stabilizing `LogarithmicAMR` sfh solves
cgarling Dec 19, 2024
8ee339c
Remove old AMR tests
cgarling Dec 20, 2024
6d5b48a
Christmas 2024 push
cgarling Jan 4, 2025
90e1675
`tsample_sfh` updates
cgarling Jan 4, 2025
842ea25
Remove old thread partitioning code `tsample_sfh`
cgarling Jan 4, 2025
fd08720
Fix `tsample_sfh` for fixed parameters
cgarling Jan 4, 2025
1a0b8fb
Refactor `mzr` to `MHmodel` in `mzr_test.jl`
cgarling Jan 4, 2025
580a098
Add ProgressMeter for `tsample_sfh`
cgarling Jan 4, 2025
7bd172a
simplify threaded sampling
cgarling Jan 4, 2025
0a22389
remove old implementation
cgarling Jan 4, 2025
f6e9704
fix tests
cgarling Jan 4, 2025
2f15e3d
Remove stale imports
cgarling Jan 8, 2025
4043104
Clean up formatting, docs
cgarling Jan 8, 2025
9163eda
Update example notebook for new APIs
cgarling Jan 8, 2025
7ce6199
Fix readme badge
cgarling Jan 8, 2025
d06b8a5
Allow for zero slope in AMR and MZR models
cgarling Jan 13, 2025
9436343
Add `nparams` method for multiple models
cgarling Jan 13, 2025
3c609c3
Rename variables to fit new API
cgarling Jan 13, 2025
9add3d9
Bump minor version for breaking changes
cgarling Jan 13, 2025
f490e70
Remove `hermitianpart` to support older Julias
cgarling Jan 13, 2025
b72278c
Clean up `tups_to_mat` type signature
cgarling Jan 13, 2025
725b245
Fix `tups_to_mat` docstring
cgarling Jan 13, 2025
8c9e482
Try to fix unbound arguments in `tups_to_mat`
cgarling Jan 13, 2025
8314707
Fix unbound arguments in `tups_to_mat`
cgarling Jan 13, 2025
52d3324
Fix methods signatures in `tups_to_mat`
cgarling Jan 13, 2025
a3e4dbd
Remove old `tups_to_mat` code
cgarling Jan 13, 2025
171e680
Add Compat.jl and PDMats.jl to dependencies
cgarling Jan 14, 2025
f276996
Fix random sampling from `BFGSResult` on old Julia
cgarling Jan 14, 2025
ecc8ba5
Reorganize old `BFGSResult` sampling code
cgarling Jan 14, 2025
b2d5509
Switch to `arch: aarch64` for mac os CI
cgarling Jan 14, 2025
ede7b1b
Update README.md
cgarling Jan 14, 2025
37ca331
Dont specialize on number of tuples `tups_to_mat`
cgarling Jan 17, 2025
3a0db69
Add more generic `tups_to_mat` for iterables
cgarling Jan 17, 2025
7a8f88c
Update docstrings of `tups_to_mat` properly
cgarling Jan 21, 2025
35fe6c2
Fix free parameter indexing bug in `fit_sfh`
cgarling Jan 25, 2025
18486f0
Add test to verify fix
cgarling Jan 25, 2025
03dc931
Add `Pkg.build` and PYTHON envar to docs CI
cgarling Jan 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- x64
include:
- os: macos-latest
arch: x64
arch: aarch64
version: '1'
- os: windows-latest
arch: x64
Expand Down Expand Up @@ -85,7 +85,8 @@ jobs:
julia --project=docs --color=yes -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
Pkg.instantiate()
Pkg.build()'
env:
PYTHON: ${{ steps.cpython3.outputs.python-path }}
- name: Run doctests
Expand All @@ -101,5 +102,6 @@ jobs:
- name: Make and deploy docs
run: julia --project=docs --color=yes docs/make.jl
env:
PYTHON: ${{ steps.cpython3.outputs.python-path }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
11 changes: 9 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name = "StarFormationHistories"
uuid = "774d3ad4-2d55-48fa-ab42-467705ebff24"
authors = ["cgarling <[email protected]>"]
version = "0.1.1"
version = "0.2.0"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DynamicHMC = "bbc10e6e-7c05-544b-b16e-64fede858acb"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
Expand All @@ -16,7 +17,9 @@ LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
Expand All @@ -35,6 +38,7 @@ DataFramesExt = "DataFrames"
TypedTablesExt = "TypedTables"

[compat]
Compat = "4.13" # for allequal(f, itr)
DataFrames = "1"
DelimitedFiles = "<0.0.1, 1"
Distributions = "0.25"
Expand All @@ -51,7 +55,9 @@ LogDensityProblems = "1, 2"
LoopVectorization = "0.12"
MCMCChains = "6"
Optim = "1.7" # Inverse Hessian estimate from BFGS
PDMats = "0.11.15" # Removed StridedArray restriction
Printf = "<0.0.1, 1"
ProgressMeter = "1"
QuadGK = "2"
Random = "<0.0.1, 1"
Roots = "2"
Expand Down Expand Up @@ -80,8 +86,9 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"

[targets]
test = ["DataFrames", "DelimitedFiles", "Distributions", "Documenter", "DynamicHMC", "InitialMassFunctions", "LinearAlgebra", "MCMCChains", "QuadGK", "Random", "SafeTestsets", "StableRNGs", "StaticArrays", "Test", "TypedTables"]
test = ["DataFrames", "DelimitedFiles", "Distributions", "Documenter", "DynamicHMC", "InitialMassFunctions", "LinearAlgebra", "MCMCChains", "QuadGK", "Random", "SafeTestsets", "StableRNGs", "StaticArrays", "StatsBase", "Test", "TypedTables"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# StarFormationHistories.jl

[![Build Status](https://github.com/cgarling/StarFormationHistories.jl/workflows/CI/badge.svg)](https://github.com/cgarling/InitialMassFunctions.jl/actions)
[![Build Status](https://github.com/cgarling/StarFormationHistories.jl/workflows/CI/badge.svg)](https://github.com/cgarling/StarFormationHistories.jl/actions)
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://cgarling.github.io/StarFormationHistories.jl/stable/)
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://cgarling.github.io/StarFormationHistories.jl/dev/)
[![codecov](https://codecov.io/github/cgarling/StarFormationHistories.jl/graph/badge.svg?token=L69R23H29M)](https://codecov.io/github/cgarling/StarFormationHistories.jl)
Expand Down Expand Up @@ -33,7 +33,7 @@ Below we additionally show example templates for different combinations of stell

## SFH Fitting

Once templates have been generated for a reasonable set of isochrones, they can be used to estimate the SFH of an observed population by modelling the observed Hess diagram as a linear combination of the templates. The coefficients on the linear combination are simply the desired star formation rates. While this can work, and we provide fitting methods that support this use, this approach is crude as it does not guarantee that the solution has a physically realistic age-metallicity relation (AMR). We additionally define a few parametric AMRs that apply constraints during the fitting process to alleviate this issue. We plan to expand the set of AMR models in the future.
Once templates have been generated for a reasonable set of isochrones, they can be used to estimate the SFH of an observed population by modelling the observed Hess diagram as a linear combination of the templates. The coefficients on the linear combination are simply the desired star formation rates. While this can work, and we provide fitting methods that support this use, this approach is crude as it does not guarantee that the solution has a physically realistic age-metallicity relation (AMR). We additionally define an API for describing general AMR models as well as mass-metallicity models (MZRs) for constraining the metallicity evolution of the population. We provide a few parametric AMRs and MZRs and describe how to define custom models.

## Acknowledgements
Support for this work was provided by the Owens Family Foundation and by NASA through grant HST-AR-17560 from the Space Telescope Science Institute, which is operated by AURA, Inc., under NASA contract NAS5-26555.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
DelimitedFiles = "1"
Expand Down
11 changes: 8 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ makedocs(
["fitting/fitting_intro.md",
"fitting/unconstrained.md",
"Constrained Metallicity Evolution" =>
["fitting/linear_amr.md",
"fitting/log_amr.md",
"fitting/fixed_amr.md"],
["fitting/hierarchical/overview.md",
"AMRs" =>
["fitting/hierarchical/linear_amr.md",
"fitting/hierarchical/log_amr.md",
"fitting/hierarchical/fixed_amr.md"],
"MZRs" =>
["fitting/hierarchical/MZR/MZR.md"],
"fitting/hierarchical/dispersion_models.md"],
"Internals" => ["fitting/internals.md",
"fitting/kernels.md"]],
"examples.md",
Expand Down
Loading
Loading