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

pyat fails to load .mat from matlab with element VariableMultipole #838

Open
oscarxblanco opened this issue Oct 2, 2024 · 0 comments
Open
Labels
bug Python For python AT code

Comments

@oscarxblanco
Copy link
Contributor

Dear all,
I get the following error when loading a .mat file saved in matlab.

>>> ring = at.load_mat('ring.mat')
Traceback (most recent call last):
  File "/home/oblanco/Documents/public/progs/pyenv/pyenvat/lib/python3.11/site-packages/at/lattice/elements.py", line 296, in __setattr__
    value = self._conversions.get(key, _nop)(value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: only length-1 arrays can be converted to Python scalars

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/oblanco/Documents/public/progs/pyenv/pyenvat/lib/python3.11/site-packages/at/load/matfile.py", line 202, in load_mat
    return Lattice(
           ^^^^^^^^
  File "/home/oblanco/Documents/public/progs/pyenv/pyenvat/lib/python3.11/site-packages/at/lattice/lattice_object.py", line 191, in __init__
    super(Lattice, self).__init__(elems)
  File "/home/oblanco/Documents/public/progs/pyenv/pyenvat/lib/python3.11/site-packages/at/lattice/lattice_object.py", line 1478, in params_filter
    for elem in elem_filter(params, *args):
  File "/home/oblanco/Documents/public/progs/pyenv/pyenvat/lib/python3.11/site-packages/at/load/matfile.py", line 140, in ringparam_filter
    for elem in elem_iterator(params, *args):
  File "/home/oblanco/Documents/public/progs/pyenv/pyenvat/lib/python3.11/site-packages/at/load/matfile.py", line 105, in _matfile_generator
    yield Element.from_dict(kwargs, index=index, check=check, quiet=quiet)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/oblanco/Documents/public/progs/pyenv/pyenvat/lib/python3.11/site-packages/at/load/utils.py", line 365, in element_from_dict
    element = cls(*(arg for arg in elem_args if arg is not None), **elem_dict)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/oblanco/Documents/public/progs/pyenv/pyenvat/lib/python3.11/site-packages/at/lattice/variable_elements.py", line 84, in __init__
    AmplitudeB = self._set_params(AmplitudeB, mode, 'B', **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/oblanco/Documents/public/progs/pyenv/pyenvat/lib/python3.11/site-packages/at/lattice/variable_elements.py", line 122, in _set_params
    self._set_sine(ab, **kwargs)
  File "/home/oblanco/Documents/public/progs/pyenv/pyenvat/lib/python3.11/site-packages/at/lattice/variable_elements.py", line 132, in _set_sine
    setattr(self, 'Frequency' + ab, frequency)
  File "/home/oblanco/Documents/public/progs/pyenv/pyenvat/lib/python3.11/site-packages/at/lattice/elements.py", line 299, in __setattr__
    self.FamName, key, exc),)
    ^^^^^^^^^^^^
AttributeError: 'VariableMultipole' object has no attribute 'FamName'

While checking the file content with scipy.io.loadmat I see it is saved, but, pyat doesn't see it.

>>> r['THERING1'][3][0][0][0]['FamName']
array(['KIDDK'], dtype='<U5')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Python For python AT code
Projects
None yet
Development

No branches or pull requests

1 participant