Coverage for python/lsst/faro/measurement/GeneralMeasurementTasks.py : 39%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import numpy as np
2from lsst.pipe.base import Struct, Task
3from lsst.pex.config import Config
4from lsst.verify import Measurement
6__all__ = ("HistMedianTask",)
9class HistMedianTask(Task):
11 ConfigClass = Config
12 _DefaultName = "histMedianTask"
14 def run(self, measurements, agg_name, package, metric):
15 self.log.info("Computing the %s of %s_%s values", agg_name, package, metric)
16 values = measurements[0].extras["values"].quantity
17 bins = measurements[0].extras["bins"].quantity
18 for m in measurements[1:]:
19 values += m.extras["values"].quantity
20 c = np.cumsum(values)
21 idx = np.searchsorted(c, c[-1] / 2.0)
22 # This is the bin lower bound
23 lower = bins[idx]
24 # This is the bin upper bound
25 upper = bins[idx + 1]
27 # Linear interpolation of median value within the bin
28 frac = (c[-1] / 2.0 - c[idx - 1]) / (c[idx] - c[idx - 1])
29 interp = lower + (upper - lower) * frac
31 return Struct(
32 measurement=Measurement(
33 f"metricvalue_{agg_name}_{package}_{metric}", interp
34 )
35 )