Skip to content

Commit

Permalink
Merge pull request BEAST-Fitting#74 from karllark/getting_running_2024
Browse files Browse the repository at this point in the history
Getting things running in 2024
  • Loading branch information
karllark authored Jul 30, 2024
2 parents 84f8eb6 + 8d43cf9 commit e41715b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 31 deletions.
40 changes: 21 additions & 19 deletions .github/workflows/tox-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ jobs:
# Only run on ubuntu by default, but can add other os's to the test matrix here.
# For example -- os: [ubuntu-latest, macos-latest, windows-latest]
# windows-latest not possible due to how temp files are used in tests currently
os: [ubuntu-latest, macos-latest]
# macos failing due to an issue installing h5py - KDG 14may24
# os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest]

# Test python version 3.x
python-ver: [9, 10, 11]
python-ver: [10, 11, 12]

# Specify which tox environments to test in this list.
# tox-env: [cov, alldeps, devdeps, astropylts]
tox-env: [alldeps]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Set up python 3.${{ matrix.python-ver }} with tox environment py3${{ matrix.python-ver }}-${{ matrix.tox-env }} on ${{ matrix.os }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.${{ matrix.python-ver }}
- name: Install base dependencies
Expand Down Expand Up @@ -71,38 +73,38 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Set up python for astropy lts test
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Test with tox
run: |
tox -e py39-astropylts
tox -e py311-astropylts
# Coverage test
cov_test:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Set up python for coverage test
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.9
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Test with tox
run: |
tox -e py311-cov
tox -e py309-cov -- --remote-data
- name: Upload coverage to codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV }}
fail_ci_if_error: true
Expand All @@ -119,11 +121,11 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Set up Python to build docs with sphinx
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -139,11 +141,11 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Python codestyle check
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
Expand Down
9 changes: 3 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,13 @@ typo in the documentation to developing a major new feature. We welcome
contributors who will abide by the `Python Software Foundation Code of Conduct
<https://www.python.org/psf/conduct/>`_.

``dust_extinction`` follows the same workflow and coding guidelines as
``megabeast`` follows the same workflow and coding guidelines as
`Astropy`_. The following pages will help you get started with contributing
fixes, code, or documentation (no git or GitHub experience necessary):

* `How to make a code contribution <https://docs.astropy.org/en/stable/development/workflow/development_workflow.html>`_

* `Coding Guidelines <https://docs.astropy.org/en/stable/development/codeguide.html>`_

* `Developer Documentation <https://docs.astropy.org/en/stable/index_dev.html>`_
* `How to make a code contribution <https://docs.astropy.org/en/latest/index_dev.html>`_

* `Coding Guidelines <https://docs.astropy.org/en/latest/development/codeguide.html>`_

For the complete list of contributors please see the `megabeast
contributors page on Github
Expand Down
2 changes: 1 addition & 1 deletion megabeast/fit_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main():
for cparam in beast_physmod_param_list:
beast_moddata[cparam] = sgrid.grid[cparam]

# get the completness from the BEAST observation model
# get the completeness from the BEAST observation model
# use the maximum completeness across the bands as the correct obsmodel
# would only have one completeness value per model
# max is the best approximation for the toothpick model (maybe??? average??)
Expand Down
19 changes: 16 additions & 3 deletions megabeast/singlepop_dust_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MB_Model:
MegaBEAST model that provides member functions to compute
the likelihood and priors for a specific physical model
"""

def __init__(self, params):
self.star_model = params.stellar_model
self.dust_model = params.fd_model
Expand All @@ -27,6 +28,9 @@ def __init__(self, params):
# define a dict that translates between mb params and physical models
self.params = ["logA", "M_ini", "Av", "Rv", "fA"]
self.physics_model = {}
print(self.params)
print(self.star_model.keys())
print(self.dust_model.keys())
for cparam in self.params:
if cparam in self.star_model.keys():
cmod = self.star_model[cparam]
Expand Down Expand Up @@ -95,7 +99,7 @@ def start_params(self):
len(np.atleast_1d(mod[ckey][cparam])) > 1
): # expand into multiple parameters
for ll, cval in enumerate(mod[ckey][cparam]):
names.append(f"{ckey}_{cparam}{ll+1}")
names.append(f"{ckey}_{cparam}{ll + 1}")
values.append(cval)
else:
names.append(f"{ckey}_{cparam}")
Expand Down Expand Up @@ -194,12 +198,19 @@ def lnlike(self, phi, star_lnpgriddata, beast_moddata):
* beast_moddata["completeness"][curindxs]
)
# checks for spoilers
# print(i, star_intprob)
if not np.isfinite(star_intprob):
raise ValueError("invidual integrated star prob is not finite")
if star_intprob == 0.0:
raise ValueError("invidual integrated star prob is zero")
pass
# print(i, star_intprob)
# raise ValueError("invidual integrated star prob is zero")
else:
logintprob += np.log(star_intprob)

logintprob += np.log(star_intprob)
if logintprob == 0.0:
print(logintprob)
exit()

return logintprob

Expand Down Expand Up @@ -288,6 +299,7 @@ def _get_best_fit_params(sampler):
nwalkers, nsteps = sampler.lnprobability.shape
for k in range(nwalkers):
tmax_lnp = np.nanmax(sampler.lnprobability[k])
print(tmax_lnp)
if tmax_lnp > max_lnp:
max_lnp = tmax_lnp
(indxs,) = np.where(sampler.lnprobability[k] == tmax_lnp)
Expand Down Expand Up @@ -317,6 +329,7 @@ def fit_ensemble(megabeast_model, star_lnpgriddata, beast_moddata):
fit_results : array
set of best fit parameters
"""

# standard minimization to find initial values
def chi2(*args):
return -1.0 * lnprob(*args)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ packages = find:
python_requires = >=3.9
setup_requires = setuptools_scm
install_requires =
numpy<2.0
scipy
astropy
matplotlib
aplpy
h5py
tqdm
emcee
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{39,310,311}-test{,-alldeps}{,-cov}
py{310,311,312}-test{,-alldeps}{,-cov}
build_docs
linkcheck
codestyle
Expand Down

0 comments on commit e41715b

Please sign in to comment.