LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
Public Member Functions | List of all members
lsst.fgcmcal.fgcmBuildStarsBase.FgcmBuildStarsBaseTask Class Reference
Inheritance diagram for lsst.fgcmcal.fgcmBuildStarsBase.FgcmBuildStarsBaseTask:
lsst.fgcmcal.fgcmBuildStars.FgcmBuildStarsTask lsst.fgcmcal.fgcmBuildStarsTable.FgcmBuildStarsTableTask

Public Member Functions

def __init__ (self, initInputs=None, butler=None, **kwargs)
 
def runDataRef (self, butler, dataRefs)
 
def fgcmMakeAllStarObservations (self, groupedDataRefs, visitCat, sourceSchema, camera, calibFluxApertureRadius=None, visitCatDataRef=None, starObsDataRef=None, inStarObsCat=None)
 
def fgcmMakeVisitCatalog (self, camera, groupedDataRefs, bkgDataRefDict=None, visitCatDataRef=None, inVisitCat=None)
 
def fgcmMatchStars (self, visitCat, obsCat, lutDataRef=None)
 

Detailed Description

Base task to build stars for FGCM global calibration

Parameters
----------
butler : `lsst.daf.persistence.Butler`

Definition at line 275 of file fgcmBuildStarsBase.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.fgcmcal.fgcmBuildStarsBase.FgcmBuildStarsBaseTask.__init__ (   self,
  initInputs = None,
  butler = None,
**  kwargs 
)

Definition at line 283 of file fgcmBuildStarsBase.py.

283  def __init__(self, initInputs=None, butler=None, **kwargs):
284  super().__init__(**kwargs)
285 
286  self.makeSubtask("sourceSelector")
287  # Only log warning and fatal errors from the sourceSelector
288  self.sourceSelector.log.setLevel(self.sourceSelector.log.WARN)
289 

Member Function Documentation

◆ fgcmMakeAllStarObservations()

def lsst.fgcmcal.fgcmBuildStarsBase.FgcmBuildStarsBaseTask.fgcmMakeAllStarObservations (   self,
  groupedDataRefs,
  visitCat,
  sourceSchema,
  camera,
  calibFluxApertureRadius = None,
  visitCatDataRef = None,
  starObsDataRef = None,
  inStarObsCat = None 
)
Compile all good star observations from visits in visitCat.  Checkpoint files
will be stored if both visitCatDataRef and starObsDataRef are not None.

Parameters
----------
groupedDataRefs : `dict` of `list`s
    Lists of `~lsst.daf.persistence.ButlerDataRef` or
    `~lsst.daf.butler.DeferredDatasetHandle`, grouped by visit.
visitCat : `~afw.table.BaseCatalog`
    Catalog with visit data for FGCM
sourceSchema : `~lsst.afw.table.Schema`
    Schema for the input src catalogs.
camera : `~lsst.afw.cameraGeom.Camera`
calibFluxApertureRadius : `float`, optional
    Aperture radius for calibration flux.
visitCatDataRef : `~lsst.daf.persistence.ButlerDataRef`, optional
    Dataref to write visitCat for checkpoints
starObsDataRef : `~lsst.daf.persistence.ButlerDataRef`, optional
    Dataref to write the star observation catalog for checkpoints.
inStarObsCat : `~afw.table.BaseCatalog`
    Input observation catalog.  If this is incomplete, observations
    will be appended from when it was cut off.

Returns
-------
fgcmStarObservations : `afw.table.BaseCatalog`
    Full catalog of good observations.

Raises
------
RuntimeError: Raised if doSubtractLocalBackground is True and
   calibFluxApertureRadius is not set.

Reimplemented in lsst.fgcmcal.fgcmBuildStarsTable.FgcmBuildStarsTableTask, and lsst.fgcmcal.fgcmBuildStars.FgcmBuildStarsTask.

Definition at line 416 of file fgcmBuildStarsBase.py.

