Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust style checks to align with jwst #295

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 12 additions & 39 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
exclude: ".*\\.asdf$"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -15,49 +17,20 @@ repos:
# - id: end-of-file-fixer
# - id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char

# - repo: https://github.com/codespell-project/codespell
# rev: v2.2.5
# hooks:
# - id: codespell
# args: ["--write-changes"]
# additional_dependencies:
# - tomli

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.5"
rev: 'v0.6.8'
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
args: ["--fix"]
# - id: ruff-format

- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.15.0
- repo: https://github.com/PyCQA/bandit
rev: 1.7.10
hooks:
- id: cython-lint
# - id: double-quote-cython-strings
- id: bandit
args: ["-r", "-ll", "src", "tests"]
braingram marked this conversation as resolved.
Show resolved Hide resolved

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (cython)
types: [cython]

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.16.2
hooks:
- id: blacken-docs
additional_dependencies:
- black==22.12.0

# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: "v3.0.1"
# hooks:
# - id: prettier
- id: cython-lint
1 change: 1 addition & 0 deletions changes/295.general.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adjust code style checks.
77 changes: 4 additions & 73 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,69 +120,12 @@ src = [
]

[tool.ruff.lint]
select = [
#"F", # Pyflakes (part of default flake8)
#"W", "E", # pycodestyle (part of default flake8)
#"I", # isort (import sorting)
# "N", # pep8-naming
#"D", # pydocstyle (docstring style guide)
#"UP", # pyupgrade (upgrade code to modern python)
"YTT", # flake8-2020 (system version info)
"ANN", # flake8-annotations (best practices for type annotations)
#"S", # flake8-bandit (security checks)
"BLE", # flake8-blind-except (prevent blind except statements)
#"B", # flake8-bugbear (prevent common gotcha bugs)
"A", # flake8-builtins (prevent shadowing of builtins)
"C4", # flake8-comprehensions (best practices for comprehensions)
"T10", # flake8-debugger (prevent debugger statements in code)
#"EM", # flake8-errormessages (best practices for error messages)
"FA", # flake8-future-annotations (correct usage future annotations)
"ISC", # flake8-implicit-str-concat (prevent implicit string concat)
"ICN", # flake8-import-conventions (enforce import conventions)
#"G", # flake8-logging-format (best practices for logging)
"INP", # flake8-no-pep420 (prevent use of PEP420, i.e. implicit name spaces)
#"PIE", # flake8-pie (misc suggested improvement linting)
# "T20", # flake8-print (prevent print statements in code)
#"PT", # flake8-pytest-style (best practices for pytest)
#"Q", # flake8-quotes (best practices for quotes)
"RSE", # flake8-raise (best practices for raising exceptions)
#"RET", # flake8-return (best practices for return statements)
#"SLF", # flake8-self (prevent private member access)
"SLOT", # flake8-slots (require __slots__ for immutable classes)
#"SIM", # flake8-simplify (suggest simplifications to code where possible)
"TID", # flake8-tidy-imports (prevent banned api and best import practices)
"TCH", # flake8-type-checking (move type checking imports into type checking blocks)
"INT", # flake8-gettext (when to use printf style strings)
# "ARG", # flake8-unused-arguments (prevent unused arguments)
#"PTH", # flake8-use-pathlib (prefer pathlib over os.path)
# "ERA", # eradicate (remove commented out code)
"PGH", # pygrep (simple grep checks)
#"PL", # pylint (general linting, flake8 alternative)
#"TRY", # tryceratops (linting for try/except blocks)
"FLY", # flynt (f-string conversion where possible)
#"NPY", # NumPy-specific checks (recommendations from NumPy)
#"PERF", # Perflint (performance linting)
"LOG",
#"RUF", # ruff specific checks
extend-select = [
"I", # isort
]
ignore = [
"ISC001", # interferes with formatter
"PLR0912", # Too many branches
"PLR0913", # Too many arguments
"PLR0915", # Too many statements
"PLR2004", # Magic value used in comparison
"ANN101", # Missing type annotation for self in method
"ANN102", # Missing type annotation for cls in classmethod

# Pydocstyle (to fix over time
"D100", # Undocumented public module
"D101", # Undocumented public class
"D102", # Undocumented public method
"D103", # Undocumented public function
"D104", # Undocumented public package
"D205", # 1 blank line required between summary line and description
"D401", # First line of docstring should be in imperative mood
"D404", # First word of docstring should not be This
# "E741", # ambiguous variable name (O/0, l/I, etc.)
# "E722", # Do not use bare `except`
]
exclude = [
"docs",
Expand All @@ -192,18 +135,6 @@ exclude = [
".eggs",
]

[tool.ruff.lint.extend-per-file-ignores]
"tests/*.py" = [
"S101",
"D",
]

[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.lint.flake8-annotations]
ignore-fully-untyped = true # Turn of annotation checking for fully untyped code

[tool.mypy]
python_version = "3.12"
warn_return_any = true
Expand Down
2 changes: 1 addition & 1 deletion src/stcal/alignment/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import functools
import logging
import re
from typing import TYPE_CHECKING
import warnings
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Callable, Sequence
Expand Down
9 changes: 3 additions & 6 deletions src/stcal/jump/jump.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import time
import warnings

import numpy as np
import cv2 as cv
import astropy.stats as stats

from astropy.convolution import Ring2DKernel
from astropy.convolution import convolve
import cv2 as cv
import numpy as np
from astropy.convolution import Ring2DKernel, convolve

from . import constants
from . import twopoint_difference as twopt
Expand Down Expand Up @@ -760,7 +758,6 @@ def extend_ellipses(
saty, satx = np.where(sat_pix == sat_flag)
jump_ellipse[saty, satx] = 0
out_gdq_cube[intg, flg_grp, :, :] = np.bitwise_or(gdq_cube[intg, flg_grp, :, :], jump_ellipse)
diff_cube = out_gdq_cube - gdq_cube
return out_gdq_cube, num_ellipses

def find_last_grp(grp, ngrps, num_grps_masked):
Expand Down
3 changes: 0 additions & 3 deletions src/stcal/jump/twopoint_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import warnings

import numpy as np
import warnings
from astropy import stats

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -490,7 +489,6 @@ def calc_med_first_diffs(in_first_diffs):
return np.nan

if first_diffs.ndim == 2: # in the case where input is a single pixel
nansum = np.sum(np.isnan(first_diffs), axis=(0, 1))
num_usable_diffs = first_diffs.size - np.sum(np.isnan(first_diffs), axis=(0, 1))
if num_usable_diffs >= 4: # if 4+, clip largest and return median
mask = np.ones_like(first_diffs).astype(bool)
Expand All @@ -500,7 +498,6 @@ def calc_med_first_diffs(in_first_diffs):
elif num_usable_diffs == 3: # if 3, no clipping just return median
return np.nanmedian(first_diffs)
elif num_usable_diffs == 2: # if 2, return diff with minimum abs
TEST = np.nanargmin(np.abs(first_diffs))
diff_min_idx = np.nanargmin(first_diffs)
location = np.unravel_index(diff_min_idx, first_diffs.shape)
return first_diffs[location]
Expand Down
6 changes: 3 additions & 3 deletions src/stcal/outlier_detection/utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""
Utility functions for outlier detection routines
"""
import warnings

import logging

import gwcs
import numpy as np
from astropy.stats import sigma_clip
from drizzle.cdrizzle import tblot
from scipy import ndimage
from skimage.util import view_as_windows
import gwcs

from stcal.alignment.util import wcs_bbox_from_shape

import logging
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)

Expand Down
5 changes: 3 additions & 2 deletions src/stcal/ramp_fitting/likely_algo_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@
Bias of the best-fit count rate from using cvec plus the observed
resultants to estimate the covariance matrix.
"""

from .likely_fit import fit_ramps

Check warning on line 282 in src/stcal/ramp_fitting/likely_algo_classes.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/likely_algo_classes.py#L282

Added line #L282 was not covered by tests

alpha = countrates[np.newaxis, :] * self.alpha_phnoise[:, np.newaxis]
alpha += sig**2 * self.alpha_readnoise[:, np.newaxis]
beta = countrates[np.newaxis, :] * self.beta_phnoise[:, np.newaxis]
Expand All @@ -291,8 +294,6 @@
# try to avoid problems with roundoff error
da_incr = da * (countrates[np.newaxis, :] + sig**2)

dalpha = da_incr * self.alpha_phnoise[:, np.newaxis]
dbeta = da_incr * self.beta_phnoise[:, np.newaxis]
result_high_a = fit_ramps(z, self, sig, countrateguess=countrates + da_incr)
# finite difference approximation to dw/da

Expand Down
13 changes: 3 additions & 10 deletions src/stcal/ramp_fitting/likely_fit.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#! /usr/bin/env python

import logging
import multiprocessing
import time
import scipy
import sys
import warnings

from multiprocessing import cpu_count
from pprint import pprint

import numpy as np
import scipy

from . import ramp_fit_class, utils
from .likely_algo_classes import IntegInfo, RampResult, Covar

from . import utils
from .likely_algo_classes import Covar, IntegInfo, RampResult

DELIM = "=" * 80
SQRT2 = np.sqrt(2)
Expand Down
5 changes: 2 additions & 3 deletions src/stcal/ramp_fitting/ols_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import logging
import multiprocessing
import sys
import time
import warnings
from multiprocessing import cpu_count
import sys

import numpy as np

from .slope_fitter import ols_slope_fitter # c extension
from . import ramp_fit_class, utils

from .slope_fitter import ols_slope_fitter # c extension

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
Expand Down
12 changes: 6 additions & 6 deletions src/stcal/ramp_fitting/ramp_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
from astropy import units as u

from . import (
gls_fit, # used only if algorithm is "GLS"
likely_fit, # used only if algorithm is "LIKELY"
ols_fit, # used only if algorithm is "OLS"
gls_fit, # used only if algorithm is "GLS"
likely_fit, # used only if algorithm is "LIKELY"
ols_fit, # used only if algorithm is "OLS"
ramp_fit_class,
)

Expand Down Expand Up @@ -261,9 +261,9 @@ def ramp_fit_data(
# a minimum of a four group ramp is needed.
ngroups = ramp_data.data.shape[1]
if algorithm.upper() == "LIKELY" and ngroups < likely_fit.LIKELY_MIN_NGROUPS:
log.info(f"When selecting the LIKELY ramp fitting algorithm the"
braingram marked this conversation as resolved.
Show resolved Hide resolved
" ngroups needs to be a minimum of {likely_fit.LIKELY_MIN_NGROUPS},"
" but ngroups = {ngroups}. Due to this, the ramp fitting algorithm"
log.info("When selecting the LIKELY ramp fitting algorithm the"
f" ngroups needs to be a minimum of {likely_fit.LIKELY_MIN_NGROUPS},"
f" but ngroups = {ngroups}. Due to this, the ramp fitting algorithm"
" is being changed to OLS_C")
algorithm = "OLS_C"

Expand Down
8 changes: 4 additions & 4 deletions src/stcal/ramp_fitting/ramp_fit_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@

def dbg_print_pixel_info(self, row, col):
print("-" * 80)
print(f" data")
print(" data")

Check warning on line 212 in src/stcal/ramp_fitting/ramp_fit_class.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/ramp_fit_class.py#L212

Added line #L212 was not covered by tests
for integ in range(self.data.shape[0]):
print(f"[{integ}] {self.data[integ, :, row, col]}")
print(f" groupdq")
print(" groupdq")

Check warning on line 215 in src/stcal/ramp_fitting/ramp_fit_class.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/ramp_fit_class.py#L215

Added line #L215 was not covered by tests
for integ in range(self.data.shape[0]):
print(f"[{integ}] {self.groupdq[integ, :, row, col]}")
# print(f" err :\n{self.err[:, :, row, col]}")
Expand Down Expand Up @@ -280,8 +280,8 @@

# XXX Make this a separate function
delimiter = "-" * 40
fd.write(f"{indent}# {delimiter}\n\n");
fd.write(f"{indent}# ({row}, {col})\n\n");
fd.write(f"{indent}# {delimiter}\n\n")
fd.write(f"{indent}# ({row}, {col})\n\n")

Check warning on line 284 in src/stcal/ramp_fitting/ramp_fit_class.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/ramp_fit_class.py#L283-L284

Added lines #L283 - L284 were not covered by tests

nints = self.data.shape[0]

Expand Down
1 change: 0 additions & 1 deletion src/stcal/ramp_fitting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import numpy as np


log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)

Expand Down
6 changes: 3 additions & 3 deletions tests/outlier_detection/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import warnings

import gwcs
import pytest
import numpy as np
import pytest
import scipy.signal
from astropy.modeling import models

from stcal.outlier_detection.utils import (
_abs_deriv,
calc_gwcs_pixmap,
compute_weight_threshold,
flag_crs,
flag_resampled_crs,
gwcs_blot,
calc_gwcs_pixmap,
reproject,
medfilt,
reproject,
)


Expand Down
Loading
Loading