Skip to content

Random#367

Merged
nabobalis merged 1 commit intomainfrom
tweaks
Sep 18, 2025
Merged

Random#367
nabobalis merged 1 commit intomainfrom
tweaks

Conversation

@nabobalis
Copy link
Member

@nabobalis nabobalis commented Sep 18, 2025

Summary by Sourcery

Refactor the PSF submodule by moving mesh parameter utilities into a separate file, clean up public API and deprecation metadata, enhance the PSF example plotting script, and standardize test assertion methods across the codebase with updated tolerances.

Enhancements:

  • Refactor filter_mesh_parameters into aiapy.psf.utils and streamline psf module exports
  • Update deprecation decorator to use version 0.11.0 for psf
  • Enhance example script with explicit figure sizing, dynamic titles, colorbars, and tight layout

Documentation:

  • Add a breaking change entry for this update in the changelog

Tests:

  • Standardize assertions to use np.testing.assert_allclose across tests with appropriate tolerances
  • Introduce new test_utils module housing tests for filter_mesh_parameters

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 18, 2025

Reviewer's Guide

This PR refactors the AIA PSF filter mesh parameter function into a new utility module, updates the PSF deconvolution example visuals with figure sizing and layout improvements, and standardizes test assertions across the codebase to use numpy.testing.assert_allclose.

Class diagram for the new filter_mesh_parameters utility

classDiagram
    class filter_mesh_parameters {
        +dict filter_mesh_parameters(use_preflightcore: bool = False)
        "Returns mesh parameters for each AIA channel as a dictionary."
        "Keys: angle_arm, error_angle_arm, spacing_e, spacing_fp, mesh_pitch, mesh_width, width, CDELT"
    }
Loading

File-Level Changes

Change Details Files
Extract filter_mesh_parameters into a dedicated utils module
  • Remove inline filter_mesh_parameters from psf.py and drop it from all
  • Add aiapy/psf/utils.py containing the filter_mesh_parameters implementation
  • Update init.py and imports to expose filter_mesh_parameters from the new utils module
  • Add new test_utils.py for filter_mesh_parameters and remove its old test from test_psf.py
aiapy/psf/psf.py
aiapy/psf/utils.py
aiapy/psf/tests/test_utils.py
aiapy/psf/tests/test_psf.py
Modernize test assertions to use numpy.testing.assert_allclose
  • Replace np.allclose assertions with np.testing.assert_allclose in calibration and spikes tests
  • Add appropriate tolerance arguments where needed
  • Drop unused pytest import in test_psf.py
aiapy/calibrate/tests/test_prep.py
aiapy/calibrate/tests/test_spikes.py
aiapy/tests/test_idl.py
Enhance PSF deconvolution example visuals
  • Rename example script to psf_deconvolution.py
  • Specify figsize for figures and apply tight_layout
  • Improve plot titles, add colorbars, and adjust subplot dimensions
examples/psf_deconvolution.py
Update deprecation decorator version
  • Change deprecated decorator version from '1.0' to '0.11.0' for psf function
aiapy/psf/psf.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@nabobalis nabobalis force-pushed the tweaks branch 2 times, most recently from 0cac46f to badb4d7 Compare September 18, 2025 22:42
@nabobalis nabobalis marked this pull request as ready for review September 18, 2025 22:43
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `aiapy/psf/utils.py:90-97` </location>
<code_context>
-    """
-    return {
-        94 * u.angstrom: {
-            "angle_arm": [49.81, 40.16, -40.28, -49.92] * u.deg,
-            "error_angle_arm": [0.02, 0.02, 0.02, 0.02] * u.deg,
-            "spacing_e": 8.99 * u.pixel,
-            "mesh_pitch": 363.0 * u.um,
-            "mesh_width": 34.0 * u.um,
-            "spacing_fp": 0.207 * u.pixel,
-            "width": (0.951 if use_preflightcore else 4.5) * u.pixel,
-            "CDELT": [0.600109, 0.600109] * u.arcsec,
-        },
-        131 * u.angstrom: {
</code_context>

<issue_to_address>
**nitpick:** Mixing 'u.deg' and 'u.degree' for units may cause confusion.

Standardize the angle unit to either 'u.deg' or 'u.degree' across all dictionary entries to ensure consistency and prevent potential bugs.
</issue_to_address>

### Comment 2
<location> `aiapy/psf/utils.py:10` </location>
<code_context>
-__all__ = ["_psf", "calculate_psf", "filter_mesh_parameters", "psf"]
-
-
-def filter_mesh_parameters(*, use_preflightcore=False):
-    """
-    Geometric parameters for meshes in AIA filters used to calculate the point
</code_context>

