SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEImplementation
src
lib
Plugin
ExternalFlag
ExternalFlagConfig.cpp
Go to the documentation of this file.
1
23
#include <boost/filesystem.hpp>
24
#include <boost/algorithm/string.hpp>
25
26
#include <boost/regex.hpp>
27
using
boost::regex;
28
using
boost::regex_match;
29
using
boost::smatch;
30
31
#include "Configuration/ProgramOptionsHelper.h"
32
33
#include "
SEFramework/FITS/FitsReader.h
"
34
35
#include "
SEImplementation/Plugin/ExternalFlag/ExternalFlagConfig.h
"
36
37
namespace
po = boost::program_options;
38
namespace
fs = boost::filesystem;
39
using
poh
=
Euclid::Configuration::ProgramOptionsHelper
;
40
41
namespace
SourceXtractor
{
42
43
namespace
{
44
45
const
std::string
FLAG_IMAGE {
"flag-image"
};
46
const
std::string
FLAG_TYPE {
"flag-type"
};
47
48
std::map<std::string, ExternalFlagConfig::Type>
available_types {
49
{
"OR"
,
ExternalFlagConfig::Type::OR
},
50
{
"AND"
,
ExternalFlagConfig::Type::AND
},
51
{
"MIN"
,
ExternalFlagConfig::Type::MIN
},
52
{
"MAX"
,
ExternalFlagConfig::Type::MAX
},
53
{
"MOST"
,
ExternalFlagConfig::Type::MOST
}
54
};
55
56
}
57
58
auto
ExternalFlagConfig::getProgramOptions
() ->
std::map<std::string, OptionDescriptionList>
{
59
return
{{
"External flag options"
, {
60
{
poh::wildcard
(
FLAG_IMAGE
).c_str(), po::value<std::string>(),
61
"The FITS file containing the external flag, several images can be provided, replace * by any identifier (ex. use numbers)"
},
62
{
poh::wildcard
(
FLAG_TYPE
).c_str(), po::value<std::string>(),
63
"The combination type of the external flag (OR, AND, MIN, MAX, MOST)"
}
64
}}};
65
}
66
67
68
void
ExternalFlagConfig::preInitialize
(
const
UserValues
&
args
) {
69
for
(
auto
& name :
poh::findWildcardNames
({
FLAG_IMAGE
,
FLAG_TYPE
},
args
)) {
70
71
// Check that the user gave both the filename and the type
72
if
(
args
.count(
poh::wildcard
(
FLAG_IMAGE
, name)) == 0) {
73
throw
Elements::Exception
() <<
"Missing option "
<<
poh::wildcard
(
FLAG_IMAGE
, name);
74
}
75
76
std::string
type;
77
if
(
args
.count(
poh::wildcard
(
FLAG_TYPE
, name)) == 0) {
78
type =
"OR"
;
79
}
else
{
80
type = boost::to_upper_copy(
args
.at(
poh::wildcard
(
FLAG_TYPE
, name)).as<
std::string
>());
81
}
82
83
// Check that the type is a valid option
84
if
(
available_types
.count(type) == 0) {
85
throw
Elements::Exception
() <<
"Invalid option "
<<
poh::wildcard
(
FLAG_TYPE
, name)
86
<<
" : "
<< type;
87
}
88
}
89
}
90
91
void
ExternalFlagConfig::initialize
(
const
UserValues
&
args
) {
92
for
(
auto
& name :
poh::findWildcardNames
({
FLAG_IMAGE
,
FLAG_TYPE
},
args
)) {
93
94
auto
& filename =
args
.at(
poh::wildcard
(
FLAG_IMAGE
, name)).
as<std::string>
();
95
std::vector<std::shared_ptr<FlagImage>
>
flag_images
;
96
boost::regex
hdu_regex
(
".*\\[[0-9]*\\]$"
);
97
98
for
(
int
i
=0;;
i
++) {
99
std::shared_ptr<FitsImageSource>
fits_image_source
;
100
if
(boost::regex_match(filename,
hdu_regex
)) {
101
if
(
i
==0) {
102
fits_image_source
=
std::make_shared<FitsImageSource>
(filename, 0,
ImageTile::LongLongImage
);
103
}
else
{
104
break
;
105
}
106
}
else
{
107
try
{
108
fits_image_source
=
std::make_shared<FitsImageSource>
(filename,
i
+1,
ImageTile::LongLongImage
);
109
}
catch
(...) {
110
if
(
i
==0) {
111
// Skip past primary HDU if it doesn't have an image
112
continue
;
113
}
else
{
114
if
(
flag_images
.size() == 0) {
115
throw
;
116
}
117
break
;
118
}
119
}
120
}
121
122
flag_images
.emplace_back(
BufferedImage<std::int64_t>::create
(
fits_image_source
));
123
}
124
125
std::string
type_str
;
126
if
(
args
.count(
poh::wildcard
(
FLAG_TYPE
, name)) == 0) {
127
type_str
=
"OR"
;
128
}
else
{
129
type_str
= boost::to_upper_copy(
args
.at(
poh::wildcard
(
FLAG_TYPE
, name)).as<
std::string
>());
130
}
131
Type
type =
available_types
.at(
type_str
);
132
133
m_flag_info_list
.emplace_back(name,
FlagInfo
{
std::move
(
flag_images
), type});
134
}
135
}
136
137
auto
ExternalFlagConfig::getFlagInfoList
()
const
->
const
std
::
vector
<
std
::
pair
<
std
::
string
,
FlagInfo
>>& {
138
return
m_flag_info_list
;
139
}
140
141
}
// SourceXtractor namespace
142
143
144
ExternalFlagConfig.h
FitsReader.h
std::string
Elements::Exception
Euclid::Configuration::ProgramOptionsHelper
Euclid::Configuration::ProgramOptionsHelper::wildcard
static std::string wildcard(const std::string &name, const std::string &instance="*")
Euclid::Configuration::ProgramOptionsHelper::findWildcardNames
static std::set< std::string > findWildcardNames(const std::vector< std::string > &option_name_list, const std::map< std::string, boost::program_options::variable_value > &options)
SourceXtractor::BufferedImage
Definition
BufferedImage.h:39
SourceXtractor::ExternalFlagConfig::Type
Type
Definition
ExternalFlagConfig.h:41
SourceXtractor::ExternalFlagConfig::Type::OR
@ OR
SourceXtractor::ExternalFlagConfig::Type::MAX
@ MAX
SourceXtractor::ExternalFlagConfig::Type::AND
@ AND
SourceXtractor::ExternalFlagConfig::Type::MOST
@ MOST
SourceXtractor::ExternalFlagConfig::Type::MIN
@ MIN
SourceXtractor::ExternalFlagConfig::getProgramOptions
std::map< std::string, OptionDescriptionList > getProgramOptions() override
Definition
ExternalFlagConfig.cpp:58
SourceXtractor::ExternalFlagConfig::initialize
void initialize(const UserValues &args) override
Definition
ExternalFlagConfig.cpp:91
SourceXtractor::ExternalFlagConfig::getFlagInfoList
const std::vector< std::pair< std::string, FlagInfo > > & getFlagInfoList() const
Definition
ExternalFlagConfig.cpp:137
SourceXtractor::ExternalFlagConfig::preInitialize
void preInitialize(const UserValues &args) override
Definition
ExternalFlagConfig.cpp:68
SourceXtractor::ExternalFlagConfig::m_flag_info_list
std::vector< std::pair< std::string, FlagInfo > > m_flag_info_list
Definition
ExternalFlagConfig.h:64
SourceXtractor::ImageTile::LongLongImage
@ LongLongImage
Definition
ImageTile.h:43
std::function
std::map
std::move
T move(T... args)
SourceXtractor
Definition
Aperture.h:30
std
STL namespace.
std::pair
std::vector
Generated by
1.10.0