Coverage for python/lsst/analysis/tools/actions/plot/calculateRange.py: 62%
16 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-30 14:25 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-30 14:25 +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/>.
22from __future__ import annotations
24__all__ = ("MinMax", "Med2Mad")
26from typing import cast
28import numpy as np
30from ...interfaces import Vector, VectorAction
31from ...statistics import nansigmaMad
34class MinMax(VectorAction):
35 """Return the maximum and minimum values of an input vector to use as the
36 minimum and maximum values of a colorbar range.
38 Parameters
39 ----------
40 data : `Vector`
41 A vector containing the data whose minimum and maximum are to be
42 returned.
44 Returns
45 -------
46 A two-element vector containing the minimum and maximum values of `data`.
47 """
49 def __call__(self, data: Vector, **kwargs) -> Vector:
50 return cast(Vector, [np.min(data), np.max(data)])
53class Med2Mad(VectorAction):
54 """Return the median +/- 2*nansigmamad values of an input vector to use
55 as the minimum and maximum values of a colorbar range.
57 Parameters
58 ----------
59 data : `Vector`
60 A vector containing the data whose median +/- 2*nansigmamad are to
61 be returned.
63 Returns
64 -------
65 A two-element vector containing the median +/- 2*nansigmamad values of
66 `data`.
67 """
69 def __call__(self, data: Vector, **kwargs) -> Vector:
70 med = np.nanmedian(data)
71 mad = nansigmaMad(data)
72 cmin = med - 2 * mad
73 cmax = med + 2 * mad
74 return cast(Vector, [cmin, cmax])