LSSTApplications  19.0.0-14-gb0260a2+599893a4c6,20.0.0+126303c00d,20.0.0+2f3d0e5c40,20.0.0+36ef800059,20.0.0+5ac7adcc0c,20.0.0+693a64958a,20.0.0+bebc1f60e8,20.0.0+cad136aba6,20.0.0+e2e26847c2,20.0.0+e69b5d60e7,20.0.0-1-g10df615+11b215b765,20.0.0-1-g253301a+36ef800059,20.0.0-1-g2b7511a+bebc1f60e8,20.0.0-1-g4d801e7+aeeb640673,20.0.0-1-g5b95a8c+f111d5f02f,20.0.0-1-g660595b+f45b7d88f4,20.0.0-1-gc96f8cb+e3b38461e6,20.0.0-1-gd1c87d7+85c46248f3,20.0.0-1-gedffbd8+d0b27f8bcb,20.0.0-16-g111fe95+e3b38461e6,20.0.0-16-g18096c8+d1a4df0137,20.0.0-16-g233ea98+a4df35922d,20.0.0-17-ga9337b4+41f27cfd54,20.0.0-2-g4dae9ad+e3b38461e6,20.0.0-2-g7818986+85c46248f3,20.0.0-2-gec03fae+ff10c6d78d,20.0.0-28-g282f9e7e+feda6aebd8,20.0.0-3-g4cc78c6+63636aeed8,20.0.0-3-g6a8623c+d1a4df0137,20.0.0-3-g750bffe+f5427621ce,20.0.0-4-gfea843c+f45b7d88f4,20.0.0-5-g357b56b+f45b7d88f4,20.0.0-5-gfcebe35+e2b15ed341,20.0.0-52-g73d9071+9bf1eb8e0a,20.0.0-7-gcda7bf1+773ba852cb,20.0.0-8-g4540fe2a+952f6d3c43,20.0.0-9-g61a2a9a3d+14f89e4eca,w.2020.40
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.synpipe.randomGalSimFakes.RandomGalSimFakesTask Class Reference
Inheritance diagram for lsst.synpipe.randomGalSimFakes.RandomGalSimFakesTask:
lsst.pipe.tasks.fakes.BaseFakeSourcesTask lsst.pipe.base.task.Task

Public Member Functions

def __init__ (self, **kwargs)
 
def run (self, exposure, background)
 
def emptyMetadata (self)
 
def getSchemaCatalogs (self)
 
def getAllSchemaCatalogs (self)
 
def getFullMetadata (self)
 
def getFullName (self)
 
def getName (self)
 
def getTaskDict (self)
 
def makeSubtask (self, name, **keyArgs)
 
def timer (self, name, logLevel=Log.DEBUG)
 
def makeField (cls, doc)
 
def __reduce__ (self)
 

Public Attributes

 rng
 
 npRand
 
 galData
 
 bitmask
 
 metadata
 
 log
 
 config
 

Static Public Attributes

 ConfigClass
 

Detailed Description

Definition at line 28 of file randomGalSimFakes.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.synpipe.randomGalSimFakes.RandomGalSimFakesTask.__init__ (   self,
**  kwargs 
)
Initialize the Task.

Subclasses that define their own __init__ should simply forward all arguments to the base
class constructor.  They can then assume self.config is an instance of their ConfigClass.

If an external catalog is used to add sources consistently to multiple overlapping images,
that catalog should generally be loaded and attached to self here, so it can be used
multiple times by the run() method.

Reimplemented from lsst.pipe.tasks.fakes.BaseFakeSourcesTask.

Definition at line 31 of file randomGalSimFakes.py.

31  def __init__(self, **kwargs):
32  BaseFakeSourcesTask.__init__(self, **kwargs)
33  print("RNG seed:", self.config.seed)
34  self.rng = lsst.afw.math.Random(seed=self.config.seed)
35  self.npRand = np.random.RandomState(self.config.seed)
36  self.galData = fits.open(self.config.galList)[1].data
37 

