msmbuilder / msmexplorer

Data visualizations for biomolecular dynamics
http://msmbuilder.org/msmexplorer/
MIT License
17 stars 17 forks source link

Argument for time units in visualizations #106

Open cing opened 7 years ago

cing commented 7 years ago

There's a few mentions about keeping track of the "frame -> time" conversions in the msmbuilder code, but I didn't see any issue about it there or here. Seems like MSME is a decent place to do this conversion for visualization purposes, maybe through some optional argument?

msultan commented 7 years ago

+1 for getting this done somehow at least . I always forget to do this properly and it would be nice to automate it. I was thinking maybe a super function that takes the plotting function and a dt values and returns the plotted function? Or we add it to every function separately ?

Sent from my iPhone

On Aug 31, 2017, at 3:42 PM, Christopher Ing notifications@github.com wrote:

There's a few mentions about keeping track of the "frame -> time" conversions in the msmbuilder code, but I didn't see any issue about it there or here. Seems like MSME is a decent place to do this conversion for visualization purposes, maybe through some optional argument?

At the very least, it's probably worth mentioning somewhere in MSME that the time units are not actually "nanoseconds" in the plot_timescales and plot_implied timescales examples, right? If FsPeptide stride was 20, then it would be correct, but I don't think that's the case?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

jeiros commented 7 years ago

The way I've done this before is using FuncFormatter

You can just use the normal plotting functions and change them using a function that you define:

from matplotlib.ticker import FuncFormatter
import numpy as np
from msmexplorer import plot_trace

ts = .1
def to_ns(x, pos):
    return '{}'.format(x * ts)

a = np.random.random_sample(size=(500, 1))

ax, _ = plot_trace(a)
plt.show()

download1

ax, _ = plot_trace(a)
formatter = FuncFormatter(to_ns)
ax.xaxis.set_major_formatter(formatter)
plt.show()

download2

cing commented 6 years ago

Wow, I was not aware this functionality existed. Are there any plots where this will not work? An interesting special case might be https://github.com/msmexplorer/msmexplorer/issues/105 , where the time colorbar is smoke and mirrors anyway?

Anyway, adding a frames_to_ns argument and two lines to each function doesn't seem too painful to me.

jeiros commented 6 years ago

A minor improvement that I found out is that you can specify a third arg for the to_ns function so the timestep does not have to be known a priori (just be passed as a variable using functools.partial):

from matplotlib.ticker import FuncFormatter
import numpy as np
from msmexplorer import plot_trace
from matplotlib import pyplot as plt
from functools import partial

def to_ns(x, pos, ts):
    return '{}'.format(x * ts)

a = np.random.random_sample(size=(500, 1))

ax, _ = plot_trace(a)
formatter = FuncFormatter(partial(to_ns, ts=0.1))
ax.xaxis.set_major_formatter(formatter)
plt.show()