Skip to content

Commit

Permalink
moose
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis committed Dec 17, 2024
1 parent 8fd8494 commit 5faff23
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 165 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
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
exclude: ".*(.fits|.fts|.fit|.header|.txt|tca.*|extern.*|aiapy/extern|^CITATION.rst)$"
repos:
- repo: https://github.com/PyCQA/docformatter
rev: master
hooks:
- id: docformatter
args: ["--in-place", "--pre-summary-newline", "--make-summary-multi"]
# This should be before any formatting hooks like isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.2"
Expand All @@ -10,22 +16,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
81 changes: 0 additions & 81 deletions .ruff.toml

This file was deleted.

5 changes: 3 additions & 2 deletions aiapy/_dev/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This package contains utilities that are only used when developing in a
copy of the source repository.
This package contains utilities that are only used when developing in a copy of
the source repository.
These files are not installed, and should not be assumed to exist at
runtime.
"""
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
3 changes: 2 additions & 1 deletion aiapy/calibrate/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,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
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
20 changes: 10 additions & 10 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,7 +71,7 @@ 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):
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.
"""
Expand All @@ -84,7 +84,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 +110,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 +162,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 +224,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 +234,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 +247,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 +262,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
14 changes: 7 additions & 7 deletions aiapy/calibrate/tests/test_spikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ def spikes(despiked_map):


@pytest.mark.remote_data
def test_respike(respiked_map, spikes):
def test_respike(respiked_map, spikes) -> None:
coords, values = spikes
for x, y, v in zip(coords.x.value, coords.y.value, values, strict=True):
assert v == respiked_map.data[int(y), int(x)]


@pytest.mark.remote_data
def test_respike_meta(respiked_map):
def test_respike_meta(respiked_map) -> None:
assert respiked_map.meta["lvl_num"] == 0.5
assert respiked_map.meta["nspikes"] == 0


@pytest.mark.remote_data
def test_fetch_with_prefetched_spikes(despiked_map, respiked_map, spikes):
def test_fetch_with_prefetched_spikes(despiked_map, respiked_map, spikes) -> None:
respiked_map_prefetched = respike(despiked_map, spikes=spikes)
assert np.allclose(respiked_map.data, respiked_map_prefetched.data)


@pytest.mark.remote_data
def test_cutout(respiked_map, despiked_map):
def test_cutout(respiked_map, despiked_map) -> None:
blc = (-500, -500) * u.arcsec
trc = (500, 500) * u.arcsec
respiked_map_cutout = respiked_map.submap(
Expand All @@ -76,15 +76,15 @@ def test_cutout(respiked_map, despiked_map):
("instrume", "not AIA", TypeError, "Input must be an AIAMap."),
],
)
def test_exceptions(despiked_map, key, value, error, match):
def test_exceptions(despiked_map, key, value, error, match) -> None:
new_meta = copy.deepcopy(despiked_map.meta)
new_meta[key] = value
with pytest.raises(error, match=match):
respike(sunpy.map.Map(despiked_map.data, new_meta))


@pytest.mark.remote_data
def test_resample_warning(despiked_map):
def test_resample_warning(despiked_map) -> None:
despiked_map_resample = despiked_map.resample((512, 512) * u.pixel)
with (
pytest.warns(AiapyUserWarning, match="is significantly different from the expected level 1 plate scale"),
Expand All @@ -95,7 +95,7 @@ def test_resample_warning(despiked_map):

@pytest.mark.remote_data
@pytest.mark.parametrize(("as_coords", "kind"), [(True, SkyCoord), (False, PixelPair)])
def test_fetch_spikes(despiked_map, as_coords, kind):
def test_fetch_spikes(despiked_map, as_coords, kind) -> None:
n_spikes = despiked_map.meta["nspikes"]
coords, values = fetch_spikes(despiked_map, as_coords=as_coords)
assert isinstance(coords, kind)
Expand Down
6 changes: 3 additions & 3 deletions aiapy/calibrate/tests/test_uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


@pytest.mark.parametrize("channel", CHANNELS)
def test_error_all_channels(channel):
def test_error_all_channels(channel) -> None:
intensity = 10.0 * u.DN / u.pix
error = estimate_error(intensity, channel, error_table=table_local)
assert error.unit == intensity.unit
Expand All @@ -33,7 +33,7 @@ def test_error_all_channels(channel):
RANDOM_GENERATOR.standard_normal((10, 10, 5)),
],
)
def test_counts_shapes(counts):
def test_counts_shapes(counts) -> None:
counts = np.abs(counts) * 1000 * u.DN / u.pix
errors = estimate_error(counts, 171 * u.angstrom, error_table=table_local)
if counts.shape == ():
Expand All @@ -57,7 +57,7 @@ def test_counts_shapes(counts):
),
],
)
def test_flags(include_preflight, include_eve, include_chianti, expectation):
def test_flags(include_preflight, include_eve, include_chianti, expectation) -> None:
with expectation:
errors = estimate_error(
1 * u.DN / u.pix,
Expand Down
Loading

0 comments on commit 5faff23

Please sign in to comment.