Coverage for python/lsst/validate/drp/calcsrd/adx.py: 29%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# LSST Data Management System
2# Copyright 2016 AURA/LSST.
3#
4# This product includes software developed by the
5# LSST Project (http://www.lsst.org/).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the LSST License Statement and
18# the GNU General Public License along with this program. If not,
19# see <https://www.lsstcorp.org/LegalNotices/>.
22import numpy as np
23import astropy.units as u
25from lsst.verify import Measurement
28def measureADx(metric, amx, afx_spec):
29 r"""Measurement of AFx (x=1,2,3): The maximum fraction of astrometric
30 distances which deviate by more than ADx milliarcsec (see AMx) (%).
32 Parameters
33 ----------
34 metric : `lsst.verify.Metric`
35 AD1, AD2, or AD3 `~lsst.verify.Metric` instance.
36 amx : `lsst.verify.Measurement`
37 And AMx measurement, providing the median astrometric scatter in
38 the annulus.
39 afx_spec : `lsst.verify.Spec`
40 Specification containing the value of the level to measure against (e.g., design,
41 minimum, stretch).
43 Returns
44 -------
45 measurement : `lsst.verify.Measurement`
46 Measurement of ADx (x=1,2,3) and associated metadata.
48 Notes
49 -----
50 This table below is provided ``validate_drp``\ 's :file:`metrics.yaml`.
52 LPM-17 dated 2011-07-06
54 Specification:
55 The rms of the astrometric distance distribution for
56 stellar pairs with separation of D arcmin (repeatability)
57 will not exceed AMx milliarcsec (median distribution for a large number
58 of sources). No more than AFx % of the sample will deviate by more than
59 ADx milliarcsec from the median. AMx, AFx, and ADx are specified for
60 D=5, 20 and 200 arcmin for x= 1, 2, and 3, in the same order (Table 18).
62 The three selected characteristic distances reflect the size of an
63 individual sensor, a raft, and the camera. The required median astrometric
64 precision is driven by the desire to achieve a proper motion accuracy of
65 0.2 mas/yr and parallax accuracy of 1.0 mas over the course of the survey.
66 These two requirements correspond to relative astrometric precision for a
67 single image of 10 mas (per coordinate).
69 ========================= ====== ======= =======
70 Astrometric Repeatability Specification
71 ------------------------- ----------------------
72 Metric Design Minimum Stretch
73 ========================= ====== ======= =======
74 AM1 (milliarcsec) 10 20 5
75 AF1 (%) 10 20 5
76 AD1 (milliarcsec) 20 40 10
77 AM2 (milliarcsec) 10 20 5
78 AF2 (%) 10 20 5
79 AD2 (milliarcsec) 20 40 10
80 AM3 (milliarcsec) 15 30 10
81 AF3 (%) 10 20 5
82 AD3 (milliarcsec) 30 50 20
83 ========================= ====== ======= =======
85 Table 18: The specifications for astrometric precision.
86 The three blocks of values correspond to D=5, 20 and 200 arcmin,
87 and to astrometric measurements performed in the r and i bands.
88 """
90 if not np.isnan(amx.quantity):
91 # No more than AFx of values will deviate by more than the
92 # AMx (50th) + AFx percentiles
93 # To compute ADx, use measured AMx and spec for AFx.
94 #
95 # The AFx spec is in terms of percentage of outliers
96 # To convert to the percentitle of the largest outliers
97 # We subtract AFx from 100. So AFx = 10 becomes threshold = 90.
98 threshold = 100 - afx_spec.threshold.value
100 # In AstroPy 3,
101 # numpy.percentitle of an array with quantities
102 # (incorrectly) returns a unitless number
103 # In AstroPy 4 + numpy >= 1.17,
104 # numpy.percentitle of an array with Quantities
105 # correctly returns a number with the same units as the input array.
106 # To be compatible with both Astropy 3.2 and Astropy 4, we:
107 # 1. Extract the array in marcsec and convert to a value.
108 # 2. Calculate the numpy.percentitle of this unitless array
109 # 3. Multiply that result by u.marcsec to get the right units.
110 rmsDistMas = amx.extras['rmsDistMas'].quantity.to(u.marcsec).value
111 afxAtPercentile = np.percentile(rmsDistMas, threshold)
112 afxAtPercentile *= u.marcsec
113 quantity = afxAtPercentile - amx.quantity
114 else:
115 quantity = np.nan * amx.quantity.unit
116 return Measurement(metric, quantity, extras=amx.extras)