Skip to content

Commit

Permalink
Maintenance update min python versions and add testing for newer vers…
Browse files Browse the repository at this point in the history
…ions (#121)

* Rename package sunkit-spex

* Update config files for new package sunkit-spex and module sunkit_spex
* Update all code references
* Update example notebooks

* Final remnants removed

* Update fitter.py

Changed two sunkit_spex back to Fitter.

* Update python version support and CI to match

---------

Co-authored-by: Shane Maloney <[email protected]>
Co-authored-by: Kris Cooper <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2023
1 parent 2827421 commit cfd41b9
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 30 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ repos:
- id: isort
args: ["--sp", "setup.cfg"]
exclude: ".*(.fits|.fts|.fit|.txt|tca.*|extern.*|.rst|.md|cm/__init__.py|docs/conf.py)$"
- repo: https://github.com/hhatto/autopep8
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v2.0.4
hooks:
- id: autopep8
args: ["--in-place","--max-line-length", "200"]
args: ["--in-place", "--max-line-length", "200"]
exclude: ".*(.fits|.fts|.fit|.txt|tca.*|extern.*|.rst|.md|cm/__init__.py)$"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.3.0
hooks:
- id: check-ast
- id: check-case-conflict
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version: 2
build:
os: ubuntu-20.04
tools:
python: "3.7"
python: "3.9"
apt_packages:
- graphviz

Expand Down
66 changes: 52 additions & 14 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ variables:
CI_NAME: Azure Pipelines
CI_BUILD_ID: $(Build.BuildId)
CI_BUILD_URL: "https://dev.azure.com/sunpy/sunxspex/_build/results?buildId=$(Build.BuildId)"
CIBW_BUILD: cp36-* cp37-* cp38-*
CIBW_BUILD: cp39-* cp310-* cp311-*
CIBW_SKIP: "*-win32 *-manylinux1_i686"

resources:
Expand Down Expand Up @@ -31,23 +31,51 @@ trigger:
jobs:
- template: run-tox-env.yml@OpenAstronomy
parameters:
toxverspec: <4
toxdeps: tox-pypi-filter
submodules: false
coverage: codecov
envs:
- macos: py38
name: py38_test_macos
- linux: codestyle
name: codestyle

- windows: py37
name: py37_win
- linux: py39
name: py39_linux_test

- linux: py38
name: py38_lin
- linux: py310
name: py310_linux_test

- linux: codestyle
name: codestyle
- linux: py311
name: py311_linux_test

# - linux: py312
# name: py312_linux_test

- macos: py39
name: py39_mac_test
coverage: false

- macos: py310
name: py310_mac_test
coverage: false

- macos: py311
name: py311_mac_test
coverage: false

# - macos: py312
# name: py312_mac_test
# coverage: false

- windows: py39
name: py39_win_test

- windows: py310
name: py310_win_test

- windows: py311
name: py311_win_test

# - windows: py312
# name: py312_win_test

# On branches which aren't master, and not Pull Requests, build the wheels but only upload them on tags
- ${{ if and(ne(variables['Build.Reason'], 'PullRequest'), not(contains(variables['Build.SourceBranch'], 'master'))) }}:
Expand All @@ -65,6 +93,16 @@ jobs:
- wheels_macos
- sdist
dependsOn:
- py38_test_macos
- py37_test
- py38_test
- codestyle
- py39_linux_test
- py310_linux_test
- py311_linux_test
# - py312_linux_test
- py39_mac_test
- py310_mac_test
- py311_mac_test
# - py312_mac_test
- py39_win_test
- py310_win_test
- py311_win_test
# - py312_win_test
1 change: 1 addition & 0 deletions changelog/121.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update minimum python version to python version to 3.9 and add testing for 3.10 and 3.11.
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ long_description = file: README.rst
[options]
zip_safe = False
packages = find:
python_requires = >=3.7
python_requires = >=3.9
setup_requires = setuptools_scm
install_requires =
sunpy
parfive < 2.0
parfive
scipy
xarray
quadpy
Expand All @@ -28,6 +28,7 @@ install_requires =
nestle
numdifftools


[options.extras_require]
test =
pytest
Expand All @@ -38,6 +39,8 @@ docs =
sphinx
sphinx-automodapi
sunpy-sphinx-theme
# Remove next line when fixed in towncrier; see https://github.com/twisted/towncrier/issues/528
importlib-resources<6
sphinx-changelog>=1.1.1

[options.package_data]
Expand Down
2 changes: 1 addition & 1 deletion sunkit_spex/emission.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def density(self, electron_energy):

def __repr__(self):
return f'{self.__class__.__name__}(p={self.p}, q={self.q}, eelow={self.eelow}, ' \
f'eebrk={self.eebrk}, eehigh={self.eehigh}, norm={self.norm})'
f'eebrk={self.eebrk}, eehigh={self.eehigh}, norm={self.norm})'


def collisional_loss(electron_energy):
Expand Down
3 changes: 2 additions & 1 deletion sunkit_spex/sunxspex_fitting/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class LoadSpec:
def __init__(self, *args, pha_file=None, arf_file=None, rmf_file=None, srm_file=None, srm_custom=None, custom_channel_bins=None, **kwargs):
"""Construct a string to show how the class was constructed (`_construction_string`) and set the `loaded_spec_data` dictionary attribute."""

self._construction_string = f"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}, **{kwargs})"
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
self.instrument_loaders = {"NuSTAR": inst.NustarLoader, "SOLO/STIX": inst.StixLoader, "RHESSI": inst.RhessiLoader}
Expand Down
11 changes: 7 additions & 4 deletions sunkit_spex/sunxspex_fitting/fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +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},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.loglikelihood = "cstat"

