-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor SN Ia e2e test to use oversampled opsim #132
Conversation
# Conflicts: # tests/tdastro/conftest.py
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
docs/notebooks/test_snia.ipynb
Outdated
"res = test_snia_end2end(\n", | ||
" None, opsim_db_file=None, opsim=False, nsample=10, return_result=True, phase_rest=np.linspace(-15, 45, 20)\n", | ||
"res, passbands = test_snia_end2end(\n", | ||
" conftest.oversampled_observations(conftest.opsim_shorten(conftest.test_data_dir())),\n", |
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.
There are a few different approaches we could use to access the opsim_shorten
here without having to change the pytest fixtures in the conftest.py file.
- [My preference] Move the directory names to the top level
__init__.py
file (or a newpaths.py
file in the base directory):
_TDASTRO_BASE_DIR = os.path.dirname(__file__)
_TDASTRO_TEST_DIR = os.path.join(_TDASTRO_BASE_DIR, "tests", "tdastro")
_TDASTRO_TEST_DATA_DIR = os.path.join(_TDASTRO_TEST_DIR, "data")
Then both the notebooks and conftest.py
use these.
We would need to include a cell to do:
base_opsim = OpSim.from_db(opsim_shorten)
oversampled_observations = oversample_opsim(
base_opsim,
pointing=(0.0, 0.0),
search_radius=180.0,
delta_t=0.01,
time_range=(61406.0, 61771.0),
bands=None,
strategy="darkest_sky",
)
but I think it would be good to explicitly include that in the notebook. It allows the user to see where you are pulling the data and how you are transforming it.
- [Not prefered] I think in notebooks it is fair to just provide a path like
test_opsim_filename = "../../tests/tdastro/data/opsim_shorten.db")
It's not as robust as the approach above, but that is okay since users are expected to interact with the notebooks.
docs/notebooks/test_snia.ipynb
Outdated
"outputs": [], | ||
"source": [ | ||
"res = test_snia_end2end(\n", | ||
" None, opsim_db_file=None, opsim=False, nsample=10, return_result=True, phase_rest=np.linspace(-15, 45, 20)\n", | ||
"res, passbands = test_snia_end2end(\n", |
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.
My preference would be not to use test_snia_end2end
here and instead repeat the code in the notebook. I know code repetition is usually considered bad, but I think the code of interest to the notebook user will be what is in that function. Leaving the code out of the notebook doesn't provide the user all the information.
Alternatively, if we really want to keep code in sync, we could break out modules into new files.
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.
We have planned to update notebook to show how model is defined with more text descriptions by breaking the end2end test into multiple steps. Right now I prefer to keep it this way so I don't need to change the same thing in two different places when experimenting.
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 agree with this, but I've just keep the same NB structure as it was before. I'd keep these changes out of the scope of this PR or ask someone to help me commiting/PRing these changes
@@ -174,22 +154,22 @@ def test_snia_end2end( | |||
saltpars = {"x0": p["x0"], "x1": p["x1"], "c": p["c"], "z": p["redshift"], "t0": p["t0"]} | |||
model = sncosmo.Model(sncosmo_modelname) |
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'd like to find an alternate way to test the code. sncosmo.Model
will download the model files each time the test is run in a new environment (including each run of the CI tests). This is already causing intermittent failures on github. We should isolate the tests from external downloads. We could do this by pre-downloading and including the model files or by comparing with known data.
tests/tdastro/conftest.py
Outdated
@@ -6,37 +6,69 @@ | |||
TEST_DIR = os.path.dirname(__file__) | |||
|
|||
|
|||
@pytest.fixture | |||
def fixture(func): |
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 would prefer to avoid this by either 1) moving the directory information into the base directory or 2) adding the full path to the notebook. See the discussion in the notebook section.
Removes the conftest changes and uses a few manual strings in the notebook instead.
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 made the suggested changes. Can you review and, if happy, merge?
This is a part of work to incorporate noise generation into the simulation pipeline started in #108
The changes:
oversampled_observations
fixturetest_snia_end2end
and helper test functiondraw_single_random_sn
to use opsim only, removes phases calculationsur
tori
and model from SALT2 to SALT3. I opened an issue about this inconsistency Investigate inconsistency between sncosmo and our band fluxes #133conftest.py
to fix it. I hope someone would volunteer to fix it in a proper way.Change Description
Solution Description
Code Quality
Project-Specific Pull Request Checklists
Bug Fix Checklist
New Feature Checklist
Documentation Change Checklist
Build/CI Change Checklist
Other Change Checklist