# Path: metatlas/datastructures/metatlas_objects.py
# FETCH_STUBS = True
# ADDUCTS = ('','[M]+','[M+H]+','[M+H]2+','[M+2H]2+','[M+H-H2O]2+','[M+K]2+','[M+NH4]+','[M+Na]+','[M+H-H2O]+','[M-H]-','[M-2H]-','[M-H+Cl]-','[M-2H]2-','[M+Cl]-','[2M+H]+','[2M-H]-','[M-H+Na]+','[M+K]+','[M+2Na]2+','[M-e]+','[M+acetate]-','[M+formate]-','[M-H+Cl]2-','[M-H+2Na]+')
# POLARITY = ('positive', 'negative', 'alternating')
# FRAGMENTATION_TECHNIQUE = ('hcd','cid','etd','ecd','irmpd')
# ID_GRADES: Dict[str, IdentificationGrade] = dict()
#     FETCH_STUBS = False
#         FETCH_STUBS = True
#     FETCH_STUBS = True
# def retrieve(object_type, **kwargs):
# def remove(object_type, **kwargs):
# def remove_objects(objects, all_versions=True, **kwargs):
# def store(objects, **kwargs):
#     def __init__(self, **kwargs):
#     def _update(self, override_user=False):
#     def clone(self, recursive=False):
#     def show_diff(self, unique_id=None):
#     def _on_update(self, change):
#     def __str__(self):
#     def __repr__(self):
#     def __getattribute__(self, name):
#     def validate(self, obj, value):
# def find_invalid_runs(**kwargs):
# def to_dataframe(objects):
# class MetatlasObject(HasTraits):
# class Method(MetatlasObject):
# class Sample(MetatlasObject):
# class LcmsRun(MetatlasObject):
# class FunctionalSet(MetatlasObject):
# class Compound(MetatlasObject):
# class Reference(MetatlasObject):
# class IdentificationGrade(MetatlasObject):
# class _IdGradeTrait(MetInstance):
# class Group(MetatlasObject):
# class MzIntensityPair(MetatlasObject):
# class FragmentationReference(Reference):
# class RtReference(Reference):
# class MzReference(Reference):
# class IntensityReference(Reference):
# class CompoundIdentification(MetatlasObject):
# class Atlas(MetatlasObject):
# class MZMineTask(MetatlasObject):
# 
# Path: metatlas/plots/plot_set.py
# def restore_matplotlib_settings(func):
#     def wrapper(*args, **kwargs):
#     def __init__(self, title: str, group_name: str):
#     def plot(self, ax: matplotlib.axes.Axes, back_color: utils.Color = "white") -> None:
#     def __init__(
#         self,
#         plots: Sequence[Plot],
#         max_plots_per_fig: int = 30,
#         x_min: Optional[float] = None,
#         x_max: Optional[float] = None,
#         y_min: Optional[float] = None,
#         y_max: Optional[float] = None,
#         sharey: bool = True,
#         font_scale: float = 2,
#     ):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_value, exc_tb):
#     def limit_axes(
#         self,
#         x_min: Optional[float],
#         x_max: Optional[float],
#         y_min: Optional[float],
#         y_max: Optional[float],
#     ) -> None:
#     def save_pdf(self, file_name: str, title: str, overwrite: bool = False) -> None:
#     def close(self):
# def _get_xy(artist: matplotlib.artist.Artist) -> Tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]:
# def _autoscale(ax: matplotlib.axes.Axes, axis: str = "y", sides: str = "both", margin: float = 0.1) -> None:
# def _update_limts(
#     low: float,
#     high: float,
#     fixed: npt.NDArray[np.float64],
#     dependent: npt.NDArray[np.float64],
#     fixed_limits: Tuple[float, float],
# ) -> Tuple[float, float]:
# def _calculate_new_limit(
#     fixed: npt.NDArray[np.float64], dependent: npt.NDArray[np.float64], fixed_limits: Tuple[float, float]
# ) -> Tuple[float, float]:
# class Plot(ABC):
# class PlotSet(ABC):
# 
# Path: metatlas/plots/utils.py
# BACKGROUND_COLORS = ["white", "lightyellow", "whitesmoke", "lavenderblush"]
# def colors() -> Generator:
# def subplot_dimensions(num: int) -> Tuple[int, int]:
# def wrap_subplots(num: int, **kwargs) -> Tuple[matplotlib.figure.Figure, List[matplotlib.axes.Axes]]:
# def is_in_range(a: List[float], start: float, stop: float) -> List[bool]:
# def fill_under(
#     ax: matplotlib.axes.Axes,
#     x: List[float],
#     y: List[float],
#     between: Optional[Tuple[float, float]] = None,
#     **kwargs,
# ) -> None:
# def pdf_with_text(text: str, file_name: str, size: int = 24):


import logging
import matplotlib
import numpy as np
from pathlib import Path
from typing import Any, Dict, List, Sequence, Tuple
from metatlas.datastructures import metatlas_objects as metob
from metatlas.plots import plot_set
from metatlas.plots import utils
"""Plot set of EIC plots for a compound. One sample per sub-plot"""
# pylint: disable=invalid-name,too-many-arguments,too-few-public-methods





logger = logging.getLogger(__name__)

MetatlasDataset = List[List[Any]]  # avoiding a circular import


class CompoundEic(plot_set.Plot):
    """EIC for one compound within a single sample"""

    def __init__(self, title: str, group_name: str, compound: Dict[str, Any], rt_buffer: float = 0.5):
        """
        compound: Compound instance
        rt_buffer: amount of time in minutes to show to each side of rt_min/rt_max/rt_peak
        """
        super().__init__(title, group_name)
        self.compound = compound

