SourceXtractorPlusPlus 0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
CheckImages.cpp
Go to the documentation of this file.
1
17/*
18 * CheckImages.cpp
19 *
20 * Created on: May 30, 2017
21 * Author: mschefer
22 */
23
30
32
33namespace SourceXtractor {
34
35namespace {
36
37std::string addNumberToFilename(boost::filesystem::path original_filename, size_t number, bool add_number) {
38 if (add_number) {
39 auto filename = original_filename.stem();
40 filename += "_" + std::to_string(number);
41 filename += original_filename.extension();
42
43 filename = original_filename.parent_path() / filename;
44
45 return filename.native();
46 } else {
47 return original_filename.native();
48 }
49}
50
51}
52
54
57
59 manager.registerConfiguration<CheckImagesConfig>();
60 manager.registerConfiguration<DetectionImageConfig>();
61 manager.registerConfiguration<MeasurementImageConfig>();
62 manager.registerConfiguration<MeasurementFrameConfig>();
63}
64
66 if (m_custom_images.count(id) != 0) {
68 if (image != nullptr) {
69 return image;
70 }
71 }
72
73 auto image = FitsWriter::newImage<SeFloat>(id + ".fits",
74 width, height);
76
77 return image;
78}
79
83
85 auto& config = manager.getConfiguration<CheckImagesConfig>();
86
88 m_residual_filename = config.getModelFittingResidualFilename();
89 m_background_filename = config.getBackgroundFilename();
90 m_variance_filename = config.getVarianceFilename();
91 m_segmentation_filename = config.getSegmentationFilename();
92 m_partition_filename = config.getPartitionFilename();
93 m_group_filename = config.getGroupFilename();
94 m_filtered_filename = config.getFilteredFilename();
95 m_thresholded_filename = config.getThresholdedFilename();
96 m_snr_filename = config.getSnrFilename();
97 m_auto_aperture_filename = config.getAutoApertureFilename();
98 m_aperture_filename = config.getApertureFilename();
99 m_moffat_filename = config.getMoffatFilename();
100 m_psf_filename = config.getPsfFilename();
101 m_ml_detection_filename = config.getMLDetectionFilename();
102
103 m_measurement_background_filename = config.getMeasurementBackgroundFilename();
104 m_measurement_variance_filename = config.getMeasurementVarianceFilename();
105
106 size_t detection_images_nb = manager.getConfiguration<DetectionImageConfig>().getExtensionsNb();
107
109
110 for (size_t i = 0; i < detection_images_nb; i++) {
111 auto detection_image = manager.getConfiguration<DetectionImageConfig>().getDetectionImage();
112 auto coordinate_system = manager.getConfiguration<DetectionImageConfig>().getCoordinateSystem();
113
116
117 if (m_segmentation_filename != "") {
118 m_segmentation_images.emplace_back(FitsWriter::newImage<int>(
120 detection_image->getWidth(), detection_image->getHeight(), coordinate_system));
121 }
122
123 if (m_partition_filename != "") {
124 m_partition_images.emplace_back(FitsWriter::newImage<int>(
126 detection_image->getWidth(), detection_image->getHeight(), coordinate_system));
127 }
128
129 if (m_group_filename != "") {
130 m_group_images.emplace_back(FitsWriter::newImage<int>(
132 detection_image->getWidth(), detection_image->getHeight(), coordinate_system));
133 }
134
135 if (m_auto_aperture_filename != "") {
136 m_auto_aperture_images.emplace_back(FitsWriter::newImage<int>(
138 detection_image->getWidth(), detection_image->getHeight(), coordinate_system));
139 }
140
141 if (m_aperture_filename != "") {
142 m_aperture_images.emplace_back(FitsWriter::newImage<int>(
144 detection_image->getWidth(), detection_image->getHeight(), coordinate_system));
145 }
146
147 if (m_moffat_filename != "") {
148 m_moffat_images.emplace_back(FitsWriter::newImage<SeFloat>(
150 detection_image->getWidth(), detection_image->getHeight(), coordinate_system));
151 }
152 }
153
154 // Measurement images
155 const auto& measurement_images_info = manager.getConfiguration<MeasurementImageConfig>().getImageInfos();
156 const auto& frames = manager.getConfiguration<MeasurementFrameConfig>().getFrames();
157 for (auto& info : measurement_images_info) {
159 label << boost::filesystem::basename(info.m_path) << "_" << info.m_image_hdu;
160 if (info.m_is_data_cube) {
161 label << "_" << info.m_image_layer;
162 }
163
164 m_measurement_frames[info.m_id] = FrameInfo {
165 label.str(),
166 info.m_measurement_image->getWidth(),
167 info.m_measurement_image->getHeight(),
168 info.m_coordinate_system,
169 frames.at(info.m_id)->getImage(LayerSubtractedImage)
170 };
171 }
172}
173
175 if (m_auto_aperture_filename.empty()) {
176 return nullptr;
177 }
178
180
184 auto filename = m_auto_aperture_filename.stem();
185 filename += "_" + frame_info.m_label;
186 filename += m_auto_aperture_filename.extension();
187 auto frame_filename = m_auto_aperture_filename.parent_path() / filename;
191 FitsWriter::newImage<int>(
192 frame_filename.native(),
193 frame_info.m_width,
194 frame_info.m_height,
195 frame_info.m_coordinate_system
196 ))).first;
197 }
198 return LockedWriteableImage<int>::create(i->second);
199}
200
202 if (m_aperture_filename.empty()) {
203 return nullptr;
204 }
205
207
209 if (i == m_measurement_aperture_images.end()) {
211 auto filename = m_aperture_filename.stem();
212 filename += "_" + frame_info.m_label;
213 filename += m_aperture_filename.extension();
214 auto frame_filename = m_aperture_filename.parent_path() / filename;
218 FitsWriter::newImage<int>(
219 frame_filename.native(),
220 frame_info.m_width,
221 frame_info.m_height,
222 frame_info.m_coordinate_system
223 ))).first;
224 }
225 return LockedWriteableImage<int>::create(i->second);
226}
227
231 return nullptr;
232 }
233
235
237 if (i == m_check_image_model_fitting.end()) {
240
241 if (m_model_fitting_image_filename.empty()) {
242 writeable_image = FitsWriter::newTemporaryImage<DetectionImage::PixelType>(
243 "sourcextractor_check_model_%%%%%%.fits",
244 frame_info.m_width, frame_info.m_height
245 );
246 } else {
247 auto filename = m_model_fitting_image_filename.stem();
248 filename += "_" + frame_info.m_label;
249 filename += m_model_fitting_image_filename.extension();
250 auto frame_filename = m_model_fitting_image_filename.parent_path() / filename;
251 writeable_image = FitsWriter::newImage<MeasurementImage::PixelType>(
252 frame_filename.native(),
253 frame_info.m_width,
254 frame_info.m_height,
255 frame_info.m_coordinate_system
256 );
257 }
259 }
261}
262
264 if (m_psf_filename.empty()) {
265 return nullptr;
266 }
267
269
270 auto i = m_check_image_psf.find(frame_number);
271 if (i == m_check_image_psf.end()) {
273 auto filename = m_psf_filename.stem();
274 filename += "_" + frame_info.m_label;
275 filename += m_psf_filename.extension();
276 auto frame_filename = m_psf_filename.parent_path() / filename;
277 i = m_check_image_psf.emplace(
280 FitsWriter::newImage<MeasurementImage::PixelType>(
281 frame_filename.native(),
282 frame_info.m_width,
283 frame_info.m_height,
284 frame_info.m_coordinate_system
285 ))).first;
286 }
288}
289
291 CheckImages::getMLDetectionImage(unsigned int plane_number, size_t index) {
292
293 if (m_ml_detection_filename.empty()) {
294 return nullptr;
295 }
296
298
299 auto i = m_check_image_ml_detection.at(index).find(plane_number);
300 if (i == m_check_image_ml_detection.at(index).end()) {
301 auto filename = m_ml_detection_filename.stem();
302 filename += "_" + std::to_string(plane_number);
303 filename += m_ml_detection_filename.extension();
304 auto frame_filename = m_ml_detection_filename.parent_path() / filename;
305 i = m_check_image_ml_detection.at(index).emplace(
308 FitsWriter::newImage<MeasurementImage::PixelType>(
309 frame_filename.native(),
310 m_detection_images.at(index)->getWidth(),
311 m_detection_images.at(index)->getHeight(),
312 m_coordinate_systems.at(index)
313 ))).first;
314 }
316}
317
320
322 for (size_t i = 0; i < detection_images_nb; i++) {
323 // if possible, save the background image
324 if (i < m_background_images.size() && m_background_images.at(i) != nullptr && m_background_filename != "") {
327 }
328
329 // if possible, save the variance image
330 if (i < m_variance_images.size() && m_variance_images.at(i) != nullptr && m_variance_filename != "") {
333 }
334
335 // if possible, save the filtered image
336 if (i < m_filtered_images.size() && m_filtered_images.at(i) != nullptr && m_filtered_filename != "") {
339 }
340
341 // if possible, save the thresholded image
345 }
346
347 // if possible, save the SNR image
348 if (i < m_snr_images.size() && m_snr_images.at(i) != nullptr && m_snr_filename != "") {
351 }
352 }
353
354 // if possible, save the measurement background images
356 for (auto &ci : m_measurement_background_images) {
357 auto& frame_info = m_measurement_frames.at(ci.first);
358
359 auto background_image = ci.second;
360 auto filename = m_measurement_background_filename.stem();
361 filename += "_" + frame_info.m_label;
362 filename += m_measurement_background_filename.extension();
363 auto frame_filename = m_measurement_background_filename.parent_path() / filename;
364 FitsWriter::writeFile(*background_image, frame_filename.native(), frame_info.m_coordinate_system);
365 }
366 }
367
368 // if possible, save the measurement variance images
370 for (auto &ci : m_measurement_variance_images) {
371 auto& frame_info = m_measurement_frames.at(ci.first);
372
373 auto variance_image = ci.second;
374 auto filename = m_measurement_variance_filename.stem();
375 filename += "_" + frame_info.m_label;
376 filename += m_measurement_variance_filename.extension();
377 auto frame_filename = m_measurement_variance_filename.parent_path() / filename;
378 FitsWriter::writeFile(*variance_image, frame_filename.native(), frame_info.m_coordinate_system);
379 }
380 }
381
382 // if possible, create and save the residual images
383 if (m_residual_filename != "") {
384 for (auto &ci : m_check_image_model_fitting) {
385 auto& frame_info = m_measurement_frames.at(ci.first);
386
387 auto residual_image = SubtractImage<SeFloat>::create(frame_info.m_subtracted_image, ci.second);
388 auto filename = m_residual_filename.stem();
389 filename += "_" + frame_info.m_label;
390 filename += m_residual_filename.extension();
391 auto frame_filename = m_residual_filename.parent_path() / filename;
392 FitsWriter::writeFile(*residual_image, frame_filename.native(), frame_info.m_coordinate_system);
393 }
394 }
395
396 for (auto const& entry : m_custom_images) {
397 if (std::get<1>(entry.second)) {
398 auto filename = entry.first;
399 if (!filename.has_extension()) {
400 filename += ".fits";
401 }
402 FitsWriter::writeFile(*std::get<0>(entry.second), filename.native());
403 }
404 }
405}
406
407}
T at(T... args)
const std::string & getModelFittingImageFilename() const
boost::filesystem::path m_partition_filename
std::vector< std::shared_ptr< WeightImage > > m_variance_images
std::vector< std::shared_ptr< DetectionImage > > m_detection_images
std::map< unsigned int, std::shared_ptr< WriteableImage< int > > > m_measurement_aperture_images
std::shared_ptr< WriteableImage< int > > getMeasurementAutoApertureImage(unsigned int frame_number)
boost::filesystem::path m_group_filename
std::map< unsigned int, std::shared_ptr< WriteableImage< MeasurementImage::PixelType > > > m_check_image_psf
boost::filesystem::path m_ml_detection_filename
void setCustomCheckImage(std::string id, std::shared_ptr< Image< SeFloat > > image)
boost::filesystem::path m_variance_filename
boost::filesystem::path m_residual_filename
std::map< unsigned int, std::shared_ptr< WriteableImage< int > > > m_measurement_auto_aperture_images
boost::filesystem::path m_filtered_filename
std::shared_ptr< WriteableImage< int > > getMeasurementApertureImage(unsigned int frame_number)
std::map< unsigned int, std::shared_ptr< Image< SeFloat > > > m_measurement_background_images
std::vector< std::shared_ptr< WriteableImage< int > > > m_group_images
std::shared_ptr< WriteableImage< float > > getMLDetectionImage(unsigned int plane_number, size_t index)
static std::unique_ptr< CheckImages > m_instance
void configure(Euclid::Configuration::ConfigManager &manager) override
Method which should initialize the object.
std::shared_ptr< WriteableImage< SeFloat > > getWriteableCheckImage(std::string id, int width, int height)
boost::filesystem::path m_auto_aperture_filename
std::map< unsigned int, std::shared_ptr< WriteableImage< MeasurementImage::PixelType > > > m_check_image_model_fitting
boost::filesystem::path m_moffat_filename
std::vector< std::shared_ptr< Image< SeFloat > > > m_filtered_images
boost::filesystem::path m_snr_filename
std::vector< std::shared_ptr< Image< SeFloat > > > m_thresholded_images
boost::filesystem::path m_measurement_variance_filename
boost::filesystem::path m_psf_filename
std::shared_ptr< WriteableImage< MeasurementImage::PixelType > > getPsfImage(unsigned int frame_number)
std::vector< std::shared_ptr< CoordinateSystem > > m_coordinate_systems
std::vector< std::shared_ptr< WriteableImage< int > > > m_partition_images
std::vector< std::shared_ptr< WriteableImage< int > > > m_aperture_images
boost::filesystem::path m_measurement_background_filename
boost::filesystem::path m_segmentation_filename
void reportConfigDependencies(Euclid::Configuration::ConfigManager &manager) const override
Registers all the Configuration dependencies.
std::vector< std::shared_ptr< WriteableImage< int > > > m_segmentation_images
std::vector< std::map< unsigned int, std::shared_ptr< WriteableImage< float > > > > m_check_image_ml_detection
boost::filesystem::path m_thresholded_filename
boost::filesystem::path m_aperture_filename
std::vector< std::shared_ptr< Image< SeFloat > > > m_snr_images
std::vector< std::shared_ptr< WriteableImage< int > > > m_auto_aperture_images
std::shared_ptr< WriteableImage< MeasurementImage::PixelType > > getModelFittingImage(unsigned int frame_number)
boost::filesystem::path m_background_filename
std::map< unsigned int, std::shared_ptr< WeightImage > > m_measurement_variance_images
std::vector< std::shared_ptr< WriteableImage< SeFloat > > > m_moffat_images
boost::filesystem::path m_model_fitting_image_filename
std::map< int, FrameInfo > m_measurement_frames
std::vector< std::shared_ptr< Image< SeFloat > > > m_background_images
std::map< boost::filesystem::path, std::tuple< std::shared_ptr< Image< SeFloat > >, bool > > m_custom_images
static void writeFile(const Image< T > &image, const std::string &filename, const std::shared_ptr< CoordinateSystem > coord_system=nullptr, bool append=false)
Definition FitsWriter.h:54
static std::shared_ptr< LockedWriteableImage< T > > create(Args &&... args)
T lock(T... args)
T make_pair(T... args)
T make_tuple(T... args)
@ LayerSubtractedImage
Definition Frame.h:39
str filename
Definition conf.py:65
T size(T... args)
T to_string(T... args)