Coverage for python/lsst/ip/isr/fringe.py : 72%

Hot-keys 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
#!/usr/bin/env python # # LSST Data Management System # Copyright 2012 LSST Corporation. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. #
"""Produce a new frame number each time""" getFrame.frame += 1 return getFrame.frame
"""Options for measuring fringes on an exposure""" doc="Offset to the random number generator seed (full seed includes exposure ID)")
"""Fringe subtraction options"""
"""Task to remove fringes from a science exposure
We measure fringe amplitudes at random positions on the science exposure and at the same positions on the (potentially multiple) fringe frames and solve for the scales simultaneously. """
"""Read the fringe frame(s)
The current implementation assumes only a single fringe frame and will have to be updated to support multi-mode fringe subtraction.
This implementation could be optimised by persisting the fringe positions and fluxes.
@param dataRef Data reference for the science exposure @param assembler An instance of AssembleCcdTask (for assembling fringe frames) @return Struct(fringes: fringe exposure or list of fringe exposures; seed: 32-bit uint derived from ccdExposureId for random number generator """ except Exception as e: raise RuntimeError("Unable to retrieve fringe for %s: %s" % (dataRef.dataId, e)) fringe = assembler.assembleCcd(fringe)
# Seed for numpy.random.RandomState must be convertable to a 32 bit unsigned integer
seed=seed)
"""Remove fringes from the provided science exposure.
Primary method of FringeTask. Fringes are only subtracted if the science exposure has a filter listed in the configuration.
@param exposure Science exposure from which to remove fringes @param fringes Exposure or list of Exposures @param seed 32-bit unsigned integer for random number generator """
return
# Placeholder implementation for multiple fringe frames # This needs to be revisited in DM-4441
ds9.mtv(exposure, title="Fringe subtracted", frame=getFrame())
"""Remove fringes from the provided science exposure.
Retrieve fringes from butler dataRef provided and remove from provided science exposure. Fringes are only subtracted if the science exposure has a filter listed in the configuration.
@param exposure Science exposure from which to remove fringes @param dataRef Data reference for the science exposure @param assembler An instance of AssembleCcdTask (for assembling fringe frames) """ return
"""Check whether we should fringe-subtract the science exposure"""
"""Remove pedestal from fringe exposure"""
"""Generate a random distribution of positions for measuring fringe amplitudes""" rng.randint(start, height, size=num)]).swapaxes(0, 1)
"""Measure fringe amplitudes for an exposure
The fringe amplitudes are measured as the statistic within a square aperture. The statistic within a larger aperture are subtracted so as to remove the background.
@param exposure Exposure to measure @param positions Array of (x,y) for fringe measurement @param title Title for display @return Array of fringe measurements """
frame = getFrame() ds9.mtv(exposure, frame=frame, title=title) if False: with ds9.Buffering(): for x, y in positions: corners = numpy.array([[-1, -1], [1, -1], [1, 1], [-1, 1], [-1, -1]]) + [[x, y]] ds9.line(corners * self.config.small, frame=frame, ctype="green") ds9.line(corners * self.config.large, frame=frame, ctype="blue")
def solve(self, science, fringes): """Solve (with iterative clipping) for the scale factors
@param science Array of science exposure fringe amplitudes @param fringes Array of arrays of fringe frame fringe amplitudes @return Array of scale factors for the fringe frames """
"""Generate an empty result for return to the user
There are no good pixels; doesn't matter what we return. """ out = out*len(fringes)
# Up-front rejection to get rid of extreme, potentially troublesome values # (e.g., fringe apertures that fall on objects). return emptyResult(" after initial rejection")
return emptyResult(" after %d rejection iterations" % i)
import matplotlib.pyplot as plot for j in range(fringes.shape[1]): fig = plot.figure(j) fig.clf() try: fig.canvas._tkcanvas._root().lift() # == Tk's raise except Exception: pass ax = fig.add_subplot(1, 1, 1) adjust = science.copy() others = set(range(fringes.shape[1])) others.discard(j) for k in others: adjust -= solution[k] * fringes[:, k] ax.plot(fringes[:, j], adjust, 'r.') xmin = fringes[:, j].min() xmax = fringes[:, j].max() ymin = solution[j] * xmin ymax = solution[j] * xmax ax.plot([xmin, xmax], [ymin, ymax], 'b-') ax.set_title("Fringe %d: %f" % (j, solution[j])) ax.set_xlabel("Fringe amplitude") ax.set_ylabel("Science amplitude") ax.set_autoscale_on(False) ax.set_xbound(lower=xmin, upper=xmax) ax.set_ybound(lower=ymin, upper=ymax) fig.show() while True: ans = input("Enter or c to continue [chp]").lower() if ans in ("", "c",): break if ans in ("p",): import pdb pdb.set_trace() elif ans in ("h", ): print("h[elp] c[ontinue] p[db]")
# Not gaining
# Final solution without rejection
"""Solve for the scale factors
@param science Array of science exposure fringe amplitudes @param fringes Array of arrays of fringe frame fringe amplitudes @return Array of scale factors for the fringe frames """ afwMath.LeastSquares.DIRECT_SVD).getSolution()
"""Subtract the fringes
@param science Science exposure @param fringes List of fringe frames @param solution Array of scale factors for the fringe frames """ raise RuntimeError("Number of fringe frames (%s) != number of scale factors (%s)" % (len(fringes), len(solution)))
"""Measure a statistic within an aperture
@param mi MaskedImage to measure @param x, y Center for aperture @param size Size of aperture @param statistic Statistic to measure @param stats StatisticsControl object @return Value of statistic within aperture """
"""Calculate a robust standard deviation of an array of values
@param vector Array of values @return Standard deviation """
"""Select values within 'clip' standard deviations of the median
Returns a boolean array. """ |