Reputation: 1
Code:
import subprocess
from PIL import Image
import colorsys
import numpy as np
for t in range(1,49):
in_file_name=f"Pf{t:02d}.bin"
subprocess.run(f"sz3 -f -i /home/jzz/compress/SDRBENCH-Hurricane-ISABEL-100x500x500/P/{in_file_name} -z /home/jzz/simulation/dataset/sz3/temp.sz3 -o /home/jzz/simulation/dataset/sz3/temp.sz3.bin -M REL -R 0.1 -3 500 500 100",shell=True,check=True)
in_data=np.fromfile(f"/home/jzz/compress/SDRBENCH-Hurricane-ISABEL-100x500x500/P/{in_file_name}",dtype=np.float32).reshape(100,500,500)
out_data=np.fromfile(f"/home/jzz/simulation/dataset/sz3/temp.sz3.bin",dtype=np.float32).reshape(100,500,500)
for h in range(100):
print(h)
mx=max(in_data[h,:,:].max(),out_data[h,:,:].max())
mn=min(in_data[h,:,:].min(),out_data[h,:,:].min())
data01=(in_data[h,:,:]-mn)/(mx-mn)
image=(np.array([list(colorsys.hsv_to_rgb(data01[i,j],1,1)) for i in range(500) for j in range(500)]).reshape(500,500,3)*255).astype(np.uint8)
image=Image.fromarray(image)
image.save(f"/home/jzz/simulation/dataset/sz3/ISABEL_P_t={t}_h={h}_x.png")
data01=(out_data[h,:,:]-mn)/(mx-mn)
image=(np.array([list(colorsys.hsv_to_rgb(data01[i,j],1,1)) for i in range(500) for j in range(500)]).reshape(500,500,3)*255).astype(np.uint8)
image=Image.fromarray(image)
image.save(f"/home/jzz/simulation/dataset/sz3/ISABEL_P_t={t}_h={h}_y.png")
subprocess.run(f"rm /home/jzz/simulation/dataset/sz3/temp.sz3",shell=True)
subprocess.run(f"rm /home/jzz/simulation/dataset/sz3/temp.sz3.bin",shell=True)
When I use 'python my_program.py' in the terminal, it starts to generate some images (which are correct) and then the program quit or the whole terminal get stuck without warnings or errors. Sometimes it gives a segment fault.
There are sufficient memory and space of hard disk.
Commenting out image.save won't help.
Commenting out image.save and image=Image.fromarray won't help.
Commenting out image.save, image=Image.fromarray and image=(np.array... make the program run until finish.
Upvotes: 0
Views: 32
Reputation: 1
The problem is solved by changing in_data[h,:,:].max()
into np.max(in_data[h,:,:])
Note: I am not quite sure why this can be a solution.
Upvotes: 0