pymmcore-plus / useq-schema

An implementation agnostic schema for describing a sequence of events during a multi-dimensional imaging acquisition.
https://pymmcore-plus.github.io/useq-schema/
BSD 3-Clause "New" or "Revised" License
14 stars 5 forks source link

fix: use cartesian coordinate system in WellPlatePlan (-x left, +x right, -y down and +y up) #175

Closed fdrgsp closed 2 weeks ago

fdrgsp commented 2 weeks ago

linked to #173

I removed all the change of sign we had in the WellPlatePlan code and only invert the y axis when we apply the transformation so that the y axis is -y down and +y up. This way we use the same cartesian coordinate system that we are already using in the _PointsPlans.

Screenshot 2024-07-05 at 4 15 45 PM
codecov[bot] commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 95.65%. Comparing base (c8996b7) to head (a5fc170).

Files Patch % Lines
src/useq/_plate.py 84.61% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #175 +/- ## ========================================== + Coverage 95.54% 95.65% +0.10% ========================================== Files 15 15 Lines 1056 1058 +2 ========================================== + Hits 1009 1012 +3 + Misses 47 46 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

tlambert03 commented 2 weeks ago

please also fix a new scaling issue that we now have in random points:

                if value.max_width == np.inf:
                    kwargs["max_width"] = plate.well_size[0] - (value.fov_width or 0.1)
                if value.max_height == np.inf:
                    kwargs["max_height"] = plate.well_size[1] - (
                        value.fov_height or 0.1
                    )

the plate.well_sizes need to be scaled by 1000

fdrgsp commented 2 weeks ago

@tlambert03 out of curiosity, if you run the test for the plate locally, does test_plate_plan_serialization fail for you?

tlambert03 commented 2 weeks ago

nope, and not on CI either obviously... whats your traceback

fdrgsp commented 2 weeks ago

nope, and not on CI either obviously... whats your traceback

the well_points_plan is always defaulting to Position()...

    def test_plate_plan_serialization() -> None:
        pp = useq.WellPlatePlan(
            plate=96,
            a1_center_xy=(500, 200),
            rotation=5,
            selected_wells=np.s_[1:5:2, :6:3],
            well_points_plan=useq.RandomPoints(num_points=10),
        )
        js = pp.model_dump_json()
        pp2 = useq.WellPlatePlan.model_validate_json(js)
>       assert pp2 == pp
E       AssertionError: assert WellPlatePlan(plate=WellPlate(rows=8, columns=12, well_spacing=(9.0, 9.0), well_size=(6.4, 6.4)), a1_center_xy=(500.0, 200.0), rotation=5.0, selected_wells=(slice(1, 5, 2), slice(None, 6, 3)), well_points_plan=Position()) == WellPlatePlan(plate=WellPlate(rows=8, columns=12, well_spacing=(9.0, 9.0), well_size=(6.4, 6.4)), a1_center_xy=(500.0, 200.0), rotation=5.0, selected_wells=(slice(1, 5, 2), slice(None, 6, 3)), well_points_plan=RandomPoints(num_points=10, max_width=6399.9, max_height=6399.9))
E
E         At index 0 diff: Position(name='B1') != Position(x=2010.7489791050302, y=-10177.428033516471, name='B1_0000')
E         Right contains 36 more items, first extra item: Position(x=1776.901041996079, y=-9937.020701044301, name='B1_0004')
E
E         Full diff:
E         - WellPlatePlan(plate=WellPlate(rows=8, columns=12, well_spacing=(9.0, 9.0), well_size=(6.4, 6.4)), a1_center_xy=(500.0, 200.0), rotation=5.0, selected_wells=(slice(1, 5, 2), slice(None, 6, 3)), well_points_plan=RandomPoints(num_points=10, max_width=6399.9, max_height=6399.9))
E         ?                                                                                                                                                                                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E         + WellPlatePlan(plate=WellPlate(rows=8, columns=12, well_spacing=(9.0, 9.0), well_size=(6.4, 6.4)), a1_center_xy=(500.0, 200.0), rotation=5.0, selected_wells=(slice(1, 5, 2), slice(None, 6, 3)), well_points_plan=Position())
E         ?                                                                                                                                                                                                                   ^^^^^^^^^^^
tlambert03 commented 2 weeks ago

the well_points_plan is always defaulting to Position()...

strange... not sure. what's in your env? it must be environment, since it's working on CI, but I wonder what it could be.

fdrgsp commented 2 weeks ago

the well_points_plan is always defaulting to Position()...

strange... not sure. what's in your env? it must be environment, since it's working on CI, but I wonder what it could be.

ok fixed it, not sure what was the conflict...