Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
("py:class", "scanspec.core.C"),
("py:class", "scanspec.core.T"),
("py:class", "pydantic.config.ConfigDict"),
("py:class", "numpy.float64"),
]

# Both the class’ and the __init__ method’s docstring are concatenated and
Expand Down
2 changes: 1 addition & 1 deletion docs/explanations/technical-terms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ documentation. Consider a 1D line scan:
Axis
----

A fixed reference that can be scanned, i.e. a motor or the `frame_` `DURATION`.
A fixed reference that can be scanned, i.e. a motor.
In the diagram above, the Axis is ``x``. `Spec.axes` will return the Axes that
should be scanned for a given Spec.

Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/iterate-a-spec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ If you need to do a fly scan

If you are conducting a fly scan then you need the frames that the motor moves
through. You can get that from the lower and upper bounds of each point. If the
scan is small enough to fit in memory on the machine you can use the `Fly(spec).frames()`
scan is small enough to fit in memory on the machine you can use the `Spec.frames`
method to produce a single `Dimension` object containing the entire scan:

>>> from scanspec.specs import Fly
Expand Down
6 changes: 3 additions & 3 deletions docs/how-to/serialize-a-spec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Lets start with an example `Spec`.
This Spec has a `repr` that shows its parameters it was instantiated with:

>>> spec
Product(outer=Line(axis='y', start=4.0, stop=5.0, num=6), inner=Line(axis='x', start=1.0, stop=2.0, num=3))
Product(outer=Line(axis='y', start=4.0, stop=5.0, num=6), inner=Line(axis='x', start=1.0, stop=2.0, num=3), gap=True)


How to Serialize
Expand All @@ -20,12 +20,12 @@ How to Serialize
We can recursively serialize it to a dictionary:

>>> spec.serialize()
{'outer': {'axis': 'y', 'start': 4.0, 'stop': 5.0, 'num': 6, 'type': 'Line'}, 'inner': {'axis': 'x', 'start': 1.0, 'stop': 2.0, 'num': 3, 'type': 'Line'}, 'type': 'Product'}
{'outer': {'axis': 'y', 'start': 4.0, 'stop': 5.0, 'num': 6, 'type': 'Line'}, 'inner': {'axis': 'x', 'start': 1.0, 'stop': 2.0, 'num': 3, 'type': 'Line'}, 'gap': True, 'type': 'Product'}

How to Deserialize
------------------

We can turn this back into a spec using `Spec.deserialize`:

>>> Spec.deserialize({'outer': {'axis': 'y', 'start': 4.0, 'stop': 5.0, 'num': 6, 'type': 'Line'}, 'inner': {'axis': 'x', 'start': 1.0, 'stop': 2.0, 'num': 3, 'type': 'Line'}, 'type': 'Product'})
Product(outer=Line(axis='y', start=4.0, stop=5.0, num=6), inner=Line(axis='x', start=1.0, stop=2.0, num=3))
Product(outer=Line(axis='y', start=4.0, stop=5.0, num=6), inner=Line(axis='x', start=1.0, stop=2.0, num=3), gap=True)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ commands =
pre-commit: pre-commit run --all-files --show-diff-on-failure {posargs}
type-checking: pyright src tests {posargs}
tests: pytest --cov=scanspec --cov-report term --cov-report xml:cov.xml {posargs}
docs: sphinx-{posargs:build -E --keep-going} -T docs build/html
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
"""

[tool.ruff]
Expand Down
132 changes: 72 additions & 60 deletions schema.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/scanspec/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ def _make_schema(
return {member.__name__: handler(member) for member in members}


def if_instance_do(x: C, cls: type[C], func: Callable[[C], T]) -> T:
def if_instance_do(
x: C, cls: type[C] | tuple[type[C], Any], func: Callable[[C], T]
) -> T:
"""If x is of type cls then return func(x), otherwise return NotImplemented.

Used as a helper when implementing operator overloading.
Expand Down Expand Up @@ -311,7 +313,7 @@ def __len__(self) -> int:
def axes(self) -> list[Axis]:
"""The axes which will move during the scan.

These will be present in `midpoints`, `lower` and `upper`.
These will be present in ``midpoints``, ``lower`` and ``upper``.
"""
return list(self.midpoints.keys())

Expand Down
3 changes: 2 additions & 1 deletion src/scanspec/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,6 @@ def scanspec_schema_text() -> str:
openapi_version=app.openapi_version,
description=app.description,
routes=app.routes,
)
),
indent=4,
)
Loading
Loading