msmexplorer icon indicating copy to clipboard operation
msmexplorer copied to clipboard

Argument for time units in visualizations

Open cing opened this issue 8 years ago • 4 comments

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?

cing avatar Aug 31 '17 22:08 cing

+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 [email protected] 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.

msultan avatar Sep 01 '17 00:09 msultan

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

jeiros avatar Sep 04 '17 13:09 jeiros

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.

cing avatar Sep 12 '17 14:09 cing

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()

jeiros avatar Sep 27 '17 07:09 jeiros