|
| 1 | +"""Example: Create a sequence transformation mapping x, y -> a, b""" |
| 2 | + |
| 3 | +from ome_zarr_models._v06.coordinate_transforms import ( |
| 4 | + Axis, |
| 5 | + CoordinateSystem, |
| 6 | + Scale, |
| 7 | + Translation, |
| 8 | + Sequence, |
| 9 | +) |
| 10 | + |
| 11 | +# Define input coordinate system (x, y) |
| 12 | +input_cs = CoordinateSystem( |
| 13 | + name="xy_space", |
| 14 | + axes=( |
| 15 | + Axis(name="x", type="space", unit="micrometer"), |
| 16 | + Axis(name="y", type="space", unit="micrometer"), |
| 17 | + ), |
| 18 | +) |
| 19 | + |
| 20 | +# Define output coordinate system (a, b) |
| 21 | +output_cs = CoordinateSystem( |
| 22 | + name="ab_space", |
| 23 | + axes=( |
| 24 | + Axis(name="a", type="space", unit="micrometer"), |
| 25 | + Axis(name="b", type="space", unit="micrometer"), |
| 26 | + ), |
| 27 | +) |
| 28 | + |
| 29 | +scale_transform = Scale( |
| 30 | + scale=(2.0, 3.0), |
| 31 | +) |
| 32 | + |
| 33 | +translation_transform = Translation( |
| 34 | + translation=(10.0, 20.0), |
| 35 | +) |
| 36 | + |
| 37 | +sequence_transform = Sequence( |
| 38 | + input="xy_space", |
| 39 | + output="ab_space", |
| 40 | + transformations=(scale_transform, translation_transform), |
| 41 | +) |
| 42 | + |
| 43 | +# Print the sequence |
| 44 | +print("Sequence transformation:") |
| 45 | +print(sequence_transform.model_dump_json(indent=2)) |
| 46 | + |
| 47 | + |
| 48 | +# Get inverse transformation |
| 49 | +inverse_sequence = sequence_transform.get_inverse() |
| 50 | +print("\nInverse sequence:") |
| 51 | +print(f" Input: {inverse_sequence.input}") |
| 52 | +print(f" Output: {inverse_sequence.output}") |
| 53 | +print(f" Transforms: {[t.type for t in inverse_sequence.transformations]}") |
0 commit comments