diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ea212c9d1..48ae22b08 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/pyproject.toml b/pyproject.toml index d2ce8fdda..54f7f970e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] diff --git a/src/stcal/ramp_fitting/ols_cas22.pyx b/src/stcal/ramp_fitting/ols_cas22.pyx index a57960b1c..820fae570 100644 --- a/src/stcal/ramp_fitting/ols_cas22.pyx +++ b/src/stcal/ramp_fitting/ols_cas22.pyx @@ -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] @@ -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] @@ -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 @@ -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