Skip to content
Snippets Groups Projects
Commit c0c79518 authored by Philipp Niedermayer's avatar Philipp Niedermayer
Browse files

Plot harmonics

parent 83bfa9c0
No related merge requests found
......@@ -58,3 +58,64 @@ def ax_set(ax, swap_xy=False, **kwargs):
else:
ax.set(**kwargs)
def plot_harmonics(ax, f, df=0, *, n=20, time=False, swap_axis=False, **plot_kwargs):
"""Add vertical lines or spans indicating the location of the frequencies / frequency bands and their harmonics
:param ax: Axis to plot onto
:param f: Frequency or list of frequencies
:param df: Bandwidth or list of bandwidths
:param n: Number of harmonics to plot
:param time: If true, plot multiples of period T=1/f
:param swap_axis: If True, swap plot axis (i.e. plot horizontal spans)
:param plot_kwargs: Keyword arguments to be passed to plotting method
"""
if not hasattr(f, '__iter__'): f = [f]
if not hasattr(df, '__iter__'): df = [df]*len(f)
#kwargs = dict(zorder=-1, color='gray', alpha=0.5, lw=1)
kwargs = dict(zorder=-1, color='gray', lw=1)
kwargs.update(plot_kwargs)
for i in range(1, n+1):
for j, (fi, dfi) in enumerate(zip(f, df)):
if dfi == 0:
method = (ax.axhline if swap_axis else ax.axvline)
args = [i/fi] if time else [i*fi]
else:
method = (ax.axhspan if swap_axis else ax.axvspan)
args = [i/(fi+dfi/2), i/(fi-dfi/2)] if time else [i*(fi-dfi/2), i*(fi+dfi/2)]
#method(*args, **kwargs)
method(*args, **dict(dict(alpha=1-np.log(1+(np.e-1)*(i-1)/n)), **kwargs))
kwargs.pop('label', None)
def plot_revolution_harmonics(ax, f0, **kwargs):
"""See plot_harmonics
"""
plot_harmonics(ax, f0, 0, **dict(dict(label='Revolution harmonics', color='lightgray', alpha=1, zorder=-3, ls=':'), **kwargs))
def plot_tune_harmonics(ax, f0, q, dq=0, *, n=20, time=False, swap_axis=False, **plot_kwargs):
"""Add vertical lines or spans indicating the location of the frequencies / frequency bands and their harmonics
:param ax: Axis to plot onto
:param f0: Revolution frequency to which the tune parameters refer
:param q: Tune or list of tunes
:param dq: Bandwidth or list of bandwidths in tune units
:param n: Number of harmonics to plot
:param time: If true, plot multiples of period T=1/f
:param swap_axis: If True, swap plot axis (i.e. plot horizontal spans)
:param plot_kwargs: Keyword arguments to be passed to plotting method
"""
if not hasattr(q, '__iter__'): q = [q]
if not hasattr(dq, '__iter__'): dq = [dq]*len(q)
plot_harmonics(ax, f0*np.array(q), f0*np.array(dq), n=n, time=time, swap_axis=swap_axis, **plot_kwargs)
def plot_excitation_harmonics(ax, f0, q, dq, **kwargs):
"""See plot_tune_harmonics
"""
plot_tune_harmonics(ax, f0, q, dq, **dict(dict(label='Excitation harmonics', ls='--', color='k'), **kwargs))
def plot_3rd_order_harmonics(ax, f0, **kwargs):
"""See plot_tune_harmonics
"""
plot_tune_harmonics(ax, f0, 1/3, 0, **dict(dict(label='1/3 resonance harmonics', color='red', zorder=-2), **kwargs))
......@@ -233,60 +233,3 @@ def plot_spill_frequency_spectrum_2D(ax, spill_data, nseg, fmax=100e3, log=True,
def plot_harmonics(ax, f, df=0, *, n=20, time=False, swap_axis=False, **plot_kwargs):
"""Add vertical lines or spans indicating the location of the frequencies / frequency bands and its harmonics
:param ax: Axis to plot onto
:param f: Frequency or list of frequencies
:param df: Bandwidth or list of bandwidths
:param n: Number of harmonics to plot
:param time: If true, plot multiples of period T=1/f
:param swap_axis: If True, swap plot axis (i.e. plot horizontal spans)
:param plot_kwargs: Keyword arguments to be passed to plotting method
"""
if not hasattr(f, '__iter__'): f = [f]
if not hasattr(df, '__iter__'): df = [df]*len(f)
kwargs = dict(zorder=-1, color='gray', alpha=0.5, lw=1)
kwargs.update(plot_kwargs)
for i in range(1, n+1):
for j, (fi, dfi) in enumerate(zip(f, df)):
if dfi == 0:
method = (ax.axhline if swap_axis else ax.axvline)
args = [i/fi] if time else [i*fi]
else:
method = (ax.axhspan if swap_axis else ax.axvspan)
args = [i/(fi+dfi/2), i/(fi-dfi/2)] if time else [i*(fi-dfi/2), i*(fi+dfi/2)]
method(*args, **kwargs)
kwargs.pop('label', None)
def plot_revolution_harmonics(ax, f0, **kwargs):
"""See plot_harmonics
"""
plot_harmonics(ax, f0, 0, **dict(dict(label='Revolution harmonics', color='lightgray', alpha=1, zorder=-3, ls=':'), **kwargs))
def plot_tune_harmonics(ax, f0, q, dq=0, *, n=20, time=False, swap_axis=False, **plot_kwargs):
"""Add vertical lines or spans indicating the location of the frequencies / frequency bands and its harmonics
:param ax: Axis to plot onto
:param f0: Revolution frequency to which the tune parameters refer
:param q: Tune or list of tunes
:param dq: Bandwidth or list of bandwidths in tune units
:param n: Number of harmonics to plot
:param time: If true, plot multiples of period T=1/f
:param swap_axis: If True, swap plot axis (i.e. plot horizontal spans)
:param plot_kwargs: Keyword arguments to be passed to plotting method
"""
if not hasattr(q, '__iter__'): q = [q]
if not hasattr(dq, '__iter__'): dq = [dq]*len(q)
plot_harmonics(ax, f0*np.array(q), f0*np.array(dq), n=n, time=time, swap_axis=swap_axis, **plot_kwargs)
def plot_excitation_harmonics(ax, f0, q, dq, **kwargs):
"""See plot_tune_harmonics
"""
plot_tune_harmonics(ax, f0, q, dq, **dict(dict(label='Excitation harmonics'), **kwargs))
def plot_3rd_order_harmonics(ax, f0, **kwargs):
"""See plot_tune_harmonics
"""
plot_tune_harmonics(ax, f0, 1/3, 0, **dict(dict(label='1/3 resonance harmonics', color='red', zorder=-2), **kwargs))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment