Hide keyboard shortcuts

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

# 

# LSST Data Management System 

# Copyright 2008-2017 LSST/AURA. 

# 

# 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/>. 

# 

 

__all__ = ["clipImage", "resetFilters", "defineFilter", 

"defineFiltersFromPolicy", "CalibNoThrow"] 

 

import numpy as np 

 

import lsst.pex.policy as pexPolicy 

import lsst.afw.detection as afwDetect 

from .maskedImage import MaskedImage, makeMaskedImage 

from .mask import Mask 

from .filter import Filter, FilterProperty 

from .calib import Calib 

 

 

def clipImage(im, minClip, maxClip): 

"""Clip an image to lie between minClip and maxclip (None to ignore)""" 

if isinstance(im, MaskedImage): 

mi = im 

else: 

mi = makeMaskedImage(im, Mask(im.getDimensions())) 

 

if minClip is not None: 

ds = afwDetect.FootprintSet( 

mi, afwDetect.Threshold(-minClip, afwDetect.Threshold.VALUE, False)) 

afwDetect.setImageFromFootprintList( 

mi.getImage(), ds.getFootprints(), minClip) 

 

if maxClip is not None: 

ds = afwDetect.FootprintSet(mi, afwDetect.Threshold(maxClip)) 

afwDetect.setImageFromFootprintList( 

mi.getImage(), ds.getFootprints(), maxClip) 

 

 

def resetFilters(): 

"""Reset registry of filters and filter properties""" 

Filter.reset() 

FilterProperty.reset() 

 

 

def defineFilter(name, lambdaEff, lambdaMin=np.nan, lambdaMax=np.nan, alias=[], force=False): 

"""Define a filter and its properties in the filter registry""" 

prop = FilterProperty(name, lambdaEff, lambdaMin, lambdaMax, force) 

Filter.define(prop) 

65 ↛ 66line 65 didn't jump to line 66, because the condition on line 65 was never true if isinstance(alias, str): 

Filter.defineAlias(name, alias) 

else: 

for a in alias: 

Filter.defineAlias(name, a) 

 

 

def defineFiltersFromPolicy(filterPolicy, reset=False): 

"""Process a Policy and define the filters""" 

 

if reset: 

Filter.reset() 

FilterProperty.reset() 

# 

# Process the Policy and define the filters 

# 

policyFile = pexPolicy.DefaultPolicyFile( 

"afw", "FilterDictionary.paf", "policy") 

defPolicy = pexPolicy.Policy.createPolicy( 

policyFile, policyFile.getRepositoryPath(), True) 

 

filterPolicy.mergeDefaults(defPolicy.getDictionary()) 

 

for p in filterPolicy.getArray("Filter"): 

Filter.define(FilterProperty(p.get("name"), p)) 

if p.exists("alias"): 

for a in p.getArray("alias"): 

Filter.defineAlias(p.get("name"), a) 

 

 

class CalibNoThrow: 

"""A class intended to be used with python's with statement, to return NaNs for negative fluxes 

instead of raising exceptions (exceptions may be raised for other purposes). 

 

E.g. 

with CalibNoThrow(): 

ax.plot([exposure.getCalib().getMagnitude(a) for a in candAmps], zGood[:,k], 'b+') 

""" 

 

def __enter__(self): 

self._throwOnNegative = Calib.getThrowOnNegativeFlux() 

Calib.setThrowOnNegativeFlux(False) 

 

def __exit__(self, *args): 

Calib.setThrowOnNegativeFlux(self._throwOnNegative)