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

Implement cartesian_to_origin #28

Merged
merged 5 commits into from
Aug 9, 2023
Merged

Implement cartesian_to_origin #28

merged 5 commits into from
Aug 9, 2023

Conversation

moeyensj
Copy link
Member

Also adds barycentric elements to the test data.

@moeyensj
Copy link
Member Author

@akoumjian @spenczar No rush on this one considering our current higher-priority work.

adam_core/coordinates/tests/test_transforms_translation.py Outdated Show resolved Hide resolved

# Calculate offset in position in mm
r_diff = np.linalg.norm(diff[:, :3], axis=1) * u.au.to(u.mm)
# Calculate offset in velocity in nm/s
Copy link
Contributor

Choose a reason for hiding this comment

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

nm/s! What a showoff

Comment on lines 62 to 78
diff = (
cartesian_coordinates_barycentric_actual.values
- cartesian_coordinates_barycentric.values
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels a bit like we could use a distance (or diff? or offset? or difference?) method on the coordinates table class

Copy link
Member Author

Choose a reason for hiding this comment

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

Great idea! Would it be confusing if it returned a residual? (https://github.com/B612-Asteroid-Institute/adam_core/blob/main/adam_core/coordinates/residuals.py#L41)

Maybe we could also define __add__ and such and then check internally if the origins and frames match. If the operators return CartesianCoordinates then properties like .r_mag and .v_mag would give us the position and velocity differences.

Copy link
Contributor

Choose a reason for hiding this comment

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

Residuals makes sense to me as a return value.

__add__ kinda makes sense as a sort of "translate" operator, yeah. It's a little trippy to think about that way, but I can see why that's a natural phrasing.

frame="ecliptic",
origin=Origin.from_kwargs(
code=[
"SOLAR_SYSTEM_BARYCENTER"
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
"SOLAR_SYSTEM_BARYCENTER"
OriginCodes.SOLAR_SYSTEM_BARYCENTER

Does this work? I'd like if it did. Maybe str(OriginCodes.SOLAR_SYSTEM_BARYCENTER) though?

Copy link
Member Author

Choose a reason for hiding this comment

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

OriginCodes.SOLAR_SYSTEM_BARYCENTER has integer values corresponding to NAIF IDs. str(OriginCodes.SOLAR_SYSTEM_BARYCENTER) returns "OriginCodes.SOLAR_SYSTEM_BARYCENTER" (which is weird). I think broadly it would be nice if we could drop the strings in favor of storing integers but I'm worried we will lose readability. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I'm not sure. You could add a __str__ method to OriginCodes that does what you want - returns self.name.

or you could do OriginCodes.SOLAR_SYSTEM_BARYCENTER.name as the literal?

I'm not really convinced these are better in any way. They might be merely different without any actual effect. I think what you have is fine, unless you feel inspired to really dig in.

Comment on lines 1225 to 1226
origins = coords.origin.code.to_numpy(zero_copy_only=False)
unique_origins = np.unique(origins)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since zero_copy_only=False, it's a good idea to do as much computation as possible in arrow-space:

Suggested change
origins = coords.origin.code.to_numpy(zero_copy_only=False)
unique_origins = np.unique(origins)
unique_origins = coords.origin.code.unique().to_numpy(zero_copy_only=False)

Copy link
Member Author

Choose a reason for hiding this comment

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

The rewrite is a little more complicated since we use the original non-deduped origin array to create a mask: mask = np.where(origins == origin_in)[0], but I'm inspired. Let me try this fully with pyarrow.

Copy link
Member Author

@moeyensj moeyensj Aug 9, 2023

Choose a reason for hiding this comment

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

This e9c6109 implementation still is not zero copy but its copying an array of booleans and not strings so hopefully that is better.

@moeyensj moeyensj mentioned this pull request Aug 9, 2023
@moeyensj moeyensj force-pushed the jm/cartesian-to-origin branch 2 times, most recently from 781a8e9 to 33b886d Compare August 9, 2023 02:59
@moeyensj moeyensj merged commit 6947443 into main Aug 9, 2023
1 check passed
@moeyensj moeyensj deleted the jm/cartesian-to-origin branch August 9, 2023 03:27
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.

2 participants