-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add Exoplanet Object #235
Add Exoplanet Object #235
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #235 +/- ##
==========================================
+ Coverage 53.80% 55.17% +1.37%
==========================================
Files 23 23
Lines 2881 2954 +73
==========================================
+ Hits 1550 1630 +80
+ Misses 1331 1324 -7 ☔ View full report in Codecov by Sentry. |
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.
Excellent! I left a number o minor inline comments below.
In addition, can you please add a test to check that you get a validation error when you pass in a period and a duration without a unit (or with the wrong kind of unit)?
stellarphot/settings/models.py
Outdated
To create an `Exoplanet` object, you can pass in the epoch, | ||
period, Identifier, coordinate, depth, and duration as keyword arguments: | ||
|
||
>>> planet = Exoplanet(epoch=Time(0, format="jd"), period=0 * u.min, |
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.
It is probably more helpful if you put in information for a real exoplanet. Maybe Kelt-1?
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.
updated to use kelt-1b info but all of it may not be correct. kinda estimated values based on the graphs from a paper i found. also the depth is based on normalized flux
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.
You can look up exoplanet data here: https://exoplanetarchive.ipac.caltech.edu/
There are likely several values for kelt-1, maybe use the most recent.
stellarphot/settings/models.py
Outdated
Depth of the exoplanet. | ||
|
||
duration : `astropy.units.Quantity`, optional | ||
Duration of the exoplanet transit as a Quantity with units of time, |
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.
Please update this description
from pydantic import ValidationError | ||
import pytest | ||
|
||
from stellarphot.settings.models import ApertureSettings | ||
from stellarphot.settings.models import ApertureSettings,Exoplanet |
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.
from stellarphot.settings.models import ApertureSettings,Exoplanet | |
from stellarphot.settings.models import ApertureSettings, Exoplanet |
Looking good -- the main thing still missing is a test for invalid values for period and duration. |
For the validation test would that be similar to this: @pytest.mark.parametrize("bad_one", ["radius", "gap", "annulus_width"])
def test_create_invalid_values(bad_one):
# Check that individual values that are bad raise an error
bad_settings = DEFAULT_APERTURE_SETTINGS.copy()
bad_settings[bad_one] = -1
with pytest.raises(ValidationError, match=bad_one):
ApertureSettings(**bad_settings) |
Yep, something like that would work |
assert u.get_physical_type(planet.duration) == "time" | ||
|
||
|
||
@pytest.mark.parametrize("bad_one", [ |
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.
Usually parametrize
is used to when you want to test with multiple values rather than a single value. I could see going two ways here:
- Test two values, like in the example you mentioned here. That maybe looks like
@pytest.mark.parametrize('bad_one', ('period', 'duration'))
and then in the test set the value ot something bad like in the example. - Test with one set of settings in which both duration and period are bad (inappropriate units) and make sure the error message has the right number of
ValidationErrors
. See this test for an example of that approach.
Either way, you should be able to start with a copy of the default exoplanet and modify values of that rather than reproducing all the settings.
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.
So I redid the tests and just have a question about the order of operation for the tests. Does this pytest run the validation tests that are in the exoplanet class that check the physical units of duration and period? When I gave period and duration units of cm it would pass this pytest.
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.
It should run the validation checks and then raise a single ValidationError
(rather than several ValueError
s) with a summary of the errors it encountered.
]) | ||
def test_create_invalid_exoplanet(bad_one): | ||
# Check that individual values that are bad raise an error | ||
with pytest.raises(ValidationError, match=".*"): |
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.
Typically if match
is included you should try to match some meaningful part of the error message. This particular value ".*"
means it will always match, which is equivalent to not having match
there at all.
A couple broader comments:
|
should i just ignore the 'line too long' issues or is there something else I can check to see if lines are too long? |
I would run |
Time: lambda v: f"{v.value}", | ||
} | ||
|
||
@classmethod |
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.
this needs one more decorator to finish turning it into something that pydantic actually validates, something like @validator("period")
(after importing validator
from pydantic
).
See https://github.com/feder-observatory/stellarphot/blob/main/stellarphot/core.py#L289 for an example. That is why leaving the units off didn't generate a validation error. Let's ,make sure it does by only making those two values bad.
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.
@Tanner728 -- do you have time to add this change or should I wrap it up 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 should have time tonight to do it.
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.
Looks like you left out the "period" argument to @validator
....
After adding the validator I get this error message when running the tests and am somewhat stumped about where its coming from. py::test_create_exoplanet_correctly failed: def test_create_exoplanet_correctly():
stellarphot\settings\tests\test_models.py:53:
pydantic\main.py:341: ValidationError |
Can you push the commit the change you made or paste the updarted code into a comment so I can take a look? |
Looks like you pushed a merge commit? You shouldn't need a merge commit.... |
Looks like you left out the "period" argument to @validator... |
(cherry picked from commit db220b3) fixing linting issues Linting fixes
Added the '@validator' decorator to TimeType, runs into QuantityType error on the period attribute
FYI, just updated this to finish off the validators (I think I did, at least, will see what the tests say) |
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.
Thanks, @Tanner728
Thank you @mwcraig. I am currently driving out to Montana but will send you a draft of the proceedings paper tonight. Thanks for finishing that validator off. |
Created the exoplanet object and added documentation for it based on the documentation of the aperture settings class above
Fixes #186