LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
utils.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 import re
24 import lsst.pex.policy as pexPolicy
25 import lsst.afw.detection as detection
26 from . import imageLib as afwImage
27 import numpy
28 
29 def clipImage(im, minClip, maxClip):
30  """Clip an image to lie between minClip and maxclip (None to ignore)"""
31 
32  if re.search("::MaskedImage<", im.__repr__()):
33  mi = im
34  else:
35  mi = afwImage.makeMaskedImage(im, afwImage.MaskU(im.getDimensions()))
36 
37  if minClip is not None:
38  ds = afwDetect.FootprintSet(mi, afwDetect.Threshold(-minClip, afwDetect.Threshold.VALUE, False))
39  afwDetect.setImageFromFootprintList(mi.getImage(), ds.getFootprints(), minClip)
40 
41  if maxclip is not None:
43  afwDetect.setImageFromFootprintList(mi.getImage(), ds.getFootprints(), maxclip)
44 
46  """Reset registry of filters and filter properties"""
47  afwImage.Filter.reset()
48  afwImage.FilterProperty.reset()
49 
50 def defineFilter(name, lambdaEff, alias=[], force=False):
51  """Define a filter and its properties in the filter registry"""
52  prop = afwImage.FilterProperty(name, lambdaEff, force)
53  afwImage.Filter.define(prop)
54  if isinstance(alias, basestring):
55  afwImage.Filter.defineAlias(name, alias)
56  else:
57  for a in alias:
58  afwImage.Filter.defineAlias(name, a)
59 
60 def defineFiltersFromPolicy(filterPolicy, reset=False):
61  """Process a Policy and define the filters"""
62 
63  if reset:
64  afwImage.Filter.reset()
65  afwImage.FilterProperty.reset()
66  #
67  # Process the Policy and define the filters
68  #
69  policyFile = pexPolicy.DefaultPolicyFile("afw", "FilterDictionary.paf", "policy")
70  defPolicy = pexPolicy.Policy.createPolicy(policyFile, policyFile.getRepositoryPath(), True)
71 
72  filterPolicy.mergeDefaults(defPolicy.getDictionary())
73 
74  for p in filterPolicy.getArray("Filter"):
75  afwImage.Filter.define(afwImage.FilterProperty(p.get("name"), p))
76  if p.exists("alias"):
77  for a in p.getArray("alias"):
78  afwImage.Filter.defineAlias(p.get("name"), a)
79 
80 class CalibNoThrow(object):
81  """A class intended to be used with python's with statement, to return NaNs for negative fluxes
82  instead of raising exceptions (exceptions may be raised for other purposes).
83 
84 E.g.
85  with CalibNoThrow():
86  ax.plot([exposure.getCalib().getMagnitude(a) for a in candAmps], zGood[:,k], 'b+')
87  """
88  def __enter__(self):
89  self._throwOnNegative = afwImage.Calib.getThrowOnNegativeFlux()
90  afwImage.Calib.setThrowOnNegativeFlux(False)
91 
92  def __exit__(self, *args):
93  afwImage.Calib.setThrowOnNegativeFlux(self._throwOnNegative)
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename Image< ImagePixelT >::Ptr image, typename Mask< MaskPixelT >::Ptr mask=typename Mask< MaskPixelT >::Ptr(), typename Image< VariancePixelT >::Ptr variance=typename Image< VariancePixelT >::Ptr())
Definition: MaskedImage.h:1067
a representation of a default Policy file that is stored as a file in the installation directory of a...
A Threshold is used to pass a threshold value to detection algorithms.
Definition: Threshold.h:44
def defineFiltersFromPolicy
Definition: utils.py:60
ImageT::Pixel setImageFromFootprintList(ImageT *image, std::vector< boost::shared_ptr< Footprint >> const &footprints, typename ImageT::Pixel const value)
Set all image pixels in a set of Footprints to a given value.
A set of Footprints, associated with a MaskedImage.
Definition: FootprintSet.h:53