Plotting surface displacement magma-2d example- help with output files

I want to plot the vertical displacement at the surface (the positive y boundary) at the end of the simulation. Based on the nomenclature and the pylith visualization I believe that data is stored here: step01_inflation-bc_ypos.h5 and step01_inflation-bc_ypos.xmf. Is this correct? What is the best way to extract the information I’m looking for?

I am new to working with hdf5 files. I’ve gotten as far as locating what I believe is the data I want in matlab using

h5disp(‘step01_inflation-bc_ypos.h5’)

data=h5read(“step01_inflation-bc_ypos.h5”,“/vertex_fields/displacement”)

However, I am unsure which rows/columns correspond the the information I’m looking for. Or if I’m even looking in the right place. Please advise.

The PyLith User Guide provides a general description of the HDF5 format.

You will need the geometry/vertces array to get the coordinates of the points. The second dimension of the displacement array matches the order of the vertices. So geometry/vertices[i,:] are the coordinates of vertex i. The corresponding displacements are at displacement[:,i,:]. displacement[i,j,k] gives component k (0=x, 1=y, 2=z) displacement of vertex j at time step i.

To get vertical surface displacement, read both geometry/vertices and displacement from the same .h5 file. Use the vertex coordinates to select the boundary vertices (for example, rows where the y-coordinate is at or near the maximum y), then index displacement at the final time step for those vertices and component 1 (vertical, with 0=x, 1=y, 2=z). In MATLAB, remember h5read uses 1-based indexing and may order dimensions as stored, so check size(displacement) before indexing. The ypos file is plausible, but confirming against the vertex coordinates avoids picking the wrong boundary.

Thank you both very much for your response. I believe I am getting closer to figuring it out. I have put together what I thought was reading the file correctly, but a glance at my plot shows that it clearly is not.

I appear to be reading the x-coordinates correctly (my mesh is 30 km wide). However, the displacement doesn’t make sense. It should look more like a straight or slightly curved line.

Below is my simple matlab script to read the file:

coordinates=h5read(‘step01_inflation-bc_ypos.h5’,‘/geometry/vertices’); % coordinates of points

displacements=h5read(‘step01_inflation-bc_ypos.h5’,‘/vertex_fields/displacement’); % displacements

displacement_final_time=displacements(1,:,51); % displacement at final time step

figure(1)

plot(coordinates(1,:),displacement_final_time)

xlabel(‘x-dimension of grid (m)’)

ylabel(‘displacement at final time?’)

What do you mean by vertex coordinates? In my case, is that the 0 - 30 km distance?

The vertices are not sorted by the x coordinate so the line is jumping back and forth in the x direction. If you plot just the points (linestyle = “.”) you should get a points that match the curve. To plot a curve, get the indices corresponding to the order of the x coordinates and use it to reorder the displacements. In Python this can be done using numpy

indices = numpy.argsort(vertices[:,0])
pyplot.plot(coordinates[indices,0], displacement[-1,indices,0])

Thank you both so much for your help. I was able to figure out how to display the data I wanted. I am excited to use this in my project!