NASA-Planetary-Science / sbpy

A Python package for small bodies research
https://sbpy.org/
Other
67 stars 34 forks source link

Initialize CircularAperture from other apertures #393

Closed mkelley closed 1 month ago

mkelley commented 8 months ago

The Afrho and Efrho classes can take a Quantity or an Aperture as an input for the photometric aperture radius, and they will convert it to a coma equivalent radius, as needed. While writing new code for PR #376, I needed to repeat that same Quantity/Aperture conversion code, and also repeat tests for each case. This seemed like an opportunity for an enhancement that could simplify the code.

Each of the Aperture classes can be converted to an effective circular aperture based on the assumption of a 1/rho coma. This PR enables any of the Aperture classes to directly initialize a CircularAperture object using that coma equivalent aperture conversion:

>>> import astropy.units as u
>>> from sbpy.activity import CircularAperture, RectangularAperture
>>>
>>> rect = RectangularAperture([1, 5] * u.arcsec)
>>> circ = CircularAperture.from_coma_equivalent(rect)
>>> print(circ)
Circular aperture, radius 1.0522971172731228 arcsec

Or, a radius may be given as a Quantity, in which case the "coma equivalent" radius is the same value:

>>> circ = CircularAperture.from_coma_equivalent(10 * u.arcsec)
>>> print(circ)
Circular aperture, radius 10.0 arcsec

With this change, the Afrho, Efrho, and any similar code that needs the effective aperture radius for a 1/rho coma can pass their input parameters to CircularAperture without the need to test for Quantity vs. Aperture input, and the developers do not need to be concerned with the conversions for testing coverage:

# works for aper as Quantity or Aperture:
rho = CircularAperture.from_coma_equivalent(aper).dim
pep8speaks commented 8 months ago

Hello @mkelley! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers:

Comment last updated at 2024-01-18 00:54:37 UTC
codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 77.55%. Comparing base (1315915) to head (4812c20). Report is 20 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #393 +/- ## ========================================== + Coverage 77.52% 77.55% +0.03% ========================================== Files 81 81 Lines 7096 7106 +10 ========================================== + Hits 5501 5511 +10 Misses 1595 1595 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mkelley commented 1 month ago

Thanks!