LSSTApplications  11.0-24-g0a022a1,14.0+77,15.0,15.0+1
LSSTDataManagementBasePackage
utils.py
Go to the documentation of this file.
1 from __future__ import print_function
2 #
3 # LSST Data Management System
4 # Copyright 2008, 2009, 2010 LSST Corporation.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 
24 import sys
25 
26 import lsst.afw.geom as afwGeom
27 
28 
29 def getDataset(butler, dataset, dataId, strict, warn):
30  """Get a dataset from a repository with an optional exception or warning if not found
31 
32  @param[in] butler: data butler
33  @param[in] dataset: name of desired dataset
34  @param[in] dataId: data ID dict
35  @param[in] strict: if True then raise RuntimeError if dataset not found
36  @param[in] warn: if True and strict False then print a warning to stderr if dataset not found
37 
38  @raise RuntimeError if dataset not found and strict true
39  """
40  try:
41  ds = butler.get(dataset, dataId=dataId, immediate=True)
42  except:
43  ds = None
44  if ds is None:
45  msg = '{} : Failed to retrieve {} dataset'.format(dataId, dataset)
46  if strict:
47  raise RuntimeError(msg)
48  elif warn:
49  print('*** Skipping ' + msg, file=sys.stderr)
50  return ds
51 
52 
53 def getPsf(butler, dataset, dataId, strict, warn):
54  """Get the PSF from a repository without reading (very much of) the exposure
55 
56  @param[in] butler: data butler
57  @param[in] dataset: name of desired dataset
58  @param[in] dataId: data ID dict of exposure containing desired PSF
59  @param[in] strict: if True then raise RuntimeError if psf not found
60  @param[in] warn: if True and strict False then print a warning to stderr if psf not found
61 
62  @raise RuntimeError if exposure not found (regardless of strict)
63  @raise RuntimeError if exposure has no PSF and strict true
64  """
65  # there is not yet a way to read just the PSF, so read a 1x1 subregion of the exposure
66  tinyBBox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(1, 1))
67  tinyExposure = butler.get(dataset + "_sub", dataId=dataId, bbox=tinyBBox,
68  imageOrigin="LOCAL", immediate=True)
69  psf = tinyExposure.getPsf()
70  if psf is None:
71  msg = '%s : %s exposure had no PSF' % (dataId, dataset)
72  psf = None
73  if strict:
74  raise RuntimeError(msg)
75  elif warn:
76  print('*** Skipping ' + msg, file=sys.stderr)
77  return psf
def getDataset(butler, dataset, dataId, strict, warn)
Definition: utils.py:29
An integer coordinate rectangle.
Definition: Box.h:55
def getPsf(butler, dataset, dataId, strict, warn)
Definition: utils.py:53
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:134