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 .baseMetric import BaseMetric 

3import healpy as hp 

4 

5__all__ = ['AreaSummaryMetric'] 

6 

7 

8class AreaSummaryMetric(BaseMetric): 

9 """ 

10 Find the min/max of a value in the best area. This is a handy substitute for when 

11 users want to know "the WFD value". 

12 

13 Parameters 

14 ---------- 

15 area : float (18000) 

16 The area to consider (sq degrees) 

17 decreasing : bool (True) 

18 Should the values be sorted by increasing or decreasing order. For values where 

19 "larger is better", decreasing is probably what you want. For metrics where 

20 "smaller is better" (e.g., astrometric precission), set decreasing to False. 

21 reduce_func : None 

22 The function to reduce the clipped values by. Will default to min/max depending on 

23 the bool val of the decreasing kwarg. 

24 

25 """ 

26 def __init__(self, col='metricdata', metricName='AreaSummary', area=18000., decreasing=True, 

27 reduce_func=None, **kwargs): 

28 super().__init__(col=col, metricName=metricName, **kwargs) 

29 self.area = area 

30 self.decreasing = decreasing 

31 self.reduce_func = reduce_func 

32 self.maskVal = np.nan # Include so all values get passed 

33 self.col = col 

34 if reduce_func is None: 

35 if decreasing: 

36 self.reduce_func = np.min 

37 else: 

38 self.reduce_func = np.max 

39 else: 

40 self.reduce_func = reduce_func 

41 

42 def run(self, dataSlice, slicePoint=None): 

43 # find out what nside we have 

44 nside = hp.npix2nside(dataSlice.size) 

45 pix_area = hp.nside2pixarea(nside, degrees=True) 

46 n_pix_needed = int(np.ceil(self.area/pix_area)) 

47 

48 # Only use the finite data 

49 data = dataSlice[self.col][np.isfinite(dataSlice[self.col])] 

50 order = np.argsort(data) 

51 if self.decreasing: 

52 order = order[::-1] 

53 result = self.reduce_func(data[order][0:n_pix_needed]) 

54 return result