scanspec.regions#

Region and its subclasses.

Inheritance diagram of scanspec.regions

Members

Region

Abstract baseclass for a Region that can Mask a Spec.

get_mask

Return a mask of the points inside the region.

find_regions

Recursively yield Regions from obj and its children.

class scanspec.regions.Region[source]#

Abstract baseclass for a Region that can Mask a Spec.

Supports operators:

axis_sets() list[set[Axis]][source]#

Produce the non-overlapping sets of axes this region spans.

mask(points: dict[Axis, ndarray[Any, dtype[floating[Any]]]]) ndarray[Any, dtype[bool]][source]#

Produce a mask of which points are in the region.

serialize() Mapping[str, Any][source]#

Serialize the Region to a dictionary.

static deserialize(obj: Any) Region[Any][source]#

Deserialize a Region from a dictionary.

scanspec.regions.get_mask(region: Region[Axis], points: dict[Axis, ndarray[Any, dtype[floating[Any]]]]) ndarray[Any, dtype[bool]][source]#

Return a mask of the points inside the region.

If there is an overlap of axes of region and points return a mask of the points in the region, otherwise return all ones

pydantic model scanspec.regions.CombinationOf[source]#

Abstract baseclass for a combination of two regions, left and right.

Show JSON schema
{
   "$defs": {
      "Circle": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within an xy circle of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Circle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Circle(\"x\", \"y\", 1, 2, 0.9)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_middle": {
               "description": "The central x point of the circle",
               "title": "X Middle",
               "type": "number"
            },
            "y_middle": {
               "description": "The central y point of the circle",
               "title": "Y Middle",
               "type": "number"
            },
            "radius": {
               "description": "Radius of the circle",
               "exclusiveMinimum": 0.0,
               "title": "Radius",
               "type": "number"
            },
            "type": {
               "const": "Circle",
               "default": "Circle",
               "enum": [
                  "Circle"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_middle",
            "y_middle",
            "radius"
         ],
         "title": "Circle",
         "type": "object"
      },
      "CombinationOf": {
         "additionalProperties": false,
         "description": "Abstract baseclass for a combination of two regions, left and right.",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "CombinationOf",
               "default": "CombinationOf",
               "enum": [
                  "CombinationOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "CombinationOf",
         "type": "object"
      },
      "DifferenceOf": {
         "additionalProperties": false,
         "description": "A point is in DifferenceOf(a, b) if in a and not in b.\n\nTypically created with the ``-`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) - Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True, False, False, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "DifferenceOf",
               "default": "DifferenceOf",
               "enum": [
                  "DifferenceOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "DifferenceOf",
         "type": "object"
      },
      "Ellipse": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within an xy ellipse of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Ellipse\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Ellipse(\"x\", \"y\", 5, 5, 2, 3, 75)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_middle": {
               "description": "The central x point of the ellipse",
               "title": "X Middle",
               "type": "number"
            },
            "y_middle": {
               "description": "The central y point of the ellipse",
               "title": "Y Middle",
               "type": "number"
            },
            "x_radius": {
               "description": "The radius along the x axis of the ellipse",
               "exclusiveMinimum": 0.0,
               "title": "X Radius",
               "type": "number"
            },
            "y_radius": {
               "description": "The radius along the y axis of the ellipse",
               "exclusiveMinimum": 0.0,
               "title": "Y Radius",
               "type": "number"
            },
            "angle": {
               "default": 0.0,
               "description": "The angle of the ellipse (degrees)",
               "title": "Angle",
               "type": "number"
            },
            "type": {
               "const": "Ellipse",
               "default": "Ellipse",
               "enum": [
                  "Ellipse"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_middle",
            "y_middle",
            "x_radius",
            "y_radius"
         ],
         "title": "Ellipse",
         "type": "object"
      },
      "IntersectionOf": {
         "additionalProperties": false,
         "description": "A point is in IntersectionOf(a, b) if in both a and b.\n\nTypically created with the ``&`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) & Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False, False,  True, False, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "IntersectionOf",
               "default": "IntersectionOf",
               "enum": [
                  "IntersectionOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "IntersectionOf",
         "type": "object"
      },
      "Polygon": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within a rotated xy polygon.\n\n.. example_spec::\n\n    from scanspec.regions import Polygon\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Polygon(\"x\", \"y\", [1.0, 6.0, 8.0, 2.0], [4.0, 10.0, 6.0, 1.0])",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_verts": {
               "description": "The Nx1 x coordinates of the polygons vertices",
               "items": {
                  "type": "number"
               },
               "minItems": 3,
               "title": "X Verts",
               "type": "array"
            },
            "y_verts": {
               "description": "The Nx1 y coordinates of the polygons vertices",
               "items": {
                  "type": "number"
               },
               "minItems": 3,
               "title": "Y Verts",
               "type": "array"
            },
            "type": {
               "const": "Polygon",
               "default": "Polygon",
               "enum": [
                  "Polygon"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_verts",
            "y_verts"
         ],
         "title": "Polygon",
         "type": "object"
      },
      "Range": {
         "additionalProperties": false,
         "description": "Mask contains points of axis >= min and <= max.\n\n>>> r = Range(\"x\", 1, 2)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True,  True, False, False])",
         "properties": {
            "axis": {
               "description": "The name matching the axis to mask in spec",
               "title": "Axis"
            },
            "min": {
               "description": "The minimum inclusive value in the region",
               "title": "Min",
               "type": "number"
            },
            "max": {
               "description": "The minimum inclusive value in the region",
               "title": "Max",
               "type": "number"
            },
            "type": {
               "const": "Range",
               "default": "Range",
               "enum": [
                  "Range"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "axis",
            "min",
            "max"
         ],
         "title": "Range",
         "type": "object"
      },
      "Rectangle": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within a rotated xy rectangle.\n\n.. example_spec::\n\n    from scanspec.regions import Rectangle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Rectangle(\"x\", \"y\", 0, 1.1, 1.5, 2.1, 30)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_min": {
               "description": "Minimum inclusive x value in the region",
               "title": "X Min",
               "type": "number"
            },
            "y_min": {
               "description": "Minimum inclusive y value in the region",
               "title": "Y Min",
               "type": "number"
            },
            "x_max": {
               "description": "Maximum inclusive x value in the region",
               "title": "X Max",
               "type": "number"
            },
            "y_max": {
               "description": "Maximum inclusive y value in the region",
               "title": "Y Max",
               "type": "number"
            },
            "angle": {
               "default": 0.0,
               "description": "Clockwise rotation angle of the rectangle",
               "title": "Angle",
               "type": "number"
            },
            "type": {
               "const": "Rectangle",
               "default": "Rectangle",
               "enum": [
                  "Rectangle"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_min",
            "y_min",
            "x_max",
            "y_max"
         ],
         "title": "Rectangle",
         "type": "object"
      },
      "Region": {
         "discriminator": {
            "mapping": {
               "Circle": "#/$defs/Circle",
               "CombinationOf": "#/$defs/CombinationOf",
               "DifferenceOf": "#/$defs/DifferenceOf",
               "Ellipse": "#/$defs/Ellipse",
               "IntersectionOf": "#/$defs/IntersectionOf",
               "Polygon": "#/$defs/Polygon",
               "Range": "#/$defs/Range",
               "Rectangle": "#/$defs/Rectangle",
               "SymmetricDifferenceOf": "#/$defs/SymmetricDifferenceOf",
               "UnionOf": "#/$defs/UnionOf"
            },
            "propertyName": "type"
         },
         "oneOf": [
            {
               "$ref": "#/$defs/CombinationOf"
            },
            {
               "$ref": "#/$defs/UnionOf"
            },
            {
               "$ref": "#/$defs/IntersectionOf"
            },
            {
               "$ref": "#/$defs/DifferenceOf"
            },
            {
               "$ref": "#/$defs/SymmetricDifferenceOf"
            },
            {
               "$ref": "#/$defs/Range"
            },
            {
               "$ref": "#/$defs/Rectangle"
            },
            {
               "$ref": "#/$defs/Polygon"
            },
            {
               "$ref": "#/$defs/Circle"
            },
            {
               "$ref": "#/$defs/Ellipse"
            }
         ]
      },
      "SymmetricDifferenceOf": {
         "additionalProperties": false,
         "description": "A point is in SymmetricDifferenceOf(a, b) if in either a or b, but not both.\n\nTypically created with the ``^`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) ^ Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True, False,  True, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "SymmetricDifferenceOf",
               "default": "SymmetricDifferenceOf",
               "enum": [
                  "SymmetricDifferenceOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "SymmetricDifferenceOf",
         "type": "object"
      },
      "UnionOf": {
         "additionalProperties": false,
         "description": "A point is in UnionOf(a, b) if in either a or b.\n\nTypically created with the ``|`` operator\n\n>>> r = Range(\"x\", 0.5, 2.5) | Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True,  True,  True, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "UnionOf",
               "default": "UnionOf",
               "enum": [
                  "UnionOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "UnionOf",
         "type": "object"
      }
   },
   "$ref": "#/$defs/CombinationOf"
}

Fields:
field left: Region[Axis] [Required]#

The left-hand Region to combine

field right: Region[Axis] [Required]#

The right-hand Region to combine

field type: Literal['CombinationOf'] = 'CombinationOf'#
axis_sets() list[set[Axis]][source]#

Produce the non-overlapping sets of axes this region spans.

pydantic model scanspec.regions.UnionOf[source]#

A point is in UnionOf(a, b) if in either a or b.

Typically created with the | operator

>>> r = Range("x", 0.5, 2.5) | Range("x", 1.5, 3.5)
>>> r.mask({"x": np.array([0, 1, 2, 3, 4])})
array([False,  True,  True,  True, False])

Show JSON schema
{
   "$defs": {
      "Circle": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within an xy circle of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Circle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Circle(\"x\", \"y\", 1, 2, 0.9)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_middle": {
               "description": "The central x point of the circle",
               "title": "X Middle",
               "type": "number"
            },
            "y_middle": {
               "description": "The central y point of the circle",
               "title": "Y Middle",
               "type": "number"
            },
            "radius": {
               "description": "Radius of the circle",
               "exclusiveMinimum": 0.0,
               "title": "Radius",
               "type": "number"
            },
            "type": {
               "const": "Circle",
               "default": "Circle",
               "enum": [
                  "Circle"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_middle",
            "y_middle",
            "radius"
         ],
         "title": "Circle",
         "type": "object"
      },
      "CombinationOf": {
         "additionalProperties": false,
         "description": "Abstract baseclass for a combination of two regions, left and right.",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "CombinationOf",
               "default": "CombinationOf",
               "enum": [
                  "CombinationOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "CombinationOf",
         "type": "object"
      },
      "DifferenceOf": {
         "additionalProperties": false,
         "description": "A point is in DifferenceOf(a, b) if in a and not in b.\n\nTypically created with the ``-`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) - Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True, False, False, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "DifferenceOf",
               "default": "DifferenceOf",
               "enum": [
                  "DifferenceOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "DifferenceOf",
         "type": "object"
      },
      "Ellipse": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within an xy ellipse of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Ellipse\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Ellipse(\"x\", \"y\", 5, 5, 2, 3, 75)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_middle": {
               "description": "The central x point of the ellipse",
               "title": "X Middle",
               "type": "number"
            },
            "y_middle": {
               "description": "The central y point of the ellipse",
               "title": "Y Middle",
               "type": "number"
            },
            "x_radius": {
               "description": "The radius along the x axis of the ellipse",
               "exclusiveMinimum": 0.0,
               "title": "X Radius",
               "type": "number"
            },
            "y_radius": {
               "description": "The radius along the y axis of the ellipse",
               "exclusiveMinimum": 0.0,
               "title": "Y Radius",
               "type": "number"
            },
            "angle": {
               "default": 0.0,
               "description": "The angle of the ellipse (degrees)",
               "title": "Angle",
               "type": "number"
            },
            "type": {
               "const": "Ellipse",
               "default": "Ellipse",
               "enum": [
                  "Ellipse"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_middle",
            "y_middle",
            "x_radius",
            "y_radius"
         ],
         "title": "Ellipse",
         "type": "object"
      },
      "IntersectionOf": {
         "additionalProperties": false,
         "description": "A point is in IntersectionOf(a, b) if in both a and b.\n\nTypically created with the ``&`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) & Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False, False,  True, False, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "IntersectionOf",
               "default": "IntersectionOf",
               "enum": [
                  "IntersectionOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "IntersectionOf",
         "type": "object"
      },
      "Polygon": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within a rotated xy polygon.\n\n.. example_spec::\n\n    from scanspec.regions import Polygon\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Polygon(\"x\", \"y\", [1.0, 6.0, 8.0, 2.0], [4.0, 10.0, 6.0, 1.0])",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_verts": {
               "description": "The Nx1 x coordinates of the polygons vertices",
               "items": {
                  "type": "number"
               },
               "minItems": 3,
               "title": "X Verts",
               "type": "array"
            },
            "y_verts": {
               "description": "The Nx1 y coordinates of the polygons vertices",
               "items": {
                  "type": "number"
               },
               "minItems": 3,
               "title": "Y Verts",
               "type": "array"
            },
            "type": {
               "const": "Polygon",
               "default": "Polygon",
               "enum": [
                  "Polygon"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_verts",
            "y_verts"
         ],
         "title": "Polygon",
         "type": "object"
      },
      "Range": {
         "additionalProperties": false,
         "description": "Mask contains points of axis >= min and <= max.\n\n>>> r = Range(\"x\", 1, 2)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True,  True, False, False])",
         "properties": {
            "axis": {
               "description": "The name matching the axis to mask in spec",
               "title": "Axis"
            },
            "min": {
               "description": "The minimum inclusive value in the region",
               "title": "Min",
               "type": "number"
            },
            "max": {
               "description": "The minimum inclusive value in the region",
               "title": "Max",
               "type": "number"
            },
            "type": {
               "const": "Range",
               "default": "Range",
               "enum": [
                  "Range"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "axis",
            "min",
            "max"
         ],
         "title": "Range",
         "type": "object"
      },
      "Rectangle": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within a rotated xy rectangle.\n\n.. example_spec::\n\n    from scanspec.regions import Rectangle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Rectangle(\"x\", \"y\", 0, 1.1, 1.5, 2.1, 30)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_min": {
               "description": "Minimum inclusive x value in the region",
               "title": "X Min",
               "type": "number"
            },
            "y_min": {
               "description": "Minimum inclusive y value in the region",
               "title": "Y Min",
               "type": "number"
            },
            "x_max": {
               "description": "Maximum inclusive x value in the region",
               "title": "X Max",
               "type": "number"
            },
            "y_max": {
               "description": "Maximum inclusive y value in the region",
               "title": "Y Max",
               "type": "number"
            },
            "angle": {
               "default": 0.0,
               "description": "Clockwise rotation angle of the rectangle",
               "title": "Angle",
               "type": "number"
            },
            "type": {
               "const": "Rectangle",
               "default": "Rectangle",
               "enum": [
                  "Rectangle"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_min",
            "y_min",
            "x_max",
            "y_max"
         ],
         "title": "Rectangle",
         "type": "object"
      },
      "Region": {
         "discriminator": {
            "mapping": {
               "Circle": "#/$defs/Circle",
               "CombinationOf": "#/$defs/CombinationOf",
               "DifferenceOf": "#/$defs/DifferenceOf",
               "Ellipse": "#/$defs/Ellipse",
               "IntersectionOf": "#/$defs/IntersectionOf",
               "Polygon": "#/$defs/Polygon",
               "Range": "#/$defs/Range",
               "Rectangle": "#/$defs/Rectangle",
               "SymmetricDifferenceOf": "#/$defs/SymmetricDifferenceOf",
               "UnionOf": "#/$defs/UnionOf"
            },
            "propertyName": "type"
         },
         "oneOf": [
            {
               "$ref": "#/$defs/CombinationOf"
            },
            {
               "$ref": "#/$defs/UnionOf"
            },
            {
               "$ref": "#/$defs/IntersectionOf"
            },
            {
               "$ref": "#/$defs/DifferenceOf"
            },
            {
               "$ref": "#/$defs/SymmetricDifferenceOf"
            },
            {
               "$ref": "#/$defs/Range"
            },
            {
               "$ref": "#/$defs/Rectangle"
            },
            {
               "$ref": "#/$defs/Polygon"
            },
            {
               "$ref": "#/$defs/Circle"
            },
            {
               "$ref": "#/$defs/Ellipse"
            }
         ]
      },
      "SymmetricDifferenceOf": {
         "additionalProperties": false,
         "description": "A point is in SymmetricDifferenceOf(a, b) if in either a or b, but not both.\n\nTypically created with the ``^`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) ^ Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True, False,  True, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "SymmetricDifferenceOf",
               "default": "SymmetricDifferenceOf",
               "enum": [
                  "SymmetricDifferenceOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "SymmetricDifferenceOf",
         "type": "object"
      },
      "UnionOf": {
         "additionalProperties": false,
         "description": "A point is in UnionOf(a, b) if in either a or b.\n\nTypically created with the ``|`` operator\n\n>>> r = Range(\"x\", 0.5, 2.5) | Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True,  True,  True, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "UnionOf",
               "default": "UnionOf",
               "enum": [
                  "UnionOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "UnionOf",
         "type": "object"
      }
   },
   "$ref": "#/$defs/UnionOf"
}

Fields:
field left: Region[Axis] [Required]#

The left-hand Region to combine

field right: Region[Axis] [Required]#

The right-hand Region to combine

field type: Literal['UnionOf'] = 'UnionOf'#
mask(points: dict[Axis, ndarray[Any, dtype[floating[Any]]]]) ndarray[Any, dtype[bool]][source]#

Produce a mask of which points are in the region.

pydantic model scanspec.regions.IntersectionOf[source]#

A point is in IntersectionOf(a, b) if in both a and b.

Typically created with the & operator.

>>> r = Range("x", 0.5, 2.5) & Range("x", 1.5, 3.5)
>>> r.mask({"x": np.array([0, 1, 2, 3, 4])})
array([False, False,  True, False, False])

Show JSON schema
{
   "$defs": {
      "Circle": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within an xy circle of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Circle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Circle(\"x\", \"y\", 1, 2, 0.9)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_middle": {
               "description": "The central x point of the circle",
               "title": "X Middle",
               "type": "number"
            },
            "y_middle": {
               "description": "The central y point of the circle",
               "title": "Y Middle",
               "type": "number"
            },
            "radius": {
               "description": "Radius of the circle",
               "exclusiveMinimum": 0.0,
               "title": "Radius",
               "type": "number"
            },
            "type": {
               "const": "Circle",
               "default": "Circle",
               "enum": [
                  "Circle"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_middle",
            "y_middle",
            "radius"
         ],
         "title": "Circle",
         "type": "object"
      },
      "CombinationOf": {
         "additionalProperties": false,
         "description": "Abstract baseclass for a combination of two regions, left and right.",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "CombinationOf",
               "default": "CombinationOf",
               "enum": [
                  "CombinationOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "CombinationOf",
         "type": "object"
      },
      "DifferenceOf": {
         "additionalProperties": false,
         "description": "A point is in DifferenceOf(a, b) if in a and not in b.\n\nTypically created with the ``-`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) - Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True, False, False, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "DifferenceOf",
               "default": "DifferenceOf",
               "enum": [
                  "DifferenceOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "DifferenceOf",
         "type": "object"
      },
      "Ellipse": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within an xy ellipse of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Ellipse\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Ellipse(\"x\", \"y\", 5, 5, 2, 3, 75)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_middle": {
               "description": "The central x point of the ellipse",
               "title": "X Middle",
               "type": "number"
            },
            "y_middle": {
               "description": "The central y point of the ellipse",
               "title": "Y Middle",
               "type": "number"
            },
            "x_radius": {
               "description": "The radius along the x axis of the ellipse",
               "exclusiveMinimum": 0.0,
               "title": "X Radius",
               "type": "number"
            },
            "y_radius": {
               "description": "The radius along the y axis of the ellipse",
               "exclusiveMinimum": 0.0,
               "title": "Y Radius",
               "type": "number"
            },
            "angle": {
               "default": 0.0,
               "description": "The angle of the ellipse (degrees)",
               "title": "Angle",
               "type": "number"
            },
            "type": {
               "const": "Ellipse",
               "default": "Ellipse",
               "enum": [
                  "Ellipse"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_middle",
            "y_middle",
            "x_radius",
            "y_radius"
         ],
         "title": "Ellipse",
         "type": "object"
      },
      "IntersectionOf": {
         "additionalProperties": false,
         "description": "A point is in IntersectionOf(a, b) if in both a and b.\n\nTypically created with the ``&`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) & Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False, False,  True, False, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "IntersectionOf",
               "default": "IntersectionOf",
               "enum": [
                  "IntersectionOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "IntersectionOf",
         "type": "object"
      },
      "Polygon": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within a rotated xy polygon.\n\n.. example_spec::\n\n    from scanspec.regions import Polygon\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Polygon(\"x\", \"y\", [1.0, 6.0, 8.0, 2.0], [4.0, 10.0, 6.0, 1.0])",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_verts": {
               "description": "The Nx1 x coordinates of the polygons vertices",
               "items": {
                  "type": "number"
               },
               "minItems": 3,
               "title": "X Verts",
               "type": "array"
            },
            "y_verts": {
               "description": "The Nx1 y coordinates of the polygons vertices",
               "items": {
                  "type": "number"
               },
               "minItems": 3,
               "title": "Y Verts",
               "type": "array"
            },
            "type": {
               "const": "Polygon",
               "default": "Polygon",
               "enum": [
                  "Polygon"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_verts",
            "y_verts"
         ],
         "title": "Polygon",
         "type": "object"
      },
      "Range": {
         "additionalProperties": false,
         "description": "Mask contains points of axis >= min and <= max.\n\n>>> r = Range(\"x\", 1, 2)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True,  True, False, False])",
         "properties": {
            "axis": {
               "description": "The name matching the axis to mask in spec",
               "title": "Axis"
            },
            "min": {
               "description": "The minimum inclusive value in the region",
               "title": "Min",
               "type": "number"
            },
            "max": {
               "description": "The minimum inclusive value in the region",
               "title": "Max",
               "type": "number"
            },
            "type": {
               "const": "Range",
               "default": "Range",
               "enum": [
                  "Range"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "axis",
            "min",
            "max"
         ],
         "title": "Range",
         "type": "object"
      },
      "Rectangle": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within a rotated xy rectangle.\n\n.. example_spec::\n\n    from scanspec.regions import Rectangle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Rectangle(\"x\", \"y\", 0, 1.1, 1.5, 2.1, 30)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_min": {
               "description": "Minimum inclusive x value in the region",
               "title": "X Min",
               "type": "number"
            },
            "y_min": {
               "description": "Minimum inclusive y value in the region",
               "title": "Y Min",
               "type": "number"
            },
            "x_max": {
               "description": "Maximum inclusive x value in the region",
               "title": "X Max",
               "type": "number"
            },
            "y_max": {
               "description": "Maximum inclusive y value in the region",
               "title": "Y Max",
               "type": "number"
            },
            "angle": {
               "default": 0.0,
               "description": "Clockwise rotation angle of the rectangle",
               "title": "Angle",
               "type": "number"
            },
            "type": {
               "const": "Rectangle",
               "default": "Rectangle",
               "enum": [
                  "Rectangle"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_min",
            "y_min",
            "x_max",
            "y_max"
         ],
         "title": "Rectangle",
         "type": "object"
      },
      "Region": {
         "discriminator": {
            "mapping": {
               "Circle": "#/$defs/Circle",
               "CombinationOf": "#/$defs/CombinationOf",
               "DifferenceOf": "#/$defs/DifferenceOf",
               "Ellipse": "#/$defs/Ellipse",
               "IntersectionOf": "#/$defs/IntersectionOf",
               "Polygon": "#/$defs/Polygon",
               "Range": "#/$defs/Range",
               "Rectangle": "#/$defs/Rectangle",
               "SymmetricDifferenceOf": "#/$defs/SymmetricDifferenceOf",
               "UnionOf": "#/$defs/UnionOf"
            },
            "propertyName": "type"
         },
         "oneOf": [
            {
               "$ref": "#/$defs/CombinationOf"
            },
            {
               "$ref": "#/$defs/UnionOf"
            },
            {
               "$ref": "#/$defs/IntersectionOf"
            },
            {
               "$ref": "#/$defs/DifferenceOf"
            },
            {
               "$ref": "#/$defs/SymmetricDifferenceOf"
            },
            {
               "$ref": "#/$defs/Range"
            },
            {
               "$ref": "#/$defs/Rectangle"
            },
            {
               "$ref": "#/$defs/Polygon"
            },
            {
               "$ref": "#/$defs/Circle"
            },
            {
               "$ref": "#/$defs/Ellipse"
            }
         ]
      },
      "SymmetricDifferenceOf": {
         "additionalProperties": false,
         "description": "A point is in SymmetricDifferenceOf(a, b) if in either a or b, but not both.\n\nTypically created with the ``^`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) ^ Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True, False,  True, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "SymmetricDifferenceOf",
               "default": "SymmetricDifferenceOf",
               "enum": [
                  "SymmetricDifferenceOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "SymmetricDifferenceOf",
         "type": "object"
      },
      "UnionOf": {
         "additionalProperties": false,
         "description": "A point is in UnionOf(a, b) if in either a or b.\n\nTypically created with the ``|`` operator\n\n>>> r = Range(\"x\", 0.5, 2.5) | Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True,  True,  True, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "UnionOf",
               "default": "UnionOf",
               "enum": [
                  "UnionOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "UnionOf",
         "type": "object"
      }
   },
   "$ref": "#/$defs/IntersectionOf"
}

Fields:
field left: Region[Axis] [Required]#

The left-hand Region to combine

field right: Region[Axis] [Required]#

The right-hand Region to combine

field type: Literal['IntersectionOf'] = 'IntersectionOf'#
mask(points: dict[Axis, ndarray[Any, dtype[floating[Any]]]]) ndarray[Any, dtype[bool]][source]#

Produce a mask of which points are in the region.

pydantic model scanspec.regions.DifferenceOf[source]#

A point is in DifferenceOf(a, b) if in a and not in b.

Typically created with the - operator.

>>> r = Range("x", 0.5, 2.5) - Range("x", 1.5, 3.5)
>>> r.mask({"x": np.array([0, 1, 2, 3, 4])})
array([False,  True, False, False, False])

Show JSON schema
{
   "$defs": {
      "Circle": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within an xy circle of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Circle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Circle(\"x\", \"y\", 1, 2, 0.9)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_middle": {
               "description": "The central x point of the circle",
               "title": "X Middle",
               "type": "number"
            },
            "y_middle": {
               "description": "The central y point of the circle",
               "title": "Y Middle",
               "type": "number"
            },
            "radius": {
               "description": "Radius of the circle",
               "exclusiveMinimum": 0.0,
               "title": "Radius",
               "type": "number"
            },
            "type": {
               "const": "Circle",
               "default": "Circle",
               "enum": [
                  "Circle"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_middle",
            "y_middle",
            "radius"
         ],
         "title": "Circle",
         "type": "object"
      },
      "CombinationOf": {
         "additionalProperties": false,
         "description": "Abstract baseclass for a combination of two regions, left and right.",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "CombinationOf",
               "default": "CombinationOf",
               "enum": [
                  "CombinationOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "CombinationOf",
         "type": "object"
      },
      "DifferenceOf": {
         "additionalProperties": false,
         "description": "A point is in DifferenceOf(a, b) if in a and not in b.\n\nTypically created with the ``-`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) - Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True, False, False, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "DifferenceOf",
               "default": "DifferenceOf",
               "enum": [
                  "DifferenceOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "DifferenceOf",
         "type": "object"
      },
      "Ellipse": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within an xy ellipse of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Ellipse\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Ellipse(\"x\", \"y\", 5, 5, 2, 3, 75)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_middle": {
               "description": "The central x point of the ellipse",
               "title": "X Middle",
               "type": "number"
            },
            "y_middle": {
               "description": "The central y point of the ellipse",
               "title": "Y Middle",
               "type": "number"
            },
            "x_radius": {
               "description": "The radius along the x axis of the ellipse",
               "exclusiveMinimum": 0.0,
               "title": "X Radius",
               "type": "number"
            },
            "y_radius": {
               "description": "The radius along the y axis of the ellipse",
               "exclusiveMinimum": 0.0,
               "title": "Y Radius",
               "type": "number"
            },
            "angle": {
               "default": 0.0,
               "description": "The angle of the ellipse (degrees)",
               "title": "Angle",
               "type": "number"
            },
            "type": {
               "const": "Ellipse",
               "default": "Ellipse",
               "enum": [
                  "Ellipse"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_middle",
            "y_middle",
            "x_radius",
            "y_radius"
         ],
         "title": "Ellipse",
         "type": "object"
      },
      "IntersectionOf": {
         "additionalProperties": false,
         "description": "A point is in IntersectionOf(a, b) if in both a and b.\n\nTypically created with the ``&`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) & Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False, False,  True, False, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "IntersectionOf",
               "default": "IntersectionOf",
               "enum": [
                  "IntersectionOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "IntersectionOf",
         "type": "object"
      },
      "Polygon": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within a rotated xy polygon.\n\n.. example_spec::\n\n    from scanspec.regions import Polygon\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Polygon(\"x\", \"y\", [1.0, 6.0, 8.0, 2.0], [4.0, 10.0, 6.0, 1.0])",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_verts": {
               "description": "The Nx1 x coordinates of the polygons vertices",
               "items": {
                  "type": "number"
               },
               "minItems": 3,
               "title": "X Verts",
               "type": "array"
            },
            "y_verts": {
               "description": "The Nx1 y coordinates of the polygons vertices",
               "items": {
                  "type": "number"
               },
               "minItems": 3,
               "title": "Y Verts",
               "type": "array"
            },
            "type": {
               "const": "Polygon",
               "default": "Polygon",
               "enum": [
                  "Polygon"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_verts",
            "y_verts"
         ],
         "title": "Polygon",
         "type": "object"
      },
      "Range": {
         "additionalProperties": false,
         "description": "Mask contains points of axis >= min and <= max.\n\n>>> r = Range(\"x\", 1, 2)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True,  True, False, False])",
         "properties": {
            "axis": {
               "description": "The name matching the axis to mask in spec",
               "title": "Axis"
            },
            "min": {
               "description": "The minimum inclusive value in the region",
               "title": "Min",
               "type": "number"
            },
            "max": {
               "description": "The minimum inclusive value in the region",
               "title": "Max",
               "type": "number"
            },
            "type": {
               "const": "Range",
               "default": "Range",
               "enum": [
                  "Range"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "axis",
            "min",
            "max"
         ],
         "title": "Range",
         "type": "object"
      },
      "Rectangle": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within a rotated xy rectangle.\n\n.. example_spec::\n\n    from scanspec.regions import Rectangle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Rectangle(\"x\", \"y\", 0, 1.1, 1.5, 2.1, 30)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_min": {
               "description": "Minimum inclusive x value in the region",
               "title": "X Min",
               "type": "number"
            },
            "y_min": {
               "description": "Minimum inclusive y value in the region",
               "title": "Y Min",
               "type": "number"
            },
            "x_max": {
               "description": "Maximum inclusive x value in the region",
               "title": "X Max",
               "type": "number"
            },
            "y_max": {
               "description": "Maximum inclusive y value in the region",
               "title": "Y Max",
               "type": "number"
            },
            "angle": {
               "default": 0.0,
               "description": "Clockwise rotation angle of the rectangle",
               "title": "Angle",
               "type": "number"
            },
            "type": {
               "const": "Rectangle",
               "default": "Rectangle",
               "enum": [
                  "Rectangle"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_min",
            "y_min",
            "x_max",
            "y_max"
         ],
         "title": "Rectangle",
         "type": "object"
      },
      "Region": {
         "discriminator": {
            "mapping": {
               "Circle": "#/$defs/Circle",
               "CombinationOf": "#/$defs/CombinationOf",
               "DifferenceOf": "#/$defs/DifferenceOf",
               "Ellipse": "#/$defs/Ellipse",
               "IntersectionOf": "#/$defs/IntersectionOf",
               "Polygon": "#/$defs/Polygon",
               "Range": "#/$defs/Range",
               "Rectangle": "#/$defs/Rectangle",
               "SymmetricDifferenceOf": "#/$defs/SymmetricDifferenceOf",
               "UnionOf": "#/$defs/UnionOf"
            },
            "propertyName": "type"
         },
         "oneOf": [
            {
               "$ref": "#/$defs/CombinationOf"
            },
            {
               "$ref": "#/$defs/UnionOf"
            },
            {
               "$ref": "#/$defs/IntersectionOf"
            },
            {
               "$ref": "#/$defs/DifferenceOf"
            },
            {
               "$ref": "#/$defs/SymmetricDifferenceOf"
            },
            {
               "$ref": "#/$defs/Range"
            },
            {
               "$ref": "#/$defs/Rectangle"
            },
            {
               "$ref": "#/$defs/Polygon"
            },
            {
               "$ref": "#/$defs/Circle"
            },
            {
               "$ref": "#/$defs/Ellipse"
            }
         ]
      },
      "SymmetricDifferenceOf": {
         "additionalProperties": false,
         "description": "A point is in SymmetricDifferenceOf(a, b) if in either a or b, but not both.\n\nTypically created with the ``^`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) ^ Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True, False,  True, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "SymmetricDifferenceOf",
               "default": "SymmetricDifferenceOf",
               "enum": [
                  "SymmetricDifferenceOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "SymmetricDifferenceOf",
         "type": "object"
      },
      "UnionOf": {
         "additionalProperties": false,
         "description": "A point is in UnionOf(a, b) if in either a or b.\n\nTypically created with the ``|`` operator\n\n>>> r = Range(\"x\", 0.5, 2.5) | Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True,  True,  True, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "UnionOf",
               "default": "UnionOf",
               "enum": [
                  "UnionOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "UnionOf",
         "type": "object"
      }
   },
   "$ref": "#/$defs/DifferenceOf"
}

Fields:
field left: Region[Axis] [Required]#

The left-hand Region to combine

field right: Region[Axis] [Required]#

The right-hand Region to combine

field type: Literal['DifferenceOf'] = 'DifferenceOf'#
mask(points: dict[Axis, ndarray[Any, dtype[floating[Any]]]]) ndarray[Any, dtype[bool]][source]#

Produce a mask of which points are in the region.

pydantic model scanspec.regions.SymmetricDifferenceOf[source]#

A point is in SymmetricDifferenceOf(a, b) if in either a or b, but not both.

Typically created with the ^ operator.

>>> r = Range("x", 0.5, 2.5) ^ Range("x", 1.5, 3.5)
>>> r.mask({"x": np.array([0, 1, 2, 3, 4])})
array([False,  True, False,  True, False])

Show JSON schema
{
   "$defs": {
      "Circle": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within an xy circle of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Circle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Circle(\"x\", \"y\", 1, 2, 0.9)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_middle": {
               "description": "The central x point of the circle",
               "title": "X Middle",
               "type": "number"
            },
            "y_middle": {
               "description": "The central y point of the circle",
               "title": "Y Middle",
               "type": "number"
            },
            "radius": {
               "description": "Radius of the circle",
               "exclusiveMinimum": 0.0,
               "title": "Radius",
               "type": "number"
            },
            "type": {
               "const": "Circle",
               "default": "Circle",
               "enum": [
                  "Circle"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_middle",
            "y_middle",
            "radius"
         ],
         "title": "Circle",
         "type": "object"
      },
      "CombinationOf": {
         "additionalProperties": false,
         "description": "Abstract baseclass for a combination of two regions, left and right.",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "CombinationOf",
               "default": "CombinationOf",
               "enum": [
                  "CombinationOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "CombinationOf",
         "type": "object"
      },
      "DifferenceOf": {
         "additionalProperties": false,
         "description": "A point is in DifferenceOf(a, b) if in a and not in b.\n\nTypically created with the ``-`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) - Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True, False, False, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "DifferenceOf",
               "default": "DifferenceOf",
               "enum": [
                  "DifferenceOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "DifferenceOf",
         "type": "object"
      },
      "Ellipse": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within an xy ellipse of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Ellipse\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Ellipse(\"x\", \"y\", 5, 5, 2, 3, 75)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_middle": {
               "description": "The central x point of the ellipse",
               "title": "X Middle",
               "type": "number"
            },
            "y_middle": {
               "description": "The central y point of the ellipse",
               "title": "Y Middle",
               "type": "number"
            },
            "x_radius": {
               "description": "The radius along the x axis of the ellipse",
               "exclusiveMinimum": 0.0,
               "title": "X Radius",
               "type": "number"
            },
            "y_radius": {
               "description": "The radius along the y axis of the ellipse",
               "exclusiveMinimum": 0.0,
               "title": "Y Radius",
               "type": "number"
            },
            "angle": {
               "default": 0.0,
               "description": "The angle of the ellipse (degrees)",
               "title": "Angle",
               "type": "number"
            },
            "type": {
               "const": "Ellipse",
               "default": "Ellipse",
               "enum": [
                  "Ellipse"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_middle",
            "y_middle",
            "x_radius",
            "y_radius"
         ],
         "title": "Ellipse",
         "type": "object"
      },
      "IntersectionOf": {
         "additionalProperties": false,
         "description": "A point is in IntersectionOf(a, b) if in both a and b.\n\nTypically created with the ``&`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) & Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False, False,  True, False, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "IntersectionOf",
               "default": "IntersectionOf",
               "enum": [
                  "IntersectionOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "IntersectionOf",
         "type": "object"
      },
      "Polygon": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within a rotated xy polygon.\n\n.. example_spec::\n\n    from scanspec.regions import Polygon\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Polygon(\"x\", \"y\", [1.0, 6.0, 8.0, 2.0], [4.0, 10.0, 6.0, 1.0])",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_verts": {
               "description": "The Nx1 x coordinates of the polygons vertices",
               "items": {
                  "type": "number"
               },
               "minItems": 3,
               "title": "X Verts",
               "type": "array"
            },
            "y_verts": {
               "description": "The Nx1 y coordinates of the polygons vertices",
               "items": {
                  "type": "number"
               },
               "minItems": 3,
               "title": "Y Verts",
               "type": "array"
            },
            "type": {
               "const": "Polygon",
               "default": "Polygon",
               "enum": [
                  "Polygon"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_verts",
            "y_verts"
         ],
         "title": "Polygon",
         "type": "object"
      },
      "Range": {
         "additionalProperties": false,
         "description": "Mask contains points of axis >= min and <= max.\n\n>>> r = Range(\"x\", 1, 2)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True,  True, False, False])",
         "properties": {
            "axis": {
               "description": "The name matching the axis to mask in spec",
               "title": "Axis"
            },
            "min": {
               "description": "The minimum inclusive value in the region",
               "title": "Min",
               "type": "number"
            },
            "max": {
               "description": "The minimum inclusive value in the region",
               "title": "Max",
               "type": "number"
            },
            "type": {
               "const": "Range",
               "default": "Range",
               "enum": [
                  "Range"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "axis",
            "min",
            "max"
         ],
         "title": "Range",
         "type": "object"
      },
      "Rectangle": {
         "additionalProperties": false,
         "description": "Mask contains points of axis within a rotated xy rectangle.\n\n.. example_spec::\n\n    from scanspec.regions import Rectangle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Rectangle(\"x\", \"y\", 0, 1.1, 1.5, 2.1, 30)",
         "properties": {
            "x_axis": {
               "description": "The name matching the x axis of the spec",
               "title": "X Axis"
            },
            "y_axis": {
               "description": "The name matching the y axis of the spec",
               "title": "Y Axis"
            },
            "x_min": {
               "description": "Minimum inclusive x value in the region",
               "title": "X Min",
               "type": "number"
            },
            "y_min": {
               "description": "Minimum inclusive y value in the region",
               "title": "Y Min",
               "type": "number"
            },
            "x_max": {
               "description": "Maximum inclusive x value in the region",
               "title": "X Max",
               "type": "number"
            },
            "y_max": {
               "description": "Maximum inclusive y value in the region",
               "title": "Y Max",
               "type": "number"
            },
            "angle": {
               "default": 0.0,
               "description": "Clockwise rotation angle of the rectangle",
               "title": "Angle",
               "type": "number"
            },
            "type": {
               "const": "Rectangle",
               "default": "Rectangle",
               "enum": [
                  "Rectangle"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "x_axis",
            "y_axis",
            "x_min",
            "y_min",
            "x_max",
            "y_max"
         ],
         "title": "Rectangle",
         "type": "object"
      },
      "Region": {
         "discriminator": {
            "mapping": {
               "Circle": "#/$defs/Circle",
               "CombinationOf": "#/$defs/CombinationOf",
               "DifferenceOf": "#/$defs/DifferenceOf",
               "Ellipse": "#/$defs/Ellipse",
               "IntersectionOf": "#/$defs/IntersectionOf",
               "Polygon": "#/$defs/Polygon",
               "Range": "#/$defs/Range",
               "Rectangle": "#/$defs/Rectangle",
               "SymmetricDifferenceOf": "#/$defs/SymmetricDifferenceOf",
               "UnionOf": "#/$defs/UnionOf"
            },
            "propertyName": "type"
         },
         "oneOf": [
            {
               "$ref": "#/$defs/CombinationOf"
            },
            {
               "$ref": "#/$defs/UnionOf"
            },
            {
               "$ref": "#/$defs/IntersectionOf"
            },
            {
               "$ref": "#/$defs/DifferenceOf"
            },
            {
               "$ref": "#/$defs/SymmetricDifferenceOf"
            },
            {
               "$ref": "#/$defs/Range"
            },
            {
               "$ref": "#/$defs/Rectangle"
            },
            {
               "$ref": "#/$defs/Polygon"
            },
            {
               "$ref": "#/$defs/Circle"
            },
            {
               "$ref": "#/$defs/Ellipse"
            }
         ]
      },
      "SymmetricDifferenceOf": {
         "additionalProperties": false,
         "description": "A point is in SymmetricDifferenceOf(a, b) if in either a or b, but not both.\n\nTypically created with the ``^`` operator.\n\n>>> r = Range(\"x\", 0.5, 2.5) ^ Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True, False,  True, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "SymmetricDifferenceOf",
               "default": "SymmetricDifferenceOf",
               "enum": [
                  "SymmetricDifferenceOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "SymmetricDifferenceOf",
         "type": "object"
      },
      "UnionOf": {
         "additionalProperties": false,
         "description": "A point is in UnionOf(a, b) if in either a or b.\n\nTypically created with the ``|`` operator\n\n>>> r = Range(\"x\", 0.5, 2.5) | Range(\"x\", 1.5, 3.5)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True,  True,  True, False])",
         "properties": {
            "left": {
               "$ref": "#/$defs/Region",
               "description": "The left-hand Region to combine"
            },
            "right": {
               "$ref": "#/$defs/Region",
               "description": "The right-hand Region to combine"
            },
            "type": {
               "const": "UnionOf",
               "default": "UnionOf",
               "enum": [
                  "UnionOf"
               ],
               "title": "Type",
               "type": "string"
            }
         },
         "required": [
            "left",
            "right"
         ],
         "title": "UnionOf",
         "type": "object"
      }
   },
   "$ref": "#/$defs/SymmetricDifferenceOf"
}

Fields:
field left: Region[Axis] [Required]#

The left-hand Region to combine

field right: Region[Axis] [Required]#

The right-hand Region to combine

field type: Literal['SymmetricDifferenceOf'] = 'SymmetricDifferenceOf'#
mask(points: dict[Axis, ndarray[Any, dtype[floating[Any]]]]) ndarray[Any, dtype[bool]][source]#

Produce a mask of which points are in the region.

pydantic model scanspec.regions.Range[source]#

Mask contains points of axis >= min and <= max.

>>> r = Range("x", 1, 2)
>>> r.mask({"x": np.array([0, 1, 2, 3, 4])})
array([False,  True,  True, False, False])

Show JSON schema
{
   "title": "Range",
   "description": "Mask contains points of axis >= min and <= max.\n\n>>> r = Range(\"x\", 1, 2)\n>>> r.mask({\"x\": np.array([0, 1, 2, 3, 4])})\narray([False,  True,  True, False, False])",
   "type": "object",
   "properties": {
      "axis": {
         "description": "The name matching the axis to mask in spec",
         "title": "Axis"
      },
      "min": {
         "description": "The minimum inclusive value in the region",
         "title": "Min",
         "type": "number"
      },
      "max": {
         "description": "The minimum inclusive value in the region",
         "title": "Max",
         "type": "number"
      },
      "type": {
         "const": "Range",
         "default": "Range",
         "enum": [
            "Range"
         ],
         "title": "Type",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "axis",
      "min",
      "max"
   ]
}

Fields:
field axis: Axis [Required]#

The name matching the axis to mask in spec

field max: float [Required]#

The minimum inclusive value in the region

field min: float [Required]#

The minimum inclusive value in the region

field type: Literal['Range'] = 'Range'#
axis_sets() list[set[Axis]][source]#

Produce the non-overlapping sets of axes this region spans.

mask(points: dict[Axis, ndarray[Any, dtype[floating[Any]]]]) ndarray[Any, dtype[bool]][source]#

Produce a mask of which points are in the region.

pydantic model scanspec.regions.Rectangle[source]#

Mask contains points of axis within a rotated xy rectangle.

# Example Spec

from scanspec.plot import plot_spec
from scanspec.regions import Rectangle
from scanspec.specs import Line

grid = Line("y", 1, 3, 10) * ~Line("x", 0, 2, 10)
spec = grid & Rectangle("x", "y", 0, 1.1, 1.5, 2.1, 30)
plot_spec(spec)

(Source code, png, hires.png, pdf)

../_images/scanspec-regions-1.png

Show JSON schema
{
   "title": "Rectangle",
   "description": "Mask contains points of axis within a rotated xy rectangle.\n\n.. example_spec::\n\n    from scanspec.regions import Rectangle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Rectangle(\"x\", \"y\", 0, 1.1, 1.5, 2.1, 30)",
   "type": "object",
   "properties": {
      "x_axis": {
         "description": "The name matching the x axis of the spec",
         "title": "X Axis"
      },
      "y_axis": {
         "description": "The name matching the y axis of the spec",
         "title": "Y Axis"
      },
      "x_min": {
         "description": "Minimum inclusive x value in the region",
         "title": "X Min",
         "type": "number"
      },
      "y_min": {
         "description": "Minimum inclusive y value in the region",
         "title": "Y Min",
         "type": "number"
      },
      "x_max": {
         "description": "Maximum inclusive x value in the region",
         "title": "X Max",
         "type": "number"
      },
      "y_max": {
         "description": "Maximum inclusive y value in the region",
         "title": "Y Max",
         "type": "number"
      },
      "angle": {
         "default": 0.0,
         "description": "Clockwise rotation angle of the rectangle",
         "title": "Angle",
         "type": "number"
      },
      "type": {
         "const": "Rectangle",
         "default": "Rectangle",
         "enum": [
            "Rectangle"
         ],
         "title": "Type",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "x_axis",
      "y_axis",
      "x_min",
      "y_min",
      "x_max",
      "y_max"
   ]
}

Fields:
field angle: float = 0.0#

Clockwise rotation angle of the rectangle

field type: Literal['Rectangle'] = 'Rectangle'#
field x_axis: Axis [Required]#

The name matching the x axis of the spec

field x_max: float [Required]#

Maximum inclusive x value in the region

field x_min: float [Required]#

Minimum inclusive x value in the region

field y_axis: Axis [Required]#

The name matching the y axis of the spec

field y_max: float [Required]#

Maximum inclusive y value in the region

field y_min: float [Required]#

Minimum inclusive y value in the region

axis_sets() list[set[Axis]][source]#

Produce the non-overlapping sets of axes this region spans.

mask(points: dict[Axis, ndarray[Any, dtype[floating[Any]]]]) ndarray[Any, dtype[bool]][source]#

Produce a mask of which points are in the region.

pydantic model scanspec.regions.Polygon[source]#

Mask contains points of axis within a rotated xy polygon.

# Example Spec

from scanspec.plot import plot_spec
from scanspec.regions import Polygon
from scanspec.specs import Line

grid = Line("y", 3, 8, 10) * ~Line("x", 1 ,8, 10)
spec = grid & Polygon("x", "y", [1.0, 6.0, 8.0, 2.0], [4.0, 10.0, 6.0, 1.0])
plot_spec(spec)

(Source code, png, hires.png, pdf)

../_images/scanspec-regions-2.png

Show JSON schema
{
   "title": "Polygon",
   "description": "Mask contains points of axis within a rotated xy polygon.\n\n.. example_spec::\n\n    from scanspec.regions import Polygon\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Polygon(\"x\", \"y\", [1.0, 6.0, 8.0, 2.0], [4.0, 10.0, 6.0, 1.0])",
   "type": "object",
   "properties": {
      "x_axis": {
         "description": "The name matching the x axis of the spec",
         "title": "X Axis"
      },
      "y_axis": {
         "description": "The name matching the y axis of the spec",
         "title": "Y Axis"
      },
      "x_verts": {
         "description": "The Nx1 x coordinates of the polygons vertices",
         "items": {
            "type": "number"
         },
         "minItems": 3,
         "title": "X Verts",
         "type": "array"
      },
      "y_verts": {
         "description": "The Nx1 y coordinates of the polygons vertices",
         "items": {
            "type": "number"
         },
         "minItems": 3,
         "title": "Y Verts",
         "type": "array"
      },
      "type": {
         "const": "Polygon",
         "default": "Polygon",
         "enum": [
            "Polygon"
         ],
         "title": "Type",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "x_axis",
      "y_axis",
      "x_verts",
      "y_verts"
   ]
}

Fields:
field type: Literal['Polygon'] = 'Polygon'#
field x_axis: Axis [Required]#

The name matching the x axis of the spec

field x_verts: list[float] [Required]#

The Nx1 x coordinates of the polygons vertices

Constraints:
  • min_length = 3

field y_axis: Axis [Required]#

The name matching the y axis of the spec

field y_verts: list[float] [Required]#

The Nx1 y coordinates of the polygons vertices

Constraints:
  • min_length = 3

axis_sets() list[set[Axis]][source]#

Produce the non-overlapping sets of axes this region spans.

mask(points: dict[Axis, ndarray[Any, dtype[floating[Any]]]]) ndarray[Any, dtype[bool]][source]#

Produce a mask of which points are in the region.

pydantic model scanspec.regions.Circle[source]#

Mask contains points of axis within an xy circle of given radius.

# Example Spec

from scanspec.plot import plot_spec
from scanspec.regions import Circle
from scanspec.specs import Line

grid = Line("y", 1, 3, 10) * ~Line("x", 0, 2, 10)
spec = grid & Circle("x", "y", 1, 2, 0.9)
plot_spec(spec)

(Source code, png, hires.png, pdf)

../_images/scanspec-regions-3.png

Show JSON schema
{
   "title": "Circle",
   "description": "Mask contains points of axis within an xy circle of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Circle\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 1, 3, 10) * ~Line(\"x\", 0, 2, 10)\n    spec = grid & Circle(\"x\", \"y\", 1, 2, 0.9)",
   "type": "object",
   "properties": {
      "x_axis": {
         "description": "The name matching the x axis of the spec",
         "title": "X Axis"
      },
      "y_axis": {
         "description": "The name matching the y axis of the spec",
         "title": "Y Axis"
      },
      "x_middle": {
         "description": "The central x point of the circle",
         "title": "X Middle",
         "type": "number"
      },
      "y_middle": {
         "description": "The central y point of the circle",
         "title": "Y Middle",
         "type": "number"
      },
      "radius": {
         "description": "Radius of the circle",
         "exclusiveMinimum": 0.0,
         "title": "Radius",
         "type": "number"
      },
      "type": {
         "const": "Circle",
         "default": "Circle",
         "enum": [
            "Circle"
         ],
         "title": "Type",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "x_axis",
      "y_axis",
      "x_middle",
      "y_middle",
      "radius"
   ]
}

Fields:
field radius: float [Required]#

Radius of the circle

Constraints:
  • gt = 0.0

field type: Literal['Circle'] = 'Circle'#
field x_axis: Axis [Required]#

The name matching the x axis of the spec

field x_middle: float [Required]#

The central x point of the circle

field y_axis: Axis [Required]#

The name matching the y axis of the spec

field y_middle: float [Required]#

The central y point of the circle

axis_sets() list[set[Axis]][source]#

Produce the non-overlapping sets of axes this region spans.

mask(points: dict[Axis, ndarray[Any, dtype[floating[Any]]]]) ndarray[Any, dtype[bool]][source]#

Produce a mask of which points are in the region.

pydantic model scanspec.regions.Ellipse[source]#

Mask contains points of axis within an xy ellipse of given radius.

# Example Spec

from scanspec.plot import plot_spec
from scanspec.regions import Ellipse
from scanspec.specs import Line

grid = Line("y", 3, 8, 10) * ~Line("x", 1 ,8, 10)
spec = grid & Ellipse("x", "y", 5, 5, 2, 3, 75)
plot_spec(spec)

(Source code, png, hires.png, pdf)

../_images/scanspec-regions-4.png

Show JSON schema
{
   "title": "Ellipse",
   "description": "Mask contains points of axis within an xy ellipse of given radius.\n\n.. example_spec::\n\n    from scanspec.regions import Ellipse\n    from scanspec.specs import Line\n\n    grid = Line(\"y\", 3, 8, 10) * ~Line(\"x\", 1 ,8, 10)\n    spec = grid & Ellipse(\"x\", \"y\", 5, 5, 2, 3, 75)",
   "type": "object",
   "properties": {
      "x_axis": {
         "description": "The name matching the x axis of the spec",
         "title": "X Axis"
      },
      "y_axis": {
         "description": "The name matching the y axis of the spec",
         "title": "Y Axis"
      },
      "x_middle": {
         "description": "The central x point of the ellipse",
         "title": "X Middle",
         "type": "number"
      },
      "y_middle": {
         "description": "The central y point of the ellipse",
         "title": "Y Middle",
         "type": "number"
      },
      "x_radius": {
         "description": "The radius along the x axis of the ellipse",
         "exclusiveMinimum": 0.0,
         "title": "X Radius",
         "type": "number"
      },
      "y_radius": {
         "description": "The radius along the y axis of the ellipse",
         "exclusiveMinimum": 0.0,
         "title": "Y Radius",
         "type": "number"
      },
      "angle": {
         "default": 0.0,
         "description": "The angle of the ellipse (degrees)",
         "title": "Angle",
         "type": "number"
      },
      "type": {
         "const": "Ellipse",
         "default": "Ellipse",
         "enum": [
            "Ellipse"
         ],
         "title": "Type",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "x_axis",
      "y_axis",
      "x_middle",
      "y_middle",
      "x_radius",
      "y_radius"
   ]
}

Fields:
field angle: float = 0.0#

The angle of the ellipse (degrees)

field type: Literal['Ellipse'] = 'Ellipse'#
field x_axis: Axis [Required]#

The name matching the x axis of the spec

field x_middle: float [Required]#

The central x point of the ellipse

field x_radius: float [Required]#

The radius along the x axis of the ellipse

Constraints:
  • gt = 0.0

field y_axis: Axis [Required]#

The name matching the y axis of the spec

field y_middle: float [Required]#

The central y point of the ellipse

field y_radius: float [Required]#

The radius along the y axis of the ellipse

Constraints:
  • gt = 0.0

axis_sets() list[set[Axis]][source]#

Produce the non-overlapping sets of axes this region spans.

mask(points: dict[Axis, ndarray[Any, dtype[floating[Any]]]]) ndarray[Any, dtype[bool]][source]#

Produce a mask of which points are in the region.

scanspec.regions.find_regions(obj: Any) Iterator[Region[Any]][source]#

Recursively yield Regions from obj and its children.