# Path: metatlas/datastructures/metatlas_objects.py
# FETCH_STUBS = True
# ADDUCTS = ('','[M]+','[M+H]+','[M+H]2+','[M+2H]2+','[M+H-H2O]2+','[M+K]2+','[M+NH4]+','[M+Na]+','[M+H-H2O]+','[M-H]-','[M-2H]-','[M-H+Cl]-','[M-2H]2-','[M+Cl]-','[2M+H]+','[2M-H]-','[M-H+Na]+','[M+K]+','[M+2Na]2+','[M-e]+','[M+acetate]-','[M+formate]-','[M-H+Cl]2-','[M-H+2Na]+')
# POLARITY = ('positive', 'negative', 'alternating')
# FRAGMENTATION_TECHNIQUE = ('hcd','cid','etd','ecd','irmpd')
# ID_GRADES: Dict[str, IdentificationGrade] = dict()
#     FETCH_STUBS = False
#         FETCH_STUBS = True
#     FETCH_STUBS = True
# def retrieve(object_type, **kwargs):
# def remove(object_type, **kwargs):
# def remove_objects(objects, all_versions=True, **kwargs):
# def store(objects, **kwargs):
#     def __init__(self, **kwargs):
#     def _update(self, override_user=False):
#     def clone(self, recursive=False):
#     def show_diff(self, unique_id=None):
#     def _on_update(self, change):
#     def __str__(self):
#     def __repr__(self):
#     def __getattribute__(self, name):
#     def validate(self, obj, value):
# def find_invalid_runs(**kwargs):
# def to_dataframe(objects):
# class MetatlasObject(HasTraits):
# class Method(MetatlasObject):
# class Sample(MetatlasObject):
# class LcmsRun(MetatlasObject):
# class FunctionalSet(MetatlasObject):
# class Compound(MetatlasObject):
# class Reference(MetatlasObject):
# class IdentificationGrade(MetatlasObject):
# class _IdGradeTrait(MetInstance):
# class Group(MetatlasObject):
# class MzIntensityPair(MetatlasObject):
# class FragmentationReference(Reference):
# class RtReference(Reference):
# class MzReference(Reference):
# class IntensityReference(Reference):
# class CompoundIdentification(MetatlasObject):
# class Atlas(MetatlasObject):
# class MZMineTask(MetatlasObject):
# 
# Path: metatlas/plots/plot_set.py
# def restore_matplotlib_settings(func):
#     def wrapper(*args, **kwargs):
#     def __init__(self, title: str, group_name: str):
#     def plot(self, ax: matplotlib.axes.Axes, back_color: utils.Color = "white") -> None:
#     def __init__(
#         self,
#         plots: Sequence[Plot],
#         max_plots_per_fig: int = 30,
#         x_min: Optional[float] = None,
#         x_max: Optional[float] = None,
#         y_min: Optional[float] = None,
#         y_max: Optional[float] = None,
#         sharey: bool = True,
#         font_scale: float = 2,
#     ):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_value, exc_tb):
#     def limit_axes(
#         self,
#         x_min: Optional[float],
#         x_max: Optional[float],
#         y_min: Optional[float],
#         y_max: Optional[float],
#     ) -> None:
#     def save_pdf(self, file_name: str, title: str, overwrite: bool = False) -> None:
#     def close(self):
# def _get_xy(artist: matplotlib.artist.Artist) -> Tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]:
# def _autoscale(ax: matplotlib.axes.Axes, axis: str = "y", sides: str = "both", margin: float = 0.1) -> None:
# def _update_limts(
#     low: float,
#     high: float,
#     fixed: npt.NDArray[np.float64],
#     dependent: npt.NDArray[np.float64],
#     fixed_limits: Tuple[float, float],
# ) -> Tuple[float, float]:
# def _calculate_new_limit(
#     fixed: npt.NDArray[np.float64], dependent: npt.NDArray[np.float64], fixed_limits: Tuple[float, float]
# ) -> Tuple[float, float]:
# class Plot(ABC):
# class PlotSet(ABC):
# 
# Path: metatlas/plots/utils.py
# BACKGROUND_COLORS = ["white", "lightyellow", "whitesmoke", "lavenderblush"]
# def colors() -> Generator:
# def subplot_dimensions(num: int) -> Tuple[int, int]:
# def wrap_subplots(num: int, **kwargs) -> Tuple[matplotlib.figure.Figure, List[matplotlib.axes.Axes]]:
# def is_in_range(a: List[float], start: float, stop: float) -> List[bool]:
# def fill_under(
#     ax: matplotlib.axes.Axes,
#     x: List[float],
#     y: List[float],
#     between: Optional[Tuple[float, float]] = None,
#     **kwargs,
# ) -> None:
# def pdf_with_text(text: str, file_name: str, size: int = 24):


# Path: metatlas/plots/compound_eic.py
import logging
import matplotlib
import numpy as np
from pathlib import Path
from typing import Any, Dict, List, Sequence, Tuple
from metatlas.datastructures import metatlas_objects as metob
from metatlas.plots import plot_set
from metatlas.plots import utils

"""Plot set of EIC plots for a compound. One sample per sub-plot"""
# pylint: disable=invalid-name,too-many-arguments,too-few-public-methods





logger = logging.getLogger(__name__)

MetatlasDataset = List[List[Any]]  # avoiding a circular import


class CompoundEic(plot_set.Plot):
    """EIC for one compound within a single sample"""

    def __init__(self, title: str, group_name: str, compound: Dict[str, Any], rt_buffer: float = 0.5):
        """
        compound: Compound instance
        rt_buffer: amount of time in minutes to show to each side of rt_min/rt_max/rt_peak
        """
        super().__init__(title, group_name)
        self.compound = compound

        rt_ref: metob.RtReference = compound["identification"].rt_references[0]