SciDataTool
SciDataTool copied to clipboard
[CO] get_along and units
Hello,
I got some DataND objects with 'Speed' and 'Torque' axis and e.g. 'Current' array data. I wanted to 'export_along' this data but had an issue that is due to some unit issue with get_along method, I think. If I use 'get_along' without any unit argument, the returned axis will have 'SI' as their units while the original units where 'rpm' and 'Nm'. My expactation would be to get the original units by default. At least the returned axis units shouldn't be 'SI'. On the other hand, I don't know how to explicitly set the desired unit with more than one axis. In the tutorials there is only the 1D case meantioned (e.g. unit="Speed{rpm}").
So any help on this issue is greatly appreciated.
Best regards, Sebastian
Hello,
I agree that the original units should be returned. I will have a look at what is going on.
Concerning requiring a specific unit for axes, the syntax is the following:
data.export_along("speed{rpm}", "torque{Nm}")
Best regards, Hélène
... here is some code to reproduce this issue more easily.
from numpy.random import rand
from SciDataTool import Data1D, DataND
speed = rand(10,1)
torque = rand(20,1)
data = rand(10,20)
Speed = Data1D(name="Speed", unit="rpm", values=speed, is_components=True)
Torque = Data1D(name="Torque", unit="Nm", values=torque, is_components=True)
axes = [Speed, Torque]
dataND = DataND(axes=axes, values=data)
Concerning requiring a specific unit for axes, the syntax is the following: data.export_along("speed{rpm}", "torque{Nm}")
So the units argument is somehow needless?!
It is used for the field itself, e.g. if you want to change the unit of your current.
Hello @helene-t
thank you for your quick response. This was very helpful.
Still I don't get the data exported, no matter what the axes orientation is, e.g. speed, torque = rand(10,1), = rand(20,1), speed, torque = rand(1,10), = rand(1,20) or speed, torque = rand(1,10), = rand(20,1).
The error messages are eighter
File "C:\Program Files\Python38\lib\site-packages\SciDataTool\Methods\DataND\export_along.py", line 159, in export_along
matrix = np.column_stack((results[axes_list_new[0].name].T, field))
File "<__array_function__ internals>", line 5, in column_stack
File "C:\Program Files\Python38\lib\site-packages\numpy\lib\shape_base.py", line 656, in column_stack
return _nx.concatenate(arrays, 1)
File "<__array_function__ internals>", line 5, in concatenate
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 1 and the array at index 1 has size 10
or
File "C:\Program Files\Python38\lib\site-packages\SciDataTool\Methods\DataND\export_along.py", line 135, in export_along
axes_list_new[0].name
IndexError: list index out of range
What am I doing wrong???
Best regards, Sebastian
The problem comes from the shape of the axes arrays ((10,1) or (1,10)). Data1D.values expects 1D arrays or lists, but accepts (n,1) shapes. I should add a "squeeze" in the export_along" method to avoid problems.
In the meantime, you can squeeze your data before creating the Data1D object, or use rand(10).