Selections¶
Region selection system for slicing 3D simulation data into lower-dimensional views.
selections
¶
Region selections: describe sub-regions and produce new FieldDatasets.
PlaneSelection
dataclass
¶
Select a 2D plane from a 3D dataset by slicing along one axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normal
|
str
|
Axis name perpendicular to the plane (e.g. |
required |
index
|
int | None
|
Integer index along the normal axis. |
None
|
Examples:
>>> from pypic.selections import PlaneSelection
>>> import copy
>>> plane = PlaneSelection(normal="z", index=3)
>>> plane.normal
'z'
>>> copy.replace(plane, index=0).index
0
Source code in src/pypic/selections.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
apply(data)
¶
Slice the dataset along the normal axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FieldDataset
|
Input dataset (must contain the |
required |
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Reduced dataset with the normal dimension removed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/pypic/selections.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
BoxSelection
dataclass
¶
Select a rectangular sub-region via integer index ranges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ranges
|
dict[str, tuple[int, int]]
|
Axis name → |
required |
Examples:
>>> from pypic.selections import BoxSelection
>>> import copy
>>> box = BoxSelection(ranges={"x": (1, 5), "y": (0, 3)})
>>> box.ranges["x"]
(1, 5)
>>> copy.replace(box, ranges={}).ranges
{}
Source code in src/pypic/selections.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
apply(data)
¶
Slice the dataset to the specified sub-region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FieldDataset
|
Input dataset. |
required |
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Sub-region with updated grid metadata. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any axis name in |
Source code in src/pypic/selections.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
SphereSelection
dataclass
¶
Mask fields inside or outside a sphere with NaN.
Unlike PlaneSelection and BoxSelection, this
preserves the grid shape — masked points become NaN rather than
being removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
tuple[float, ...]
|
Center point in coordinate units. Length must match the dataset dimensionality (3 for 3D, 2 for a previously sliced 2D dataset). |
required |
radius
|
float
|
Radius in the same coordinate units as center. |
required |
keep
|
str
|
Which region to keep: |
'inside'
|
Examples:
>>> from pypic.selections import SphereSelection
>>> import copy
>>> s = SphereSelection(center=(0.0, 0.0, 0.0), radius=3.375, keep="outside")
>>> s.radius
3.375
>>> copy.replace(s, keep="inside").keep
'inside'
Source code in src/pypic/selections.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
apply(data)
¶
Apply the spherical mask, returning a new FieldDataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FieldDataset
|
Input dataset. |
required |
Returns:
| Type | Description |
|---|---|
FieldDataset
|
Same grid shape, with masked points set to |
Raises:
| Type | Description |
|---|---|
ValueError
|
If center length does not match the dataset dimensionality, radius is not positive, or keep is invalid. |
Source code in src/pypic/selections.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |