In [1]:
import signac
import pandas as pd
project = signac.get_project(root='projects/tutorial')
Let's first create a basic index and use it to construct an index data frame:
In [2]:
df_index = pd.DataFrame(project.index())
df_index.head()
Out[2]:
It is a good idea, to explicitly use the _id
value as index key:
In [3]:
df_index = df_index.set_index(['_id'])
df_index.head()
Out[3]:
Furthermore, the index would be more useful if each statepoint parameter had its own column.
In [4]:
statepoints = {doc['_id']: doc['statepoint'] for doc in project.index()}
df = pd.DataFrame(statepoints).T.join(df_index)
df.head()
Out[4]:
Now we can select specific data subsets, for example to calculate the mean gas volume of argon for a pressure p between 2.0 and 5.0:
In [5]:
df[(df.fluid=='argon') & (df.p > 2.0) & (df.p <= 5.0)].V_gas.mean()
Out[5]:
Or we can plot a p-V phase diagram for argon (requires matplotlib).
In [6]:
% matplotlib inline
df_water = df[df.fluid=='argon'][['p', 'V_liq', 'V_gas']]
df_water.sort_values('p').set_index('p').plot(logy=True)
Out[6]:
Or we group the data by fluid and compare the gas densities for low pressures:
In [7]:
from matplotlib import pyplot as plt
for fluid, group in df[df.p < 2].groupby('fluid'):
d = group.sort_values('p')
plt.plot(d['p'], d['V_gas'] / d['N'], label=fluid)
plt.xlabel('p')
plt.ylabel(r'$\rho_{gas}$')
plt.legend(loc=0)
Out[7]: