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 to create a AfidSet class #14

Merged
merged 18 commits into from
Aug 24, 2023
Merged

Conversation

kaitj
Copy link
Contributor

@kaitj kaitj commented Aug 23, 2023

Proposed changes
First pass refactor to include an AfidSet class in-time for the mini sprint. There are still a few things to iron out, but I think this should provide the basic model and some examples of needed methods (for json handling). The test cases at the moment are very basic (e.g. loading the existing valid fcsv file), but would like to include a mock AfidSet to use in tests in the future.

Types of changes
What types of changes does your code introduce? Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other (if none of the other choices apply)

Checklist
Put an x in the boxes that apply. You can also fill these out after creating the PR. If you are unsure about any of the choices, don't hesitate to ask!

  • Changes have been tested to ensure that fix is effective or that a feature works.
  • Changes pass the unit tests
  • Code has been run through the poe quality task
  • I have included necessary documentation or comments (as necessary)
  • Any dependent changes have been merged and published

Notes
All PRs will undergo the unit testing before being reviewed. You may be requested to explain or make additional changes before the PR is accepted.

An `afids.py` file has been added in order to create an AFIDSet dict
class, enabling the storing of both metadata information, well as
loading fiducials from files directly into a dataframe. The choice of
using a dataframe here is for easier downstream manipulation.

  - `get_afid` has been moved into here as a method of the AfidSet class

Moved extension specific file handling into its own `.py` files (e.g.
`extensions/fcsv.py`). This choice was made to simplify the maintenance of handling
different file extensions.

  - Separate semi-private methods are used for grabbing the metadata, as
well as loading the fiducials into a polars dataframe.

Additionally `io.py` has been refactored to
generalize the handling of different file types (calling the methods
within the different `extensions`).

Updates poetry.lock and pyproject.toml to include the `attrs` library
@kaitj kaitj added the maintenance Updates or improvements that do not change functionality of the code label Aug 23, 2023
@github-actions github-actions bot requested a review from tkkuehn August 23, 2023 13:57
@codecov
Copy link

codecov bot commented Aug 23, 2023

Codecov Report

Merging #14 (e13eebd) into main (c809d22) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##              main       #14    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files            6         8     +2     
  Lines          150       348   +198     
==========================================
+ Hits           150       348   +198     
Components Coverage Δ
afids_utils/afids.py ∅ <ø> (∅)
afids_utils/ext 100.00% <100.00%> (∅)
afids_utils/transforms.py 100.00% <ø> (ø)

Copy link
Contributor

@tkkuehn tkkuehn left a comment

Choose a reason for hiding this comment

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

This is looking good, just a few requests/questions

afids_utils/afids.py Outdated Show resolved Hide resolved
afids_utils/io.py Outdated Show resolved Hide resolved
afids_utils/afids.py Outdated Show resolved Hide resolved
afids_utils/tests/test_io.py Outdated Show resolved Hide resolved

slicer_version: str = attr.field()
coord_system: str = attr.field()
afids_df: pl.DataFrame = attr.field()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think my preferred approach would be to define an Afid class with a label and x, y, z coords, then make this a list[Afid], and add a validator that it contains 32 Afids with labels in order.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can certainly do that - it'd be similar to how we had it implemented in the validator. The validation logic is implemented, just not as a separate method (under load) currently. If we do switch to doing it that way, than I would say lets just get rid of the use of dataframes all together - I don't see foresee any use case for them and would save us an additional dependency.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good on all counts, with the note that I think it makes sense to implement the validation logic as an attrs validator to check the validation regardless of where the AFIDs are coming from

Copy link
Contributor Author

@kaitj kaitj Aug 23, 2023

Choose a reason for hiding this comment

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

That works for me, with the validation logic currently in place, lets move the attrs validator as a thing to do during the sprint. Should be easy enough to take what is currently there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, this has been done now with the latest commit sans attrs validator.

- Remove `io.py`, moving methods to the AfidSet class. `load` is now a ClassMethod while `save` is a method of the instance.
- Added an `AfidPosition` class, which is now used to store AFIDs
- Drops polars from use, favouring `List[AfidPosition]` instead
- Update mismatched desc in template.fcsv
- Update strategies.py to generate coords using `AfidPosition`
- Update all tests to correspond with changes made
@kaitj kaitj requested a review from tkkuehn August 23, 2023 21:31
@kaitj
Copy link
Contributor Author

kaitj commented Aug 23, 2023

I think at this point, minus some of the additional stuff we talked about and barring any major changes - we should try to get this pushed in as the base code to build off of for the sprint.

@kaitj kaitj linked an issue Aug 24, 2023 that may be closed by this pull request
@kaitj kaitj mentioned this pull request Aug 24, 2023
9 tasks
@kaitj kaitj merged commit fa3e85f into afids:main Aug 24, 2023
7 checks passed
@kaitj kaitj deleted the maint/afids_class branch August 24, 2023 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Updates or improvements that do not change functionality of the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate automatic typehinting
2 participants