Skip to content

Instantly share code, notes, and snippets.

@n01r
Last active July 9, 2022 01:01
Show Gist options
  • Select an option

  • Save n01r/416bd07621f4e9b55f626f1abff78a5c to your computer and use it in GitHub Desktop.

Select an option

Save n01r/416bd07621f4e9b55f626f1abff78a5c to your computer and use it in GitHub Desktop.
Format ParticleHistogram Header for WarpX ReducedDiag
#!/usr/bin/env python
import numpy as np
import pandas as pd
import re
df = pd.read_csv("histHAll.txt",delimiter='\s+')
# the columns look like this:
# #[0]step() [1]time(s) [2]bin1=0.000220() [3]bin2=0.000660() [4]bin3=0.001100()
# matches words, strings surrounded by " ' ", dots, minus signs and e for scientific notation in numbers
nested_list = [re.findall(r"[\w'\.]+",col) for col in df.columns]
index = pd.MultiIndex.from_tuples(nested_list, names=('column#', 'name','bin value'))
df.columns=(index)
steps = df.values[:,0].astype(int)
time = df.values[:,1]
data = df.values[:,2:]
edge_vals = np.array([float(row[2]) for row in df.columns[2:]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment