lsst.ip.isr
g77367d4607+9ad7ce67b7
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Isr.cc
Go to the documentation of this file.
1
// -*- lsst-c++ -*-
2
3
/*
4
* LSST Data Management System
5
* Copyright 2008, 2009, 2010 LSST Corporation.
6
*
7
* This product includes software developed by the
8
* LSST Project (http://www.lsst.org/).
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the LSST License Statement and
21
* the GNU General Public License along with this program. If not,
22
* see <http://www.lsstcorp.org/LegalNotices/>.
23
*/
24
25
#include <cmath>
26
27
#include "
lsst/geom.h
"
28
#include "
lsst/afw/math.h
"
29
#include "
lsst/afw/math/Statistics.h
"
30
#include "
lsst/ip/isr/isr.h
"
31
32
namespace
lsst
{
namespace
ip
{
namespace
isr
{
33
34
template
<
typename
PixelT>
35
size_t
maskNans
(
afw::image::MaskedImage<PixelT>
const
& mi,
afw::image::MaskPixel
maskVal,
36
afw::image::MaskPixel
allow)
37
{
38
typedef
typename
afw::image::MaskedImage<PixelT>::x_iterator
x_iterator;
39
size_t
nPix = 0;
40
for
(
int
y = 0; y != mi.
getHeight
(); ++y) {
41
for
(x_iterator ptr = mi.
row_begin
(y), end = mi.
row_end
(y); ptr != end; ++ptr) {
42
if
(!(ptr.mask() & allow) && (!
std::isfinite
(ptr.image()) ||
43
!
std::isfinite
(ptr.variance()))) {
44
nPix += 1;
45
ptr.mask() |= maskVal;
46
}
47
}
48
}
49
return
nPix;
50
}
51
52
template
<
typename
ImagePixelT>
53
std::vector<double>
fitOverscanImage
(
54
afw::image::MaskedImage<ImagePixelT>
const
&
overscan
,
55
std::vector<std::string>
badPixelMask,
56
bool
isTransposed
57
) {
58
typedef
afw::image::MaskedImage<ImagePixelT>
MaskedImage;
59
64
const
int
height =
overscan
.getHeight();
65
const
int
width =
overscan
.getWidth();
66
67
int
length = height;
68
if
(isTransposed) {
69
length = width;
70
}
71
72
std::vector<double>
values(length);
73
74
afw::math::StatisticsControl
statControl;
75
statControl.
setAndMask
(
overscan
.getMask()->getPlaneBitMask(badPixelMask));
76
77
const
int
x0 =
overscan
.getX0();
78
const
int
y0 =
overscan
.getY0();
79
auto
origin =
geom::Point2I
(x0, y0);
80
geom::Extent2I
shifter;
81
geom::Extent2I
extents;
82
if
(isTransposed) {
83
shifter =
geom::Extent2I
(1, 0);
84
extents =
geom::Extent2I
(1, height);
85
}
else
{
86
shifter =
geom::Extent2I
(0, 1);
87
extents =
geom::Extent2I
(width, 1);
88
}
89
90
for
(
int
x = 0; x < length; ++x) {
91
MaskedImage mi = MaskedImage(
overscan
,
geom::Box2I
(origin, extents));
92
values[x] =
afw::math::makeStatistics
(mi,
afw::math::MEDIAN
, statControl).
getValue
();
93
origin.shift(shifter);
94
}
95
return
values;
96
}
97
98
template
<
typename
ImagePixelT>
99
std::vector<double>
fitOverscanImageMean
(
100
afw::image::MaskedImage<ImagePixelT>
const
&
overscan
,
101
std::vector<std::string>
badPixelMask,
102
bool
isTransposed
103
) {
104
typedef
afw::image::MaskedImage<ImagePixelT>
MaskedImage;
105
110
const
int
height =
overscan
.getHeight();
111
const
int
width =
overscan
.getWidth();
112
113
int
length = height;
114
if
(isTransposed) {
115
length = width;
116
}
117
118
std::vector<double>
values(length);
119
120
afw::math::StatisticsControl
statControl;
121
statControl.
setAndMask
(
overscan
.getMask()->getPlaneBitMask(badPixelMask));
122
123
const
int
x0 =
overscan
.getX0();
124
const
int
y0 =
overscan
.getY0();
125
auto
origin =
geom::Point2I
(x0, y0);
126
geom::Extent2I
shifter;
127
geom::Extent2I
extents;
128
if
(isTransposed) {
129
shifter =
geom::Extent2I
(1, 0);
130
extents =
geom::Extent2I
(1, height);
131
}
else
{
132
shifter =
geom::Extent2I
(0, 1);
133
extents =
geom::Extent2I
(width, 1);
134
}
135
136
for
(
int
x = 0; x < length; ++x) {
137
MaskedImage mi = MaskedImage(
overscan
,
geom::Box2I
(origin, extents));
138
values[x] =
afw::math::makeStatistics
(mi,
afw::math::MEAN
, statControl).
getValue
();
139
origin.shift(shifter);
140
}
141
return
values;
142
}
143
144
std::string
between
(
std::string
&s,
char
ldelim,
char
rdelim) {
145
std::string::iterator b(s.
begin
());
146
std::string::iterator e(s.
end
());
147
std::string::iterator lp;
148
std::string::iterator rp;
149
150
std::string
result
;
151
152
if
((lp =
std::find
(b, e, ldelim)) != e)
153
if
((rp =
std::find
(++lp, e, rdelim)) != e)
154
result
=
std::string
(lp, rp);
155
156
return
result
;
157
}
158
159
// Explicit instantiations
160
161
template
162
std::vector<double>
fitOverscanImage<int>
(
163
afw::image::MaskedImage<int>
const
&,
std::vector<std::string>
badPixelMask,
bool
isTransposed);
164
template
165
std::vector<double>
fitOverscanImage<float>
(
166
afw::image::MaskedImage<float>
const
&,
std::vector<std::string>
badPixelMask,
bool
isTransposed);
167
template
168
std::vector<double>
fitOverscanImage<double>
(
169
afw::image::MaskedImage<double>
const
&,
std::vector<std::string>
badPixelMask,
bool
isTransposed);
170
171
template
172
std::vector<double>
fitOverscanImageMean<int>
(
173
afw::image::MaskedImage<int>
const
&,
std::vector<std::string>
badPixelMask,
bool
isTransposed);
174
template
175
std::vector<double>
fitOverscanImageMean<float>
(
176
afw::image::MaskedImage<float>
const
&,
std::vector<std::string>
badPixelMask,
bool
isTransposed);
177
template
178
std::vector<double>
fitOverscanImageMean<double>
(
179
afw::image::MaskedImage<double>
const
&,
std::vector<std::string>
badPixelMask,
bool
isTransposed);
180
181
template
class
CountMaskedPixels<float>
;
182
template
class
CountMaskedPixels<double>
;
183
template
class
CountMaskedPixels<int>
;
184
185
// Function to mask nans in a masked image
186
template
size_t
maskNans<float>
(
afw::image::MaskedImage<float>
const
&,
afw::image::MaskPixel
,
187
afw::image::MaskPixel
);
188
template
size_t
maskNans<double>
(
afw::image::MaskedImage<double>
const
&,
afw::image::MaskPixel
,
189
afw::image::MaskPixel
);
190
template
size_t
maskNans<int>
(
afw::image::MaskedImage<int>
const
&,
afw::image::MaskPixel
,
191
afw::image::MaskPixel
);
192
193
}}}
// namespace lsst::ip::isr
Statistics.h
std::string
std::string::begin
T begin(T... args)
lsst::afw::image::MaskedImage
lsst::afw::image::MaskedImage::getHeight
int getHeight() const
lsst::afw::image::MaskedImage::x_iterator
MaskedImageIterator< typename Image::x_iterator, typename Mask::x_iterator, typename Variance::x_iterator > x_iterator
lsst::afw::image::MaskedImage::row_end
x_iterator row_end(int y) const
lsst::afw::image::MaskedImage::row_begin
x_iterator row_begin(int y) const
lsst::afw::math::StatisticsControl
lsst::afw::math::StatisticsControl::setAndMask
void setAndMask(int andMask)
lsst::afw::math::Statistics::getValue
double getValue(Property const prop=NOTHING) const
lsst::geom::Box2I
lsst::ip::isr::CountMaskedPixels
Remove all non-astronomical counts from the Chunk Exposure's pixels.
Definition
isr.h:51
std::string::end
T end(T... args)
std::find
T find(T... args)
geom.h
std::isfinite
T isfinite(T... args)
isr.h
math.h
lsst::afw::image::MaskPixel
std::int32_t MaskPixel
lsst::afw::math::makeStatistics
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
lsst::afw::math::MEDIAN
MEDIAN
lsst::afw::math::MEAN
MEAN
lsst::geom::Extent2I
Extent< int, 2 > Extent2I
lsst::geom::Point2I
Point< int, 2 > Point2I
lsst::ip::isr.binImageDataTask.result
result
Definition
binImageDataTask.py:147
lsst::ip::isr.overscan
Definition
overscan.py:1
lsst::ip::isr
Definition
applyLookupTable.h:34
lsst::ip::isr::fitOverscanImageMean
std::vector< double > fitOverscanImageMean(lsst::afw::image::MaskedImage< ImagePixelT > const &overscan, std::vector< std::string > badPixelMask, bool isTransposed)
Definition
Isr.cc:99
lsst::ip::isr::maskNans
size_t maskNans(afw::image::MaskedImage< PixelT > const &mi, afw::image::MaskPixel maskVal, afw::image::MaskPixel allow=0)
Mask NANs in an image.
Definition
Isr.cc:35
lsst::ip::isr::fitOverscanImage
std::vector< double > fitOverscanImage(lsst::afw::image::MaskedImage< ImagePixelT > const &overscan, std::vector< std::string > badPixelMask, bool isTransposed)
Definition
Isr.cc:53
lsst::ip::isr::between
std::string between(std::string &s, char ldelim, char rdelim)
Definition
Isr.cc:144
lsst::ip
Definition
applyLookupTable.h:33
lsst
std::vector
Generated on
for lsst.ip.isr by
1.18.0