Repository navigation
This release lets a function array with uncertain inputs or outputs be evaluated, at new inputs which may be uncertain too. It also adds na.despike_mask(), which returns the mask of the pixels that na.despike() replaces, and fixes na.despike() around pixels which aren't finite.
Function arrays with uncertain inputs or outputs
FunctionArray.__call__() and regrid() used to raise a TypeError whenever the inputs of the function, its outputs or the new inputs were uncertain. Now they resample the nominal values and the samples, and the outputs of the result are uncertain (#277).
# A height map sampled on a grid along "x" and "y"
f = na.FunctionArray(inputs=grid, outputs=height)
# The positions of rays on the mirror, along "ray", uncertain since
# the alignment of the mirror is uncertain
points = na.Cartesian2dVectorArray(
x=na.NormalUncertainScalarArray(x_ray, width=0.1 * u.mm),
y=na.NormalUncertainScalarArray(y_ray, width=0.1 * u.mm),
)
f(points, axis=("x", "y")) # uncertain heights along "ray"- Uncertain inputs: if the inputs which are resampled are uncertain, the function's own or the new ones, their nominal values and their samples are resampled separately, each with weights of their own. The samples of the function's inputs, of its outputs and of the new inputs go together, sample by sample.
- Uncertain outputs: if only the outputs are uncertain, their nominal values and samples share the weights, which are computed once. Weights computed in advance with
weights()can be used for them. - Weights computed in advance:
weights()raises aValueErrorfor uncertain inputs, since each of their samples has weights of its own. So doesregrid()if it is given weights computed in advance for uncertain inputs. - Components which aren't resampled: a component which isn't resampled, like the wavelength of a map for each wavelength, may be uncertain. The result keeps the function's own, as for any other component which isn't resampled. It doesn't change the weights, so they can still be computed in advance.
- Bounds:
boundsapplies to each sample on its own, so"nan"sets only the samples outside the grid to NaN, and"raise"raises if any sample is outside. - Memory: for the multilinear method, the samples of uncertain points on a grid which isn't uncertain are interpolated as more points, so the outputs of the function aren't copied once per sample.
Despiking
na.despike_mask() is added, and na.despike() is fixed around pixels which aren't finite (#276):
na.despike_mask()takes the same arguments asna.despike()and returns the boolean mask of the pixels which astroscrappy flags as cosmic rays, the onesna.despike()replaces. It works on scalar, uncertain and function arrays, so spikes can be masked, as when fitting lines, rather than interpolated over.- Pixels which aren't finite: both functions now ignore the pixels where
array,inbkgorinvarisn't finite, as well as wherewhereis false. Before, a NaN spread to its neighbors through the median filters and the Laplacian of astroscrappy. A spike near NaN pixels ofarraywas replaced with NaN, and whereinbkgwas NaN, the result was NaN too, thougharraywas finite there. An image with no valid pixels is left alone. - Only the flagged pixels change:
na.despike()used to write back the whole output of astroscrappy, which is single precision, so every pixel was rounded to single precision and, withinbkg, pixels which weren't flagged moved too. - Other fixes:
invarandpsfkof any dtype work, where any dtype butfloat32raised aValueError.psfkis also aligned to the axes of each image, rather than passed in its own axis order.- Implicit uncertain arrays, like
na.NormalUncertainScalarArray, work, where they raised anAttributeError. - A function array given as
where,inbkgorinvarwith anarraywhich isn't a function array raises aTypeError, where it was ignored, and one whose inputs differ from those ofarrayraises aValueError. - An integer
wherecounts nonzero as true, where it masked every pixel. inbkgandinvarare converted to the unit ofarray, squared forinvar, when both have units, where their units were dropped.
Behavior change: na.despike() no longer rounds the pixels it doesn't flag to single precision, and pixels near ones which aren't finite may be flagged differently, so its results differ from those of 2.17.0.
Full Changelog: v2.17.0...v2.18.0