Becksteinlab / GromacsWrapper

GromacsWrapper wraps system calls to GROMACS tools into thin Python classes (GROMACS 4.6.5 - 2024 supported).
https://gromacswrapper.readthedocs.org
GNU General Public License v3.0
171 stars 54 forks source link

How to use decimate_mean #106

Closed frchalaoux closed 7 years ago

frchalaoux commented 7 years ago

Hi,

I don't understand what are the 'a' and kwargs arguments of decimate_mean. Have you an real example how to use decimate_mean(a, maxpoints, kwargs) ?

Cheers, François-Régis Chalaoux.

orbeckst commented 7 years ago

Did you have a look at http://gromacswrapper.readthedocs.io/en/latest/gromacs/core/fileformats/xvg.html#plotting ? See also decimate().

If the docs are still unclear just ping me again.

orbeckst commented 7 years ago

For decimate():

Under the hood it uses numkit.timeseries - Coarse graining time series.

frchalaoux commented 7 years ago

From orbeckst: a is the array that you are coarsening

In my case I want to obtain a simple average curve of my pressure along the time (mean or smooth), so should 'a' be the pressure column from the xvg file, i.e columns[1] ? Have you an example of decimate_mean or smooth method with an 'a' argument ?

orbeckst commented 7 years ago

If you just want to plot, use xvg.plot() with method and maxpoints (using the example):

xvg.plot(columns=[0,1], method="mean", maxpoints=100)   # bin-averaged data (100 bins)
xvg.plot(columns=[0,1], maxpoints=None, alpha=0.1)           # all data, light gray

plot_mean_100

The xvg.decimate() method itself takes a 1D or 2D array as input. A 1D array is turned into a 2D array where the first column is just the index. If you want to use it with the data in the xvg you could do something like:

time_pressure = xvg.array[[0, 1]]  # select column 0 as time and column 1 as P
time_pressure_coarse = xvg.decimate("mean", time_pressure, maxpoints=1000)

should 'a' be the pressure column from the xvg file, i.e columns[1]

It can be just the data but if this was a time series you probably want to include the independent variable (time) as well as the 0-th column as in my example, i.e. columns [0, 1].

frchalaoux commented 7 years ago

Thanks a lot Oliver, I sleept happy last tonight, It works perfectly. Yours examples and explanations should be introduced in the doc, they will help newbies with your very rich API. I'dont close the thread cause xvg.plot(columns=[0,1], method="mean", maxpoints=100) works well but I have to investigate decimate now. I run everything in Jupyter and it's really fine.

frchalaoux commented 7 years ago

decimate is ok for me, I can produce arrays that I can manipulate then plot with xvg.plot. Usefull.

frchalaoux commented 7 years ago

Can someone show me how to add a label or a legend to a xvg plot object ? I can't find how to pass **kwargs to xvg.plot() method.

frchalaoux commented 7 years ago

It works now for example to add a label:

pressure.plot(label="Pressure") plt.legend(loc='upper left') plt.show()

I close until ...