Member Function Documentation

◆ __reduce__()

def lsst.pipe.base.task.Task.__reduce__ (   self)
inherited
Pickler.

Reimplemented in lsst.obs.base.defineVisits.DefineVisitsTask, lsst.obs.base.ingest.RawIngestTask, lsst.pipe.drivers.multiBandDriver.MultiBandDriverTask, and lsst.pipe.drivers.coaddDriver.CoaddDriverTask.

Definition at line 373 of file task.py.

373  def __reduce__(self):
374  """Pickler.
375  """
376  return self.__class__, (self.config, self._name, self._parentTask, None)

◆ emptyMetadata()

def lsst.pipe.base.task.Task.emptyMetadata (   self)
inherited
Empty (clear) the metadata for this Task and all sub-Tasks.

Definition at line 153 of file task.py.

153  def emptyMetadata(self):
154  """Empty (clear) the metadata for this Task and all sub-Tasks.
155  """
156  for subtask in self._taskDict.values():
157  subtask.metadata = dafBase.PropertyList()
158 

◆ getAllSchemaCatalogs()

def lsst.pipe.base.task.Task.getAllSchemaCatalogs (   self)
inherited
Get schema catalogs for all tasks in the hierarchy, combining the results into a single dict.

Returns
-------
schemacatalogs : `dict`
    Keys are butler dataset type, values are a empty catalog (an instance of the appropriate
    lsst.afw.table Catalog type) for all tasks in the hierarchy, from the top-level task down
    through all subtasks.

Notes
-----
This method may be called on any task in the hierarchy; it will return the same answer, regardless.

The default implementation should always suffice. If your subtask uses schemas the override
`Task.getSchemaCatalogs`, not this method.

Definition at line 188 of file task.py.

188  def getAllSchemaCatalogs(self):
189  """Get schema catalogs for all tasks in the hierarchy, combining the results into a single dict.
190 
191  Returns
192  -------
193  schemacatalogs : `dict`
194  Keys are butler dataset type, values are a empty catalog (an instance of the appropriate
195  lsst.afw.table Catalog type) for all tasks in the hierarchy, from the top-level task down
196  through all subtasks.
197 
198  Notes
199  -----
200  This method may be called on any task in the hierarchy; it will return the same answer, regardless.
201 
202  The default implementation should always suffice. If your subtask uses schemas the override
203  `Task.getSchemaCatalogs`, not this method.
204  """
205  schemaDict = self.getSchemaCatalogs()
206  for subtask in self._taskDict.values():
207  schemaDict.update(subtask.getSchemaCatalogs())
208  return schemaDict
209 

◆ getFullMetadata()

def lsst.pipe.base.task.Task.getFullMetadata (   self)
inherited
Get metadata for all tasks.

Returns
-------
metadata : `lsst.daf.base.PropertySet`
    The `~lsst.daf.base.PropertySet` keys are the full task name. Values are metadata
    for the top-level task and all subtasks, sub-subtasks, etc..

Notes
-----
The returned metadata includes timing information (if ``@timer.timeMethod`` is used)
and any metadata set by the task. The name of each item consists of the full task name
with ``.`` replaced by ``:``, followed by ``.`` and the name of the item, e.g.::

    topLevelTaskName:subtaskName:subsubtaskName.itemName

using ``:`` in the full task name disambiguates the rare situation that a task has a subtask
and a metadata item with the same name.

Definition at line 210 of file task.py.