<issue_to_address>
**issue (complexity):** Consider refactoring the function to use shared constants and a per-channel table to reduce code repetition.

Here’s one way to collapse most of the repetition by moving per‐channel values into a small table and then iterating over it.  All of the shared constants (`mesh_pitch`, `mesh_width`, default `width`, default `error_angle_arm`) live in one dict, and only the truly varying bits live in your table:

```python
import astropy.units as u

# module‐level constants
_COMMON = {
    "mesh_pitch": 363.0 * u.um,
    "mesh_width": 34.0 * u.um,
    "error_angle_arm": [0.02, 0.02, 0.02, 0.02] * u.deg,
    "default_width": 4.5 * u.pixel,
}

# per‐channel parameters
_CHANNELS = [
    {
        "wave":   94,
        "angle": [49.81, 40.16, -40.28, -49.92],
        "spacing_e":  8.99,
        "spacing_fp": 0.207,
        "preflight_width": 0.951,
        "cdelt": 0.600109,
    },
    {
        "wave":  131,
        "angle": [50.27, 40.17, -39.70, -49.95],
        "spacing_e":  12.37,
        "spacing_fp": 0.289,
        "preflight_width": 1.033,
        "cdelt": 0.600698,
    },
    # … repeat for 171, 193, 211, 304, 335 …
    {
        "wave": 193,
        "angle": [49.82, 39.57, -40.12, -50.37],
        "spacing_e": 18.39,
        "spacing_fp": 0.425,
        "preflight_width": 1.512,
        "cdelt": 0.600758,
        "error_angle_arm": [0.02, 0.02, 0.03, 0.04],
    },
]

def filter_mesh_parameters(*, use_preflightcore=False):
    meshinfo = {}
    for ch in _CHANNELS:
        w = ch["wave"] * u.angstrom
        # start with common parameters
        params = {
            **{k: _COMMON[k] for k in ("mesh_pitch", "mesh_width")},
            "angle_arm": ch["angle"] * u.deg,
            "spacing_e": ch["spacing_e"] * u.pixel,
            "spacing_fp": ch["spacing_fp"] * u.pixel,
            "CDELT": [ch["cdelt"], ch["cdelt"]] * u.arcsec,
            # pick preflight or default width
            "width": ((ch["preflight_width"] if use_preflightcore
                       else _COMMON["default_width"].value)
                      * u.pixel),
        }
        # override error_angle_arm if present, otherwise use common
        err = ch.get("error_angle_arm", _COMMON["error_angle_arm"])
        params["error_angle_arm"] = err * u.deg

        meshinfo[w] = params

    return meshinfo
```

– Extracts all the nearly‐identical fields into `_COMMON`  
– Moves only the changing numbers into `_CHANNELS`  
– Builds the final dict in a simple loop, preserving exactly the same units and values.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@nabobalis nabobalis force-pushed the tweaks branch 2 times, most recently from 25490c9 to 33c9af4 Compare September 18, 2025 22:50
@nabobalis nabobalis merged commit b3cf53d into main Sep 18, 2025
20 checks passed
@nabobalis nabobalis deleted the tweaks branch September 18, 2025 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant