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

Fix problems reading .mat files #341

Merged
merged 3 commits into from
Dec 28, 2021
Merged

Fix problems reading .mat files #341

merged 3 commits into from
Dec 28, 2021

Conversation

lfarv
Copy link
Contributor

@lfarv lfarv commented Dec 23, 2021

This fixes #340.

  • Workaround a bug (?) in scipy.io.loadmat where empty strings from .mat files disappear,
  • Fix problems with particle objects in .mat, .m and .repr files

@lfarv lfarv added Matlab For Matlab/Octave AT code bug fix labels Dec 23, 2021
@simoneliuzzo
Copy link
Contributor

save/load of a mat file from python does not give errors

@simoneliuzzo
Copy link
Contributor

simoneliuzzo commented Dec 24, 2021

sorry I have to take it back. I tried an other file.

a file saved in python has the RF cavities with DriftPass, and gives this error:

AttributeError: Error in element 136: PassMethod DriftPass is not compatible with Class RFCavity.
{'FamName': 'RFC', 'Length': 1e-12, 'PassMethod': 'DriftPass', 'Voltage': 9000000.0, 'Frequency': 352371625.9975046, 'HarmNumber': 979.0, 'Energy': 6000000000.0, 'TimeLag': 0.0}

I think the problem rises when saving a lattice with radiation off (that turns also the cavity off)

@lfarv
Copy link
Contributor Author

lfarv commented Dec 24, 2021

@simoneliuzzo : this is a different problem. The "coherence" test when reading a file is too strict. We'll change that: I agree that DriftPass may be use for any class. For the moment, you can skip the test by adding "check=False" to the arguments of the load function (load_lattice or load_mat).

@lfarv
Copy link
Contributor Author

lfarv commented Dec 24, 2021

@simoneliuzzo: side remark: you should NEVER use lengths like 1.0E-12.

  • for cavities, it's not dramatic: it just adds a half-long drift (0.5E-12) on each side of the the (thin) cavity,
  • for multipoles it's much worse: apart from being about 20 times slower than a thin multipole (slices, drifts and kicks) thus increasing the numerical errors, it may be wrong because some computations like sin(x)/x may be inaccurate for small arguments.

@lfarv
Copy link
Contributor Author

lfarv commented Dec 24, 2021

The coherence test is relaxed so that 'DriftPass' is allowed for any Element class.

@lfarv lfarv merged commit 0021104 into master Dec 28, 2021
@lfarv lfarv deleted the load_save branch December 28, 2021 15:52
lfarv added a commit that referenced this pull request Dec 28, 2021
* Fix problems with Particle objects in .mat files

* Fix problems with Particle objects in .mat, .m and .repr files

* Allow DriftPass on any class when reading a .mat file
@simoneliuzzo
Copy link
Contributor

it works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix Matlab For Matlab/Octave AT code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File save/load not possible
2 participants