LSSTApplications  18.0.0+46,18.0.0+93,19.0.0,19.0.0+1,19.0.0+2,19.0.0+3,19.0.0+4,19.0.0-1-g20d9b18+2,19.0.0-1-g3dc8cbe+2,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+2,19.0.0-1-g5db401e+3,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+2,19.0.0-1-g8c57eb9+2,19.0.0-1-g9828021+2,19.0.0-1-gb5175dc+2,19.0.0-1-gd7f3e1b+2,19.0.0-1-gdc0e4a7+2,19.0.0-1-ge272bc4+2,19.0.0-2-g0d9f9cd+2,19.0.0-2-g1c703f9ef+1,19.0.0-2-g3d9e4fb2+2,19.0.0-2-gd955cfd+2,19.0.0-3-g2d13df8,19.0.0-3-g63079e6+2,19.0.0-7-g8a434f2+1,19.0.0-7-gf796fef9+3,w.2019.49
LSSTDataManagementBasePackage
Classes | Functions
lsst.cp.pipe.utils Namespace Reference

Classes

class  NonexistentDatasetTaskDataIdContainer
 
class  PairedVisitListTaskRunner
 
class  SingleVisitListTaskRunner
 

Functions

def countMaskedPixels (maskedIm, maskPlane)
 
def parseCmdlineNumberString (inputString)
 
def checkExpLengthEqual (exp1, exp2, v1=None, v2=None, raiseWithMessage=False)
 
def validateIsrConfig (isrTask, mandatory=None, forbidden=None, desirable=None, undesirable=None, checkTrim=True, logName=None)
 

Function Documentation

◆ checkExpLengthEqual()

def lsst.cp.pipe.utils.checkExpLengthEqual (   exp1,
  exp2,
  v1 = None,
  v2 = None,
  raiseWithMessage = False 
)
Check the exposure lengths of two exposures are equal.

Parameters:
-----------
exp1 : `lsst.afw.image.exposure.ExposureF`
    First exposure to check
exp2 : `lsst.afw.image.exposure.ExposureF`
    Second exposure to check
v1 : `int` or `str`, optional
    First visit of the visit pair
v2 : `int` or `str`, optional
    Second visit of the visit pair
raiseWithMessage : `bool`
    If True, instead of returning a bool, raise a RuntimeError if exposure
times are not equal, with a message about which visits mismatch if the
information is available.

Raises:
-------
RuntimeError
    Raised if the exposure lengths of the two exposures are not equal

Definition at line 162 of file utils.py.

162 def checkExpLengthEqual(exp1, exp2, v1=None, v2=None, raiseWithMessage=False):
163  """Check the exposure lengths of two exposures are equal.
164 
165  Parameters:
166  -----------
167  exp1 : `lsst.afw.image.exposure.ExposureF`
168  First exposure to check
169  exp2 : `lsst.afw.image.exposure.ExposureF`
170  Second exposure to check
171  v1 : `int` or `str`, optional
172  First visit of the visit pair
173  v2 : `int` or `str`, optional
174  Second visit of the visit pair
175  raiseWithMessage : `bool`
176  If True, instead of returning a bool, raise a RuntimeError if exposure
177  times are not equal, with a message about which visits mismatch if the
178  information is available.
179 
180  Raises:
181  -------
182  RuntimeError
183  Raised if the exposure lengths of the two exposures are not equal
184  """
185  expTime1 = exp1.getInfo().getVisitInfo().getExposureTime()
186  expTime2 = exp2.getInfo().getVisitInfo().getExposureTime()
187  if expTime1 != expTime2:
188  if raiseWithMessage:
189  msg = "Exposure lengths for visit pairs must be equal. " + \
190  "Found %s and %s" % (expTime1, expTime2)
191  if v1 and v2:
192  msg += " for visit pair %s, %s" % (v1, v2)
193  raise RuntimeError(msg)
194  else:
195  return False
196  return True
197 
198 
def checkExpLengthEqual(exp1, exp2, v1=None, v2=None, raiseWithMessage=False)
Definition: utils.py:162

◆ countMaskedPixels()

def lsst.cp.pipe.utils.countMaskedPixels (   maskedIm,
  maskPlane 
)
Count the number of pixels in a given mask plane.

Definition at line 35 of file utils.py.

35 def countMaskedPixels(maskedIm, maskPlane):
36  """Count the number of pixels in a given mask plane."""
37  maskBit = maskedIm.mask.getPlaneBitMask(maskPlane)
38  nPix = np.where(np.bitwise_and(maskedIm.mask.array, maskBit))[0].flatten().size
39  return nPix
40 
41 
def countMaskedPixels(maskedIm, maskPlane)
Definition: utils.py:35

◆ parseCmdlineNumberString()

def lsst.cp.pipe.utils.parseCmdlineNumberString (   inputString)
Parse command line numerical expression sytax and return as list of int

Take an input of the form "'1..5:2^123..126'" as a string, and return
a list of ints as [1, 3, 5, 123, 124, 125, 126]

Definition at line 77 of file utils.py.

77 def parseCmdlineNumberString(inputString):
78  """Parse command line numerical expression sytax and return as list of int
79 
80  Take an input of the form "'1..5:2^123..126'" as a string, and return
81  a list of ints as [1, 3, 5, 123, 124, 125, 126]
82  """
83  outList = []
84  for subString in inputString.split("^"):
85  mat = re.search(r"^(\d+)\.\.(\d+)(?::(\d+))?$", subString)
86  if mat:
87  v1 = int(mat.group(1))
88  v2 = int(mat.group(2))
89  v3 = mat.group(3)
90  v3 = int(v3) if v3 else 1
91  for v in range(v1, v2 + 1, v3):
92  outList.append(int(v))
93  else:
94  outList.append(int(subString))
95  return outList
96 
97 
def parseCmdlineNumberString(inputString)
Definition: utils.py:77

