LSSTApplications  12.1-5-gbdcc3ab+2,15.0+13,15.0+26,15.0-1-g19261fa+17,15.0-1-g60afb23+26,15.0-1-g615e0bb+18,15.0-1-g788a293+26,15.0-1-ga91101e+26,15.0-1-gae1598d+12,15.0-1-gd076f1f+24,15.0-1-gdf18595+5,15.0-1-gf4f1c34+12,15.0-11-g7db6e543+4,15.0-12-g3681e7a+4,15.0-15-gc15de322,15.0-16-g83b84f4,15.0-2-g100d730+19,15.0-2-g1f9c9cf+4,15.0-2-g8aea5f4+1,15.0-2-gf38729e+21,15.0-29-ga12a2b06e,15.0-3-g11fe1a0+14,15.0-3-g707930d+3,15.0-3-g9103c06+12,15.0-3-gd3cbb57+3,15.0-4-g2d82b59,15.0-4-g535e784+10,15.0-4-g92ca6c3+4,15.0-4-gf906033+2,15.0-5-g23e394c+14,15.0-5-g4be42a9,15.0-6-g69628aa,15.0-6-g86e3f3d+1,15.0-6-gfa9b38f+4,15.0-7-g949993c+3,15.0-8-g67a62d3+1,15.0-8-gcf05001+1,15.0-9-g1e7c341+1,w.2018.21
LSSTDataManagementBasePackage
utils.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008-2017 LSST/AURA.
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 __all__ = ["clipImage", "resetFilters", "defineFilter",
24  "defineFiltersFromPolicy", "CalibNoThrow"]
25 
26 import numpy as np
27 
28 import lsst.pex.policy as pexPolicy
29 import lsst.afw.detection as afwDetect
30 from .maskedImage import MaskedImage, makeMaskedImage
31 from .mask import Mask
32 from .filter import Filter, FilterProperty
33 from .calib import Calib
34 
35 
36 def clipImage(im, minClip, maxClip):
37  """Clip an image to lie between minClip and maxclip (None to ignore)"""
38  if isinstance(im, MaskedImage):
39  mi = im
40  else:
41  mi = makeMaskedImage(im, Mask(im.getDimensions()))
42 
43  if minClip is not None:
45  mi, afwDetect.Threshold(-minClip, afwDetect.Threshold.VALUE, False))
46  afwDetect.setImageFromFootprintList(
47  mi.getImage(), ds.getFootprints(), minClip)
48 
49  if maxClip is not None:
51  afwDetect.setImageFromFootprintList(
52  mi.getImage(), ds.getFootprints(), maxClip)
53 
54 
56  """Reset registry of filters and filter properties"""
57  Filter.reset()
58  FilterProperty.reset()
59 
60 
61 def defineFilter(name, lambdaEff, lambdaMin=np.nan, lambdaMax=np.nan, alias=[], force=False):
62  """Define a filter and its properties in the filter registry"""
63  prop = FilterProperty(name, lambdaEff, lambdaMin, lambdaMax, force)
64  Filter.define(prop)
65  if isinstance(alias, str):
66  Filter.defineAlias(name, alias)
67  else:
68  for a in alias:
69  Filter.defineAlias(name, a)
70 
71 
72 def defineFiltersFromPolicy(filterPolicy, reset=False):
73  """Process a Policy and define the filters"""
74 
75  if reset:
76  Filter.reset()
77  FilterProperty.reset()
78  #
79  # Process the Policy and define the filters
80  #
81  policyFile = pexPolicy.DefaultPolicyFile(
82  "afw", "FilterDictionary.paf", "policy")
83  defPolicy = pexPolicy.Policy.createPolicy(
84  policyFile, policyFile.getRepositoryPath(), True)
85 
86  filterPolicy.mergeDefaults(defPolicy.getDictionary())
87 
88  for p in filterPolicy.getArray("Filter"):
89  Filter.define(FilterProperty(p.get("name"), p))
90  if p.exists("alias"):
91  for a in p.getArray("alias"):
92  Filter.defineAlias(p.get("name"), a)
93 
94 
96  """A class intended to be used with python's with statement, to return NaNs for negative fluxes
97  instead of raising exceptions (exceptions may be raised for other purposes).
98 
99 E.g.
100  with CalibNoThrow():
101  ax.plot([exposure.getCalib().getMagnitude(a) for a in candAmps], zGood[:,k], 'b+')
102  """
103 
104  def __enter__(self):
105  self._throwOnNegative = Calib.getThrowOnNegativeFlux()
106  Calib.setThrowOnNegativeFlux(False)
107 
108  def __exit__(self, *args):
109  Calib.setThrowOnNegativeFlux(self._throwOnNegative)
def defineFiltersFromPolicy(filterPolicy, reset=False)
Definition: utils.py:72
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:43
MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > * makeMaskedImage(typename std::shared_ptr< Image< ImagePixelT >> image, typename std::shared_ptr< Mask< MaskPixelT >> mask=Mask< MaskPixelT >(), typename std::shared_ptr< Image< VariancePixelT >> variance=Image< VariancePixelT >())
A function to return a MaskedImage of the correct type (cf.
Definition: MaskedImage.h:1268
def defineFilter(name, lambdaEff, lambdaMin=np.nan, lambdaMax=np.nan, alias=[], force=False)
Definition: utils.py:61
def clipImage(im, minClip, maxClip)
Definition: utils.py:36
A set of Footprints, associated with a MaskedImage.
Definition: FootprintSet.h:53