Repository: gammapy/gammapy

Issue:
Exposing `FitResult` ?
Should we expose the `FitResult` class ? 

I think it would be a good idea. It could help debugging and understanding why a fit failed. 


Discussion:
Maybe a `FitResult.write()` might be useful too.

Resolving patch:
diff --git a/gammapy/modeling/__init__.py b/gammapy/modeling/__init__.py
--- a/gammapy/modeling/__init__.py
+++ b/gammapy/modeling/__init__.py
@@ -1,7 +1,7 @@
 # Licensed under a 3-clause BSD style license - see LICENSE.rst
 """Models and fitting."""
 from .covariance import Covariance
-from .fit import Fit
+from .fit import CovarianceResult, Fit, FitResult, OptimizeResult
 from .parameter import Parameter, Parameters, PriorParameter, PriorParameters
 from .scipy import stat_profile_ul_scipy
 from .selection import select_nested_models
@@ -9,6 +9,9 @@
 __all__ = [
     "Covariance",
     "Fit",
+    "FitResult",
+    "OptimizeResult",
+    "CovarianceResult",
     "Parameter",
     "Parameters",
     "select_nested_models",
diff --git a/gammapy/modeling/fit.py b/gammapy/modeling/fit.py
--- a/gammapy/modeling/fit.py
+++ b/gammapy/modeling/fit.py
@@ -15,7 +15,7 @@
 from .scipy import confidence_scipy, optimize_scipy
 from .sherpa import optimize_sherpa
 
-__all__ = ["Fit"]
+__all__ = ["Fit", "FitResult", "OptimizeResult", "CovarianceResult"]
 
 log = logging.getLogger(__name__)
 
@@ -311,7 +311,7 @@ def confidence(self, datasets, parameter, sigma=1, reoptimize=True):
 
         For the scipy backend ``kwargs`` are forwarded to `~scipy.optimize.brentq`. If the
         confidence estimation fails, the bracketing interval can be adapted by modifying the
-        the upper bound of the interval (``b``) value.
+        upper bound of the interval (``b``) value.
 
         Parameters
         ----------
@@ -581,7 +581,15 @@ def _repr_html_(self):
 
 
 class CovarianceResult(FitStepResult):
-    """Covariance result object."""
+    """Covariance result object.
+
+    Parameters
+    ----------
+    matrix : `~numpy.ndarray`, optional
+        The covariance matrix. Default is None.
+    kwargs : dict
+        Extra ``kwargs`` are passed to the backend.
+    """
 
     def __init__(self, matrix=None, **kwargs):
         self._matrix = matrix
@@ -594,7 +602,23 @@ def matrix(self):
 
 
 class OptimizeResult(FitStepResult):
-    """Optimize result object."""
+    """Optimize result object.
+
+    Parameters
+    ----------
+    models : `~gammapy.modeling.models.DatasetModels`
+        Best fit models.
+    nfev : int
+        Number of function evaluations.
+    total_stat : float
+        Value of the fit statistic at minimum.
+    trace : `~astropy.table.Table`
+        Parameter trace from the optimisation.
+    minuit : `~iminuit.minuit.Minuit`, optional
+        Minuit object. Default is None.
+    kwargs : dict
+        Extra ``kwargs`` are passed to the backend.
+    """
 
     def __init__(self, models, nfev, total_stat, trace, minuit=None, **kwargs):
         self._models = models
@@ -644,11 +668,13 @@ def __str__(self):
 class FitResult:
     """Fit result class.
 
+    The fit result class provides the results from the optimisation and covariance of the fit.
+
     Parameters
     ----------
-    optimize_result : `OptimizeResult`
+    optimize_result : `~OptimizeResult`
         Result of the optimization step.
-    covariance_result : `CovarianceResult`
+    covariance_result : `~CovarianceResult`
         Result of the covariance step.
     """
 


Test patch: