spectuner.spectral_plot

class spectuner.spectral_plot.PeakPlot(freqs: ndarray, delta_v: float = 100.0, n_col: int = 4, plot_width: float = 4, plot_height: float = 3)[source]

Multi-window plot for visualizing the spectrum.

This class make sub-plots around the given frequencies and automatically merge overlapping windows.

Parameters:
  • freqs – Cenetral frequencies for each window.

  • delta_v – Velocity width in km/s of each window. Windows with overlaps will be merged.

  • n_col – Number of windows per row.

  • plot_width – Figure width of each sub-plot.

  • plot_height – Figure height of each sub-plot.

property fig

Figure.

property axes

Axes.

property bounds

X-limits of each plot.

plot_spec_from_config(config: Config, step_plot: bool = True, ylim_factor: float | None = None, y_top_min: float = 0.0, color='k', **kwargs)[source]

Plot the spectrum defined in the config dict.

Parameters:
  • config – Config dict.

  • step_plot – Whether to use plt.step instead of plt.plot.

  • ylim_factor – Factor to multiply the maximum value of the spectrum to set the y-axis limit.

  • y_top_min – Minimum value of the y-axis limit.

  • **kwargs – Keyword arguments passed to plt.plot or plt.step.

plot_spec(freq_data: list, spec_data: list, step_plot: bool = False, ylim_factor: float | None = None, y_top_min: float = 0.0, **kwargs)[source]

Plot a spectrum.

Parameters:
  • freq_data – List of 1D arrays that specifies the frequency values.

  • spec_data – List of 1D arrays that specifies the intensity values.

  • step_plot – Whether to use plt.step instead of plt.plot.

  • ylim_factor – Factor to multiply the maximum value of the spectrum to set the y-axis limit.

  • y_top_min – Minimum value of the y-axis limit.

  • **kwargs – Keyword arguments passed to plt.plot or plt.step.

vlines(freqs: ndarray, **kwargs)[source]

Plot vertical lines.

Parameters:
  • freqs – Frequencies of the vertical lines.

  • **kwargs – Keyword arguments passed to plt.vlines.

vtexts(freqs: ndarray, texts: ndarray, h_txt_offset: float = 0.015, v_txt_offset: float = 0.95, **kwargs)[source]

Plot vertical texts.

Parameters:
  • freqs – Frequencies to plot the texts.

  • texts – Texts to show.

  • h_txt_offset – Horizontal offset of the texts.

  • v_txt_offset – Vertical offset of the texts.

  • **kwargs – Keyword arguments passed to plt.text.

class spectuner.spectral_plot.SpectralPlot(freq_data: list, freq_per_row: float = 1000.0, width: float = 20.0, height: float = 3.0, n_minor_tick: int = 10, axes: ndarray | None = None)[source]

Multi-row plot for visualizing the spectrum of multiple spectral windows.

Parameters:
  • freq_data – List of 1D arrays that specifies the frequency values for each spectral window.

  • freq_per_row – Frequency range to show in each row. The unit should be the same as freq_data.

  • width – Figure width.

  • height – Figure height of each row.

  • n_minor_tick – Number of minor ticks. Set to 0 to disable minor ticks.

  • axes – Axes to plot. If None, create a new figure.

classmethod from_config(config: Config, freq_per_row: float = 1000.0, width: float = 20.0, height: float = 3.0, n_minor_tick: int = 10, axes: ndarray | None = None, color: str = 'k', **kwargs)[source]

Create a plot from a Config instance.

Parameters:
  • configConfig instance.

  • freq_per_row – Frequency range to show in each row. The unit should be the same as defined in config.

  • width – Figure width.

  • height – Figure height of each row.

  • n_minor_tick – Number of minor ticks. Set to 0 to disable minor ticks.

  • axes – Axes to plot. If None, create a new figure.

  • color – Color of the spectrum defined in config.

  • **kwargs – Other arguments passed to plt.plot to plot the spectrum defined in config.

property fig

Figure.

property axes

Axes.

property bounds

X-limits of each plot.

plot_ident_result(ident_result: IdentResult, key: int | None = None, name: str | None = None, show_lines: bool = True, color: str = 'k', color_blen: str = 'r', color_fp: str = 'b', h_txt_offset: float = 0.0025, v_txt_offset: float = 0.95, fontsize: float = 12, T_base_data: list | None = None, kwargs_spec: dict | None = None)[source]

Plot a identification result.

This method is a combination of plot_spec and plot_names. This method reads the curret y limts to plot the lines. Therefore, this method should be called after set_ylim.

Parameters:
  • ident_result – Identification result.

  • key – Molecule ID. This is used to plot the result of a single molecule in a combined result.

  • name – Molecule name. This is used to plot the result of a single molecule in a combined result.

  • show_lines – Whether to show the vertical lines that indicate the molecules.

  • txt_offset – Text offset of the lines. Larger values mean farther from the line.

  • color – Line color of the peaks that match the observed spectrum. Set color='none' to hide the lines.

  • color_blen – Line color of the peaks that match the observed spectrum but contributed by multiple species. Set color_blen='none' to hide the lines.

  • color_fp – Color of the peaks found in the fitted spectrum but missing from the observed spectrum. Set color_fp='none' to hide the lines.

  • fontsize – Font size of the molecules.

  • T_base_data – Base intensity data.

  • kwargs_spec – Keyword arguments passed to plt.plot to plot the spectrum.

plot_spec(freq_data: list, spec_data: list, *args, color: str = 'C0', **kwargs)[source]

Plot a spectrum.

Parameters:
  • freq_data – List of 1D arrays specifiyng the frequency of each spectral window.

  • spec_data – List of 1D arrays specifiyng the intensity of each spectral window.

  • *args – Arguments passed to plt.plot.

  • color – Color of the spectrum.

  • **kwargs – Keyword arguments passed to plt.plot.

plot_names(freqs: ndarray, name_list: list, key: int | None = None, color: str = 'k', color_blen: str = 'r', linestyles: str = '--', h_txt_offset: float = 0.0025, v_txt_offset: float = 0.95, fontsize: float = 12)[source]

Plot the identitied names of the lines.

Parameters:
  • freqs – Frequencies of the lines.

  • name_list – Names of the lines.

  • key – Molecule ID. This is used to plot the result of a single molecule in a combined result.

  • color – Line color of the peaks that match the observed spectrum.

  • color_blen – Line color of the peaks that match the observed spectrum but contributed by multiple species.

  • linestyles – Line styles.

  • h_txt_offset – Horizontal text offset. Larger values mean farther from the line.

  • v_txt_offset – Vertical text offset. Smaller values mean farther from the top.

  • fontsize – Font size of the molecules.

plot_unknown_lines(ident_result: IdentResult, color: str = 'grey', linestyle: str = '-', alpha: float = 0.5)[source]

Plot unidentified lines.

Parameters:
  • ident_result – Identification result.

  • color – Color of the lines.

  • linestyle – Line style.

  • alpha – Transparency.

vlines(freqs: ndarray, **kwargs)[source]

Plot vertical lines.

Parameters:
  • freqs – Frequencies of the lines.

  • **kwargs – Keyword arguments passed to plt.vlines.

set_ylim(y_min: float, y_max: float, **kwargs)[source]

Set the y limits for each plot.

Parameters:
  • y_min – Minimum y value.

  • y_max – Maximum y value.

  • **kwargs – Keyword arguments passed to plt.set_ylim.

get_ylim(ax)[source]

Get the y limits for the given axis.

Parameters:

ax – Axis.