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

feat: add generation of random points in grid_plan #132

Closed fdrgsp closed 10 months ago

fdrgsp commented 10 months ago

This PR adds the RandomPoints plan, a type of grid_plan with the ability to generate a specified number of random points within a specified area.

The random generation is using numpy and if a random_seed attribute is specified, the generation of points is reproducible.

By setting allow_overlap=True together with fov_width and fov_height, the generated point will be at least fov_width and fov_height away from each other (Manhattan distance).


For quick test to see how it works:

from useq import RandomPoints
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse, Rectangle
fig, ax = plt.subplots()
w, h = (10, 10)
fw, fh = (1, 1)
shape = "ellipse"
rn = RandomPoints(
    num_points=10,
    max_width=w,
    max_height=h,
    shape=shape,
    random_seed=0,
    allow_overlap=False,
    fov_width=fw,
    fov_height=fh,
)
if shape == "ellipse":
    ax.add_patch(Ellipse((0, 0), w, h, fill=False, color="m"))
else:
    ax.add_patch(Rectangle((-w / 2, -h / 2), w, h, fill=False, color="m"))
for p in list(rn):
    x, y, _, _, _ = p
    plt.plot(x, y, "go")
    ax.add_patch(Rectangle((x - (fw/2), y - (fh/2)), fw, fh, fill=False,
 color="g"))
plt.axis("equal")
fig.show()
codecov[bot] commented 10 months ago

Codecov Report

Patch coverage: 98.21% and project coverage change: -0.02% :warning:

Comparison is base (56f3394) 98.19% compared to head (c16da53) 98.18%.

:exclamation: Current head c16da53 differs from pull request most recent head abf5919. Consider uploading reports for the commit abf5919 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #132 +/- ## ========================================== - Coverage 98.19% 98.18% -0.02% ========================================== Files 14 14 Lines 833 880 +47 ========================================== + Hits 818 864 +46 - Misses 15 16 +1 ``` | [Files Changed](https://app.codecov.io/gh/pymmcore-plus/useq-schema/pull/132?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pymmcore-plus) | Coverage Δ | | |---|---|---| | [src/useq/\_grid.py](https://app.codecov.io/gh/pymmcore-plus/useq-schema/pull/132?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pymmcore-plus#diff-c3JjL3VzZXEvX2dyaWQucHk=) | `99.46% <98.18%> (-0.54%)` | :arrow_down: | | [src/useq/\_\_init\_\_.py](https://app.codecov.io/gh/pymmcore-plus/useq-schema/pull/132?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pymmcore-plus#diff-c3JjL3VzZXEvX19pbml0X18ucHk=) | `100.00% <100.00%> (ø)` | |

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

fdrgsp commented 10 months ago

looks good! All set for merge?

yes! Thanks for the help!