Expand Down Expand Up @@ -845,7 +846,7 @@ def add_var(self, overwrite=False, quiet=False, **user_kwarg):
for k, i in user_kwarg.items():
if k in self.dynamic_vars and not overwrite:
vb = f"Variable {k} already exists. Please set `overwrite=True`, delete this with " \
f"`del_var({k})`,\nor use a different variable name."
f"`del_var({k})`,\nor use a different variable name."
elif not k in self.dynamic_vars:
vb = f"Argument name {k} already exists **in globals** and is not a good idea to " \
f"overwrite. Please use a different variable name."
Expand Down Expand Up @@ -2046,7 +2047,8 @@ def _fit_setup(self):
photon_channel_bins, photon_channel_mids, photon_channel_widths, srm = self._photon_space_reduce(ph_bins=photon_channel_bins,
ph_mids=photon_channel_mids,
ph_widths=photon_e_binning,
srm=srm) # arf (for NuSTAR at least) makes ~half of the rows all zeros (>80 keV), remove them and cut fitting time by a third
# arf (for NuSTAR at least) makes ~half of the rows all zeros (>80 keV), remove them and cut fitting time by a third
srm=srm)
# photon_e_binning

# remove the count space reduce since this now needs to reduce the livetimes and baclgrounds if they are there
Expand Down Expand Up @@ -2336,7 +2338,8 @@ def _calc_counts_model(self, photon_model, parameters=None, spectrum="spectrum1"
photon_channel_bins, _, _, srm = self._photon_space_reduce(ph_bins=[self.data.loaded_spec_data[spectrum]['photon_channel_bins']],
ph_mids=[self.data.loaded_spec_data[spectrum]['photon_channel_bins']],
ph_widths=[self.data.loaded_spec_data[spectrum]['photon_channel_binning']],
srm=[self.data.loaded_spec_data[spectrum]['srm']]) # arf (for NuSTAR at least) makes ~half of the rows all zeros (>80 keV), remove them and cut fitting time by a third
# arf (for NuSTAR at least) makes ~half of the rows all zeros (>80 keV), remove them and cut fitting time by a third
srm=[self.data.loaded_spec_data[spectrum]['srm']])
photon_channel_bins, srm = photon_channel_bins[0], srm[0]

if type(parameters) == type(None):
Expand Down
6 changes: 4 additions & 2 deletions sunkit_spex/sunxspex_fitting/instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ class NustarLoader(InstrumentBlueprint):
def __init__(self, pha_file, arf_file=None, rmf_file=None, srm_custom=None, custom_channel_bins=None, custom_photon_bins=None, **kwargs):
"""Construct a string to show how the class was constructed (`_construction_string`) and set the `_loaded_spec_data` dictionary attribute."""

self._construction_string = f"NustarLoader(pha_file={pha_file},arf_file={arf_file},rmf_file={rmf_file},srm_custom={srm_custom},custom_channel_bins={custom_channel_bins},custom_photon_bins={custom_photon_bins},**{kwargs})"
self._construction_string = (f"NustarLoader(pha_file={pha_file}, arf_file={arf_file}, rmf_file={rmf_file}, srm_custom={srm_custom}, "
f"custom_channel_bins={custom_channel_bins}, custom_photon_bins={custom_photon_bins}, **{kwargs})")
self._loaded_spec_data = self._load1spec(pha_file, f_arf=arf_file, f_rmf=rmf_file, srm=srm_custom, channel_bins=custom_channel_bins, photon_bins=custom_photon_bins)

def _load1spec(self, f_pha, f_arf=None, f_rmf=None, srm=None, channel_bins=None, photon_bins=None):
Expand Down Expand Up @@ -569,7 +570,8 @@ class RhessiLoader(InstrumentBlueprint):
def __init__(self, pha_file, srm_file=None, srm_custom=None, custom_channel_bins=None, custom_photon_bins=None, **kwargs):
"""Construct a string to show how the class was constructed (`_construction_string`) and set the `_loaded_spec_data` dictionary attribute."""

self._construction_string = f"RhessiLoader(pha_file={pha_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 = (f"RhessiLoader(pha_file={pha_file}, srm_file={srm_file}, srm_custom={srm_custom}, "
f"custom_channel_bins={custom_channel_bins}, custom_photon_bins={custom_photon_bins}, **{kwargs})")
self._loaded_spec_data = self._load1spec(pha_file, srm_file, srm=srm_custom, channel_bins=custom_channel_bins, photon_bins=custom_photon_bins)

self._time_fmt, self._time_scale = "isot", "utc"
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{37,38}
py{39,310,311}
build_docs
codestyle
isolated_build = true
Expand All @@ -20,7 +20,7 @@ requires =
pypi_filter_requirements = https://raw.githubusercontent.com/sunpy/package-template/master/sunpy_version_pins.txt

# Pass through the following environemnt variables which may be needed for the CI
passenv = HOME WINDIR LC_ALL LC_CTYPE CC CI TRAVIS
passenv = HOME, WINDIR, LC_ALL, LC_CTYPE, CC, CI, TRAVIS

# Run the tests in a temporary directory to make sure that we don't import
# the package from the source tree
Expand Down Expand Up @@ -59,5 +59,6 @@ description = Run all style and file checks with pre-commit
deps =
pre-commit
commands =
python -V
pre-commit install-hooks
pre-commit run --all-files

0 comments on commit cfd41b9

Please sign in to comment.