Coverage for python/lsst/analysis/tools/actions/plot/calculateRange.py: 60%

15 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-23 13:09 +0000

1# This file is part of analysis_tools. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21 

22from __future__ import annotations 

23 

24__all__ = ("MinMax", "Med2Mad") 

25 

26from typing import cast 

27 

28from ...interfaces import Vector, VectorAction 

29from ...math import nanMax, nanMedian, nanMin, nanSigmaMad 

30 

31 

32class MinMax(VectorAction): 

33 """Return the maximum and minimum values of an input vector to use as the 

34 minimum and maximum values of a colorbar range. 

35 

36 Parameters 

37 ---------- 

38 data : `Vector` 

39 A vector containing the data whose minimum and maximum are to be 

40 returned. 

41 

42 Returns 

43 ------- 

44 A two-element vector containing the minimum and maximum values of `data`. 

45 """ 

46 

47 def __call__(self, data: Vector, **kwargs) -> Vector: 

48 return cast(Vector, [nanMin(data), nanMax(data)]) 

49 

50 

51class Med2Mad(VectorAction): 

52 """Return the median +/- 2*nansigmamad values of an input vector to use 

53 as the minimum and maximum values of a colorbar range. 

54 

55 Parameters 

56 ---------- 

57 data : `Vector` 

58 A vector containing the data whose median +/- 2*nansigmamad are to 

59 be returned. 

60 

61 Returns 

62 ------- 

63 A two-element vector containing the median +/- 2*nansigmamad values of 

64 `data`. 

65 """ 

66 

67 def __call__(self, data: Vector, **kwargs) -> Vector: 

68 med = nanMedian(data) 

69 mad = nanSigmaMad(data) 

70 cmin = med - 2 * mad 

71 cmax = med + 2 * mad 

72 return cast(Vector, [cmin, cmax])