Skip to content

Commit c22e027

Browse files
Fix import bug; add imageio dependency
1 parent bb42d74 commit c22e027

File tree

2 files changed

+60
-25
lines changed

2 files changed

+60
-25
lines changed

pyself/model2d.py

+58-24
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44

55
# Other SELF modules
6-
import self.geometry as geometry
6+
import pyself.geometry as geometry
77

88
class model:
99
def __init__(self):
1010
self.solution = None
1111
self.pvdata = None # Pyvista data
1212
self.varnames = None
1313
self.varunits = None
14-
self.nvar = 0
1514
self.geom = geometry.semquad()
1615

1716
def load(self, hdf5File):
@@ -26,26 +25,56 @@ def load(self, hdf5File):
2625

2726
if 'controlgrid' in list(f.keys()):
2827

29-
s = f['controlgrid/solution']
30-
self.solution = []
31-
i = 0
32-
for k in s.keys():
33-
if k == 'metadata':
34-
for v in s[f"{k}/name"].keys():
35-
self.solution.append( {"name":s[f"{k}/name/{v}"][()][0].decode('utf-8'), "units":s[f"{k}/units/{v}"][()][0].decode('utf-8'), 'data': None} )
36-
self.nvar = len(self.solution)
28+
controlgrid = f['controlgrid']
29+
for group_name in controlgrid.keys():
30+
31+
if( group_name == 'geometry' ):
32+
continue
33+
34+
group = controlgrid[group_name]
35+
# Create a list to hold data for this group
36+
setattr(self, group_name, [])
37+
group_data = getattr(self, group_name)
38+
print(f"Loading {group_name} group")
39+
40+
# Load metadata information
41+
if( 'metadata' in list(group.keys()) ):
42+
for v in group[f"metadata/name"].keys():
43+
44+
name = group[f"metadata/name/{v}"].asstr()[()][0]
45+
try:
46+
units = group[f"metadata/units/{v}"].asstr()[()][0]
47+
except:
48+
units = "error"
49+
50+
group_data.append({
51+
"name": name,
52+
"units": units,
53+
'data': None
54+
})
3755
else:
38-
d = s[k]
39-
N = d.shape[2]
40-
# Find index for this field
41-
i=0
42-
for sol in self.solution:
43-
if sol['name'] == k:
44-
break
45-
else:
46-
i+=1
47-
48-
self.solution[i]['data'] = da.from_array(d, chunks=(self.geom.daskChunkSize,N,N))
56+
print(f"Error: /controlgrid/{group_name}/metadata group not found in {hdf5File}.")
57+
return 1
58+
59+
for k in group.keys():
60+
k_decoded = k.encode('utf-8').decode('utf-8')
61+
if k == 'metadata':
62+
continue
63+
else:
64+
print(f"Loading {k_decoded} field")
65+
# Load the actual data
66+
d = group[k]
67+
N = d.shape[2]
68+
69+
# Find index for this field
70+
i = 0
71+
for sol in group_data:
72+
if sol['name'] == k_decoded:
73+
break
74+
else:
75+
i += 1
76+
77+
group_data[i]['data'] = da.from_array(d, chunks=(self.geom.daskChunkSize, N, N))
4978

5079
self.generate_pyvista()
5180

@@ -97,8 +126,13 @@ def generate_pyvista(self):
97126

98127
# Load fields into pvdata
99128
k = 0
100-
for var in self.solution:
101-
self.pvdata.point_data.set_array(var['data'].flatten(),var['name'])
102-
k+=1
129+
for attr in self.__dict__:
130+
if not attr in ['pvdata','varnames','varunits','geom']:
131+
controlgroup = getattr(self, attr)
132+
#print(f"Loading {attr} into pvdata")
133+
for var in controlgroup:
134+
# print(f"Loading {var['name']} into pvdata")
135+
self.pvdata.point_data.set_array(var['data'].flatten(),var['name'])
136+
k+=1
103137

104138
print(self.pvdata)

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
packages=['pyself'],
1212
install_requires=['h5py>=3.7.0',
1313
'dask',
14-
'pyvista'],
14+
'pyvista',
15+
'imageio[ffmpeg]'],
1516
classifiers=[
1617
'Development Status :: 1 - Planning',
1718
'Intended Audience :: Science/Research',

0 commit comments

Comments
 (0)