210  def getFullMetadata(self):
211  """Get metadata for all tasks.
212 
213  Returns
214  -------
215  metadata : `lsst.daf.base.PropertySet`
216  The `~lsst.daf.base.PropertySet` keys are the full task name. Values are metadata
217  for the top-level task and all subtasks, sub-subtasks, etc..
218 
219  Notes
220  -----
221  The returned metadata includes timing information (if ``@timer.timeMethod`` is used)
222  and any metadata set by the task. The name of each item consists of the full task name
223  with ``.`` replaced by ``:``, followed by ``.`` and the name of the item, e.g.::
224 
225  topLevelTaskName:subtaskName:subsubtaskName.itemName
226 
227  using ``:`` in the full task name disambiguates the rare situation that a task has a subtask
228  and a metadata item with the same name.
229  """
230  fullMetadata = dafBase.PropertySet()
231  for fullName, task in self.getTaskDict().items():
232  fullMetadata.set(fullName.replace(".", ":"), task.metadata)
233  return fullMetadata
234 

◆ getFullName()

def lsst.pipe.base.task.Task.getFullName (   self)
inherited
Get the task name as a hierarchical name including parent task names.

Returns
-------
fullName : `str`
    The full name consists of the name of the parent task and each subtask separated by periods.
    For example:

    - The full name of top-level task "top" is simply "top".
    - The full name of subtask "sub" of top-level task "top" is "top.sub".
    - The full name of subtask "sub2" of subtask "sub" of top-level task "top" is "top.sub.sub2".

Definition at line 235 of file task.py.

235  def getFullName(self):
236  """Get the task name as a hierarchical name including parent task names.
237 
238  Returns
239  -------
240  fullName : `str`
241  The full name consists of the name of the parent task and each subtask separated by periods.
242  For example:
243 
244  - The full name of top-level task "top" is simply "top".
245  - The full name of subtask "sub" of top-level task "top" is "top.sub".
246  - The full name of subtask "sub2" of subtask "sub" of top-level task "top" is "top.sub.sub2".
247  """
248  return self._fullName
249 

◆ getName()

def lsst.pipe.base.task.Task.getName (   self)
inherited
Get the name of the task.

Returns
-------
taskName : `str`
    Name of the task.

See also
--------
getFullName

Definition at line 250 of file task.py.

250  def getName(self):
251  """Get the name of the task.
252 
253  Returns
254  -------
255  taskName : `str`
256  Name of the task.
257 
258  See also
259  --------
260  getFullName
261  """
262  return self._name
263 

◆ getSchemaCatalogs()

def lsst.pipe.base.task.Task.getSchemaCatalogs (   self)
inherited
Get the schemas generated by this task.

Returns
-------
schemaCatalogs : `dict`
    Keys are butler dataset type, values are an empty catalog (an instance of the appropriate
    `lsst.afw.table` Catalog type) for this task.

Notes
-----

.. warning::

   Subclasses that use schemas must override this method. The default implemenation returns
   an empty dict.

This method may be called at any time after the Task is constructed, which means that all task
schemas should be computed at construction time, *not* when data is actually processed. This
reflects the philosophy that the schema should not depend on the data.

Returning catalogs rather than just schemas allows us to save e.g. slots for SourceCatalog as well.

See also
--------
Task.getAllSchemaCatalogs

Definition at line 159 of file task.py.

159  def getSchemaCatalogs(self):
160  """Get the schemas generated by this task.
161 
162  Returns
163  -------
164  schemaCatalogs : `dict`
165  Keys are butler dataset type, values are an empty catalog (an instance of the appropriate
166  `lsst.afw.table` Catalog type) for this task.
167 
168  Notes
169  -----
170 
171  .. warning::
172 
173  Subclasses that use schemas must override this method. The default implemenation returns
174  an empty dict.
175 
176  This method may be called at any time after the Task is constructed, which means that all task
177  schemas should be computed at construction time, *not* when data is actually processed. This
178  reflects the philosophy that the schema should not depend on the data.
179 
180  Returning catalogs rather than just schemas allows us to save e.g. slots for SourceCatalog as well.
181 
182  See also
183  --------
184  Task.getAllSchemaCatalogs
185  """
186  return {}
187 

