Skip to content

Commit

Permalink
fix: supports the export of empty event
Browse files Browse the repository at this point in the history
  • Loading branch information
rzyu45 committed Jan 2, 2025
1 parent 774cf5c commit 29d928e
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions Solverz/utilities/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,34 @@ def save_result(sol: aesol | daesol, name: str, dir: str = None):
for j in range(Y.var_size[var]):
tempd[var + f'_{j}'] = Y[var][:, j]
Y_dict[var] = pd.DataFrame(tempd)
with pd.ExcelWriter(dir+f'{name}.xlsx', engine='openpyxl') as writer:
with pd.ExcelWriter(dir + f'{name}.xlsx', engine='openpyxl') as writer:
# Write each DataFrame to a different sheet
T.to_excel(writer, sheet_name='Time')
for var, df in Y_dict.items():
df.to_excel(writer, sheet_name=var)
if sol.ie is not None:
te = pd.DataFrame({'te': sol.te})
ie = pd.DataFrame({'ie': sol.ie})
ye = sol.ye
ye_d = dict()
for var in ye.var_list:
tempd = dict()
for j in range(ye.var_size[var]):
tempd[var + f'_{j}'] = ye[var][:, j]
ye_d[var] = pd.DataFrame(tempd)
with pd.ExcelWriter(dir+f'event_in_{name}.xlsx', engine='openpyxl') as writer:
# Write each DataFrame to a different sheet
te.to_excel(writer, sheet_name='Event Time')
ie.to_excel(writer, sheet_name='Event Index')
for var, df in ye_d.items():
df.to_excel(writer, sheet_name=var)
if len(sol.ie) > 0:
te = pd.DataFrame({'te': sol.te})
ie = pd.DataFrame({'ie': sol.ie})
ye = sol.ye
ye_d = dict()
for var in ye.var_list:
tempd = dict()
for j in range(ye.var_size[var]):
tempd[var + f'_{j}'] = ye[var][:, j]
ye_d[var] = pd.DataFrame(tempd)
with pd.ExcelWriter(dir + f'event_in_{name}.xlsx', engine='openpyxl') as writer:
# Write each DataFrame to a different sheet
te.to_excel(writer, sheet_name='Event Time')
ie.to_excel(writer, sheet_name='Event Index')
for var, df in ye_d.items():
df.to_excel(writer, sheet_name=var)
elif isinstance(sol, aesol):
y = sol.y
y_dict = dict()
for var in y.var_list:
y_dict[var] = pd.DataFrame({var: y[var]})
with pd.ExcelWriter(dir+f'{name}.xlsx', engine='openpyxl') as writer:
with pd.ExcelWriter(dir + f'{name}.xlsx', engine='openpyxl') as writer:
# Write each DataFrame to a different sheet
for name, df in y_dict.items():
df.to_excel(writer, sheet_name=name)
Expand Down

0 comments on commit 29d928e

Please sign in to comment.