35 """Evaluate the CoaddBoundedField.
37 This accepts either a Point2D or an array of x and y
40 When arrays are passed, this uses a vectorized version
41 of CoaddBoundedField::evaluate(). If the coadd bounded
42 field has throwOnMissing then this will return NaN
43 for missing values; otherwise it will return 0.0.
47 x : `lsst.geom.Point2D` or `np.ndarray`
49 y : `np.ndarray`, optional
54 values : `float` or `np.ndarray`
55 Evaluated value or array of values.
57 if isinstance(x, Point2D):
58 return self._evaluate(x)
60 _x = np.atleast_1d(x).ravel()
61 _y = np.atleast_1d(y).ravel()
63 if len(_x) != len(_y):
64 raise ValueError(
"x and y arrays must be the same length.")
66 ra, dec = self.getCoaddWcs().pixelToSkyArray(_x, _y)
68 sums = np.zeros(len(_x))
69 wts = np.zeros_like(sums)
71 for elt
in self.getElements():
72 ix, iy = elt.wcs.skyToPixelArray(ra, dec)
73 in_box = elt.field.getBBox().contains(ix, iy)
75 in_box &= elt.validPolygon.contains(ix, iy)
76 sums[in_box] += elt.weight*elt.field.evaluate(ix[in_box], iy[in_box])
77 wts[in_box] += elt.weight
80 values = np.zeros(len(_x))
81 values[good] = sums[good]/wts[good]
83 if self.getThrowOnMissing():
84 values[~good] = np.nan