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

Add Exoplanet Object #235

Merged
merged 9 commits into from
Jan 2, 2024
Merged

Add Exoplanet Object #235

merged 9 commits into from
Jan 2, 2024

Conversation

Tanner728
Copy link
Contributor

@Tanner728 Tanner728 commented Dec 26, 2023

Created the exoplanet object and added documentation for it based on the documentation of the aperture settings class above

Fixes #186

@codecov-commenter
Copy link

codecov-commenter commented Dec 26, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d35a332) 53.80% compared to head (2d5c764) 55.17%.
Report is 24 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@mwcraig mwcraig left a 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 Show resolved Hide resolved
stellarphot/settings/models.py Outdated Show resolved Hide resolved
stellarphot/settings/models.py Outdated Show resolved Hide resolved
stellarphot/settings/models.py Outdated Show resolved Hide resolved
stellarphot/settings/models.py Outdated Show resolved Hide resolved
stellarphot/settings/models.py Outdated Show resolved Hide resolved
stellarphot/settings/models.py Outdated Show resolved Hide resolved
stellarphot/settings/models.py Outdated Show resolved Hide resolved
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,
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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/tests/test_models.py Outdated Show resolved Hide resolved
Depth of the exoplanet.

duration : `astropy.units.Quantity`, optional
Duration of the exoplanet transit as a Quantity with units of time,
Copy link
Contributor

@mwcraig mwcraig Dec 27, 2023

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from stellarphot.settings.models import ApertureSettings,Exoplanet
from stellarphot.settings.models import ApertureSettings, Exoplanet

@mwcraig
Copy link
Contributor

mwcraig commented Dec 27, 2023

Looking good -- the main thing still missing is a test for invalid values for period and duration.

@Tanner728
Copy link
Contributor Author

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)

@mwcraig
Copy link
Contributor

mwcraig commented Dec 27, 2023

Yep, something like that would work

assert u.get_physical_type(planet.duration) == "time"


@pytest.mark.parametrize("bad_one", [
Copy link
Contributor

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:

  1. 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.
  2. 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.

Copy link
Contributor Author

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.

Copy link
Contributor

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 ValueErrors) 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=".*"):
Copy link
Contributor

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.

@mwcraig
Copy link
Contributor

mwcraig commented Dec 27, 2023

A couple broader comments:

  • Please try to fix the linting issues before committing so there aren't a bunch of lint fix commit.
  • Don't rely on what VS Code says is too long a line unless you update the line length to 88. It seems like in several cases you have "overshortened" the lines.

@Tanner728
Copy link
Contributor Author

should i just ignore the 'line too long' issues or is there something else I can check to see if lines are too long?

@mwcraig
Copy link
Contributor

mwcraig commented Dec 27, 2023

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 tox -e lint before you commit -- if it doesn't complain about lines being too long then you are OK. When we talked yesterday I thought your vscode was marking lines longer than 79 characters even though the project line length limit is 88.

Time: lambda v: f"{v.value}",
}

@classmethod
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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....

@Tanner728
Copy link
Contributor Author

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():

  planet = Exoplanet(**DEFAULT_EXOPLANET_SETTINGS)

stellarphot\settings\tests\test_models.py:53:


???
E pydantic.error_wrappers.ValidationError: 1 validation error for Exoplanet
E period
E 'Quantity' object with a scalar value does not support indexing (type=type_error)

pydantic\main.py:341: ValidationError

@mwcraig
Copy link
Contributor

mwcraig commented Jan 1, 2024

Can you push the commit the change you made or paste the updarted code into a comment so I can take a look?

@mwcraig
Copy link
Contributor

mwcraig commented Jan 1, 2024

Looks like you pushed a merge commit? You shouldn't need a merge commit....

@mwcraig
Copy link
Contributor

mwcraig commented Jan 2, 2024

Looks like you left out the "period" argument to @validator...

Tanner728 and others added 8 commits January 2, 2024 12:36
(cherry picked from commit d9736f3)
(cherry picked from commit 3d7617e)
(cherry picked from commit db220b3)

fixing linting issues

Linting fixes
Added the '@validator' decorator to TimeType, runs into QuantityType error on the period attribute
@mwcraig
Copy link
Contributor

mwcraig commented Jan 2, 2024

FYI, just updated this to finish off the validators (I think I did, at least, will see what the tests say)

Copy link
Contributor

@mwcraig mwcraig left a comment

Choose a reason for hiding this comment

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

Thanks, @Tanner728

@mwcraig mwcraig merged commit 78b4b7e into feder-observatory:main Jan 2, 2024
9 checks passed
@Tanner728
Copy link
Contributor Author

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.

@Tanner728 Tanner728 deleted the exoplanet branch January 2, 2024 19:43
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.

Make an object to represent an exoplanet
3 participants