# Path: src/naima/plot.py
# def find_ML(sampler, modelidx):
#     """
#     Find Maximum Likelihood parameters as those in the chain with a highest log
#     probability.
#     """
#     lnprobability = sampler.get_log_prob()
#     index = np.unravel_index(np.argmax(lnprobability), lnprobability.shape)
#     MLp = sampler.get_chain()[index]
#     blobs = sampler.get_blobs()
#     if modelidx is not None and blobs is not None:
#         blob = blobs[index][modelidx]
#         if isinstance(blob, u.Quantity):
#             modelx = sampler.data["energy"].copy()
#             model_ML = blob.copy()
#         elif len(blob) == 2:
#             modelx = blob[0].copy()
#             model_ML = blob[1].copy()
#         else:
#             raise TypeError("Model {0} has wrong blob format".format(modelidx))
#     elif modelidx is not None and hasattr(sampler, "modelfn"):
#         blob = _process_blob(
#             [sampler.modelfn(MLp, sampler.data)],
#             modelidx,
#             energy=sampler.data["energy"],
#         )
#         modelx, model_ML = blob[0], blob[1][0]
#     else:
#         modelx, model_ML = None, None
# 
#     MLerr = []
#     for dist in sampler.get_chain(flat=True).T:
#         hilo = np.percentile(dist, [16.0, 84.0])
#         MLerr.append((hilo[1] - hilo[0]) / 2.0)
#     ML = lnprobability[index]
# 
#     return ML, MLp, MLerr, (modelx, model_ML)


import os
import astropy.units as u
import h5py
import numpy as np
    import yaml  # noqa
from pathlib import Path
from astropy import log
from astropy.io.misc.hdf5 import read_table_hdf5, write_table_hdf5
from astropy.table import Table
from .plot import find_ML
    from matplotlib import pyplot as plt
    from .plot import plot_blob, plot_chain, plot_corner
        from matplotlib.backends.backend_pdf import PdfPages
# Licensed under a 3-clause BSD style license - see LICENSE.rst



try:

    HAS_PYYAML = True
except ImportError:
    HAS_PYYAML = False

__all__ = [
    "save_diagnostic_plots",
    "save_results_table",

# Path: src/naima/plot.py
# def find_ML(sampler, modelidx):
#     """
#     Find Maximum Likelihood parameters as those in the chain with a highest log
#     probability.
#     """
#     lnprobability = sampler.get_log_prob()
#     index = np.unravel_index(np.argmax(lnprobability), lnprobability.shape)
#     MLp = sampler.get_chain()[index]
#     blobs = sampler.get_blobs()
#     if modelidx is not None and blobs is not None:
#         blob = blobs[index][modelidx]
#         if isinstance(blob, u.Quantity):
#             modelx = sampler.data["energy"].copy()
#             model_ML = blob.copy()
#         elif len(blob) == 2:
#             modelx = blob[0].copy()
#             model_ML = blob[1].copy()
#         else:
#             raise TypeError("Model {0} has wrong blob format".format(modelidx))
#     elif modelidx is not None and hasattr(sampler, "modelfn"):
#         blob = _process_blob(
#             [sampler.modelfn(MLp, sampler.data)],
#             modelidx,
#             energy=sampler.data["energy"],
#         )
#         modelx, model_ML = blob[0], blob[1][0]
#     else:
#         modelx, model_ML = None, None
# 
#     MLerr = []
#     for dist in sampler.get_chain(flat=True).T:
#         hilo = np.percentile(dist, [16.0, 84.0])
#         MLerr.append((hilo[1] - hilo[0]) / 2.0)
#     ML = lnprobability[index]
# 
#     return ML, MLp, MLerr, (modelx, model_ML)


# Path: src/naima/analysis.py
import os
import astropy.units as u
import h5py
import numpy as np
    import yaml  # noqa
from pathlib import Path
from astropy import log
from astropy.io.misc.hdf5 import read_table_hdf5, write_table_hdf5
from astropy.table import Table
from .plot import find_ML
    from matplotlib import pyplot as plt
    from .plot import plot_blob, plot_chain, plot_corner
        from matplotlib.backends.backend_pdf import PdfPages

# Licensed under a 3-clause BSD style license - see LICENSE.rst



try:

    HAS_PYYAML = True
except ImportError:
    HAS_PYYAML = False

__all__ = [
    "save_diagnostic_plots",
    "save_results_table",

    "save_run",