SourceXtractorPlusPlus
1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEImplementation
src
lib
Plugin
ExternalFlag
ExternalFlagConfig.cpp
Go to the documentation of this file.
1
22
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
poh
Euclid::Configuration::ProgramOptionsHelper poh
Definition
AutoPhotometryConfig.cpp:30
ExternalFlagConfig.h
FitsReader.h
std::map::at
T at(T... args)
std::string
std::string::c_str
T c_str(T... args)
Elements::Exception
Euclid::Configuration::Configuration::UserValues
std::map< std::string, boost::program_options::variable_value > UserValues
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::create
static std::shared_ptr< BufferedImage< T > > create(std::shared_ptr< const ImageSource > source, std::shared_ptr< TileManager > tile_manager=TileManager::getInstance())
Definition
BufferedImage.cpp:32
SourceXtractor::ExternalFlagConfig::Type
Type
Definition
ExternalFlagConfig.h:41
SourceXtractor::ExternalFlagConfig::Type::OR
@ OR
Definition
ExternalFlagConfig.h:42
SourceXtractor::ExternalFlagConfig::Type::MAX
@ MAX
Definition
ExternalFlagConfig.h:42
SourceXtractor::ExternalFlagConfig::Type::AND
@ AND
Definition
ExternalFlagConfig.h:42
SourceXtractor::ExternalFlagConfig::Type::MOST
@ MOST
Definition
ExternalFlagConfig.h:42
SourceXtractor::ExternalFlagConfig::Type::MIN
@ MIN
Definition
ExternalFlagConfig.h:42
SourceXtractor::ExternalFlagConfig::FlagInfo
std::pair< std::vector< std::shared_ptr< FlagImage > >, Type > FlagInfo
Definition
ExternalFlagConfig.h:45
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::map::count
T count(T... args)
std::make_shared
T make_shared(T... args)
std::map
std::move
T move(T... args)
SourceXtractor
Definition
Aperture.h:30
boost::filesystem
boost::program_options
std
STL namespace.
std::pair
std::shared_ptr
std::type
std::vector
Generated by
1.15.0