◆ getTaskDict()

def lsst.pipe.base.task.Task.getTaskDict (   self)
inherited
Get a dictionary of all tasks as a shallow copy.

Returns
-------
taskDict : `dict`
    Dictionary containing full task name: task object for the top-level task and all subtasks,
    sub-subtasks, etc..

Definition at line 264 of file task.py.

264  def getTaskDict(self):
265  """Get a dictionary of all tasks as a shallow copy.
266 
267  Returns
268  -------
269  taskDict : `dict`
270  Dictionary containing full task name: task object for the top-level task and all subtasks,
271  sub-subtasks, etc..
272  """
273  return self._taskDict.copy()
274 

◆ makeField()

def lsst.pipe.base.task.Task.makeField (   cls,
  doc 
)
inherited
Make a `lsst.pex.config.ConfigurableField` for this task.

Parameters
----------
doc : `str`
    Help text for the field.

Returns
-------
configurableField : `lsst.pex.config.ConfigurableField`
    A `~ConfigurableField` for this task.

Examples
--------
Provides a convenient way to specify this task is a subtask of another task.

Here is an example of use::

    class OtherTaskConfig(lsst.pex.config.Config)
aSubtask = ATaskClass.makeField("a brief description of what this task does")

Definition at line 329 of file task.py.

329  def makeField(cls, doc):
330  """Make a `lsst.pex.config.ConfigurableField` for this task.
331 
332  Parameters
333  ----------
334  doc : `str`
335  Help text for the field.
336 
337  Returns
338  -------
339  configurableField : `lsst.pex.config.ConfigurableField`
340  A `~ConfigurableField` for this task.
341 
342  Examples
343  --------
344  Provides a convenient way to specify this task is a subtask of another task.
345 
346  Here is an example of use::
347 
348  class OtherTaskConfig(lsst.pex.config.Config)
349  aSubtask = ATaskClass.makeField("a brief description of what this task does")
350  """
351  return ConfigurableField(doc=doc, target=cls)
352 

◆ makeSubtask()

def lsst.pipe.base.task.Task.makeSubtask (   self,
  name,
**  keyArgs 
)
inherited
Create a subtask as a new instance as the ``name`` attribute of this task.

Parameters
----------
name : `str`
    Brief name of the subtask.
keyArgs
    Extra keyword arguments used to construct the task. The following arguments are automatically
    provided and cannot be overridden:

    - "config".
    - "parentTask".

Notes
-----
The subtask must be defined by ``Task.config.name``, an instance of pex_config ConfigurableField
or RegistryField.

Definition at line 275 of file task.py.

275  def makeSubtask(self, name, **keyArgs):
276  """Create a subtask as a new instance as the ``name`` attribute of this task.
277 
278  Parameters
279  ----------
280  name : `str`
281  Brief name of the subtask.
282  keyArgs
283  Extra keyword arguments used to construct the task. The following arguments are automatically
284  provided and cannot be overridden:
285 
286  - "config".
287  - "parentTask".
288 
289  Notes
290  -----
291  The subtask must be defined by ``Task.config.name``, an instance of pex_config ConfigurableField
292  or RegistryField.
293  """
294  taskField = getattr(self.config, name, None)
295  if taskField is None:
296  raise KeyError(f"{self.getFullName()}'s config does not have field {name!r}")
297  subtask = taskField.apply(name=name, parentTask=self, **keyArgs)
298  setattr(self, name, subtask)
299 

◆ run()

def lsst.synpipe.randomGalSimFakes.RandomGalSimFakesTask.run (   self,
  exposure,
  background 
)
Add fake sources to the given Exposure, making use of the given BackgroundList if desired.

If pixels in the Exposure are replaced, not added to, extra care should be taken with the background,
mask, and variance planes.  The Exposure as given is background-subtracted (using the supplied
background model) and should be returned in the same state.

