Skip to content

Commit

Permalink
Merge pull request #20 from nemocrys:arvedes/issue7
Browse files Browse the repository at this point in the history
Read output of SaveData/SaveScalars solver to pandas dataframe
  • Loading branch information
arvedes authored Nov 21, 2022
2 parents c745790 + c0be68b commit 9ead297
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.0.3
- post: add function to read output of SaveData/SaveScalars solver to pandas dataframe

v1.0.2
- add referencing to other bodies / boundaries (issue #17) using the StringFromList class

Expand Down
23 changes: 23 additions & 0 deletions pyelmer/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from dataclasses import dataclass


Expand Down Expand Up @@ -224,3 +225,25 @@ def plot_residuals(sim_dir, solvers, save=False):
fig.savefig(fig_dir + fig.title + ".png")

return figs, axes


def dat_to_dataframe(dat_file):
"""Read a .dat file generated by elmer (e.g. SaveData/SaveScalars
solver) into a pandas dataframe.
Args:
dat_file (str): file path of elmer .dat file
Returns:
pandas.core.frame.DataFrame: content of dat file with header
"""
with open(f"{dat_file}.names") as f:
lines = f.readlines()
names = []
names_start = False
for line in lines:
if names_start == True:
names.append(line.split(":")[-1].strip())
if "Data on different columns" in line:
names_start = True
return pd.read_table(dat_file, names=names, delim_whitespace=True)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"matplotlib",
"numpy",
"objectgmsh",
"pandas",
],
python_requires=">=3.7",
)

0 comments on commit 9ead297

Please sign in to comment.