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

Rewrite np.percentile section to handle units for AstroPy 3, 4. #116

Merged
merged 3 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 19 additions & 3 deletions python/lsst/validate/drp/calcsrd/adx.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,25 @@ def measureADx(metric, amx, afx_spec):
# No more than AFx of values will deviate by more than the
# AMx (50th) + AFx percentiles
# To compute ADx, use measured AMx and spec for AFx.
afxAtPercentile = np.percentile(
amx.extras['rmsDistMas'].quantity.to(u.marcsec),
100. - afx_spec.threshold.value) * u.marcsec
#
# The AFx spec is in terms of percentage of outliers
# To convert to the percentitle of the largest outliers
# We subtract AFx from 100. So AFx = 10 becomes threshold = 90.
threshold = 100 - afx_spec.threshold.value

# In AstroPy 3,
# numpy.percentitle of an array with quantities
# (incorrectly) returns a unitless number
# In AstroPy 4 + numpy >= 1.17,
# numpy.percentitle of an array with Quantities
# correctly returns a number with the same units as the input array.
# To be compatible with both Astropy 3.2 and Astropy 4, we:
# 1. Extract the array in marcsec and convert to a value.
# 2. Calculate the numpy.percentitle of this unitless array
# 3. Multiply that result by u.marcsec to get the right units.
rmsDistMas = amx.extras['rmsDistMas'].quantity.to(u.marcsec).value
afxAtPercentile = np.percentile(rmsDistMas, threshold)
afxAtPercentile *= u.marcsec
quantity = afxAtPercentile - amx.quantity
else:
quantity = np.nan * amx.quantity.unit
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/validate/drp/calcsrd/pa2.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ def measurePA2(metric, pa1, pf1_thresh):
magDiffs = pa1.extras['magDiff'].quantity[0, :]

pf1Percentile = 100.*u.percent - pf1_thresh
return Measurement(metric, np.percentile(np.abs(magDiffs), pf1Percentile.value) * magDiffs.unit,
return Measurement(metric, np.percentile(np.abs(magDiffs.value), pf1Percentile.value) * magDiffs.unit,
extras=datums)