Incorrect prefix with recyprocal units when it needs to convert
din14970 opened this issue · 4 comments
I noticed that the scalebar incorrectly handles the prefix for reciprocal units, I noticed this when I was trying to measure distances in a Fourrier transform of an image. My original image has a pixel size of 0.007 nm/pixel, but everything is stored in meters, so 7e-12 m. The scalebar has no problem interpreting this value and puts a scalebar in nm on the image.
To calculate the scale of my Fourrier transform, I take the meters value and convert. My image is 4096x4096 pixels so the scale in the FFT is 1/(7e-12 * 4096)=3.4e7 m^-1/pixel. This is equivalent to 0.034 nm^-1/pixel. When I pass the scale in nm^-1 to the scalebar, it uses the correct nm^-1 units. However, when I pass the scale in m^-1, the scalebar uses Gm^-1.
Might be easily fixed if you associate the reciprical factor with the prefix, line 124 in dimensions.py
Edited it on my own computer and seems to work
the tests in test_dimension were also wrong:
0.02 1/m = 0.0002 1/cm or 20 1/km
0.002 1/m = 2 1/km
Updated them in a second commit
Thank you for finding and fixing the issue. I know release version 0.6.2 with the fix.