Skip to content

Commit

Permalink
moose
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis committed Dec 16, 2024
1 parent 8fd8494 commit 4cb1978
Show file tree
Hide file tree
Showing 36 changed files with 171 additions and 207 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ known_sunpy = sunpy
known_first_party = aiapy
length_sort = false
length_sort_sections = stdlib
line_length = 110
line_length = 120
multi_line_output = 3
no_lines_before = LOCALFOLDER
sections = STDLIB, THIRDPARTY, ASTROPY, SUNPY, FIRSTPARTY, LOCALFOLDER
5 changes: 1 addition & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*|extern.*|aiapy/extern|^CITATION.rst)$"
repos:
# This should be before any formatting hooks like isort
- repo: https://github.com/astral-sh/ruff-pre-commit
Expand All @@ -10,22 +11,18 @@ repos:
rev: 5.13.2
hooks:
- id: isort
exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*|extern.*|aiapy/extern)$"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-ast
- id: check-case-conflict
- id: trailing-whitespace
exclude: ".*(.fits|.fts|.fit|.header|.txt)$"
- id: check-yaml
- id: debug-statements
- id: check-added-large-files
args: ["--enforce-all", "--maxkb=1054"]
- id: end-of-file-fixer
exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*|.json)$|^CITATION.rst$"
- id: mixed-line-ending
exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*)$"
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
Expand Down
126 changes: 63 additions & 63 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
# Allow unused variables when underscore-prefixed.
lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
target-version = "py310"
line-length = 120
exclude = [
".git,",
"__pycache__",
"build",
"aiapy/version.py",
extend-exclude=[
"__pycache__",
"build",
"tools/**",
]

[lint]
select = [
"E",
"F",
"W",
"UP",
"PT",
"BLE",
"A",
"C4",
"INP",
"PIE",
"T20",
"RET",
"TID",
"PTH",
"PD",
"PLC",
"PLE",
"FLY",
"NPY",
"PERF",
"RUF",
lint.select = [
"ALL",
]
extend-ignore = [
# pycodestyle (E, W)
"E501", # ignore line length will use a formatter instead
# pyupgrade (UP)
"UP038", # Use | in isinstance - not compatible with models and is slower
# pytest (PT)
"PT001", # Always use pytest.fixture()
"PT023", # Always use () on pytest decorators
# flake8-pie (PIE)
"PIE808", # Disallow passing 0 as the first argument to range
# flake8-use-pathlib (PTH)
"PTH123", # open() should be replaced by Path.open()
# Ruff (RUF)
"RUF003", # Ignore ambiguous quote marks, doesn't allow ' in comments
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF013", # PEP 484 prohibits implicit `Optional`
"RUF015", # Prefer `next(iter(...))` over single element slice
lint.extend-ignore = [
"ANN001", # Missing type annotation for function argument
"ANN002", # Missing type annotation for variable
"ANN003", # Missing type annotation for keyword
"ANN201", # Missing return type annotation for public function
"ANN202", # Missing return type annotation for private function
"ANN205", # Missing return type annotation for staticmethod
"ANN206", # Missing return type annotation for classmethod
"COM812", # May cause conflicts when used with the formatter
"D200", # One-line docstring should fit on one line
"D205", # 1 blank line required between summary line and description
"D400", # First line should end with a period
"D401", # First line should be in imperative mood
"D404", # First word of the docstring should not be "This"
"E501", # Line too long
"FIX001", # Line contains FIXME, consider resolving the issue
"FIX002", # Line contains TODO, consider resolving the issue
"ISC001", # May cause conflicts when used with the formatter
"PLR0913", # Too many arguments in function definition
"TD001", # Invalid TODO tag: `FIXME`
"TD002", # Missing author in TODO
"TD003", # Missing issue link on the line following this TODO
]

[lint.per-file-ignores]
"setup.py" = [
"INP001", # File is part of an implicit namespace package.
]
"conftest.py" = [
"INP001", # File is part of an implicit namespace package.
"examples/*.py" = [
"B018", # Not print but display
"D400", # First line should end with a period, question mark, or exclamation point
"ERA001", # Commented out code
"INP001", # Implicit namespace package
"T201", # Use print
]
"docs/conf.py" = [
"E402" # Module imports not at top of file
"D100", # Missing docstring in public module
"INP001", # conf.py is part of an implicit namespace package
]
"docs/*.py" = [
"INP001", # File is part of an implicit namespace package.
"setup.py" = [
"D100", # Missing docstring in public module
]
"examples/**.py" = [
"T201", # allow use of print in examples
"INP001", # File is part of an implicit namespace package.
"*tests/__init__.py" = [
"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
]
"__init__.py" = [
"E402", # Module level import not at top of cell
"F401", # Unused import
"F403", # from {name} import * used; unable to detect undefined names
"F405", # {name} may be undefined, or defined from star imports
"*tests/*/__init__.py" = [
"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
]
"test_*.py" = [
"E402", # Module level import not at top of cell
"D100", # Missing docstring in public module
"D103", # Missing docstring in public function
"N806", # in function should be lowercase
"PLR2004", # Magic value used in comparison
"S101", # Use of `assert` detected
]
"*version.py" = [
"D100", # Missing docstring in public module
]
"*conftest.py" = [
"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
]

[lint.pydocstyle]
convention = "numpy"

[format]
docstring-code-format = true
indent-style = "space"
quote-style = "double"
3 changes: 2 additions & 1 deletion aiapy/_dev/scm_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
except ImportError:
raise
except Exception as e:
raise ValueError("setuptools_scm can not determine version.") from e
msg = "setuptools_scm can not determine version."
raise ValueError(msg) from e
4 changes: 1 addition & 3 deletions aiapy/calibrate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Subpackage for calibrating AIA imaging data.
"""
"""Subpackage for calibrating AIA imaging data."""

from .meta import *
from .prep import *
Expand Down
7 changes: 3 additions & 4 deletions aiapy/calibrate/meta.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Functions for updating/fixing header keywords.
"""
"""Functions for updating/fixing header keywords."""

import copy
import warnings
Expand Down Expand Up @@ -127,7 +125,8 @@ def update_pointing(smap, *, pointing_table=None):
# NOTE: In sunpy >=6.0, the reference_date property was introduced which, for
# AIA maps, will always be pulled from "T_OBS"
t_obs_in_interval = np.logical_and(
smap.reference_date >= pointing_table["T_START"], smap.reference_date < pointing_table["T_STOP"]
smap.reference_date >= pointing_table["T_START"],
smap.reference_date < pointing_table["T_STOP"],
)
if not t_obs_in_interval.any():
msg = (
Expand Down
4 changes: 1 addition & 3 deletions aiapy/calibrate/prep.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Functions for calibrating AIA images.
"""
"""Functions for calibrating AIA images."""

import warnings

Expand Down
14 changes: 7 additions & 7 deletions aiapy/calibrate/tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from aiapy.util.exceptions import AiapyUserWarning


def test_fix_observer_location(aia_171_map):
def test_fix_observer_location(aia_171_map) -> None:
smap_fixed = fix_observer_location(aia_171_map)
# NOTE: AIAMap already fixes the .observer_coordinate property with HAE
assert smap_fixed.meta["hgln_obs"] == smap_fixed.observer_coordinate.lon.value
Expand Down Expand Up @@ -47,7 +47,7 @@ def mock_pointing_table():


@pytest.mark.remote_data
def test_fix_pointing(aia_171_map, pointing_table):
def test_fix_pointing(aia_171_map, pointing_table) -> None:
keys = ["CRPIX1", "CRPIX2", "CDELT1", "CDELT2", "CROTA2"]
# Remove keys to at least test that they get set
for k in keys:
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_fix_pointing(aia_171_map, pointing_table):
(1.001, 1),
],
)
def test_update_pointing_accuracy(aia_171_map, pointing_table, t_delt_factor, expected_entry):
def test_update_pointing_accuracy(aia_171_map, pointing_table, t_delt_factor, expected_entry) -> None:
t_start = pointing_table[0]["T_START"]
t_delt = pointing_table[0]["T_STOP"] - t_start # This is nearly always 3 hours
aia_171_map.meta["T_OBS"] = (t_start + t_delt * t_delt_factor).isot
Expand All @@ -88,7 +88,7 @@ def test_update_pointing_accuracy(aia_171_map, pointing_table, t_delt_factor, ex


@pytest.mark.remote_data
def test_update_pointing_submap_raises_exception(aia_171_map, pointing_table):
def test_update_pointing_submap_raises_exception(aia_171_map, pointing_table) -> None:
m = aia_171_map.submap(
SkyCoord(0, 0, unit="arcsec", frame=aia_171_map.coordinate_frame),
top_right=aia_171_map.top_right_coord,
Expand All @@ -98,14 +98,14 @@ def test_update_pointing_submap_raises_exception(aia_171_map, pointing_table):


@pytest.mark.remote_data
def test_update_pointing_resampled_raises_exception(aia_171_map, pointing_table):
def test_update_pointing_resampled_raises_exception(aia_171_map, pointing_table) -> None:
m = aia_171_map.resample((512, 512) * u.pixel)
with pytest.raises(ValueError, match="Input must be at the full resolution"):
update_pointing(m, pointing_table=pointing_table)


@pytest.mark.remote_data
def test_update_pointing_no_entry_raises_exception(aia_171_map, pointing_table):
def test_update_pointing_no_entry_raises_exception(aia_171_map, pointing_table) -> None:
# This tests that an exception is thrown when entry corresponding to
# T_START <= T_OBS < T_END cannot be found in the pointing table.
# We explicitly set the T_OBS key
Expand All @@ -114,7 +114,7 @@ def test_update_pointing_no_entry_raises_exception(aia_171_map, pointing_table):
update_pointing(aia_171_map, pointing_table=pointing_table)


def test_fix_pointing_missing_value(aia_171_map, mock_pointing_table):
def test_fix_pointing_missing_value(aia_171_map, mock_pointing_table) -> None:
# Adjust map to a date we know has missing pointing information
aia_171_map.meta["date-obs"] = "2010-09-30T06:51:48.344"
aia_171_map.meta["t_obs"] = aia_171_map.meta["date-obs"]
Expand Down
24 changes: 11 additions & 13 deletions aiapy/calibrate/tests/test_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def non_sdo_map():
return Map(sunpy.data.test.get_test_filepath("hsi_image_20101016_191218.fits"))


def test_register(aia_171_map, lvl_15_map):
def test_register(aia_171_map, lvl_15_map) -> None:
"""
Test that header info for the map has been correctly updated after the map
has been scaled to 0.6 arcsec / pixel and aligned with solar north.
Expand All @@ -50,7 +50,7 @@ def test_register(aia_171_map, lvl_15_map):
assert lvl_15_map.meta["lvl_num"] == 1.5


def test_register_filesave(lvl_15_map):
def test_register_filesave(lvl_15_map) -> None:
"""
Test that adjusted header values are still correct after saving the map and
reloading it.
Expand All @@ -71,10 +71,8 @@ def test_register_filesave(lvl_15_map):
assert load_map.meta["lvl_num"] == 1.5


def test_register_unsupported_maps(aia_171_map, non_sdo_map):
"""
Make sure we raise an error when an unsupported map is passed in.
"""
def test_register_unsupported_maps(aia_171_map, non_sdo_map) -> None:
"""Make sure we raise an error when an unsupported map is passed in."""
# A submap
original_cutout = aia_171_map.submap(aia_171_map.center, top_right=aia_171_map.top_right_coord)
with pytest.raises(ValueError, match="Input must be a full disk image."):
Expand All @@ -84,7 +82,7 @@ def test_register_unsupported_maps(aia_171_map, non_sdo_map):
register(non_sdo_map)


def test_register_level_15(lvl_15_map):
def test_register_level_15(lvl_15_map) -> None:
with pytest.warns(
AiapyUserWarning,
match="Image registration should only be applied to level 1 data",
Expand All @@ -110,7 +108,7 @@ def test_register_level_15(lvl_15_map):
),
],
)
def test_correct_degradation(aia_171_map, correction_table, version):
def test_correct_degradation(aia_171_map, correction_table, version) -> None:
original_corrected = correct_degradation(
aia_171_map,
correction_table=correction_table,
Expand Down Expand Up @@ -162,7 +160,7 @@ def test_correct_degradation(aia_171_map, correction_table, version):
),
],
)
def test_degradation(correction_table, version, time_correction_truth):
def test_degradation(correction_table, version, time_correction_truth) -> None:
# NOTE: this just tests an expected result from aiapy, not necessarily an
# absolutely correct result. It was calculated for the above time and
# the specific correction table file.
Expand Down Expand Up @@ -224,7 +222,7 @@ def test_degradation(correction_table, version, time_correction_truth):
),
],
)
def test_degradation_all_wavelengths(wavelength, result):
def test_degradation_all_wavelengths(wavelength, result) -> None:
obstime = astropy.time.Time("2015-01-01T00:00:00", scale="utc")
time_correction = degradation(
wavelength * u.angstrom,
Expand All @@ -234,7 +232,7 @@ def test_degradation_all_wavelengths(wavelength, result):


@pytest.mark.remote_data
def test_degradation_4500():
def test_degradation_4500() -> None:
# 4500 has a max version of 3, so by default it will error
obstime = astropy.time.Time("2015-01-01T00:00:00", scale="utc")
with pytest.raises(
Expand All @@ -247,7 +245,7 @@ def test_degradation_4500():
assert u.allclose(correction, 1.0 * u.dimensionless_unscaled)


def test_degradation_time_array():
def test_degradation_time_array() -> None:
obstime = astropy.time.Time("2015-01-01T00:00:00", scale="utc")
obstime = obstime + np.linspace(0, 1, 100) * u.year
correction_table = get_test_filepath("aia_V8_20171210_050627_response_table.txt")
Expand All @@ -262,7 +260,7 @@ def test_degradation_time_array():
assert tc == degradation(94 * u.angstrom, o, correction_table=correction_table, calibration_version=8)


def test_register_cupy(aia_171_map):
def test_register_cupy(aia_171_map) -> None:
pytest.importorskip("cupy")
cupy_map = register(aia_171_map, method="cupy")
scipy_map = register(aia_171_map, method="scipy")
Expand Down
Loading

0 comments on commit 4cb1978

Please sign in to comment.