.H5 Load Error

87 views
Skip to first unread message

David Collins

unread,
Feb 7, 2023, 5:01:55 PM2/7/23
to scalismo
I am trying to work with a .h5 file created externally. The file should be sound and I can load it in e.g. Matlab. But when I try loading it in scalismo (either through the GUI or using code) I get an error message. 

Using the GUI it says: "ERROR: Expected H5ScalarDS when reading attrbiute"

When trying with code, the error says "java.lang.Exception: Expected H5ScalarDS when reading attribute
  at scalismo.io.HDF5File.readStringAttribute(HDF5Utils.scala:62)
  at scalismo.io.StatismoIO$$anonfun$5.apply(StatismoIO.scala:118)
  at scalismo.io.StatismoIO$$anonfun$5.apply(StatismoIO.scala:116)
  at scala.util.Success.flatMap(Try.scala:231)
  at scalismo.io.StatismoIO$.readStatismoMeshModel(StatismoIO.scala:116)
  ... 30 elided"

What can I do to solve this? 

David Collins

unread,
Feb 8, 2023, 4:27:02 AM2/8/23
to scalismo
Just to add that this file is from a large-scale and well known cardiac imaging research project, so I think the issue lies with scalismo, not the file itself 

David Collins

unread,
Feb 8, 2023, 7:01:17 AM2/8/23
to scalismo
Here is a link to the download options for the H5 files I am trying to utilise (bottom of page). Neither will load for me 

On Tuesday, February 7, 2023 at 10:01:55 PM UTC David Collins wrote:

Max

unread,
Feb 8, 2023, 7:57:15 AM2/8/23
to scalismo
Hi,

you cannot load this file with Scalismo.

Scalismo requires a special structure of the H5 file, see https://edoc.unibas.ch/29542/1/IJ_871_1_statismo_ij.pdf, Appendix A.1.
In order to load the H5 file from the website you first have to make sure that the file structure is compatible with what Scalismo requires (ie, you need to create a new H5 file in the Scalismo format and fill in the information from the downloaded file). If you want to load this model as a PDM, you also have to provide connectivity information (not just a point cloud), which, unfortunately, cannot be downloaded from the website you shared.

Hope that helps!
Max

David Collins

unread,
Feb 8, 2023, 9:03:21 AM2/8/23
to scalismo
Hi Max, 

Thanks, that's really helpful. Would creating a new h5 file in the format required for scalismo be a trivial or particularly difficult task? I don't think the course made this incompatibility issue particularly obvious and so I was unaware this would be an issue. Unfortunately, th cardiac atlases I've referred to are an important starting point for a project I'm involved in, as I need to use it to fit it to my own cardiac model data. 

Best wishes, 

Dave

Max

unread,
Feb 8, 2023, 11:49:04 AM2/8/23
to scalismo
Hi Dave,

no, that's not an issue. You can do this for example using Python and h5py (https://docs.h5py.org/en/stable/). However, you would need a triangulation for the mean shape.

Best
Max

David Collins

unread,
Mar 8, 2023, 8:27:05 AM3/8/23
to scalismo
Hi Max, 

I've really been trying to delve deeper to convert the h5 file I shared into an appropriate format that scalismo will accept but I am really struggling to do it. Do you know any step by step resources or code you could point me toward for achieving this? I am starting to run low on time! Thank you. 

Dave

Marcel Luethi

unread,
Mar 8, 2023, 11:47:46 AM3/8/23
to David Collins, scalismo
Hi David,

Have you tried to compare the file that you produce with a valid scalismo h5 file? You can download one here: https://shape-the-world.org/models/vertebra-models/

If you open both your and the downloaded file in hdfview, it should be easy to spot the difference. I assume that the problem is that you forgot to specify the attributes for the dataset or groups.

Best regards,

Marcel


