Skip to content

Reference Frame Coordinate Transformations #379

Open

Description

@Relm-Arrowny

Part of #373 Live plotting:

Implement coordinate transformation mathematics to align and translate different reference frames (e.g., optical webcam, sample stage motor limits, reconstructed ptychography) into a universal reference frame.

Goals

Acceptance criteria : What journeys should the user be able to complete to consider your feature done
Be as specific as you can, check them off once they work. Add more if you find more requirements during development. Issue should only be considered done after all of them are checked

  • Spatial Alignment: Multi-layered scans, camera feeds, and stage limits overlay with perfect spatial overlap.
  • Consistent Calibration: Transforming physical stage movements into pixel coordinates and vice versa produces accurate mapping for visualisation and future scans definition.

Tasks

base on the goals, deduce the tasks required. check them off once they're done

Caution

Decision needed

  • Universal Frame definition: Define the a reference frame (X-ray beam frame) as the single source of truth coordinate system.
  • Transformation: Implement translation, scaling, and rotation matrices to map external coordinate spaces to the reference frame.

Activity

  1. changed the title [-]Universal Beam Coordinate System, establish the X-ray beam frame as the single source of truth coordinate system?[/-] [+]Reference Frame Coordinate Transformations[/+] on Sep 9, 2026
  2. DanPorter commented on Sep 16, 2026

    @DanPorter
    Collaborator

    An example set of transformations might look like:

    Back end

    1. Sample motor positions, x,y,z
    2. Convert x,y,z to lab (x-ray incident beam) image/grid frame x',y'
    3. Convert lab frame to energy independent frame (zoom)
      Pass to front end
    4. apply universal plot corrections (e.g. rotate by 90 degrees)
    5. apply choice of image coordinate system (user choice of origin)
    6. apply layer specific corrections (user defined delta-x, delta-y)
    7. Convert to pixel positions on surface plot
  3. NKatti2011 commented on Sep 16, 2026

    @NKatti2011
    Collaborator

    Notes from a meeting with David Burn & @EmsArnold, 15/09/2026.

    Summary

    The model is a series of transformation matrices. Each layer corresponds to a
    stage or to a drift factor, and a coordinate is expressed by choosing how far down that
    series you go. A reference frame is chosen per measurement, and the UI should let
    the user toggle between frames, sample coordinates vs motor coordinates, for example.
    Commissioning needs to expose more depth in the matrix series than a normal experiment does.

    • The instrument was designed to rotate rather than translate under temperature
      change. The centre of that rotation is not necessarily inside the region of interest.
    • Some experiments tilt and rotate the sample.
    • The instrument is deliberately not mounted on granite. Adding mass to chase mechanical
      stability was tried and did not work, so the design instead accepts wobble and corrects
      for it.

    Drift factors include temperature, time, rotation and translation. The correction is a
    product of matrices. Users should not be doing drift correction by hand during an
    experiment; it is intended to run as a feedback loop.

    Origin

    Users start with a dummy coordinate system. A user will define an origin at least once
    per sample, and plausibly more often than that.

    Where the maths lives.

    The same transformation maths is needed in at least three places, at three very
    different rates:

    1. Low-level controls / hardware. Feedback loop may run at kHz across 12
      interferometers, PandABoxes and motion controllers. A transformation matrix is fixed
      here during commissioning.
    2. UI and UI software. High-level matrices are fed back from the UI. A user's
      offsets become real-space transformations and motor moves.
    3. Processing pipeline. Users will want to supply offsets for reconstructed images
      after processing, in order to find the ROI. This is the "alignment" stage.

    This means the maths package cannot be bolted onto the Davidia server.
    It needs to be a standalone library that controls, the UI and
    the processing pipeline can all consume. Which individual matrices sit in hardware and
    which sit in software is unresolved, and a follow-up meeting with low-level controls is
    needed to settle it
    .

    Architecture sketch from the meeting

    [UI] ------> [UI Software] --------> [Device Controllers] ------> [Devices]
    
     user input                          system input
                                         (matrix fixed at commissioning)
    
     [M_sample][M_temp]        -------->    [M_?][M_complex]
    

    Also wanted

    • Pixel to real-space translation, with an indication of it visible in the UI. i19 -> Thanks for providing link @EmsArnold
      reportedly already has a pixel-to-real-stage-position function worth looking at. This
      may deserve its own issue.
    • An x-y-z scanner for the sample as a virtual device, z included, plus a correction
      factor, driven by a software feedback loop. A virtual device already exists. Software
      feeds it scan positions; the hardware side does a substantial amount of coordinate
      transformation.

    Scope to define

    • The frame and offsets need to be persisted so the processing-level
      maths can reproduce them. We need to confirm with whoever owns the metadata what that record
      should look like, and whether Tiled is the right home for it (likely).
    • Which matrices must live in hardware and which in software: requires a meeting
      with low-level controls
    • Forward mapping: reference frame to pixel
    • Inverse mapping: pixel to real space (needed by Interactive ROI Selection Tool #380; i19 reportedly has a
      pixel-to-real-stage-position function to look at)
    • Stage configuration needs to be saved somewhere with global access: beamline server or
      DAQ config server. We need to decide what else besides stage configuration lives there.
    • Relationship to existing reshaping code: locate Hiran's and decide whether this is
      the same package
    • Relationship to SWIFT's trajectory maths: consume or duplicate
    • Ownership
  4. DanPorter commented on Sep 16, 2026

    @DanPorter
    Collaborator

    Thanks @NKatti2011, that's great.
    Was there any discussion about where the transformation matrices would be stored? The commissioning transformations may be hard-coded into the controllers, but anything like M_sample and M_temp will be defined during the experiment but need to be persistent between users. One option could be to store these in tiled or another one to store the data in a specific database service (which we would need to make or request).
    Either way, it is related to #389

  5. NKatti2011 commented on Sep 16, 2026

    @NKatti2011
    Collaborator

    @DanPorter No this hasnt been decided yet and probably needs to be hashed out in this next meeting or in a further meeting with people for controls and analysis. Likely Tiled but writing in data in the shape we want is something that is being developed by Core within Nexus-writer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Data VisDecision neededDecision is required before this is ready to be scoped

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions