Git Product home page Git Product logo

Comments (5)

lfarv avatar lfarv commented on June 3, 2024

Hello @lnadolski,

In Matlab, atloadlattice works as expected with V7.3 lattice files: load (and consequently atloadlattice) automatically detects the format.

However in python, we rely on SciPy which state: "v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.". In addition, SciPy mentions:

"You will need an HDF5 Python library to read MATLAB 7.3 format mat files. Because SciPy does not supply one, we do not implement the HDF5 / 7.3 interface here."

Decoding the private Matlab structure starting with a plain HDF5 reader looks difficult. So for file exchange with python, you must stick to the V7 format.

from at.

lnadolski avatar lnadolski commented on June 3, 2024

Dear @lfarv

This is good to know.
Maybe we should add a note in pyAT.

from at.

lfarv avatar lfarv commented on June 3, 2024

I found the hdf5storage project which claims to support V7.3 .mat files. The project does not seem to be alive any more, but it may work. I would not like to have PyAT depend on this package, but if it works (still to be checked), we could have PyAT check that if the package is available (the user explicitly installed it), it will use it, otherwise it will stick to SciPy.

from at.

lfarv avatar lfarv commented on June 3, 2024

Forget hdf5storage, I could not make it work: it hangs forever…

from at.

T-Nicholls avatar T-Nicholls commented on June 3, 2024

Hello both,

When I try and load a v7.3 .mat lattice file using at.load_lattice I get the error: NotImplementedError: Please use HDF reader for matlab v7.3 files, e.g. h5py. To me that's clearly telling the user that the v7.3 file is the issue; however, if we wanted to be more specific we could catch that error from scipy and reraise it with a message telling the user that they need to save the lattice file in Matlab using an earlier version.

Alternatively, if there is significant demand, we could write new functions specifically to support v7.3 files. I briefly tried loading a v7.3 file using h5py and it seemed feasible as it, at least partially, decodes the data but it's significantly more convoluted than using scipy:

>>> import h5py
>>> f = h5py.File("test_73_lattice.mat", "r")
>>> ring = f["RING"][0]
>>> len(ring)
2190
>>> f[ring[0]].keys()
<KeysViewHDF5 ['Class', 'Energy', 'FamName', 'Length', 'Limits', 'PassMethod']>
>>> list(f[ring[1]]['Length'])
[array([4.38])]
>>> "".join(chr(i) for i in numpy.asarray(f[ring[12]]['FamName']).flatten())
'Q3D'
>>> list(f[ring[12]]['PolynomB'])
[array([0.]), array([-0.9750889])]

from at.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.