Skip to content

Commit a2f2fff

Browse files
committed
[Python] Fix FlameBase.set_initial_guess from HDF
1 parent 0a969e5 commit a2f2fff

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

interfaces/cython/cantera/onedim.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ def set_initial_guess(self, *args, data=None, group=None, **kwargs):
106106
:param data:
107107
Restart data, which are typically based on an earlier simulation
108108
result. Restart data may be specified using a `SolutionArray`,
109-
`pandas.DataFrame`, or the path to a previously saved CSV file.
109+
`pandas.DataFrame`, or previously saved CSV or HDF container files.
110110
Note that restart data do not overwrite boundary conditions.
111-
DataFrame input requires a working installation of *pandas*, which
112-
can be installed using pip or conda.
111+
DataFrame input requires a working installation of *pandas*, whereas
112+
HDF input requires an installation of *h5py*. These packages can be
113+
installed using pip or conda (``pandas`` and ``h5py``, respectively).
114+
:param group:
115+
Group identifier within a HDF container file (only used in
116+
combination with HDF restart data).
113117
"""
114118
super().set_initial_guess(*args, data=data, group=group, **kwargs)
115119
if data is None:
@@ -121,14 +125,16 @@ def set_initial_guess(self, *args, data=None, group=None, **kwargs):
121125
arr = data
122126

123127
elif isinstance(data, str):
124-
if data.endswith('.csv'):
128+
if data.endswith('.hdf5') or data.endswith('.h5'):
129+
# data source identifies a HDF file
130+
arr = SolutionArray(self.gas, extra=self.other_components())
131+
arr.read_hdf(data, group=group, subgroup=self.domains[1].name)
132+
elif data.endswith('.csv'):
125133
# data source identifies a CSV file
126134
arr = SolutionArray(self.gas, extra=self.other_components())
127135
arr.read_csv(data)
128136
else:
129-
raise ValueError(
130-
f"'{data}' does not identify CSV file ending with '.csv'."
131-
)
137+
raise ValueError(f"'{data}' does not identify CSV or HDF file.")
132138
else:
133139
# data source is presumably a pandas DataFrame
134140
arr = SolutionArray(self.gas, extra=self.other_components())

0 commit comments

Comments
 (0)