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

Refactor _SGDB4 class #171

Merged
merged 11 commits into from
Nov 29, 2024
Merged

Refactor _SGDB4 class #171

merged 11 commits into from
Nov 29, 2024

Conversation

pnuu
Copy link
Member

@pnuu pnuu commented Nov 21, 2024

This PR refactors the _SGDB4 class.

  • __init__()
  • propagate()
  • Tests passed
  • Passes flake8 pyorbital

@pnuu pnuu self-assigned this Nov 21, 2024
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 86.38743% with 52 lines in your changes missing coverage. Please review.

Project coverage is 87.81%. Comparing base (7eb57a5) to head (6fb6efd).
Report is 31 commits behind head on main.

Files with missing lines Patch % Lines
pyorbital/orbital.py 86.38% 52 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #171      +/-   ##
==========================================
- Coverage   88.45%   87.81%   -0.65%     
==========================================
  Files          16       16              
  Lines        2391     2626     +235     
==========================================
+ Hits         2115     2306     +191     
- Misses        276      320      +44     
Flag Coverage Δ
unittests 87.81% <86.38%> (-0.65%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@coveralls
Copy link

coveralls commented Nov 21, 2024

Coverage Status

coverage: 88.193% (+0.3%) from 87.904%
when pulling 054f4ee on pnuu:refactor-sgdp4
into 9700076 on pytroll:main.

@pnuu
Copy link
Member Author

pnuu commented Nov 22, 2024

The refactoring of the propagate() method is ugly. But given the original implementation in C, I don't think there's no way of making the code absolutely beautiful if the refavtorer has no deep understanding of orbital mechanics. Maybe not even with the in-depth knowledge, but I want to hope someone has the brilliance to simplify this stuff.

I will go through the code once or twice early next week, but feel free to give suggestions.

Copy link
Member

@djhoese djhoese left a comment

Choose a reason for hiding this comment

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

Are you able to remove the noqa comment on _SGDP4.__init__ and have it pass pre-commit?

@pnuu
Copy link
Member Author

pnuu commented Nov 28, 2024

Are you able to remove the noqa comment on _SGDP4.__init__ and have it pass pre-commit?

Oh yeah, well spotted. Removed and pre-commit checks pass.

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

Thanks a lot for tackling this! a couple of comments inline...

Comment on lines 813 to 814
params = {"utc_time": utc_time}
params["ts"] = self._get_timedelta_in_minutes(params)
Copy link
Member

Choose a reason for hiding this comment

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

why the switch to dict? for the rest we’re using objects, right? So how about a class for keplerian computations?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to put all the shared intermediate variables to attributes, which are already pretty numerous. There are also so many interconnections that I thought this was at least the easiest way to sort them out somehow.

I'll have another look tomorrow from the "add a new class" perspective.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, after "a bit" of shuffling, I did 6fb6efd

Comment on lines 603 to 612
def _calculate_mean_motion_and_semi_major_axis(self):
a_1 = (XKE / self.mean_motion) ** (2.0 / 3)
delta_1 = ((3 / 2.0) * (CK2 / a_1**2) * ((3 * np.cos(self.inclination)**2 - 1) /
(1 - self.excentricity**2)**(2.0 / 3)))
a_0 = a_1 * (1 - delta_1 / 3 - delta_1**2 - (134.0 / 81) * delta_1**3)
delta_0 = ((3 / 2.0) * (CK2 / a_0**2) * ((3 * np.cos(self.inclination)**2 - 1) /
(1 - self.excentricity**2)**(2.0 / 3)))

self.original_mean_motion = self.mean_motion / (1 + delta_0)
self.semi_major_axis = a_0 / (1 - delta_0)
Copy link
Member

Choose a reason for hiding this comment

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

this method has minimal side effects, could we remove them and just return the mean motion and semi major axis?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean that instead of calculating them together we'd have the same intermediate computations done twice and then have two methods? I think I considered that and opted for the merged one for less computations. I don't mind changing this to two methods though.

Copy link
Member

Choose a reason for hiding this comment

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

no calculating them together is fine, just that I thought it would be nicer to have eg self.original_mean_motion, self.semi_major_axis = self._calculate_mean_motion_and_semi_major_axis()

Copy link
Member Author

Choose a reason for hiding this comment

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

Adapted in c3023d5

Copy link
Member

Choose a reason for hiding this comment

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

IMO it looks better, thanks a lot!

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

LGTM!

@mraspaud mraspaud merged commit 92ec3a3 into pytroll:main Nov 29, 2024
16 of 18 checks passed
@pnuu pnuu deleted the refactor-sgdp4 branch November 29, 2024 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants