Skip to content

Commit

Permalink
Updates from the package template (#179)
Browse files Browse the repository at this point in the history
* Automatic package template update

* Ignore A005 for the moment

---------

Co-authored-by: DanRyanIrish <[email protected]>
Co-authored-by: Shane Maloney <[email protected]>
  • Loading branch information
3 people authored Jan 28, 2025
1 parent d6ca8af commit 175e3dd
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/sunpy/package-template",
"commit": "d6b86e07efa31959f43e99ba32d323cf76736a05",
"commit": "37ffb52646450caa4de8ea084725dbff65fe0995",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down Expand Up @@ -32,7 +32,7 @@
".github/workflows/sub_package_update.yml"
],
"_template": "https://github.com/sunpy/package-template",
"_commit": "d6b86e07efa31959f43e99ba32d323cf76736a05"
"_commit": "37ffb52646450caa4de8ea084725dbff65fe0995"
}
},
"directory": null
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
# This should be before any formatting hooks like isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.6"
rev: "v0.9.2"
hooks:
- id: ruff
args: ["--fix"]
Expand All @@ -27,7 +27,7 @@ repos:
- id: mixed-line-ending
exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*)$"
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.0
hooks:
- id: codespell
additional_dependencies:
Expand Down
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extend-ignore = [
"N802", # Function name should be lowercase
"N803", # Argument name should be lowercase
"N806", # Variable in function should be lowercase
"A005", # Module `io` shadows a Python standard-library module
]

