Skip to content

Commit 159f25f

Browse files
authored
Add science-friendly Specs II (#192)
* add `scanspec.specs.Ellipse` * add `scanspec.specs.Polygon` * add CR suggestions, fix CI * test: add test_ellipse and test_polygon * remove regions * update plot_spec: fix docstring, add "region" outlines * doc: update README.md * fix docstring * fix docstring * chore: stricter typing in _get_boundaries * fix README example
1 parent 4ce5022 commit 159f25f

File tree

13 files changed

+722
-1529
lines changed

13 files changed

+722
-1529
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ Specify step and flyscan paths in a serializable, efficient and Pythonic way usi
1212
- Specs like Line or Spiral
1313
- Optionally Snaking
1414
- Zip, Product and Concat to compose
15-
- Masks with multiple Regions to restrict
1615

1716
Serialize the Spec rather than the expanded Path and reconstruct it on the
18-
server. It can them be iterated over like a [cycler][], or a stack of scan Frames
17+
server. It can then be iterated over like a [cycler][], or a stack of scan Frames
1918
can be produced and expanded Paths created to consume chunk by chunk.
2019

2120
[cycler]: https://matplotlib.org/cycler/
@@ -31,11 +30,9 @@ An example ScanSpec of a 2D snaked grid flyscan inside a circle spending 0.4s at
3130
each point:
3231

3332
```python
34-
from scanspec.specs import Line, Fly
35-
from scanspec.regions import Circle
33+
from scanspec.specs import Ellipse, Fly
3634

37-
grid = Line(y, 2.1, 3.8, 12) * ~Line(x, 0.5, 1.5, 10)
38-
spec = Fly(0.4 @ grid) & Circle(x, y, 1.0, 2.8, radius=0.5)
35+
spec = Fly(0.4 @ Ellipse(x, 1, 1, 1/9, y, 2.8, y_step=1.7/11, snake=True))
3936
```
4037

4138
Which when plotted looks like:

docs/explanations/why-stack-frames.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ Frames object it would take 100 * 2000 * 2000 float64 = 3.2GB of RAM. The scan
4141
itself is likely to be executed over a long period of time, so it makes sense to
4242
save on the memory and calculate the squashed points as they are needed.
4343

44-
What about Regions?
45-
-------------------
46-
47-
Regions will stop the regularity of the nested Frames objects, so will cause
48-
them to be squashed into a single Frames object. Taking our example above, if we
49-
`Mask` the grid with a `Circle`, then the `Linspace` in ``x`` won't have 3 points in
50-
each iteration, the number of points is dependent on ``y``. This means that a
51-
`Mask` will squash any Specs together referred to by its Regions.
5244

5345
How does this stack relate to HDF5 Dimensions?
5446
----------------------------------------------

docs/tutorials/creating-a-spec.rst

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,38 +76,20 @@ Spec of our grid we get:
7676
spec = Linspace("y", 3, 4, 3) * ~Linspace("x", 1, 2, 5)
7777

7878

79-
Masking with Regions
80-
--------------------
81-
82-
We can apply a `Mask` to only include frames where the midpoints are within a
83-
given `Region` using the ``&`` operator:
84-
85-
.. example_spec::
86-
87-
from scanspec.specs import Linspace
88-
from scanspec.regions import Circle
89-
90-
spec = Linspace("y", 3, 4, 3) * ~Linspace("x", 1, 2, 5) & Circle("x", "y", 1.5, 3.5, 0.6)
79+
Snaked Regions
80+
--------------
9181

92-
93-
Masking with Multiple Regions
94-
-----------------------------
95-
96-
We can apply set-like operators to Masked Specs:
97-
98-
- ``|``: `UnionOf` two Regions
99-
- ``&``: `IntersectionOf` two Regions
100-
- ``-``: `DifferenceOf` two Regions
101-
- ``^``: `SymmetricDifferenceOf` two Regions
82+
We can construct an `Ellipse` or a `Polygon` with a grid or a snaked grid
83+
by passing the optional parameter ``snake``.
10284

10385
For example:
10486

10587
.. example_spec::
10688

107-
from scanspec.specs import Linspace
108-
from scanspec.regions import Circle
89+
from scanspec.specs import Ellipse
90+
91+
spec = Ellipse("x", 0, 1, 0.1, "y", 5, 10, 0.5, snake=True)
10992

110-
spec = Linspace("y", 3, 4, 3) * ~Linspace("x", 1, 2, 5) & Circle("x", "y", 1.5, 3.5, 0.6) - Circle("x", "y", 1.4, 3.5, 0.2)
11193

11294

11395
Conclusion

0 commit comments

Comments
 (0)