Reimplemented from lsst.pipe.tasks.fakes.BaseFakeSourcesTask.

Definition at line 38 of file randomGalSimFakes.py.

38  def run(self, exposure, background):
39 
40  self.log.info("Adding fake random galaxies")
41  psf = exposure.getPsf()
42  psfBBox = psf.computeImage().getBBox()
43  minMargin = int(np.floor(max(psfBBox.getWidth(), psfBBox.getHeight())/2)) + 1
44  md = exposure.getMetadata()
45  expBBox = exposure.getBBox()
46  scalingMatrix = np.array([[0.0, 1.0], [1.0, 0.0]]) / exposure.getWcs().pixelScale().asArcseconds()
47 
48  if self.config.nGal == 0:
49  doGal = enumerate(self.galData)
50  else:
51  inds = self.npRand.choice(list(range(len(self.galData))), size=self.config.nGal, replace=False)
52  doGal = list(zip(inds, self.galData[inds]))
53 
54  for igal, gal in doGal:
55  try:
56  galident = gal["ID"]
57  except KeyError:
58  galident = igal + 1
59 
60  try:
61  flux = exposure.getCalib().getFlux(float(gal['mag']))
62  except KeyError:
63  raise KeyError("No mag column in %s table"%self.config.galList)
64 
65  # don't put the galaxy within one PSF box of the edge
66  # or within the given pixel margin
67  if self.config.margin is not None:
68  margin = self.config.margin
69  else:
70  margin = minMargin
71  bboxI = (exposure.getBBox(lsst.afw.image.PARENT))
72  bboxI.grow(-margin)
73  bboxD = lsst.afw.geom.BoxD(bboxI)
74  x = self.rng.flat(bboxD.getMinX(), bboxD.getMaxX())
75  y = self.rng.flat(bboxD.getMinY(), bboxD.getMaxY())
76  # TODO: check for overlaps here and regenerate x,y if necessary
77 
78  psfImage = psf.computeKernelImage(lsst.afw.geom.Point2D(x, y))
79  galArray = makeFake.makeGalaxy(flux, gal, psfImage.getArray(), self.config.galType,
80  transform=scalingMatrix)
81  galImage = lsst.afw.image.ImageF(galArray.astype(np.float32))
82  galBBox = galImage.getBBox(lsst.afw.image.PARENT)
83  galImage = lsst.afw.math.offsetImage(galImage,
84  x - galBBox.getWidth()/2.0 + 0.5,
85  y - galBBox.getHeight()/2.0 + 0.5,
86  'lanczos3')
87  galBBox = galImage.getBBox(lsst.afw.image.PARENT)
88 
89  # check that we're within the larger exposure, otherwise crop
90  if expBBox.contains(galImage.getBBox(lsst.afw.image.PARENT)) is False:
91  newBBox = galImage.getBBox(lsst.afw.image.PARENT)
92  newBBox.clip(expBBox)
93  self.log.info("Cropping FAKE%d from %s to %s"%(galident, str(galBBox), str(newBBox)))
94  galImage = galImage.Factory(galImage, newBBox, lsst.afw.image.PARENT)
95  galBBox = newBBox
96 
97  galMaskedImage = lsst.afw.image.MaskedImageF(galImage)
98 
99  mask = galMaskedImage.getMask()
100  mask.set(self.bitmask)
101 
102  md.set("FAKE%d" % gal['ID'], "%.3f, %.3f" % (x, y))
103  self.log.info("Adding fake at: %.1f,%.1f" % (x, y))
104 
105  # TODO: set the mask
106  galMaskedImage.getMask().set(self.bitmask)
107  subMaskedImage = exposure.getMaskedImage().Factory(exposure.getMaskedImage(),
108  galMaskedImage.getBBox(lsst.afw.image.PARENT),
109  lsst.afw.image.PARENT)
110  subMaskedImage += galMaskedImage

◆ timer()

