-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-21166: Create DiaCalculation plugins that replicate current ap_association behavior #56
Changes from 1 commit
e8d4cb7
eb2e05e
9ceb70b
9978e8a
7305a0c
8ca252e
ab1ca86
ae418da
4148b2c
8d2d6b7
12a62c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,16 @@ | |
import numpy as np | ||
|
||
import lsst.geom as geom | ||
import lsst.pex.config as pexConfig | ||
|
||
from .diaCalculation import ( | ||
DiaObjectCalculationPluginConfig, | ||
DiaObjectCalculationPlugin) | ||
from lsst.meas.base.pluginRegistry import register | ||
|
||
__all__ = ("MeanDiaPositionConfig", "MeanDiaPosition", | ||
"WeightedMeanDiaPsFluxConfig", "WeightedMeanDiaPsFlux") | ||
"WeightedMeanDiaPsFluxConfig", "WeightedMeanDiaPsFlux", | ||
"PercentileDiaPsFlux", "PercentileDiaPsFluxConfig") | ||
|
||
|
||
class MeanDiaPositionConfig(DiaObjectCalculationPluginConfig): | ||
|
@@ -92,10 +94,12 @@ class WeightedMeanDiaPsFluxConfig(DiaObjectCalculationPluginConfig): | |
class WeightedMeanDiaPsFlux(DiaObjectCalculationPlugin): | ||
"""Compute the weighted mean and mean error on the point source fluxes | ||
of the DiaSource measured on the difference image. | ||
|
||
Additionally store number of usable data points. | ||
""" | ||
|
||
ConfigClass = WeightedMeanDiaPsFluxConfig | ||
outputCols = ["PSFluxMean", "PSFluxMeanErr"] | ||
outputCols = ["PSFluxMean", "PSFluxMeanErr", "PSFFluxNdata"] | ||
|
||
@classmethod | ||
def getExecutionOrder(cls): | ||
|
@@ -128,13 +132,90 @@ def calculate(self, | |
filterDiaFluxes["psFluxErr"] ** 2) | ||
fluxMean /= tot_weight | ||
fluxMeanErr = np.sqrt(1 / tot_weight) | ||
nFluxData = np.sum(np.isfinite(filterDiaFluxes["psFlux"])) | ||
else: | ||
fluxMean = np.nan | ||
fluxMeanErr = np.nan | ||
|
||
nFluxData = 0 | ||
if np.isfinite(fluxMean) and np.isfinite(fluxMeanErr): | ||
diaObject["%sPSFluxMean" % filterName] = fluxMean | ||
diaObject["%sPSFluxMeanErr" % filterName] = fluxMeanErr | ||
diaObject["{}PSFluxMean".format(filterName)] = fluxMean | ||
diaObject["{}PSFluxMeanErr".format(filterName)] = fluxMeanErr | ||
diaObject["{}PSFluxNdata".format(filterName)] = nFluxData | ||
else: | ||
self.fail(diaObject, filterName) | ||
|
||
def fail(self, diaObject, filterName, error=None): | ||
"""Set diaObject position values to nan. | ||
|
||
Parameters | ||
---------- | ||
diaObject : `dict` | ||
Summary object to store values in. | ||
filterName : `str` | ||
Simple name of the filter for the flux being calculated. | ||
error : `BaseException` | ||
Error to pass. | ||
""" | ||
diaObject["{}PSFluxMean".format(filterName)] = np.nan | ||
diaObject["{}PSFluxMeanErr".format(filterName)] = np.nan | ||
diaObject["{}PSFluxNdata".format(filterName)] = 0 | ||
|
||
|
||
class PercentileDiaPsFluxConfig(DiaObjectCalculationPluginConfig): | ||
|
||
percentiles = pexConfig.ListField( | ||
dtype=int, | ||
default=[5, 25, 50, 75, 95], | ||
doc="Percentiles to calculate to compute values for. Should be " | ||
"integer values." | ||
) | ||
|
||
|
||
@register("ap_percentileFlux") | ||
class PercentileDiaPsFlux(DiaObjectCalculationPlugin): | ||
""" | ||
""" | ||
|
||
ConfigClass = PercentileDiaPsFluxConfig | ||
outputCols = [] | ||
|
||
def __init__(self, config, name, metadata): | ||
DiaObjectCalculationPlugin.__init__(self, config, name) | ||
self.outputCols = ["PSFluxPercentile{:02d}".format(percent) | ||
for percent in self.config.percentiles] | ||
|
||
@classmethod | ||
def getExecutionOrder(cls): | ||
return cls.DEFAULT_CATALOGCALCULATION | ||
|
||
def calculate(self, | ||
diaObject, | ||
diaSources, | ||
filterDiaFluxes, | ||
filterName, | ||
**kwargs): | ||
"""Compute the weighted mean and mean error of the point source flux. | ||
|
||
Parameters | ||
---------- | ||
diaObject : `dict` | ||
Summary object to store values in. | ||
diaSources : `pandas.DataFrame` | ||
DataFrame representing all diaSources associated with this | ||
diaObject. | ||
filterDiaFluxes : `pandas.DataFrame` | ||
DataFrame representing diaSources associated with this | ||
diaObject that are observed in the band pass ``filterName``. | ||
filterName : `str` | ||
Simple, string name of the filter for the fluxb eing calculated. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo |
||
""" | ||
if len(filterDiaFluxes) > 0: | ||
pTiles = np.nanpercentile(filterDiaFluxes["psFlux"], | ||
self.config.percentiles) | ||
for pTile, tilePercent in zip(pTiles, self.config.precentiles): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. precentile or percentile? |
||
diaObject[ | ||
"{}PSFluxPercentile{:02d}".format(filterName, | ||
tilePercent)] = pTile | ||
else: | ||
self.fail(diaObject, filterName) | ||
|
||
|
@@ -150,5 +231,6 @@ def fail(self, diaObject, filterName, error=None): | |
error : `BaseException` | ||
Error to pass. | ||
""" | ||
diaObject["%sPSFluxMean" % filterName] = np.nan | ||
diaObject["%sPSFluxMeanErr" % filterName] = np.nan | ||
for pTile in self.config.precentiles: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. precentile |
||
diaObject["{}PSFluxPercentile{:02d}".format(filterName, | ||
pTile)] = np.nan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a doc string missing here?