--
You received this message because you are subscribed to the Google Groups "scalismo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalismo+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalismo/63fb31b3-f5ff-4c52-a507-fdbbe90bf83an%40googlegroups.com.

David Collins

unread,
Mar 9, 2023, 8:42:35 AM3/9/23
to scalismo
Thank you so much for the hdfview pointer - its super useful and I am now reconfiguring my h5 file to mirror the example you gave! Does scalismo require that the h5 file be meshed? Currently it exists as a point cloud of vertices in 3D space. I am looking into solutions to mesh it but so far the results are sub-optimal and so I wanted to know if scalismo needs a mesh? I think this is the only barrier now to being able to use the file for my work. 

Thank you! 

Dave

Marcel Luethi

unread,
Mar 9, 2023, 11:06:01 AM3/9/23
to David Collins, scalismo
Glad to hear that hdf5 turns out to be helpful.
It is possible to work with models that only consist of points only. 

You can find attached an example h5 models, that shows you the format.
In the current version of scalismo, it cannot easily be visualized, but this should be fixed in the next version (which will appear very soon).

Best regards,
Marcel


point-cloud-model.h5

David Collins

unread,
Mar 9, 2023, 12:47:20 PM3/9/23
to scalismo
Many thanks Marcel, this is really helpful. I've tried loading the point cloud h5 model you provided in hdfviewer but I get an error message telling me its an unsupported file type. I am doing something wrong? I'm wondering I can just omit the 'cells' dataset under the 'representer' group when defining the model? 

Best wishes, 

Dave

Marcel Luethi

unread,
Mar 9, 2023, 1:33:45 PM3/9/23
to David Collins, scalismo
I forgot to mention:  You need to use the following method to read it:
StatisticalModelIO.readStatisticalPointModel3D(YOUR_H5_FILE).

It might also work to leave out the cell, but even if it works this does not seem to be a good idea, because many of the operations on meshes expect cells.

Best regards,

Marcel


David Collins

unread,
Mar 9, 2023, 1:37:29 PM3/9/23
to scalismo
Thanks Marcel. 

I meant that I can't view it in hdfViewer to inspect its structure so I can match it with my own .h5 file. Am I doing something wrong? 

For the cell dataset in the .h5 file, I assumed this referred to the indexes for the mesh faces/triangles and so if the .h5 file was a point cloud file, this could be left out? Without being able to mesh my point cloud .h5 file, this is the only way I am able to proceed with my study. 

Thanks so much for the help so far!

Best wishes, 

Dave

Marcel Luethi

unread,
Mar 9, 2023, 1:53:45 PM3/9/23
to David Collins, scalismo
Strange, works well on my side. Maybe the file got corrupted? Can you try downloading it using this link:

Best regards,
Marcel

David Collins

unread,
Mar 9, 2023, 2:10:01 PM3/9/23
to scalismo
Thanks Marcel, this now works and I can inspect the structure to replicate! 

In the meantime I will try to figure out a way to create an acceptable mesh from the file (matlab and meshlab both not doing a good enough job currently). If I can't create a mesh from it, I may just have to see how far I can go with analysis using the point cloud version of the h5 file. Although from what you said before, it doesn't sound like I will be able to get very far with it :(. 
How long is it until the new release where that won't be an issue? 

Best wishes, 

Dave

Marcel Luethi

unread,
Mar 9, 2023, 2:29:54 PM3/9/23
to David Collins, scalismo
You can already use it in the current version, but you need a workaround. A snapshot release that supports it should be available within a few days and the final release maybe in 2-3 weeks time (depending on how many bugs we find in the meantime).

Best regards,
Marcel

David Collins

unread,
Mar 9, 2023, 4:34:20 PM3/9/23
to scalismo
Ah amazing, look forward to the release! Will there be some accompanying release notes/tutorial detailing how to work with these model types (apologies if they are already there and I've missed them!)? 

Best wishes, 

Dave

Reply all
Reply to author
Forward
0 new messages