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 classes for coordinate spaces and transforms #218

Merged
merged 25 commits into from
Sep 18, 2024
Merged

Conversation

jp-dark
Copy link
Collaborator

@jp-dark jp-dark commented Sep 12, 2024

New classes:

  • Axis: simple data class storing a name, optional units, and optional scale
  • CoordinateSpace: used to define coordinate spaces for spatial data
  • CoordinateTransform: abstract base class for coordinate transforms
  • AffineTransform: implementation for a generic affine coordinate transform
  • ScaleTransform: implementation for a coordinate transform that scales axes (may be isotropic/uniform)
  • IdentityTransform: implementation for an identity transform that only applies a name change to axes

@jp-dark jp-dark marked this pull request as ready for review September 13, 2024 14:51
Copy link
Member

@johnkerl johnkerl left a comment

Choose a reason for hiding this comment

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

LGTM with minor suggestions

python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
Copy link

@ivirshup ivirshup left a comment

Choose a reason for hiding this comment

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

Looks mostly good, but I left some comments.

One important thing: "dunder methods" tend not to show up in rendered docs so I think the class docs need to explicitly say that these things are composable and @ is the operator for doing that. Alternatively I would add a compose method so that it's more discoverable (via tab completion or doc method table).

python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/__init__.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
Copy link
Member

@bkmartinjr bkmartinjr left a comment

Choose a reason for hiding this comment

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

LGTM

python-spec/src/somacore/coordinates.py Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
- Drop scale from units
- Use `attrs` instead of `dataclass`
- Remove ABC meta class (bug)
- Add docstrings to Axis
- Use `attrs` for CoordinateSpace
- Add helper function for validation
python-spec/src/somacore/coordinates.py Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/types.py Outdated Show resolved Hide resolved
jp-dark and others added 3 commits September 17, 2024 10:24
Make CoordinateSpace classes call the super.__init__ from the level
above.
Co-authored-by: paul fisher <paul.fisher@tiledb.com>
Add new methods that throw value errors for mismatched axes with a
more meaningful error message.
Copy link
Contributor

@thetorpedodog thetorpedodog left a comment

Choose a reason for hiding this comment

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

The solution to the class hierarchy situation here is good; I just have a few more suggestions (sorry) mostly about the operator implementation.

python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
python-spec/src/somacore/coordinates.py Outdated Show resolved Hide resolved
Copy link
Member

@johnkerl johnkerl left a comment

Choose a reason for hiding this comment

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

🚢

@jp-dark jp-dark merged commit 9cb6f80 into main Sep 18, 2024
7 checks passed
@jp-dark jp-dark deleted the dark/coordinate-space branch September 18, 2024 20:50
@jp-dark
Copy link
Collaborator Author

jp-dark commented Sep 20, 2024

[sc-50289]



@attrs.define(frozen=True)
class CoordinateSpace(
Copy link
Member

Choose a reason for hiding this comment

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

Can we also implement __eq__ for CoordinateSpace in here?

Copy link
Contributor

Choose a reason for hiding this comment

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

coming back from the dead to say that attrs gives you __eq__ for free

@ryan-williams ryan-williams mentioned this pull request Sep 23, 2024
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.

7 participants