Skip to content

Commit

Permalink
Add cython lint
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson committed Aug 11, 2023
1 parent 11f52c5 commit 23bfff3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ repos:
- id: ruff
args: ["--fix", "--show-fixes"]

- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.15.0
hooks:
- id: cython-lint
- id: double-quote-cython-strings

- repo: https://github.com/psf/black
rev: "23.7.0"
hooks:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ exclude = [
[tool.ruff.extend-per-file-ignores]
"tests/*.py" = ["S101"] # Turn off assert error for test files

[tool.cython-lint]
max-line-length = 88

[tool.repo-review]
ignore = ["MY", "PC140", "GH200", "GH210", "GH211"]
28 changes: 14 additions & 14 deletions src/stcal/ramp_fitting/ols_cas22.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ cdef int PTABLE_LENGTH = 6


cdef inline float get_weight_power(float s):
cdef int ise
for i in range(PTABLE_LENGTH):
if s < PTABLE[0][i]:
return PTABLE[1][i - 1]
Expand Down Expand Up @@ -87,8 +86,8 @@ cdef inline (float, float, float) fit_one_ramp(
for i in range(nres):
# Casertano+22, Eq. 45
ww[i] = ((((1 + weight_power) * nn[start + i]) /
(1 + weight_power * nn[start + i])) *
fabs((tbar[start + i] - tbarmid) / tscale) ** weight_power)
(1 + weight_power * nn[start + i])) *
fabs((tbar[start + i] - tbarmid) / tscale) ** weight_power)
# Casertano+22 Eq. 35
f0 += ww[i]
f1 += ww[i] * tbar[start + i]
Expand Down Expand Up @@ -160,21 +159,22 @@ def fit_ramps(np.ndarray[float, ndim=2] resultants,
"""
cdef int nresultant = len(ma_table)
if nresultant != resultants.shape[0]:
raise RuntimeError(f'MA table length {nresultant} does not match number of resultants {resultants.shape[0]}')
raise RuntimeError(f"MA table length {nresultant} does not match "
f"number of resultants {resultants.shape[0]}")

cdef np.ndarray[int] nn = np.array([x[1] for x in ma_table]).astype('i4')
cdef np.ndarray[int] nn = np.array([x[1] for x in ma_table]).astype("i4")
# number of reads in each resultant
cdef np.ndarray[float] tbar = ma_table_to_tbar(ma_table, read_time).astype('f4')
cdef np.ndarray[float] tau = ma_table_to_tau(ma_table, read_time).astype('f4')
cdef np.ndarray[float] tbar = ma_table_to_tbar(ma_table, read_time).astype("f4")
cdef np.ndarray[float] tau = ma_table_to_tau(ma_table, read_time).astype("f4")
cdef int npixel = resultants.shape[1]
cdef int nramp = (np.sum(dq[0, :] == 0) +
np.sum((dq[:-1, :] != 0) & (dq[1:, :] == 0)))
cdef np.ndarray[float] slope = np.zeros(nramp, dtype='f4')
cdef np.ndarray[float] slopereadvar = np.zeros(nramp, dtype='f4')
cdef np.ndarray[float] slopepoissonvar = np.zeros(nramp, dtype='f4')
cdef np.ndarray[int] resstart = np.zeros(nramp, dtype='i4') - 1
cdef np.ndarray[int] resend = np.zeros(nramp, dtype='i4') - 1
cdef np.ndarray[int] pix = np.zeros(nramp, dtype='i4') - 1
cdef np.ndarray[float] slope = np.zeros(nramp, dtype="f4")
cdef np.ndarray[float] slopereadvar = np.zeros(nramp, dtype="f4")
cdef np.ndarray[float] slopepoissonvar = np.zeros(nramp, dtype="f4")
cdef np.ndarray[int] resstart = np.zeros(nramp, dtype="i4") - 1
cdef np.ndarray[int] resend = np.zeros(nramp, dtype="i4") - 1
cdef np.ndarray[int] pix = np.zeros(nramp, dtype="i4") - 1
cdef int i, j
cdef int inramp = -1
cdef int rampnum = 0
Expand All @@ -194,7 +194,7 @@ def fit_ramps(np.ndarray[float, ndim=2] resultants,
resend[rampnum] = j - 1
rampnum += 1
else:
raise ValueError('unhandled case')
raise ValueError("unhandled case")
if inramp:
resend[rampnum] = j
rampnum += 1
Expand Down

0 comments on commit 23bfff3

Please sign in to comment.