Coverage for python/lsst/sims/maf/metrics/coverageMetric.py : 30%

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 .baseMetric import BaseMetric
4__all__ = ['YearCoverageMetric']
7class YearCoverageMetric(BaseMetric):
8 """Count the number of bins covered by nightCol -- default bins are 'years'.
9 Handy for checking that a point on the sky gets observed every year, as the default settings
10 result in the metric returning the number years in the dataslice (when used with a HealpixSlicer).
12 Parameters
13 ----------
14 nightCol: str, opt
15 Data column to histogram. Default 'night'.
16 bins: numpy.ndarray, opt
17 Bins to use in the histogram. Default corresponds to years 0-10 (with 365.25 nights per year).
18 units: str, opt
19 Units to use for the metric result. Default 'N years'.
21 Returns
22 -------
23 integer
24 Number of histogram bins where the histogram value is greater than 0.
25 Typically this will be the number of years in the 'nightCol'.
26 """
28 def __init__(self, nightCol='night', bins=None, units=None, **kwargs):
29 self.nightCol = nightCol
30 if bins is None:
31 self.bins = np.arange(0, np.ceil(365.25*10.), 365.25) - 0.5
32 else:
33 self.bins = bins
35 if units is None:
36 units = 'N years'
38 super().__init__([nightCol], units=units)
40 def run(self, dataSlice, slicePoint):
41 hist, be = np.histogram(dataSlice[self.nightCol], bins=self.bins)
42 result = np.where(hist > 0)[0].size
43 return result