Skip to content

Commit

Permalink
Fitter legacy (#137)
Browse files Browse the repository at this point in the history
* Changed fittter_legacy module to fitting_legacy and added new fitting module

---------

Co-authored-by: Kristopher Cooper <[email protected]>
Co-authored-by: Shane Maloney <[email protected]>
  • Loading branch information
3 people authored Feb 21, 2024
1 parent 2257afb commit 2deabc0
Show file tree
Hide file tree
Showing 20 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions changelog/137.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Renamed `sunxspex_fitting` module to `fitting_legacy` and added a new `fitting` module.
4 changes: 2 additions & 2 deletions docs/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Software and API.
.. automodapi:: sunkit_spex.io
.. automodapi:: sunkit_spex.emission
.. automodapi:: sunkit_spex.constants
.. automodapi:: sunkit_spex.sunxspex_fitting
.. automodapi:: sunkit_spex.sunxspex_fitting.io
.. automodapi:: sunkit_spex.fitting_legacy
.. automodapi:: sunkit_spex.fitting_legacy.io
.. automodapi:: sunkit_spex.photon_power_law
2 changes: 1 addition & 1 deletion sunkit_spex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .version import __version__

__all__ = []
from . import io, sunxspex_fitting, thermal
from . import fitting_legacy, io, thermal
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from astropy.io import fits

from sunkit_spex.sunxspex_fitting import instruments as inst # sunkit_spex.sunxspex_fitting.instruments
from sunkit_spex.sunxspex_fitting.parameter_handler import ( # sunkit_spex.sunxspex_fitting.parameter_handler
from sunkit_spex.fitting_legacy import instruments as inst # sunkit_spex.fitting_legacy.instruments
from sunkit_spex.fitting_legacy.parameter_handler import ( # sunkit_spex.fitting_legacy.parameter_handler
_make_into_list,
isnumber,
)
Expand All @@ -27,7 +27,7 @@ class LoadSpec:
Parameters
----------
*args : dict
Dictionaries for custom data to be passed to `sunkit_spex.sunxspex_fitting.instruments.CustomLoader`.
Dictionaries for custom data to be passed to `sunkit_spex.fitting_legacy.instruments.CustomLoader`.
These will be added before any instrument file entries from `pha_file`.
pha_file : string or list of strings
Expand Down Expand Up @@ -123,7 +123,7 @@ def __init__(self, *args, pha_file=None, arf_file=None, rmf_file=None, srm_file=
self._construction_string = (f"LoadSpec(*{args}, pha_file={pha_file}, arf_file={arf_file}, rmf_file={rmf_file}, "
f"srm_file={srm_file}, srm_custom={srm_custom}, custom_channel_bins={custom_channel_bins}, **{kwargs})")

# from sunkit_spex.sunxspex_fitting.instruments import * gives us the instrument specific loaders, keys should match up to the "TELESCOP" header entry in spec file
# from sunkit_spex.fitting_legacy.instruments import * gives us the instrument specific loaders, keys should match up to the "TELESCOP" header entry in spec file
self.instrument_loaders = {"NuSTAR": inst.NustarLoader, "SOLO/STIX": inst.StixLoader, "RHESSI": inst.RhessiLoader}

pha_file, arf_file, rmf_file, srm_file, srm_custom, custom_channel_bins, instruments = self._sort_files(pha_file=pha_file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@

from astropy.table import Table

from sunkit_spex.logging import get_logger
from sunkit_spex.sunxspex_fitting.data_loader import LoadSpec
from sunkit_spex.sunxspex_fitting.instruments import rebin_any_array
from sunkit_spex.sunxspex_fitting.likelihoods import LogLikelihoods
from sunkit_spex.sunxspex_fitting.parameter_handler import Parameters, isnumber
from sunkit_spex.sunxspex_fitting.photon_models_for_fitting import ( # noqa
from sunkit_spex.fitting_legacy.data_loader import LoadSpec
from sunkit_spex.fitting_legacy.instruments import rebin_any_array
from sunkit_spex.fitting_legacy.likelihoods import LogLikelihoods
from sunkit_spex.fitting_legacy.parameter_handler import Parameters, isnumber
from sunkit_spex.fitting_legacy.photon_models_for_fitting import ( # noqa
defined_photon_models,
f_vth,
thick_fn,
thick_warm,
)
from sunkit_spex.sunxspex_fitting.rainbow_text import rainbow_text_lines
from sunkit_spex.fitting_legacy.rainbow_text import rainbow_text_lines
from sunkit_spex.logging import get_logger

warnings.filterwarnings("ignore", category=RuntimeWarning)
warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning)
Expand All @@ -66,7 +66,7 @@ class Fitter:
Parameters
----------
*args : dict
Dictionaries for custom data to be passed to `sunkit_spex.sunxspex_fitting.instruments.CustomLoader`.
Dictionaries for custom data to be passed to `sunkit_spex.fitting_legacy.instruments.CustomLoader`.
These will be added before any instrument file entries from `pha_file`.
pha_file : string or list of strings
Expand Down Expand Up @@ -270,7 +270,7 @@ class Fitter:
Colour cycle to be used when plotting submodels.
Default = plt.rcParams['axes.prop_cycle'].by_key()['color']
_construction_string_sunxspex : str
_construction_string_sunkit_spex : str
String to be returned from __repr__() dunder method.
_corresponding_submod_inputs : list of strings
Expand Down Expand Up @@ -401,8 +401,8 @@ def __init__(self, *args, pha_file=None, arf_file=None, rmf_file=None, srm_file=
self.data = LoadSpec(*args, pha_file=pha_file, arf_file=arf_file, rmf_file=rmf_file, srm_file=srm_file, srm_custom=srm_custom,
custom_channel_bins=custom_channel_bins, custom_photon_bins=custom_photon_bins, **kwargs)

self._construction_string_sunxspex = (f"Fitter({args}, pha_file={pha_file}, arf_file={arf_file}, rmf_file={rmf_file}, srm_file={srm_file}, "
f"srm_custom={srm_custom}, custom_channel_bins={custom_channel_bins}, custom_photon_bins={custom_photon_bins}, **{kwargs})")
self._construction_string_sunkit_spex = (f"Fitter({args}, pha_file={pha_file}, arf_file={arf_file}, rmf_file={rmf_file}, srm_file={srm_file}, "
f"srm_custom={srm_custom}, custom_channel_bins={custom_channel_bins}, custom_photon_bins={custom_photon_bins}, **{kwargs})")

self.loglikelihood = "cstat"

Expand Down Expand Up @@ -778,7 +778,7 @@ def del_photon_model(self, function_name):
logger.indo(f"Model {function_name} removed.")
else:
logger.warning(
"Default models imported from sunkit_spex.sunxspex_fitting.photon_models_for_fitting are protected.")
"Default models imported from sunkit_spex.fitting_legacy.photon_models_for_fitting are protected.")

def add_var(self, overwrite=False, quiet=False, **user_kwarg):
""" Add user variable to fitting namespace.
Expand Down Expand Up @@ -4685,7 +4685,7 @@ def __setstate__(self, d):

def __repr__(self):
"""Provide a representation to construct the class from scratch."""
return self._construction_string_sunxspex
return self._construction_string_sunkit_spex

def __str__(self):
"""Provide a printable, user friendly representation of what the class contains."""
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import pytest
from numpy.testing import assert_allclose

from sunkit_spex.sunxspex_fitting.fitter import Fitter
from sunkit_spex.sunxspex_fitting.instruments import CustomLoader, InstrumentBlueprint
from sunkit_spex.fitting_legacy.fitter import Fitter
from sunkit_spex.fitting_legacy.instruments import CustomLoader, InstrumentBlueprint

rng = np.random.default_rng(2022)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np

from sunkit_spex.sunxspex_fitting.io import (
from sunkit_spex.fitting_legacy.io import (
_read_arf,
_read_pha,
_read_rhessi_spec_file,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from numpy.testing import assert_allclose

from sunkit_spex.sunxspex_fitting.likelihoods import LogLikelihoods
from sunkit_spex.fitting_legacy.likelihoods import LogLikelihoods


def test_cstat():
Expand Down

0 comments on commit 2deabc0

Please sign in to comment.