Jupyter: w_ipa
This is an example jupyter/ipython notebook for WESTPA simulations, designed for interactive analysis using w_ipa. Use this as a template for further browser-based interactive analysis of simulations.
You'll want to start each notebook session with the following:
import w_ipython
w = w_ipython.WIPI()
w.main()
The w object can then be used for analysis. Schemes can be listed and changed with
w.list_schemes
w.scheme = SCHEME_NUMBER/NAME
Run help(w), or w.introduction for more details.
Happy analyzing!
In [1]:
%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
import w_ipa
w = w_ipa.WIPI()
# At startup, it will load or run the analysis schemes specified in the configuration file (typically west.cfg)
w.main()
w.interface = 'matplotlib'
In [2]:
# Set the iteration to the second to last one.
w.iteration -= 1
# Access the current iteration dictionary, and return an interesting segment:
# the heaviest one in the current segment!
# Note that we can access either as attributes or dictionary keys!
# Attributes can be tab completed when running in console mode.
heaviest_segment = w.current.maxweight.seg_id
print('{} is the walker with the maximum weight!\n'.format(heaviest_segment))
# We can index the current iteration according to the seg_id...
print('Indexing according to a seg_id returns all properties on the segment.')
print('Children and parents have the same properties/keys.')
print(str(w.current[heaviest_segment]) + '\n')
# ... we can also see what its parents were like, or what any children are like, should they exist!
print('Where did it come from? Does it have any descendents?')
print('{} is the parent!'.format(w.past[heaviest_segment].seg_id))
print('{} is/are the children!\n'.format(w.future[heaviest_segment].seg_id))
# We can see that the past/future objects are keyed to seg_ids in the CURRENT iteration, always.
# We can also see all available properties on the current iteration, and index THOSE according to a segment.
# As an example:
print('Can we index either way?')
print(str((w.current.pcoord[heaviest_segment] == w.current[heaviest_segment].pcoord)[0]) + '\n')
# w.current also contains the output from w_direct/w_reweight/w_assign for the current iteration.
# w.past contains the same output, from the prior iteration, keyed to the current seg_id
print('What properties exist in the current dictionary?')
print(w.current)
In [3]:
# Let's trace our heaviest walker to see its history!
hs_trace = w.trace(heaviest_segment)
print('What data can we access from our trace for segment {}?'.format(heaviest_segment))
print(hs_trace.keys())
# Then plot something interesting about it, like the pcoord or the weight changes over time.
# The resulting plot is per time point, not iteration.
plt.plot(hs_trace['pcoord'])
plt.show()
plt.plot(np.log10(hs_trace['weights']))
plt.show()
# We can plot the state changes over time, too, if we wanted.
plt.plot(hs_trace['states'])
Out[3]:
In [4]:
# There's a built in plotting interface that can be used to plot interesting things!
# Try running this command directly from the terminal in w_ipa.
print(w.state_labels)
w.current.direct.rate_evolution.plot(interface='matplotlib')
print("Rate evolution from state 0 to 1")
w.current.direct.rate_evolution.plot(1,0,interface='matplotlib')
print("Rate evolution from state 1 to 0")
In [ ]: