Skip to content

v2.18.0

Latest

Choose a tag to compare

@roytsmart roytsmart released this 29 Oct 18:21
ed0b11f

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 a ValueError for uncertain inputs, since each of their samples has weights of its own. So does regrid() 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: bounds applies 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 as na.despike() and returns the boolean mask of the pixels which astroscrappy flags as cosmic rays, the ones na.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, inbkg or invar isn't finite, as well as where where is false. Before, a NaN spread to its neighbors through the median filters and the Laplacian of astroscrappy. A spike near NaN pixels of array was replaced with NaN, and where inbkg was NaN, the result was NaN too, though array was 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, with inbkg, pixels which weren't flagged moved too.
  • Other fixes:
    • invar and psfk of any dtype work, where any dtype but float32 raised a ValueError. psfk is 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 an AttributeError.
    • A function array given as where, inbkg or invar with an array which isn't a function array raises a TypeError, where it was ignored, and one whose inputs differ from those of array raises a ValueError.
    • An integer where counts nonzero as true, where it masked every pixel.
    • inbkg and invar are converted to the unit of array, squared for invar, 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