Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize CircularAperture from other apertures #393

Merged

Conversation

mkelley
Copy link
Member

@mkelley mkelley commented Jan 18, 2024

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
Copy link

pep8speaks commented Jan 18, 2024

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! 🍻

Comment last updated at 2024-01-18 00:54:37 UTC

Copy link

codecov bot commented Jan 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mkelley mkelley requested a review from hhsieh00 January 18, 2024 20:24
@jianyangli jianyangli added this to the v0.5 milestone Jan 18, 2024
Copy link
Collaborator

@hhsieh00 hhsieh00 left a comment

Choose a reason for hiding this comment

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

All seems to check out. Tested documentation examples on OSX and works fine.

@mkelley mkelley merged commit eaff110 into NASA-Planetary-Science:main Aug 19, 2024
9 checks passed
@mkelley
Copy link
Member Author

mkelley commented Aug 19, 2024

Thanks!

@mkelley mkelley deleted the initialize-ap-from-ap-2024.01 branch August 19, 2024 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants