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

Renishaw reader calculates the scale for the microscope image incorrectly #301

Open
Asharits opened this issue Aug 13, 2024 · 3 comments
Open
Labels
type: bug Something isn't working

Comments

@Asharits
Copy link

Describe the bug

In the Renishaw reader, the scale for the microscope image (WHTL) is being calculated incorrectly for hyperspectral maps. This causes the mapped area (red box) to show up in the wrong area.

To Reproduce

I verified this by comparing images to mapped area in the WiRE versus what Hyperspy is plotting for multiple datasets.

Expected behavior

I am not sure where in the reader this is being calculated but it is an easy fix. In the original metadata for the microscope image, FocalPlaneXYOrigins contains the origin for X and Y. FocalPlaneXResolution and FocalPlaneYResolution contains the length of the image. These values just need to be added to the origin values and then divided by the image shape to obtain the correct scale.

I tested this out on some of my datasets and it fixed the scale and the red box was now in the correct place.

Python environment:

  • RosettaSciIO version: 0.6
  • Python version: 3.11.8
  • HyperSpy version: 2.1.1
@Asharits Asharits added the type: bug Something isn't working label Aug 13, 2024
@ericpre
Copy link
Member

ericpre commented Aug 13, 2024

Are you saying that the offset and scale of the microscope image are incorrect but the hyperspectral maps are correct?

The scale and offset of the microscope image are calculated in

def _parse_axes_from_metadata(exif_tags, sizes):
# return of axes must not be empty, or dimensions are lost
# if no exif_tags exist, axes are set to a scale of 1 per pixel,
# unit is set to None, hyperspy will parse it as a traits.api.undefined value
offsets = [0, 0]
fields_of_views = [sizes[1], sizes[0]]
unit = None
if exif_tags is not None:
# Fallback to default value when tag not available
offsets = exif_tags.get("FocalPlaneXYOrigins", offsets)
# jpg files made with Renishaw have this tag
fields_of_views = exif_tags.get("FieldOfViewXY", fields_of_views)
unit = FocalPlaneResolutionUnit_mapping[
exif_tags.get("FocalPlaneResolutionUnit", unit)
]
axes = [
{
"name": name,
"units": unit,
"size": size,
"scale": fields_of_views[i] / size,
"offset": offsets[i],
"index_in_array": i,
}
for i, name, size in zip([1, 0], ["y", "x"], sizes)
]
return axes

And what it does seems to be consistent with your description of how it should be calculated.

As I remember, the data that I have doesn't have this issue. Can you share files and screenshots?

@Asharits
Copy link
Author

Asharits commented Aug 14, 2024

Hmm, I wonder why it isn't working for me. Below is a screenshot of the same dataset from WiRE and in Hyperspy. You can see the map area does not match up.

WiRE Screenshot
Screenshot 2024-08-14 141404

Hyperspy Screenshot
Screenshot 2024-08-14 111531

@Asharits
Copy link
Author

To me it looks like an issue with the way scale is calculated using FieldOfViewXY. Maybe there is a difference depending on the version of WiRE? I am on 5.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants