Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions sdf_helper/HDF5_plotter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import h5py
import numpy as np
import matplotlib.pyplot as plt

f = h5py.File('data.h5','r') #開啟h5檔案
print(f.keys()) #可以檢視所有的主鍵
domain = f['Electric_Field_Ey'][:] #取出主鍵為data的所有的鍵值
f.close()

plt.contourf(domain)
plt.colorbar()
plt.show()
plt.clf()
30 changes: 30 additions & 0 deletions sdf_helper/SDF2HDF5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 6 22:40:44 2021

@author: Jennan Wang
"""

import sdf_helper as sh
import h5py

sdf_file_name = '0004.sdf' #sdf file name, assume call it at same folder for sdf
data = sh.getdata(sdf_file_name) #get attribute string
attri_str = str(sh.list_variables(data)).splitlines() #string processing...
variable_str_list = [] #string processing...
h5f = h5py.File(str(sdf_file_name+'.h5'), 'w') #open hdf5 file
h5f_data = [] #container for hdf5 data

for i in attri_str:
variable_str_list.append((i.split(' '))[0]) #string processing...
exec("h5f_data.append(data.%s.data)" % (variable_str_list[-1]))
#put sdf data to container for hdf5 data by calling it's variables
h5f.create_dataset(variable_str_list[-1], data=h5f_data[-1]) #write to hdf5 file

h5f.close() #close hdf5 file






6 changes: 6 additions & 0 deletions sdf_helper/sdf_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2042,13 +2042,19 @@ def subarray(base, slices):

def list_variables(data):
dct = data.__dict__
str_variables = ''
for key in sorted(dct):
try:
val = dct[key]
print('{} {} {}'.format(key, type(val),
np.array2string(np.array(val.dims), separator=', ')))
str_variables += '{} {} {}'.format(key, type(val),
np.array2string(np.array(val.dims), separator=', '))
str_variables += '\n'
except:
return str_variables
pass
return str_variables


def escape_latex(string):
Expand Down