0

I am working on a project and I do a simulation in a program called Prismatic to get files which I want to use later, Prismatic outputs files in h5 format, which I was able to extract data out of them using Python, the simulation produces an image, which is saved in two data sets (dim1, dim2), each is a numpy array of size 219 and I having trying to create the image from them again but I am not sure how that works, I tried to stack the numpy arrays but I just get a line in the image, I just learned about numpy arrays I don't know much about them yet, can anyone help? that's my code here.

fi = h5py.File('ty.h5')
a = fi['4DSTEM_simulation']['data']['realslices']['annular_detector_depth0000']['dim1'][:]
b = fi['4DSTEM_simulation']['data']['realslices']['annular_detector_depth0000']['dim2'][:]
merge_arr = numpy.stack((a, b), axis=0)
data = Image.fromarray(merge_arr)
if data.mode != 'RGB':
    data = data.convert('RGB')
3
  • An RGB image is an array with shape (n,m,3). What is the shape of your two numpy arrays? Commented Jun 14, 2021 at 3:26
  • when I print their shape I get (219,) for both, and both have the same values for all entries, which I am guessing is because simulation output is symmetric Commented Jun 14, 2021 at 3:28
  • [link]file.io/riS5juuYLNin Commented Jun 14, 2021 at 11:19

1 Answer 1

2

Ok Given your dataset,I managed to find an image.

from matplotlib import pyplot as plt
%matplotlib inline # remove this if you are not using a jupyter notebook
import h5py
# data link https://file.io/riS5juuYLNin

f = h5py.File('ty.h5')

realslice = (f['4DSTEM_simulation']
 ['data']
 ['realslices']
 ['annular_detector_depth0000']
 ['realslice'])[:]

plt.imshow(realslice)
#plt.show() # add this if you are not using a jupyter notebook

enter image description here

The real tools to figure this out were seeing what the keys were at a given level of the file f, as in f.keys() or f['4DSTEM_simulation'].keys() and so on, then looking at the shapes of the items within by exacting the available objects these keys access. Eventually I found one that was an image. I do not know anything about this data so maybe there are more. It seems your original problem isn't actually anything needing solving. Two 246x1 arrays definitely doesn't form an image in a unique way.

Sign up to request clarification or add additional context in comments.

1 Comment

That looks perfect, thank you so much, that is the expected image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.