Possible issue with plotting after defining units

13 views
Skip to first unread message

Christian Buhl Sørensen

unread,
Jan 7, 2019, 1:32:21 PM1/7/19
to hyperspy-users
I started using hyperspy to work on hyperspectral camera data, and I'm really impressed.

My experimental setup acquires time-resolved images of a light pulse, and I can then do a FFT to see the images at discrete frequencies. That goes something like this:


s = hs.signals.Signal2D(cube)
s.plot()
\\\\
S = s.transpose().fft().transpose()
S.plot()

That works very well. 


When I want to introduce units, I assume that the scale parameter should be the stepsize. Eg. time step between samples or mm on acquisition plane. I define the units using:

s.axes_manager[0].scale_as_quantity = '{:f} ps'.format(𝝙t*1e12)
s.axes_manager[1].scale_as_quantity = '{:f} mm'.format(30/256)
s.axes_manager[2].scale_as_quantity = '{:f} mm'.format(30/255)

But here is the issue:
When I then plot the temporal data, I get a x-axis that has labels in the range [0; 801] (the first dimensionality of the time data), and not [0-16] as I expect. Furthermore, when I drag the cursor line, it moves only a fraction of the cursor displacement on the screen. I.e. when I drag the red cursor line across the entire plot, it only moves about 1/10 as the cursor. 

I assume I'm using the units wrong, but I have not been able to find any pointers on that. 


Cheers,
Christian

Josh Taillon

unread,
Jan 7, 2019, 1:41:37 PM1/7/19
to hypersp...@googlegroups.com
Hi Christian,

You're right that the 'scale' parameter should be the size of each pixel in the given dimension. I'm not exactly sure of the problem in your code, as I have never used our "scale_as_quantity" option. Perhaps there's an unknown bug there. Can you try setting the scale and units separately to see if it works?

i.e. something like:

s.axes_manager[0].scale = timestep*1e12
s.axes_manager[0].units = 'ps'
s.axes_manager[1].scale = 30/256
s.axes_manager[1].units = 'mm'
s.axes_manager[2].scale = 30/255
s.axes_manager[2].units = 'mm'


- Josh

(also, if you'd like more interactive assistance, you can post in the gitter chat room)

--
You received this message because you are subscribed to the Google Groups "hyperspy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hyperspy-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Joshua Taillon

Christian Buhl Sørensen

unread,
Jan 7, 2019, 3:30:51 PM1/7/19
to hyperspy-users
Hi Josh, 

Thank you for your very swift reply. It helped me significantly further. I'm now able to get it to work, properly, with a little tweak. I will document it here, and start an issue on the github, as there is still a problem that persists.

When I set the parameters as per your suggestion, the time and one of the axes scales correctly. The weird effect with the cursor movement is now negated, and I get the expected time-range. However, the axis
 s.axes_manager[1]
is still not scaled, and the aspect ratio of the otherwise square image is skewed. 

If I define 
s.axes_manager[0].scale = timestep*1e12
s.axes_manager[0].units = 'ps'
s.axes_manager[1].scale = 30/256.1
s.axes_manager[1].units = 'mm'
s.axes_manager[2].scale = 30/255
s.axes_manager[2].units = 'mm'
 *Adding the 0.1 to the /256

It works on both axis. 

I've checked the type(s.axes_manager[2].scale), and that shows float, so flawed typecasting is not the problem, when it fails. 



Cheers,
Christian
Reply all
Reply to author
Forward
0 new messages