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 33aa541
Show file tree
Hide file tree
Showing 37 changed files with 156 additions and 199 deletions.
4 changes: 2 additions & 2 deletions .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ skip =
default_section = THIRDPARTY
include_trailing_comma = true
known_astropy = astropy, asdf
known_sunpy = sunpy
known_sunpy = sunpy, drms
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.

10 changes: 10 additions & 0 deletions aiapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"""
``aiapy``
=========
Python library for AIA data analysis.
* Homepage: https://aia.lmsal.com
* Documentation: https://aiapy.readthedocs.io/en/stable/
"""

from itertools import compress
from pathlib import Path

Expand Down
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
7 changes: 4 additions & 3 deletions aiapy/calibrate/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sunpy.map import contains_full_disk

from aiapy.calibrate.util import get_pointing_table
from aiapy.util.exceptions import AiapyUserWarning
from aiapy.util.exceptions import AIApyUserWarning

__all__ = ["fix_observer_location", "update_pointing"]

Expand Down 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 Expand Up @@ -170,7 +171,7 @@ def update_pointing(smap, *, pointing_table=None):
# these cases, we just want to skip updating the pointing information.
warnings.warn(
f"Missing value in pointing table for {key}. This key will not be updated.",
AiapyUserWarning,
AIApyUserWarning,
stacklevel=3,
)
else:
Expand Down
4 changes: 2 additions & 2 deletions aiapy/calibrate/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from aiapy.calibrate.transform import _rotation_function_names
from aiapy.calibrate.util import _select_epoch_from_correction_table, get_correction_table
from aiapy.util import AiapyUserWarning
from aiapy.util import AIApyUserWarning
from aiapy.util.decorators import validate_channel

__all__ = ["correct_degradation", "degradation", "register"]
Expand Down Expand Up @@ -80,7 +80,7 @@ def register(smap, *, missing=None, order=3, method="scipy"):
if smap.processing_level is None or smap.processing_level > 1:
warnings.warn(
"Image registration should only be applied to level 1 data",
AiapyUserWarning,
AIApyUserWarning,
stacklevel=3,
)
# Target scale is 0.6 arcsec/pixel, but this needs to be adjusted if the
Expand Down
10 changes: 7 additions & 3 deletions aiapy/calibrate/spikes.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
"""
Functions for re-inserting "spikes" into level 1 AIA images.
"""

import copy
import warnings

import drms
import numpy as np

import astropy.units as u
from astropy.io import fits
from astropy.wcs.utils import pixel_to_pixel

import drms
from sunpy.map.mapbase import PixelPair
from sunpy.map.sources.sdo import AIAMap

from aiapy.util import AiapyUserWarning
from aiapy.util import AIApyUserWarning

__all__ = ["fetch_spikes", "respike"]

Expand Down Expand Up @@ -85,7 +89,7 @@ def respike(smap, *, spikes=None):
"in any way from the level 1 image, the spike data will likely be "
"reinserted in the incorrect pixel positions."
),
AiapyUserWarning,
AIApyUserWarning,
stacklevel=3,
)
# FIXME: Should raise an exception? Or just return with a warning?
Expand Down
18 changes: 9 additions & 9 deletions aiapy/calibrate/tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

from aiapy.calibrate import fix_observer_location, update_pointing
from aiapy.calibrate.util import get_pointing_table
from aiapy.util.exceptions import AiapyUserWarning
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,11 +114,11 @@ 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"]
with pytest.warns(AiapyUserWarning, match="Missing value in pointing table"):
with pytest.warns(AIApyUserWarning, match="Missing value in pointing table"):
aia_171_map_updated = update_pointing(aia_171_map, pointing_table=mock_pointing_table)
assert aia_171_map.meta["crpix1"] == aia_171_map_updated.meta["crpix1"]
assert aia_171_map.meta["crpix2"] == aia_171_map_updated.meta["crpix2"]
Loading

0 comments on commit 33aa541

Please sign in to comment.