示例#1
0
def test_mpl():
    try:
        from pwtools import mpl
        try:
            import os
            print(os.environ['DISPLAY'])
            fig,ax = mpl.fig_ax(dpi=15,num=20)
            assert fig.dpi == 15
            assert fig.number == 20
            
            pl = mpl.Plot(dpi=15,num=20)
            assert pl.fig.dpi == 15
            assert pl.fig.number == 20
            
            dct = mpl.prepare_plots(['test'], dpi=15,num=20)
            assert dct['test'].fig.dpi == 15
            assert dct['test'].fig.number == 20
        except KeyError:
            tools.skip("no DISPLAY environment variable, skipping test")
    except ImportError:
        tools.skipping("couldn't import matplotlib, skipping test")
示例#2
0
def test_mpl():
    try:
        from pwtools import mpl
        try:
            import os
            print os.environ['DISPLAY']
            fig,ax = mpl.fig_ax(dpi=15,num=20)
            assert fig.dpi == 15
            assert fig.number == 20
            
            pl = mpl.Plot(dpi=15,num=20)
            assert pl.fig.dpi == 15
            assert pl.fig.number == 20
            
            dct = mpl.prepare_plots(['test'], dpi=15,num=20)
            assert dct['test'].fig.dpi == 15
            assert dct['test'].fig.number == 20
        except KeyError:
            tools.skip("no DISPLAY environment variable, skipping test")
    except ImportError:
        tools.skipping("couldn't import matplotlib, skipping test")
示例#3
0
#
# Note that in general, you don't know to which frequency aliases have been put
# and just using a bandpass around you desired frequency band won't help. The
# only solution in this case is to avoid aliasing in the first place :)


import numpy as np
from pwtools import mpl
from scipy.signal import hanning
from scipy.fftpack import fft
from pwtools.signal import fftsample, FIRFilter, pad_zeros

pi = np.pi
plt = mpl.plt

plots = mpl.prepare_plots(["freq", "filt_pad", "filt_nopad"])
nyq = 100  # Hz
df = 1.0  # Hz
dt, nstep = fftsample(nyq, df, mode="f")
t = np.linspace(0, 1, int(nstep))
filt1 = FIRFilter(cutoff=[10, 50], nyq=nyq, mode="bandpass", ripple=60, width=10)
filt2 = FIRFilter(cutoff=[10, 50], nyq=nyq, mode="bandpass", ntaps=100, window="hamming")
plots["freq"].ax.plot(filt1.w, abs(filt1.h), label="filt1")
plots["freq"].ax.plot(filt2.w, abs(filt2.h), label="filt2")
plots["freq"].ax.legend()

for pad in [True, False]:
    x = np.sin(2 * pi * 20 * t) + np.sin(2 * pi * 80 * t)
    if pad:
        x = pad_zeros(x, nadd=len(x))
        pl = plots["filt_pad"]
示例#4
0
# Hz). As such, the aliased 50+120 signal behaves exactly like a 50+80 signal.
#
# Note that in general, you don't know to which frequency aliases have been put
# and just using a bandpass around you desired frequency band won't help. The
# only solution in this case is to avoid aliasing in the first place :)

import numpy as np
from pwtools import mpl
from scipy.signal import hanning
from scipy.fftpack import fft
from pwtools.signal import fftsample, FIRFilter, pad_zeros

pi = np.pi
plt = mpl.plt

plots = mpl.prepare_plots(['freq', 'filt_pad', 'filt_nopad'])
nyq = 100  # Hz
df = 1.0  # Hz
dt, nstep = fftsample(nyq, df, mode='f')
t = np.linspace(0, 1, int(nstep))
filt1 = FIRFilter(cutoff=[10, 50],
                  nyq=nyq,
                  mode='bandpass',
                  ripple=60,
                  width=10)
filt2 = FIRFilter(cutoff=[10, 50],
                  nyq=nyq,
                  mode='bandpass',
                  ntaps=100,
                  window='hamming')
plots['freq'].ax.plot(filt1.w, abs(filt1.h), label='filt1')
示例#5
0
文件: run.py 项目: elcorto/pwtools
                    cryst_const=np.array([2.85]*3 + [60]*3),
                    symbols=['Al','N'])
io.write_lammps('lmp.struct', crys.scell(st,(3,3,3)))

# write lmp.in for nvt or npt
common.file_write('lmp.in', lmp_in_templ.format(ensemble=ens_txt))

# run lammps
common.system("mpirun -np 2 lammps < lmp.in", wait=True)

# read trajectory
trtxt_orig = io.read_lammps_md_txt('log.lammps')
trdcd = io.read_lammps_md_dcd('log.lammps')

# plotting
plots = mpl.prepare_plots(['coords', 'coords_frac', 'velocity', 
                           'cryst_const', 'cell'])
for name,pl in plots.iteritems():
    trtxt = trtxt_orig.copy()
    print name
    xtxt = getattr(trtxt, name)
    setattr(trtxt, name, None)
    xcalc = eval('trtxt.get_%s()' %name)
    if name == 'cell':
        sl = np.s_[Ellipsis]
        func = lambda x: np.reshape(x, (x.shape[0], 9))
    elif name in trtxt.attrs_nstep_3d:
        # coords_frac and coords: only x-coord (index=0)
        sl = np.s_[Ellipsis,0]
        func = lambda x: x
    else:
        sl = np.s_[Ellipsis]
示例#6
0
                    cryst_const=np.array([2.85]*3 + [60]*3),
                    symbols=['Al','N'])
io.write_lammps('lmp.struct', crys.scell(st,(3,3,3)))

# write lmp.in for nvt or npt
common.file_write('lmp.in', lmp_in_templ.format(ensemble=ens_txt))

# run lammps
common.system("mpirun -np 2 lammps < lmp.in", wait=True)

# read trajectory
trtxt_orig = io.read_lammps_md_txt('log.lammps')
trdcd = io.read_lammps_md_dcd('log.lammps')

# plotting
plots = mpl.prepare_plots(['coords', 'coords_frac', 'velocity', 
                           'cryst_const', 'cell'])
for name,pl in plots.items():
    trtxt = trtxt_orig.copy()
    print(name)
    xtxt = getattr(trtxt, name)
    setattr(trtxt, name, None)
    xcalc = eval('trtxt.get_%s()' %name)
    if name == 'cell':
        sl = np.s_[Ellipsis]
        func = lambda x: np.reshape(x, (x.shape[0], 9))
    elif name in trtxt.attrs_nstep_3d:
        # coords_frac and coords: only x-coord (index=0)
        sl = np.s_[Ellipsis,0]
        func = lambda x: x
    else:
        sl = np.s_[Ellipsis]