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

Use generic named variables in coordinates module #656

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

TONYOG12
Copy link

This commit addresses the first point on issue #650 by replacing named variables for each coordinate type with generic variable names

Addresses #650

@JeS24

This commit addresses the first point on issue einsteinpy#650 by replacing named variables for each coordinate type with generic variable names
@auto-assign auto-assign bot requested a review from JeS24 January 30, 2024 02:26
@TONYOG12 TONYOG12 changed the title addresses point 1 of #650 Use generic named variables in coordinates module Jan 30, 2024
@TONYOG12 TONYOG12 marked this pull request as draft January 30, 2024 02:41
@pep8speaks
Copy link

pep8speaks commented Jan 30, 2024

Hello @TONYOG12! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 84:13: W503 line break before binary operator
Line 127:9: W503 line break before binary operator
Line 128:9: W503 line break before binary operator
Line 132:9: W503 line break before binary operator
Line 133:9: W503 line break before binary operator
Line 174:9: W503 line break before binary operator
Line 175:9: W503 line break before binary operator
Line 179:9: W503 line break before binary operator
Line 180:9: W503 line break before binary operator

Line 218:72: W504 line break after binary operator

Comment last updated at 2024-06-18 12:27:02 UTC

Copy link

codecov bot commented Jan 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.13%. Comparing base (cffc0ca) to head (abfd6f6).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #656       /-   ##
==========================================
- Coverage   97.33%   97.13%   -0.21%     
==========================================
  Files          68       68              
  Lines        2515     2336     -179     
==========================================
- Hits         2448     2269     -179     
  Misses         67       67              

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

@TONYOG12 TONYOG12 marked this pull request as ready for review January 30, 2024 20:04
Copy link
Member

Choose a reason for hiding this comment

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

This file is not tested. Is mypy giving issues?

src/einsteinpy/coordinates/conversion.py Show resolved Hide resolved
src/einsteinpy/coordinates/core.py Show resolved Hide resolved
src/einsteinpy/coordinates/core.py Outdated Show resolved Hide resolved
src/einsteinpy/coordinates/core.py Show resolved Hide resolved
src/einsteinpy/coordinates/differential.py Show resolved Hide resolved
src/einsteinpy/coordinates/differential.py Show resolved Hide resolved
return cartesian_to_spherical(t, x, y, z, v_x, v_y, v_z)
return cartesian_to_spherical_novel(t, x, y, z)
@jit
def calculate_coordinates(r, th, p, alpha):
Copy link
Member

@JeS24 JeS24 Feb 2, 2024

Choose a reason for hiding this comment

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

Is the refactoring approach in #644 (comment) causing any issues ? (Apart from not any) ? That way should lead to clearer and more compact code. The idea is that the position and velocity conversions are jit-compiled, and these function names (cartesian_to_spherical vs cartesian_to_spherical_novel) are changed to something more comprehensible.

Copy link
Author

Choose a reason for hiding this comment

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

Alright thanks for the pointers, will refactor based on that approach

@JeS24
Copy link
Member

JeS24 commented Feb 2, 2024

Notes for posterity:

added the base classes to eliminate code repetition
Copy link
Member

@JeS24 JeS24 left a comment

Choose a reason for hiding this comment

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

@TONYOG12 Thank you for the updated commit. I have reviewed the changes again. Besides these, the utils changes are left (function names change, see #656 (comment) & #644 (comment)).

"system": self.system,
}
self._dimension_order = ("t", "x", "y", "z")
self._dimension_order = ("e0", "e1", "e2", "e3")

def __str__(self):
Copy link
Member

Choose a reason for hiding this comment

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

You can add the __str__ and __repr__ methods in the Base class itself. Instead of child-class name, like "Cartesian Coordinates", you can use f"{self.__class__.__name__} Coordinates \n ...".

Copy link
Member

Choose a reason for hiding this comment

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

Similarly, __getitem__ and position can also be part of the Base class.

Copy link
Member

Choose a reason for hiding this comment

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

As for member variables, self._dimension and self._dimension_order are the same across the 3 classes and can kept in the Base class.

Copy link
Author

Choose a reason for hiding this comment

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

Resolved

z-Component of 3-Position
v_x : float, optional
u0 : float, optional
Copy link
Member

Choose a reason for hiding this comment

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

u0 should correspond to the temporal component of velocity, like how e0 is the temporal component for (4-)position. So, here, you can start at u1, u2, u3 and rename v_t to u0 elsewhere (e.g., in differential.py)

Copy link
Author

Choose a reason for hiding this comment

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

Resolved

e0=u.s, e1=u.m, e2=u.m, e3=u.m, u0=u.m / u.s, u1=u.m / u.s, u2=u.m / u.s
)
def __init__(self, e0, e1, e2, e3, u0, u1, u2):
super().__init__(e0, e1, e2, e3, u0, u1, u2)
self.system = "Cartesian"

def __str__(self):
Copy link
Member

Choose a reason for hiding this comment

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

As with BaseCoordinate in core.py, the __str__ and __repr__ methods can be moved to the BaseDifferential class using the {self.__class__.__name__} trick.

Copy link
Member

Choose a reason for hiding this comment

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

Similarly, position and velocity methods can be in the Base class, as they do not change for the child-classes. The same also applies to the v_t (rename to u0) property and its setter. Both can be moved to the Base class.

Copy link
Author

Choose a reason for hiding this comment

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

Done

def cartesian_to_bl_fast(e0, e1, e2, e3, e4, u0=None, u1=None, u2=None):
vel = [u0, u1, u2]
if all(u is not None for u in vel) and any(u != 0 for u in vel):
return cartesian_to_bl(e0, e1, e2, e3, e4, u0, u1, u2)
Copy link
Member

Choose a reason for hiding this comment

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

e4 is actually u0 (v_t). Refer to the comment in src/einsteinpy/coordinates/conversion.py.

@TONYOG12 TONYOG12 marked this pull request as draft May 20, 2024 15:57
@TONYOG12 TONYOG12 requested a review from JeS24 June 17, 2024 15:42
@TONYOG12 TONYOG12 marked this pull request as ready for review June 17, 2024 15:43
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.

3 participants