287 **kwargs):
288 """Compute the weighted mean and mean error of the point source flux.
289
290 Parameters
291 ----------
292 diaObject : `dict`
293 Summary object to store values in.
294 diaSources : `pandas.DataFrame`
295 DataFrame representing all diaSources associated with this
296 diaObject.
297 filterDiaSources : `pandas.DataFrame`
298 DataFrame representing diaSources associated with this
299 diaObject that are observed in the band pass ``band``.
300 band : `str`
301 Simple, string name of the filter for the flux being calculated.
302 **kwargs
303 Any additional keyword arguments that may be passed to the plugin.
304 """
305 meanName = "{}_psfFluxMean".format(band)
306 errName = "{}_psfFluxMeanErr".format(band)
307 nDataName = "{}_psfFluxNdata".format(band)
308 if meanName not in diaObjects.columns:
309 diaObjects[meanName] = np.nan
310 if errName not in diaObjects.columns:
311 diaObjects[errName] = np.nan
312 if nDataName not in diaObjects.columns:
313 diaObjects[nDataName] = 0
314
315 def _weightedMean(df):
316 tmpDf = df[~np.logical_or(np.isnan(df["psfFlux"]),
317 np.isnan(df["psfFluxErr"]))]
318 tot_weight = np.nansum(1 / tmpDf["psfFluxErr"] ** 2)
319 fluxMean = np.nansum(tmpDf["psfFlux"]
320 / tmpDf["psfFluxErr"] ** 2)
321 fluxMean /= tot_weight
322 if tot_weight > 0:
323 fluxMeanErr = np.sqrt(1 / tot_weight)
324 else:
325 fluxMeanErr = np.nan
326 nFluxData = len(tmpDf)
327
328 return pd.Series({meanName: fluxMean,
329 errName: fluxMeanErr,
330 nDataName: nFluxData},
331 dtype="object")
332
333 diaObjects.loc[:, [meanName, errName, nDataName]] = \
334 filterDiaSources.apply(_weightedMean)
335
336