Hide keyboard shortcuts

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 

5 

6__all__ = ("HistMedianTask", ) 

7 

8 

9class HistMedianTask(Task): 

10 

11 ConfigClass = Config 

12 _DefaultName = "histMedianTask" 

13 

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.) 

22 # This is the bin lower bound 

23 lower = bins[idx] 

24 # This is the bin upper bound 

25 upper = bins[idx+1] 

26 

27 # Linear interpolation of median value within the bin 

28 frac = (c[-1]/2. - c[idx-1])/(c[idx] - c[idx-1]) 

29 interp = lower + (upper - lower)*frac 

30 

31 return Struct(measurement=Measurement(f"metricvalue_{agg_name}_{package}_{metric}", interp))