Skip to content
Open
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
47 changes: 23 additions & 24 deletions .pre-commit-config.yaml

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were changes needed here?

Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
ci:
autoupdate_commit_msg: "chore(deps): update pre-commit hooks"
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"
autoupdate_schedule: "monthly"

exclude: ^.cruft.json|.copier-answers.yml$

repos:
- repo: https://github.com/adamchainz/blacken-docs
rev: "1.20.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==25.*]
additional_dependencies: [black==24.*]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v6.0.0"
Expand All @@ -28,44 +25,46 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
# - repo: https://github.com/pre-commit/pygrep-hooks
# rev: "v1.10.0"
# hooks:
# - id: rst-backticks
# - id: rst-directive-colons
# - id: rst-inline-touching-normal

- repo: https://github.com/rbubley/mirrors-prettier
rev: "v3.8.3"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
args: [--prose-wrap=always]
# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: "v4.0.0-alpha.8"
# hooks:
# - id: prettier
# types_or: [yaml, markdown, html, css, scss, javascript, json]
# args: [--prose-wrap=always]
Comment on lines +28 to +40

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these removed?


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

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v2.0.0"
hooks:
- id: mypy
files: eye_patch|tests
files: flint|tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
files: flint|tests
files: eye_patch|tests

Bad copy-paste

args: ["--ignore-missing-imports"]
additional_dependencies:
- numpy
- capn-crunch
- pytest-stub
- pytest
- types-PyYAML

- repo: https://github.com/crate-ci/typos
rev: "v1.46.0"
hooks:
- id: typos

- repo: https://github.com/codespell-project/codespell
rev: "v2.4.2"
hooks:
- id: codespell
additional_dependencies:
- tomli; python_version<'3.11'

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.11.0.1"
Expand Down
45 changes: 45 additions & 0 deletions eye_patch/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import annotations

import logging

# Create logger
logging.captureWarnings(True)
logger = logging.getLogger("eye-patch")
logger.setLevel(logging.INFO)

# Create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)


class CustomFormatter(logging.Formatter):
"""A custom logger formatter"""

grey = "\x1b[38;20m"
blue = "\x1b[34;20m"
green = "\x1b[32;20m"
yellow = "\x1b[33;20m"
red = "\x1b[31;20m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
format_str = "%(asctime)s.%(msecs)03d %(module)s - %(funcName)s: %(message)s"

FORMATS = { # noqa: RUF012
logging.DEBUG: f"{blue}%(levelname)s{reset} {format_str}",
logging.INFO: f"{green}%(levelname)s{reset} {format_str}",
logging.WARNING: f"{yellow}%(levelname)s{reset} {format_str}",
logging.ERROR: f"{red}%(levelname)s{reset} {format_str}",
logging.CRITICAL: f"{bold_red}%(levelname)s{reset} {format_str}",
}

def format(self, record):
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt, "%Y-%m-%d %H:%M:%S")
return formatter.format(record)


# Add formatter to ch
ch.setFormatter(CustomFormatter())

# Add ch to logger
logger.addHandler(ch)
12 changes: 8 additions & 4 deletions eye_patch/masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from __future__ import annotations

import logging
from argparse import ArgumentParser
from pathlib import Path
from typing import NamedTuple, TypeAlias
Expand All @@ -26,6 +25,7 @@
from scipy.ndimage import binary_fill_holes, label, maximum_filter, minimum_filter
from scipy.signal import fftconvolve

from eye_patch.logging import logger
from eye_patch.naming import FITSMaskNames, create_fits_mask_names

# Add explicit export so mypy on tests is ok
Expand All @@ -37,8 +37,6 @@
# during fits file creation.
MaskLike: TypeAlias = NDArray[np.floating]

logger = logging.getLogger("__name__")


class MaskingOptions(BaseOptions):
"""Contains options for the creation of clean masks from some subject
Expand Down Expand Up @@ -916,7 +914,7 @@ def create_snr_mask_from_fits(
logger.info(f"Writing {mask_names.mask_fits}")
fits.writeto(
filename=mask_names.mask_fits,
data=mask_data,
data=mask_data.astype(np.float32),
header=fits_header,
overwrite=overwrite,
)
Expand Down Expand Up @@ -965,6 +963,12 @@ def convolve_image_by_scale(
logger.info(f"Generating gaussian kernel for {scale=} {fwhm=:.3f} {sigma=:.3f}")

pix_sigma = int(sigma * 5)
if pix_sigma < 1:
# linspace can only take integer inputs, and if sigma is too small then this array comes
# out as length zero.
msg = f"{scale=} is too small and an appropriately sized kernel can not be formed. Consider removing it. "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Consider removing it."

What does "it" mean here? Can we make this message more explicit on what to change?

raise ValueError(msg)

x = np.linspace(0, pix_sigma, pix_sigma)
y = np.linspace(0, pix_sigma, pix_sigma)

Expand Down
Loading