def lsst.pipe.base.task.Task.timer (   self,
  name,
  logLevel = Log.DEBUG 
)
inherited
Context manager to log performance data for an arbitrary block of code.

Parameters
----------
name : `str`
    Name of code being timed; data will be logged using item name: ``Start`` and ``End``.
logLevel
    A `lsst.log` level constant.

Examples
--------
Creating a timer context::

    with self.timer("someCodeToTime"):
pass  # code to time

See also
--------
timer.logInfo

Definition at line 301 of file task.py.

301  def timer(self, name, logLevel=Log.DEBUG):
302  """Context manager to log performance data for an arbitrary block of code.
303 
304  Parameters
305  ----------
306  name : `str`
307  Name of code being timed; data will be logged using item name: ``Start`` and ``End``.
308  logLevel
309  A `lsst.log` level constant.
310 
311  Examples
312  --------
313  Creating a timer context::
314 
315  with self.timer("someCodeToTime"):
316  pass # code to time
317 
318  See also
319  --------
320  timer.logInfo
321  """
322  logInfo(obj=self, prefix=name + "Start", logLevel=logLevel)
323  try:
324  yield
325  finally:
326  logInfo(obj=self, prefix=name + "End", logLevel=logLevel)
327 

Member Data Documentation

◆ bitmask

lsst.pipe.tasks.fakes.BaseFakeSourcesTask.bitmask
inherited

Definition at line 61 of file fakes.py.

◆ config

lsst.pipe.base.task.Task.config
inherited

Definition at line 149 of file task.py.

◆ ConfigClass

lsst.synpipe.randomGalSimFakes.RandomGalSimFakesTask.ConfigClass
static

Definition at line 29 of file randomGalSimFakes.py.

◆ galData

lsst.synpipe.randomGalSimFakes.RandomGalSimFakesTask.galData

Definition at line 36 of file randomGalSimFakes.py.

◆ log

lsst.pipe.base.task.Task.log
inherited

Definition at line 148 of file task.py.

◆ metadata

lsst.pipe.base.task.Task.metadata
inherited

Definition at line 121 of file task.py.

◆ npRand

lsst.synpipe.randomGalSimFakes.RandomGalSimFakesTask.npRand

Definition at line 35 of file randomGalSimFakes.py.

◆ rng

lsst.synpipe.randomGalSimFakes.RandomGalSimFakesTask.rng

Definition at line 34 of file randomGalSimFakes.py.


The documentation for this class was generated from the following file:
lsst::log.log.logContinued.info
def info(fmt, *args)
Definition: logContinued.py:201
lsst::daf::base::PropertyList
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68
lsst.pipe.base.argumentParser.getTaskDict
def getTaskDict(config, taskDict=None, baseName="")
Definition: argumentParser.py:921
lsst.pipe.tasks.assembleCoadd.run
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)
Definition: assembleCoadd.py:720
lsst.pipe.base.timer.logInfo
def logInfo(obj, prefix, logLevel=Log.DEBUG)
Definition: timer.py:62
max
int max
Definition: BoundedField.cc:104
lsst::afw::math::Random
A class that can be used to generate sequences of random numbers according to a number of different a...
Definition: Random.h:57
items
std::vector< SchemaItem< Flag > > * items
Definition: BaseColumnView.cc:142
lsst::afw::image.slicing.Factory
Factory
Definition: slicing.py:252
list
daf::base::PropertyList * list
Definition: fits.cc:913
lsst::afw::math::offsetImage
std::shared_ptr< ImageT > offsetImage(ImageT const &image, float dx, float dy, std::string const &algorithmName="lanczos5", unsigned int buffer=0)
Return an image offset by (dx, dy) using the specified algorithm.
Definition: offsetImage.cc:41
lsst::daf::base::PropertySet
Class for storing generic metadata.
Definition: PropertySet.h:67
set
daf::base::PropertySet * set
Definition: fits.cc:912