392 def fgcmMatchStars(self, visitCat, obsCat, lutHandle=None):
393 """
394 Use FGCM code to match observations into unique stars.
395
396 Parameters
397 ----------
398 visitCat: `afw.table.BaseCatalog`
399 Catalog with visit data for fgcm
400 obsCat: `afw.table.BaseCatalog`
401 Full catalog of star observations for fgcm
402 lutHandle: `lsst.daf.butler.DeferredDatasetHandle`, optional
403 Data reference to fgcm look-up table (used if matching reference stars).
404
405 Returns
406 -------
407 fgcmStarIdCat: `afw.table.BaseCatalog`
408 Catalog of unique star identifiers and index keys
409 fgcmStarIndicesCat: `afwTable.BaseCatalog`
410 Catalog of unique star indices
411 fgcmRefCat: `afw.table.BaseCatalog`
412 Catalog of matched reference stars.
413 Will be None if `config.doReferenceMatches` is False.
414 """
415
416
417 visitFilterNames = np.zeros(len(visitCat), dtype='a30')
418 for i in range(len(visitCat)):
419 visitFilterNames[i] = visitCat[i]['physicalFilter']
420
421
422 visitIndex = np.searchsorted(visitCat['visit'],
423 obsCat['visit'])
424
425 obsFilterNames = visitFilterNames[visitIndex]
426
427 if self.config.doReferenceMatches:
428
429 lutCat = lutHandle.get()
430
431 stdFilterDict = {filterName: stdFilter for (filterName, stdFilter) in
432 zip(lutCat[0]['physicalFilters'].split(','),
433 lutCat[0]['stdPhysicalFilters'].split(','))}
434 stdLambdaDict = {stdFilter: stdLambda for (stdFilter, stdLambda) in
435 zip(lutCat[0]['stdPhysicalFilters'].split(','),
436 lutCat[0]['lambdaStdFilter'])}
437
438 del lutCat
439
440 referenceFilterNames = self._getReferenceFilterNames(visitCat,
441 stdFilterDict,
442 stdLambdaDict)
443 self.log.info("Using the following reference filters: %s" %
444 (', '.join(referenceFilterNames)))
445
446 else:
447
448 referenceFilterNames = []
449
450
451 starConfig = {'logger': self.log,
452 'useHtm': True,
453 'filterToBand': self.config.physicalFilterMap,
454 'requiredBands': self.config.requiredBands,
455 'minPerBand': self.config.minPerBand,
456 'matchRadius': self.config.matchRadius,
457 'isolationRadius': self.config.isolationRadius,
458 'matchNSide': self.config.matchNside,
459 'coarseNSide': self.config.coarseNside,
460 'densNSide': self.config.densityCutNside,
461 'densMaxPerPixel': self.config.densityCutMaxPerPixel,
462 'randomSeed': self.config.randomSeed,
463 'primaryBands': self.config.primaryBands,
464 'referenceFilterNames': referenceFilterNames}
465
466
467 fgcmMakeStars = fgcm.FgcmMakeStars(starConfig)
468
469
470
471
472
473
474
475 conv = obsCat[0]['ra'].asDegrees() / float(obsCat[0]['ra'])
476 fgcmMakeStars.makePrimaryStars(obsCat['ra'] * conv,
477 obsCat['dec'] * conv,
478 filterNameArray=obsFilterNames,
479 bandSelected=False)
480
481
482 fgcmMakeStars.makeMatchedStars(obsCat['ra'] * conv,
483 obsCat['dec'] * conv,
484 obsFilterNames)
485
486 if self.config.doReferenceMatches:
487 fgcmMakeStars.makeReferenceMatches(self.fgcmLoadReferenceCatalog)
488
489
490
491 objSchema = self._makeFgcmObjSchema()
492
493
495 fgcmStarIdCat.reserve(fgcmMakeStars.objIndexCat.size)
496 for i in range(fgcmMakeStars.objIndexCat.size):
497 fgcmStarIdCat.addNew()
498
499
500 fgcmStarIdCat['fgcm_id'][:] = fgcmMakeStars.objIndexCat['fgcm_id']
501 fgcmStarIdCat['ra'][:] = fgcmMakeStars.objIndexCat['ra']
502 fgcmStarIdCat['dec'][:] = fgcmMakeStars.objIndexCat['dec']
503 fgcmStarIdCat['obsArrIndex'][:] = fgcmMakeStars.objIndexCat['obsarrindex']
504 fgcmStarIdCat['nObs'][:] = fgcmMakeStars.objIndexCat['nobs']
505
506 obsSchema = self._makeFgcmObsSchema()
507
509 fgcmStarIndicesCat.reserve(fgcmMakeStars.obsIndexCat.size)
510 for i in range(fgcmMakeStars.obsIndexCat.size):
511 fgcmStarIndicesCat.addNew()
512
513 fgcmStarIndicesCat['obsIndex'][:] = fgcmMakeStars.obsIndexCat['obsindex']
514
515 if self.config.doReferenceMatches:
516 refSchema = self._makeFgcmRefSchema(len(referenceFilterNames))
517
519 fgcmRefCat.reserve(fgcmMakeStars.referenceCat.size)
520
521 for i in range(fgcmMakeStars.referenceCat.size):
522 fgcmRefCat.addNew()
523
524 fgcmRefCat['fgcm_id'][:] = fgcmMakeStars.referenceCat['fgcm_id']
525 fgcmRefCat['refMag'][:, :] = fgcmMakeStars.referenceCat['refMag']
526 fgcmRefCat['refMagErr'][:, :] = fgcmMakeStars.referenceCat['refMagErr']
527
528 md = PropertyList()
529 md.set("REFSTARS_FORMAT_VERSION", REFSTARS_FORMAT_VERSION)
530 md.set("FILTERNAMES", referenceFilterNames)
531 fgcmRefCat.setMetadata(md)
532
533 else:
534 fgcmRefCat = None
535
536 return fgcmStarIdCat, fgcmStarIndicesCat, fgcmRefCat
537