422  inStarObsCat=None):
423  """
424  Compile all good star observations from visits in visitCat. Checkpoint files
425  will be stored if both visitCatDataRef and starObsDataRef are not None.
426 
427  Parameters
428  ----------
429  groupedDataRefs : `dict` of `list`s
430  Lists of `~lsst.daf.persistence.ButlerDataRef` or
431  `~lsst.daf.butler.DeferredDatasetHandle`, grouped by visit.
432  visitCat : `~afw.table.BaseCatalog`
433  Catalog with visit data for FGCM
434  sourceSchema : `~lsst.afw.table.Schema`
435  Schema for the input src catalogs.
436  camera : `~lsst.afw.cameraGeom.Camera`
437  calibFluxApertureRadius : `float`, optional
438  Aperture radius for calibration flux.
439  visitCatDataRef : `~lsst.daf.persistence.ButlerDataRef`, optional
440  Dataref to write visitCat for checkpoints
441  starObsDataRef : `~lsst.daf.persistence.ButlerDataRef`, optional
442  Dataref to write the star observation catalog for checkpoints.
443  inStarObsCat : `~afw.table.BaseCatalog`
444  Input observation catalog. If this is incomplete, observations
445  will be appended from when it was cut off.
446 
447  Returns
448  -------
449  fgcmStarObservations : `afw.table.BaseCatalog`
450  Full catalog of good observations.
451 
452  Raises
453  ------
454  RuntimeError: Raised if doSubtractLocalBackground is True and
455  calibFluxApertureRadius is not set.
456  """
457  raise NotImplementedError("fgcmMakeAllStarObservations not implemented.")
458 

◆ fgcmMakeVisitCatalog()

def lsst.fgcmcal.fgcmBuildStarsBase.FgcmBuildStarsBaseTask.fgcmMakeVisitCatalog (   self,
  camera,
  groupedDataRefs,
  bkgDataRefDict = None,
  visitCatDataRef = None,
  inVisitCat = None 
)
Make a visit catalog with all the keys from each visit

Parameters
----------
camera: `lsst.afw.cameraGeom.Camera`
   Camera from the butler
groupedDataRefs: `dict`
   Dictionary with visit keys, and `list`s of
   `lsst.daf.persistence.ButlerDataRef`
bkgDataRefDict: `dict`, optional
   Dictionary of gen3 dataRefHandles for background info.
visitCatDataRef: `lsst.daf.persistence.ButlerDataRef`, optional
   Dataref to write visitCat for checkpoints
inVisitCat: `afw.table.BaseCatalog`, optional
   Input (possibly incomplete) visit catalog

Returns
-------
visitCat: `afw.table.BaseCatalog`

Definition at line 459 of file fgcmBuildStarsBase.py.

460  visitCatDataRef=None, inVisitCat=None):
461  """
462  Make a visit catalog with all the keys from each visit
463 
464  Parameters
465  ----------
466  camera: `lsst.afw.cameraGeom.Camera`
467  Camera from the butler
468  groupedDataRefs: `dict`
469  Dictionary with visit keys, and `list`s of
470  `lsst.daf.persistence.ButlerDataRef`
471  bkgDataRefDict: `dict`, optional
472  Dictionary of gen3 dataRefHandles for background info.
473  visitCatDataRef: `lsst.daf.persistence.ButlerDataRef`, optional
474  Dataref to write visitCat for checkpoints
475  inVisitCat: `afw.table.BaseCatalog`, optional
476  Input (possibly incomplete) visit catalog
477 
478  Returns
479  -------
480  visitCat: `afw.table.BaseCatalog`
481  """
482 
483  self.log.info("Assembling visitCatalog from %d %ss" %
484  (len(groupedDataRefs), self.config.visitDataRefName))
485 
486  nCcd = len(camera)
487 
488  if inVisitCat is None:
489  schema = self._makeFgcmVisitSchema(nCcd)
490 
491  visitCat = afwTable.BaseCatalog(schema)
492  visitCat.reserve(len(groupedDataRefs))
493  visitCat.resize(len(groupedDataRefs))
494 
495  visitCat['visit'] = list(groupedDataRefs.keys())
496  visitCat['used'] = 0
497  visitCat['sources_read'] = False
498  else:
499  visitCat = inVisitCat
500 
501  # No matter what, fill the catalog. This will check if it was
502  # already read.
503  self._fillVisitCatalog(visitCat, groupedDataRefs,
504  bkgDataRefDict=bkgDataRefDict,
505  visitCatDataRef=visitCatDataRef)
506 
507  return visitCat
508 
daf::base::PropertyList * list
Definition: fits.cc:913

◆ fgcmMatchStars()

def lsst.fgcmcal.fgcmBuildStarsBase.FgcmBuildStarsBaseTask.fgcmMatchStars (   self,
  visitCat,
  obsCat,
  lutDataRef = None 
)
Use FGCM code to match observations into unique stars.

Parameters
----------
visitCat: `afw.table.BaseCatalog`
   Catalog with visit data for fgcm
obsCat: `afw.table.BaseCatalog`
   Full catalog of star observations for fgcm
lutDataRef: `lsst.daf.persistence.ButlerDataRef` or
            `lsst.daf.butler.DeferredDatasetHandle`, optional
   Data reference to fgcm look-up table (used if matching reference stars).

Returns
-------
fgcmStarIdCat: `afw.table.BaseCatalog`
   Catalog of unique star identifiers and index keys
fgcmStarIndicesCat: `afwTable.BaseCatalog`
   Catalog of unique star indices
fgcmRefCat: `afw.table.BaseCatalog`
   Catalog of matched reference stars.
   Will be None if `config.doReferenceMatches` is False.

Definition at line 686 of file fgcmBuildStarsBase.py.

686  def fgcmMatchStars(self, visitCat, obsCat, lutDataRef=None):
687  """
688  Use FGCM code to match observations into unique stars.
689 
690  Parameters
691  ----------
692  visitCat: `afw.table.BaseCatalog`
693  Catalog with visit data for fgcm
694  obsCat: `afw.table.BaseCatalog`
695  Full catalog of star observations for fgcm
696  lutDataRef: `lsst.daf.persistence.ButlerDataRef` or
697  `lsst.daf.butler.DeferredDatasetHandle`, optional
698  Data reference to fgcm look-up table (used if matching reference stars).
699 
700  Returns
701  -------
702  fgcmStarIdCat: `afw.table.BaseCatalog`
703  Catalog of unique star identifiers and index keys
704  fgcmStarIndicesCat: `afwTable.BaseCatalog`
705  Catalog of unique star indices
706  fgcmRefCat: `afw.table.BaseCatalog`
707  Catalog of matched reference stars.
708  Will be None if `config.doReferenceMatches` is False.
709  """
710  # get filter names into a numpy array...
711  # This is the type that is expected by the fgcm code
712  visitFilterNames = np.zeros(len(visitCat), dtype='a30')
713  for i in range(len(visitCat)):
714  visitFilterNames[i] = visitCat[i]['physicalFilter']
715 
716  # match to put filterNames with observations
717  visitIndex = np.searchsorted(visitCat['visit'],
718  obsCat['visit'])
719 
720  obsFilterNames = visitFilterNames[visitIndex]
721 
722  if self.config.doReferenceMatches:
723  # Get the reference filter names, using the LUT
724  lutCat = lutDataRef.get()
725 
726  stdFilterDict = {filterName: stdFilter for (filterName, stdFilter) in
727  zip(lutCat[0]['physicalFilters'].split(','),
728  lutCat[0]['stdPhysicalFilters'].split(','))}
729  stdLambdaDict = {stdFilter: stdLambda for (stdFilter, stdLambda) in
730  zip(lutCat[0]['stdPhysicalFilters'].split(','),
731  lutCat[0]['lambdaStdFilter'])}
732 
733  del lutCat
734 
735  referenceFilterNames = self._getReferenceFilterNames(visitCat,
736  stdFilterDict,
737  stdLambdaDict)
738  self.log.info("Using the following reference filters: %s" %
739  (', '.join(referenceFilterNames)))
740 
741  else:
742  # This should be an empty list
743  referenceFilterNames = []
744 
745  # make the fgcm starConfig dict
746  starConfig = {'logger': self.log,
747  'filterToBand': self.config.physicalFilterMap,
748  'requiredBands': self.config.requiredBands,
749  'minPerBand': self.config.minPerBand,
750  'matchRadius': self.config.matchRadius,
751  'isolationRadius': self.config.isolationRadius,
752  'matchNSide': self.config.matchNside,
753  'coarseNSide': self.config.coarseNside,
754  'densNSide': self.config.densityCutNside,
755  'densMaxPerPixel': self.config.densityCutMaxPerPixel,
756  'randomSeed': self.config.randomSeed,
757  'primaryBands': self.config.primaryBands,
758  'referenceFilterNames': referenceFilterNames}
759 
760  # initialize the FgcmMakeStars object
761  fgcmMakeStars = fgcm.FgcmMakeStars(starConfig)
762 
763  # make the primary stars
764  # note that the ra/dec native Angle format is radians
765  # We determine the conversion from the native units (typically
766  # radians) to degrees for the first observation. This allows us
767  # to treate ra/dec as numpy arrays rather than Angles, which would
768  # be approximately 600x slower.
769  conv = obsCat[0]['ra'].asDegrees() / float(obsCat[0]['ra'])
770  fgcmMakeStars.makePrimaryStars(obsCat['ra'] * conv,
771  obsCat['dec'] * conv,
772  filterNameArray=obsFilterNames,
773  bandSelected=False)
774 
775  # and match all the stars
776  fgcmMakeStars.makeMatchedStars(obsCat['ra'] * conv,
777  obsCat['dec'] * conv,
778  obsFilterNames)
779 
780  if self.config.doReferenceMatches:
781  fgcmMakeStars.makeReferenceMatches(self.fgcmLoadReferenceCatalog)
782 
783  # now persist
784 
785  objSchema = self._makeFgcmObjSchema()
786 
787  # make catalog and records
788  fgcmStarIdCat = afwTable.BaseCatalog(objSchema)
789  fgcmStarIdCat.reserve(fgcmMakeStars.objIndexCat.size)
790  for i in range(fgcmMakeStars.objIndexCat.size):
791  fgcmStarIdCat.addNew()
792 
793  # fill the catalog
794  fgcmStarIdCat['fgcm_id'][:] = fgcmMakeStars.objIndexCat['fgcm_id']
795  fgcmStarIdCat['ra'][:] = fgcmMakeStars.objIndexCat['ra']
796  fgcmStarIdCat['dec'][:] = fgcmMakeStars.objIndexCat['dec']
797  fgcmStarIdCat['obsArrIndex'][:] = fgcmMakeStars.objIndexCat['obsarrindex']
798  fgcmStarIdCat['nObs'][:] = fgcmMakeStars.objIndexCat['nobs']
799 
800  obsSchema = self._makeFgcmObsSchema()
801 
802  fgcmStarIndicesCat = afwTable.BaseCatalog(obsSchema)
803  fgcmStarIndicesCat.reserve(fgcmMakeStars.obsIndexCat.size)
804  for i in range(fgcmMakeStars.obsIndexCat.size):
805  fgcmStarIndicesCat.addNew()
806 
807  fgcmStarIndicesCat['obsIndex'][:] = fgcmMakeStars.obsIndexCat['obsindex']
808 
809  if self.config.doReferenceMatches:
810  refSchema = self._makeFgcmRefSchema(len(referenceFilterNames))
811 
812  fgcmRefCat = afwTable.BaseCatalog(refSchema)
813  fgcmRefCat.reserve(fgcmMakeStars.referenceCat.size)
814 
815  for i in range(fgcmMakeStars.referenceCat.size):
816  fgcmRefCat.addNew()
817 
818  fgcmRefCat['fgcm_id'][:] = fgcmMakeStars.referenceCat['fgcm_id']
819  fgcmRefCat['refMag'][:, :] = fgcmMakeStars.referenceCat['refMag']
820  fgcmRefCat['refMagErr'][:, :] = fgcmMakeStars.referenceCat['refMagErr']
821 
822  md = PropertyList()
823  md.set("REFSTARS_FORMAT_VERSION", REFSTARS_FORMAT_VERSION)
824  md.set("FILTERNAMES", referenceFilterNames)
825  fgcmRefCat.setMetadata(md)
826 
827  else:
828  fgcmRefCat = None
829 
830  return fgcmStarIdCat, fgcmStarIndicesCat, fgcmRefCat
831 

◆ runDataRef()

def lsst.fgcmcal.fgcmBuildStarsBase.FgcmBuildStarsBaseTask.runDataRef (   self,
  butler,
  dataRefs 
)
Cross-match and make star list for FGCM Input

Parameters
----------
butler:  `lsst.daf.persistence.Butler`
dataRefs: `list` of `lsst.daf.persistence.ButlerDataRef`
   Source data references for the input visits.

Raises
------
RuntimeErrror: Raised if `config.doReferenceMatches` is set and
   an fgcmLookUpTable is not available, or if computeFluxApertureRadius()
   fails if the calibFlux is not a CircularAperture flux.

Definition at line 295 of file fgcmBuildStarsBase.py.

295  def runDataRef(self, butler, dataRefs):
296  """
297  Cross-match and make star list for FGCM Input
298 
299  Parameters
300  ----------
301  butler: `lsst.daf.persistence.Butler`
302  dataRefs: `list` of `lsst.daf.persistence.ButlerDataRef`
303  Source data references for the input visits.
304 
305  Raises
306  ------
307  RuntimeErrror: Raised if `config.doReferenceMatches` is set and
308  an fgcmLookUpTable is not available, or if computeFluxApertureRadius()
309  fails if the calibFlux is not a CircularAperture flux.
310  """
311  datasetType = dataRefs[0].butlerSubset.datasetType
312  self.log.info("Running with %d %s dataRefs", len(dataRefs), datasetType)
313 
314  if self.config.doReferenceMatches:
315  self.makeSubtask("fgcmLoadReferenceCatalog", butler=butler)
316  # Ensure that we have a LUT
317  if not butler.datasetExists('fgcmLookUpTable'):
318  raise RuntimeError("Must have fgcmLookUpTable if using config.doReferenceMatches")
319  # Compute aperture radius if necessary. This is useful to do now before
320  # any heavy lifting has happened (fail early).
321  calibFluxApertureRadius = None
322  if self.config.doSubtractLocalBackground:
323  try:
324  calibFluxApertureRadius = computeApertureRadiusFromDataRef(dataRefs[0],
325  self.config.instFluxField)
326  except RuntimeError as e:
327  raise RuntimeError("Could not determine aperture radius from %s. "
328  "Cannot use doSubtractLocalBackground." %
329  (self.config.instFluxField)) from e
330 
331  camera = butler.get('camera')
332  groupedDataRefs = self._findAndGroupDataRefsGen2(butler, camera, dataRefs)
333 
334  # Make the visit catalog if necessary
335  # First check if the visit catalog is in the _current_ path
336  # We cannot use Gen2 datasetExists() because that checks all parent
337  # directories as well, which would make recovering from faults
338  # and fgcmcal reruns impossible.
339  visitCatDataRef = butler.dataRef('fgcmVisitCatalog')
340  filename = visitCatDataRef.get('fgcmVisitCatalog_filename')[0]
341  if os.path.exists(filename):
342  # This file exists and we should continue processing
343  inVisitCat = visitCatDataRef.get()
344  if len(inVisitCat) != len(groupedDataRefs):
345  raise RuntimeError("Existing visitCatalog found, but has an inconsistent "
346  "number of visits. Cannot continue.")
347  else:
348  inVisitCat = None
349 
350  visitCat = self.fgcmMakeVisitCatalog(camera, groupedDataRefs,
351  visitCatDataRef=visitCatDataRef,
352  inVisitCat=inVisitCat)
353 
354  # Persist the visitCat as a checkpoint file.
355  visitCatDataRef.put(visitCat)
356 
357  starObsDataRef = butler.dataRef('fgcmStarObservations')
358  filename = starObsDataRef.get('fgcmStarObservations_filename')[0]
359  if os.path.exists(filename):
360  inStarObsCat = starObsDataRef.get()
361  else:
362  inStarObsCat = None
363 
364  rad = calibFluxApertureRadius
365  sourceSchemaDataRef = butler.dataRef('src_schema')
366  sourceSchema = sourceSchemaDataRef.get('src_schema', immediate=True).schema
367  fgcmStarObservationCat = self.fgcmMakeAllStarObservations(groupedDataRefs,
368  visitCat,
369  sourceSchema,
370  camera,
371  calibFluxApertureRadius=rad,
372  starObsDataRef=starObsDataRef,
373  visitCatDataRef=visitCatDataRef,
374  inStarObsCat=inStarObsCat)
375  visitCatDataRef.put(visitCat)
376  starObsDataRef.put(fgcmStarObservationCat)
377 
378  # Always do the matching.
379  if self.config.doReferenceMatches:
380  lutDataRef = butler.dataRef('fgcmLookUpTable')
381  else:
382  lutDataRef = None
383  fgcmStarIdCat, fgcmStarIndicesCat, fgcmRefCat = self.fgcmMatchStars(visitCat,
384  fgcmStarObservationCat,
385  lutDataRef=lutDataRef)
386 
387  # Persist catalogs via the butler
388  butler.put(fgcmStarIdCat, 'fgcmStarIds')
389  butler.put(fgcmStarIndicesCat, 'fgcmStarIndices')
390  if fgcmRefCat is not None:
391  butler.put(fgcmRefCat, 'fgcmReferenceStars')
392 
def computeApertureRadiusFromDataRef(dataRef, fluxField)
Definition: utilities.py:808

The documentation for this class was generated from the following file: