From 258b9b95b6c1cf382ee53fafe1b4e653e9ecc5da Mon Sep 17 00:00:00 2001 From: Shane Maloney Date: Tue, 28 Jan 2025 13:52:27 +0000 Subject: [PATCH] Ignore A005 for the moment --- .ruff.toml | 1 + sunkit_spex/legacy/emission.py | 6 +++--- .../legacy/fitting/photon_models_for_fitting.py | 2 +- sunkit_spex/legacy/integrate.py | 2 +- sunkit_spex/legacy/thermal.py | 15 +++++++-------- sunkit_spex/models/physical/thermal.py | 15 +++++++-------- sunkit_spex/spectrum/spectrum.py | 4 ++-- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.ruff.toml b/.ruff.toml index d4dc5ed8..ff7fcbf0 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -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] diff --git a/sunkit_spex/legacy/emission.py b/sunkit_spex/legacy/emission.py index 6f660d56..f04ee295 100755 --- a/sunkit_spex/legacy/emission.py +++ b/sunkit_spex/legacy/emission.py @@ -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) @@ -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): @@ -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") diff --git a/sunkit_spex/legacy/fitting/photon_models_for_fitting.py b/sunkit_spex/legacy/fitting/photon_models_for_fitting.py index c80bf31e..e4a6e70a 100644 --- a/sunkit_spex/legacy/fitting/photon_models_for_fitting.py +++ b/sunkit_spex/legacy/fitting/photon_models_for_fitting.py @@ -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"], } diff --git a/sunkit_spex/legacy/integrate.py b/sunkit_spex/legacy/integrate.py index 9c563cfc..918ad1a4 100644 --- a/sunkit_spex/legacy/integrate.py +++ b/sunkit_spex/legacy/integrate.py @@ -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)) diff --git a/sunkit_spex/legacy/thermal.py b/sunkit_spex/legacy/thermal.py index 23a865e6..151386fa 100644 --- a/sunkit_spex/legacy/thermal.py +++ b/sunkit_spex/legacy/thermal.py @@ -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. @@ -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) @@ -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 @@ -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 @@ -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[*, *, *]) diff --git a/sunkit_spex/models/physical/thermal.py b/sunkit_spex/models/physical/thermal.py index b26a2e31..5bb2263a 100644 --- a/sunkit_spex/models/physical/thermal.py +++ b/sunkit_spex/models/physical/thermal.py @@ -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. @@ -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) @@ -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 @@ -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 @@ -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[*, *, *]) diff --git a/sunkit_spex/spectrum/spectrum.py b/sunkit_spex/spectrum/spectrum.py index df6e6cbb..40a80a0a 100644 --- a/sunkit_spex/spectrum/spectrum.py +++ b/sunkit_spex/spectrum/spectrum.py @@ -159,7 +159,7 @@ class Spectrum(NDCube):