Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-coordinate data from other sources #4

Closed
4 tasks done
volcan01010 opened this issue Jun 28, 2023 · 2 comments · Fixed by #12
Closed
4 tasks done

Re-coordinate data from other sources #4

volcan01010 opened this issue Jun 28, 2023 · 2 comments · Fixed by #12

Comments

@volcan01010
Copy link
Contributor

volcan01010 commented Jun 28, 2023

Summary

As a TACTool user, I want to be able to recreate point locations from other sources (e.g. Scanning Electron Microscope exports) into TACTool image coordinates so that I can see where those locations lie on the images.

Description

Background

Many analytical instruments provide ways to export point locations as CSV files.
These locations are based on an internal coordinate reference system e.g. microns from the bottom left of the stage.
TACTool stores point locations in pixel coordinates.
When TACTool data are loaded into an instrument, the operator marks the position of the REF points in the instrument and the instrument uses these to convert the other coordinates into instrument coordinate reference system.
Here, we would like to convert data from instrument coordinates into TACTool pixel coordinates so that data points exported from the instrument can be overlain onto the image.

Coordinate conversion

The coordinate conversion needs to map the x, y coordinates of 3 points so that they match the x, y coordinates of 3 other points.
An SEM (or similar) instrument is able to rotate samples and zoom in and out, so the transformation should be a rotation and a stretch.

Matt has a spreadsheet that does the transformation, otherwise we can look it up. I'd be surprised if there isn't already a Python implementation.
I think it is an "affine transformation": http://en.wikipedia.org/wiki/Affine_transformation
Shapely has some functions that should help:

We could write a function that generates the transform function:

@dataclasses.dataclass
class Point:
  x: float
  y: float

def transform_factory(source_ref_points: list[Point], target_ref_points: list[Point]) -> Callable[(Point), Point]
    """Return a function that will transform x, y coordinates to new system.
    ...

The transform function could be df.apply()'d to the analysis points in a CSV by a function like:

def transform_points(input_data: pd.DataFrame, transform: Callable[Point]) -> pd.DataFrame:
    """Transform X, Y coordinates of input data using `transform` function."""
    ...

TACTool implementation

We could have an extra option in the drop down menu - "Re-coordinate CSV".
This could open a dialog that takes a CSV file and an output CSV file name.
It can use that, plus the 3 REF points set on the TACTool canvas (dialog only enabled once they are set?) to convert the input CSV file and write it out into TACTool format, with TACTool pixel-based coordinates.

The source points for the transform come from the input CSV file, while the destination points are the ones in the current TACTool canvas. This means that the recoordinated CSV file has points that match up with the current TACTool canvas.

The user can open that file in a separate TACTool window to check that it works.

Acceptance criteria

  • transform factory function returns a function to do the transform
  • transforming the SEM ref points results in the TACTool ref points
  • TACTool gui has dialog to call function against input and output CSV file
  • GUI function takes TACTool points from current canvas (and requires 3 points to be present
@leorudczenko
Copy link
Contributor

leorudczenko commented Jan 23, 2024

Based on further conversations with Matt, he has said that the easiest workflow for them in terms of re-coordination would be:

  • Load an image
  • Add 3 new reference points which will be the basis of the re-coordination
  • Load an SEM CSV file for re-coordination
    • This process should load the SEM CSV file data as TACtool Analysis Points, retaining just the coordinates and the ID value as they can link the ID value back to the original data if needed
    • Then, it should re-coordinate these points based on the 3 reference points on the canvas
    • Then, it should clear the current canvas and load these newly re-coordinated points onto the canvas
  • Then, the user can add/delete points as needed before the final TACtool CSV export manually

Moreover, he has said that the option to enable/disable the ghost point feature is good and he would like it to stay.

@leorudczenko
Copy link
Contributor

leorudczenko commented Jan 26, 2024

This work is currently being continued on the branch ghost-point to avoid conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants