at.plot.resonances#

AT plotting functions related to resonances.

Functions

farey_sequence(nthorder[, verbose])

Return the Farey sequence, and the resonance sequence of nth order.

plot_tune_diagram([orders, periodicity, ...])

Plot the tune diagram and resonance lines for a given order, periodicity and window.

create_linepalette([linestyle, linecolor, ...])

Create a line palette to plot resonance lines.

create_linepalette(linestyle=None, linecolor=None, linewidth=None, addtolabel=None)[source]#

Create a line palette to plot resonance lines.

Parameters:
  • linestyle (str | None) –

    str or dictionary. If ‘dots’ it uses dotted styles as linestyles

    {“normal”: “dashdot”, “skew”: “dotted”}

    If a dictionary is passed, it should contain

    {“normal”: style1, “skew”: style2}

    Default: {“normal”: ‘-’, “skew”: ‘–‘}

  • linecolor (str | None) – defines one color to be used. e.g. ‘k’. Default: custom values. See plot_tune_diagram()

  • linewidth (int | None) – defines one integer value for the line width, e.g. 1. Default: custom values. See plot_tune_diagram()

  • addtolabel (str | None) – adds a string to the line label

Returns:

Dict dictionary contaning the line properties for resonance plots.

farey_sequence(nthorder, verbose=False)[source]#

Return the Farey sequence, and the resonance sequence of nth order.

Parameters:
  • nthorder (int) – natural number bigger than 0.

  • verbose (bool) – prints extra info. Default: False.

Returns:
  • fareyseqfloat – list of elements with the Farey sequence in Float format. See Eqs.(1,2,3) of [1].

  • fareyseqfrac – list of elements with the Farey sequence in Fraction format. See Eqs.(1,2,3) of [1].

Raises:

ValueError – if given order is lower than 0, or window is zero.

[1] R.Tomas. ‘From Farey sequences to resonance diagrams.

Phys.Rev.Acc.Beams 17, 014001 (2014)’

plot_tune_diagram(orders=(1, 2, 3), periodicity=1, window=(0, 1, 0, 1), verbose=False, legend=False, show=True, block=False, debug=False, axes=None, linestyle=None, linecolor=None, linewidth=None, addtolabel=None, **kwargs)[source]#

Plot the tune diagram and resonance lines for a given order, periodicity and window.

Parameters:
  • orders (int) – integer or tuple of integers larger than zero. Default (1,2,3).

  • periodicity (int) – periodicity of the machine, integer larger than zero. Default: 1.

  • window (list) – (min_nux,max_nux,min_nuy,max_nuy) tuple of 4 values for the tune minimum and maximum window. Default: (0,1,0,1). window is ignored if the parameter axes is given.

  • verbose (bool) – print verbose output.

  • legend (bool) – print legend on the plot. Default: False.

  • show (bool) – show plot. Default: True.

  • block (bool) – passed to plot.show(). Default: False.

  • debug (bool) – extra output to check line construction. Default: False.

  • axes (Axes | None) – Axes for plotting the resonances. If None, a new figure will be created. Note that if axes are given then window is ignored.

  • linestyle (dict | None) –

    sets the line style for normal and skew resonances. If ‘dots’ is given it will use dashdot and dotted for normal and skew resonances, respectively. A dictionary could be passed containing

    {“normal”: style1, “skew”:style2}

    to plot using style1 and style2. Default: uses “-” and “–”. See Normal and Skew convention.

  • linecolor (str | None) – sets a single color for all the resonances. By default a custom palette is used. See Lines Color and Width.

  • resonances. (linewidth = integer width to be used for all) – Default: See Color and Width below

  • addtolabel (str | None) – adds a string to the line label, e.g. for the fourth order normal resonance “4n”+addtolabel

  • kwargs (dict[str, any]) –

    • only: if ‘normal’ plots only normal resonances.

      if ‘skew’ plots only skew resonances. Otherwise ignored. See the notes on Normal and Skew convention.

    • linedict: use it to pass a dictionary with custom line styles.

      See notes below.

Returns:
  • Axes object from matplotlib.axes._axes

  • List of handles for the legend

  • List of labels for the legend

NOTES: The resonance equation is \(a\nu_x + b\nu_y = c\) with \(a,b\) and \(c\) integers. The order \(N=abs(a)+abs(b)\).

Normal and Skew convention: Line style is similar to reson.m from Matlab Middle Layer, MML, by L. Nadolski. Normal resonances are plotted with a continuous line. Skew resonances, i.e. N-abs(a) is odd, are plotted in dashed lines.

Lines Color and Width: Line style is similar to reson.m from Matlab Middle Layer, MML, by L. Nadolski. 1st: black, width 4 2nd: blue, width 3 3rd: red, width 2 4th: green, width 1 5th: magenta, witdh 1 6th: cyan, width 1 7th: yellow, width 1 8th: darkcyan, width 1 9th: ‘lightgreen’, width 1 10th to 15th: RGB increased in steps of 0.1, width 1

Custom Style: You could pass a custom line style in a dictionary as linedict = mydictionary, where mydictionary should contain two entries dict(“normal”: normald, “skew”: skewd). normald and skewd are also dictionaries, each entry contains as key the resonance order and as value the line properties to use in the plot. The default dictionary is created with :pyt:func:`create_linepalette`

mydictionary = at.plot.resonances.create_linepalette()

you could edit the needed entries.

Raises:

ValueError – if given resonances are lower than 0, or window is zero.