[lint.per-file-ignores]
Expand Down
6 changes: 3 additions & 3 deletions sunkit_spex/legacy/emission.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def _split_and_integrate(*, model, photon_energies, maxfcn, rerr, eelow, eebrk,
clight = const.get_constant("clight")

if not eelow <= eebrk <= eehigh:
raise ValueError(f"Condition eelow <= eebrek <= eehigh not satisfied " f"({eelow}<={eebrk}<={eehigh}).")
raise ValueError(f"Condition eelow <= eebrek <= eehigh not satisfied ({eelow}<={eebrk}<={eehigh}).")

# Create arrays for integral sums and error flags.
intsum1 = np.zeros_like(photon_energies, dtype=np.float64)
Expand Down Expand Up @@ -740,7 +740,7 @@ def bremsstrahlung_thin_target(photon_energies, p, eebrk, q, eelow, eehigh, efd=
flux *= fcoeff

return flux
raise Warning("The photon energies are higher than the highest electron energy or not " "greater than zero")
raise Warning("The photon energies are higher than the highest electron energy or not greater than zero")


def bremsstrahlung_thick_target(photon_energies, p, eebrk, q, eelow, eehigh, integrator=None):
Expand Down Expand Up @@ -835,4 +835,4 @@ def bremsstrahlung_thick_target(photon_energies, p, eebrk, q, eelow, eehigh, int

return (fcoeff / decoeff) * flux

raise Warning("The photon energies are higher than the highest electron energy or not " "greater than zero")
raise Warning("The photon energies are higher than the highest electron energy or not greater than zero")
2 changes: 1 addition & 1 deletion sunkit_spex/legacy/fitting/photon_models_for_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
defined_photon_models = {
"f_vth": ["T", "EM"],
"thick_fn": ["total_eflux", "index", "e_c"],
"thick_warm": ["tot_eflux", "indx", "ec", "plasma_d", "loop_temp", "length"],
"thick_warm": ["tot_eflux", "index", "ec", "plasma_d", "loop_temp", "length"],
}


Expand Down
2 changes: 1 addition & 1 deletion sunkit_spex/legacy/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ def fixed_quad(func, a, b, n=5, args=(), func_kwargs={}):
x, w = _cached_roots_legendre(n)
x = np.real(x)
if np.any(np.isinf(a)) or np.any(np.isinf(b)):
raise ValueError("Gaussian quadrature is only available for " "finite limits.")
raise ValueError("Gaussian quadrature is only available for finite limits.")
y = (b - a).reshape(-1, 1) * (x + 1) / 2.0 + a.reshape(-1, 1)
return np.squeeze((b - a).reshape(1, -1) / 2.0 * np.sum(w * func(y, *args, **func_kwargs), axis=1))
15 changes: 7 additions & 8 deletions sunkit_spex/legacy/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,11 @@ def _calculate_abundance_normalized_line_intensities(logT, data_grid, line_logT_
for i in range(n_temperatures):
# Identify the "temperature" bin to which the input "temperature"
# corresponds and its two nearest neighbors.
indx = temperature_bins[i] - 1 + np.arange(3)
index = temperature_bins[i] - 1 + np.arange(3)
# Interpolate the 2nd axis to produce a function that gives the data
# as a function of 1st axis, say energy, at a given value along the 2nd axis,
# say "temperature".
get_intensities_at_logT = interpolate.interp1d(line_logT_bins[indx], data_grid[:, indx], kind="quadratic")
get_intensities_at_logT = interpolate.interp1d(line_logT_bins[index], data_grid[:, index], kind="quadratic")
# Use function to get interpolated_data as a function of the first axis at
# the input value along the 2nd axis,
# e.g. line intensities as a function of energy at a given temperature.
Expand Down Expand Up @@ -733,8 +733,7 @@ def _error_if_input_outside_valid_range(input_values, grid_range, param_name, pa
grid_range = u.Quantity(grid_range, unit=param_unit).to_value(message_unit)
param_unit = message_unit
message = (
f"All input {param_name} values must be within the range "
f"{grid_range[0]}--{grid_range[1]} {param_unit}. "
f"All input {param_name} values must be within the range {grid_range[0]}--{grid_range[1]} {param_unit}. "
)
raise ValueError(message)

Expand Down Expand Up @@ -925,8 +924,8 @@ def _calculate_abundances(abundance_type, relative_abundances):
# logt = LOGT # grid temperatures = log(temperature)
# ntemp = len(logt)
# selt = np.argwhere(logt<=u)[-1] # what gap does my temp land in the logt array (inclusive of the lower boundary)
# indx = np.clip([selt-1, selt, selt+1], 0, ntemp-1) # find the indexes either side of that gap
# tband = logt[indx]
# index = np.clip([selt-1, selt, selt+1], 0, ntemp-1) # find the indexes either side of that gap
# tband = logt[index]
# s=1
# x0, x1, x2 = tband[0][0], tband[1][0], tband[2][0] # temperatures either side of that gap

Expand All @@ -936,7 +935,7 @@ def _calculate_abundances(abundance_type, relative_abundances):

# # all wavelengths divided by corresponding temp[0] (first row), then exvl/temp[1] second row, exvl/temp[2] third row
# # inverse boltzmann factor of hv/kT and 11.6e6 from keV-to-J conversion over k = 1.6e-16 / 1.381e-23 ~ 11.6e6
# exponential = (np.ones((3,1)) @ ewvl_exp) / ((10**logt[indx]/11.6e6) @ np.ones((1,nwvl)))
# exponential = (np.ones((3,1)) @ ewvl_exp) / ((10**logt[index]/11.6e6) @ np.ones((1,nwvl)))
# exponential = np.exp(np.clip(exponential, None, 80)) # not sure why clipping at 80
# # this is just from dE/dA = E/A from E=hc/A (A=wavelength) for change of variables from Angstrom to keV: dE = dA * (E/A)
# # have this repeated for 3 rows since this is the form of the expontial's different temps
Expand Down Expand Up @@ -966,7 +965,7 @@ def _calculate_abundances(abundance_type, relative_abundances):
# # totcont_lo is the continuum <1 keV I think and totcont is >=1 keV, so adding the wavelength dimension of each of these you get the number of wavlengths provided by continuum_info[1]['edge_str']['WVL']
# # look here for more info on how the CHIANTI file is set-up **** https://hesperia.gsfc.nasa.gov/ssw/packages/xray/idl/setup_chianti_cont.pro ****
# # this exact script won't create the folder Python is using the now since some of the wavelengths and deltas don't match-up
# totcontindx = np.concatenate((continuum_info[1]["totcont_lo"][:, indx.T[0], :], continuum_info[1]["totcont"][:, indx.T[0], :]), axis=2) # isolate temps and then combine along wavelength axis
# totcontindx = np.concatenate((continuum_info[1]["totcont_lo"][:, index.T[0], :], continuum_info[1]["totcont"][:, index.T[0], :]), axis=2) # isolate temps and then combine along wavelength axis
# # careful from here on out. IDL's indexes are backwards to Pythons
# # Python's a[:,:,0] == IDL's a[0,*,*], a[:,0,:] == a[*,0,*], and then a[0,:,:] == a[*,*,0]
# tcdbase = totcontindx # double(totcontindx[*, *, *])
Expand Down
15 changes: 7 additions & 8 deletions sunkit_spex/models/physical/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,11 @@ def _calculate_abundance_normalized_line_intensities(logT, data_grid, line_logT_
for i in range(n_temperatures):
# Identify the "temperature" bin to which the input "temperature"
# corresponds and its two nearest neighbors.
indx = temperature_bins[i] - 1 + np.arange(3)
index = temperature_bins[i] - 1 + np.arange(3)
# Interpolate the 2nd axis to produce a function that gives the data
# as a function of 1st axis, say energy, at a given value along the 2nd axis,
# say "temperature".
get_intensities_at_logT = interpolate.interp1d(line_logT_bins[indx], data_grid[:, indx], kind="quadratic")
get_intensities_at_logT = interpolate.interp1d(line_logT_bins[index], data_grid[:, index], kind="quadratic")
# Use function to get interpolated_data as a function of the first axis at
# the input value along the 2nd axis,
# e.g. line intensities as a function of energy at a given temperature.
Expand Down Expand Up @@ -737,8 +737,7 @@ def _error_if_input_outside_valid_range(input_values, grid_range, param_name, pa
grid_range = u.Quantity(grid_range, unit=param_unit).to_value(message_unit)
param_unit = message_unit
message = (
f"All input {param_name} values must be within the range "
f"{grid_range[0]}--{grid_range[1]} {param_unit}. "
f"All input {param_name} values must be within the range {grid_range[0]}--{grid_range[1]} {param_unit}. "
)
raise ValueError(message)

Expand Down Expand Up @@ -929,8 +928,8 @@ def _calculate_abundances(abundance_type, relative_abundances):
# logt = LOGT # grid temperatures = log(temperature)
# ntemp = len(logt)
# selt = np.argwhere(logt<=u)[-1] # what gap does my temp land in the logt array (inclusive of the lower boundary)
# indx = np.clip([selt-1, selt, selt+1], 0, ntemp-1) # find the indexes either side of that gap
# tband = logt[indx]
# index = np.clip([selt-1, selt, selt+1], 0, ntemp-1) # find the indexes either side of that gap
# tband = logt[index]
# s=1
# x0, x1, x2 = tband[0][0], tband[1][0], tband[2][0] # temperatures either side of that gap

Expand All @@ -940,7 +939,7 @@ def _calculate_abundances(abundance_type, relative_abundances):

# # all wavelengths divided by corresponding temp[0] (first row), then exvl/temp[1] second row, exvl/temp[2] third row
# # inverse boltzmann factor of hv/kT and 11.6e6 from keV-to-J conversion over k = 1.6e-16 / 1.381e-23 ~ 11.6e6
# exponential = (np.ones((3,1)) @ ewvl_exp) / ((10**logt[indx]/11.6e6) @ np.ones((1,nwvl)))
# exponential = (np.ones((3,1)) @ ewvl_exp) / ((10**logt[index]/11.6e6) @ np.ones((1,nwvl)))
# exponential = np.exp(np.clip(exponential, None, 80)) # not sure why clipping at 80
# # this is just from dE/dA = E/A from E=hc/A (A=wavelength) for change of variables from Angstrom to keV: dE = dA * (E/A)
# # have this repeated for 3 rows since this is the form of the expontial's different temps
Expand Down Expand Up @@ -970,7 +969,7 @@ def _calculate_abundances(abundance_type, relative_abundances):
# # totcont_lo is the continuum <1 keV I think and totcont is >=1 keV, so adding the wavelength dimension of each of these you get the number of wavlengths provided by continuum_info[1]['edge_str']['WVL']
# # look here for more info on how the CHIANTI file is set-up **** https://hesperia.gsfc.nasa.gov/ssw/packages/xray/idl/setup_chianti_cont.pro ****
# # this exact script won't create the folder Python is using the now since some of the wavelengths and deltas don't match-up
# totcontindx = np.concatenate((continuum_info[1]["totcont_lo"][:, indx.T[0], :], continuum_info[1]["totcont"][:, indx.T[0], :]), axis=2) # isolate temps and then combine along wavelength axis
# totcontindx = np.concatenate((continuum_info[1]["totcont_lo"][:, index.T[0], :], continuum_info[1]["totcont"][:, index.T[0], :]), axis=2) # isolate temps and then combine along wavelength axis
# # careful from here on out. IDL's indexes are backwards to Pythons
# # Python's a[:,:,0] == IDL's a[0,*,*], a[:,0,:] == a[*,0,*], and then a[0,:,:] == a[*,*,0]
# tcdbase = totcontindx # double(totcontindx[*, *, *])
Expand Down
5 changes: 3 additions & 2 deletions sunkit_spex/spectrum/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from astropy.utils import lazyproperty

__all__ = ["SpectralAxis", "Spectrum", "gwcs_from_array"]
__doctest_requires__ = {"Spectrum": ["ndcube>=2.3"]}


def gwcs_from_array(array):
Expand Down Expand Up @@ -158,7 +159,7 @@ class Spectrum(NDCube):
<sunkit_spex.spectrum.spectrum.Spectrum object at ...
NDCube
------
Dimensions: [10.] pix
Shape: (10,)
Physical Types of Axes: [('em.energy',)]
Unit: W
Data Type: float64
Expand Down Expand Up @@ -204,7 +205,7 @@ def __init__(
if spectral_axis is not None:
# Ensure that the spectral axis is an astropy Quantity
if not isinstance(spectral_axis, u.Quantity):
raise ValueError("Spectral axis must be a `Quantity` or " "`SpectralAxis` object.")
raise ValueError("Spectral axis must be a `Quantity` or `SpectralAxis` object.")

# If a spectral axis is provided as an astropy Quantity, convert it
# to a SpectralAxis object.
Expand Down

0 comments on commit 175e3dd

Please sign in to comment.