◆ validateIsrConfig()

def lsst.cp.pipe.utils.validateIsrConfig (   isrTask,
  mandatory = None,
  forbidden = None,
  desirable = None,
  undesirable = None,
  checkTrim = True,
  logName = None 
)
Check that appropriate ISR settings have been selected for the task.

Note that this checks that the task itself is configured correctly rather
than checking a config.

Parameters
----------
isrTask : `lsst.ip.isr.IsrTask`
    The task whose config is to be validated

mandatory : `iterable` of `str`
    isr steps that must be set to True. Raises if False or missing

forbidden : `iterable` of `str`
    isr steps that must be set to False. Raises if True, warns if missing

desirable : `iterable` of `str`
    isr steps that should probably be set to True. Warns is False, info if
missing

undesirable : `iterable` of `str`
    isr steps that should probably be set to False. Warns is True, info if
missing

checkTrim : `bool`
    Check to ensure the isrTask's assembly subtask is trimming the images.
This is a separate config as it is very ugly to do this within the
normal configuration lists as it is an option of a sub task.

Raises
------
RuntimeError
    Raised if ``mandatory`` config parameters are False,
    or if ``forbidden`` parameters are True.

TypeError
    Raised if parameter ``isrTask`` is an invalid type.

Notes
-----
Logs warnings using an isrValidation logger for desirable/undesirable
options that are of the wrong polarity or if keys are missing.

Definition at line 200 of file utils.py.

200  checkTrim=True, logName=None):
201  """Check that appropriate ISR settings have been selected for the task.
202 
203  Note that this checks that the task itself is configured correctly rather
204  than checking a config.
205 
206  Parameters
207  ----------
208  isrTask : `lsst.ip.isr.IsrTask`
209  The task whose config is to be validated
210 
211  mandatory : `iterable` of `str`
212  isr steps that must be set to True. Raises if False or missing
213 
214  forbidden : `iterable` of `str`
215  isr steps that must be set to False. Raises if True, warns if missing
216 
217  desirable : `iterable` of `str`
218  isr steps that should probably be set to True. Warns is False, info if
219  missing
220 
221  undesirable : `iterable` of `str`
222  isr steps that should probably be set to False. Warns is True, info if
223  missing
224 
225  checkTrim : `bool`
226  Check to ensure the isrTask's assembly subtask is trimming the images.
227  This is a separate config as it is very ugly to do this within the
228  normal configuration lists as it is an option of a sub task.
229 
230  Raises
231  ------
232  RuntimeError
233  Raised if ``mandatory`` config parameters are False,
234  or if ``forbidden`` parameters are True.
235 
236  TypeError
237  Raised if parameter ``isrTask`` is an invalid type.
238 
239  Notes
240  -----
241  Logs warnings using an isrValidation logger for desirable/undesirable
242  options that are of the wrong polarity or if keys are missing.
243  """
244  if not isinstance(isrTask, ipIsr.IsrTask):
245  raise TypeError(f'Must supply an instance of lsst.ip.isr.IsrTask not {type(isrTask)}')
246 
247  configDict = isrTask.config.toDict()
248 
249  if logName and isinstance(logName, str):
250  log = lsst.log.getLogger(logName)
251  else:
252  log = lsst.log.getLogger("isrValidation")
253 
254  if mandatory:
255  for configParam in mandatory:
256  if configParam not in configDict:
257  raise RuntimeError(f"Mandatory parameter {configParam} not found in the isr configuration.")
258  if configDict[configParam] is False:
259  raise RuntimeError(f"Must set config.isr.{configParam} to True for this task.")
260 
261  if forbidden:
262  for configParam in forbidden:
263  if configParam not in configDict:
264  log.warn(f"Failed to find forbidden key {configParam} in the isr config. The keys in the"
265  " forbidden list should each have an associated Field in IsrConfig:"
266  " check that there is not a typo in this case.")
267  continue
268  if configDict[configParam] is True:
269  raise RuntimeError(f"Must set config.isr.{configParam} to False for this task.")
270 
271  if desirable:
272  for configParam in desirable:
273  if configParam not in configDict:
274  log.info(f"Failed to find key {configParam} in the isr config. You probably want" +
275  " to set the equivalent for your obs_package to True.")
276  continue
277  if configDict[configParam] is False:
278  log.warn(f"Found config.isr.{configParam} set to False for this task." +
279  " The cp_pipe Config recommends setting this to True.")
280  if undesirable:
281  for configParam in undesirable:
282  if configParam not in configDict:
283  log.info(f"Failed to find key {configParam} in the isr config. You probably want" +
284  " to set the equivalent for your obs_package to False.")
285  continue
286  if configDict[configParam] is True:
287  log.warn(f"Found config.isr.{configParam} set to True for this task." +
288  " The cp_pipe Config recommends setting this to False.")
289 
290  if checkTrim: # subtask setting, seems non-trivial to combine with above lists
291  if not isrTask.assembleCcd.config.doTrim:
292  raise RuntimeError("Must trim when assembling CCDs. Set config.isr.assembleCcd.doTrim to True")
293