Skip to content

Commit a90d4b7

Browse files
authored
Merge pull request #68 from ebertin/feature/mf_checkimages_wcs
Generate check images for the model fitting via CheckImage classes
2 parents 7861177 + 2109b75 commit a90d4b7

File tree

12 files changed

+138
-106
lines changed

12 files changed

+138
-106
lines changed

SEFramework/SEFramework/Frame/Frame.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ class Frame {
151151
return sqrt(m_variance_map->getValue(0,0)) * m_detection_threshold;
152152
}
153153

154+
std::string getLabel() const {
155+
return m_label;
156+
}
157+
154158
//
155159
// Setters
156160
//
@@ -197,6 +201,10 @@ class Frame {
197201
m_filtered_variance_map = nullptr;
198202
}
199203

204+
void setLabel(const std::string &label) {
205+
m_label = label;
206+
}
207+
200208
private:
201209

202210
void applyFilter() {
@@ -227,6 +235,8 @@ class Frame {
227235
std::shared_ptr<Image<T>> m_interpolated_image;
228236
std::shared_ptr<Image<T>> m_filtered_image;
229237
std::shared_ptr<Image<T>> m_filtered_variance_map;
238+
239+
std::string m_label;
230240
};
231241

232242
using DetectionImageFrame = Frame<DetectionImage::PixelType>;

SEImplementation/SEImplementation/CheckImages/CheckImages.h

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
#include <map>
1313
#include <iostream>
1414

15+
#include <boost/filesystem/path.hpp>
16+
1517
#include "SEFramework/Configuration/Configurable.h"
1618
#include "SEFramework/CoordinateSystem/CoordinateSystem.h"
1719
#include "SEFramework/Image/Image.h"
1820
#include "SEFramework/Image/VectorImage.h"
1921
#include "SEFramework/Image/SubtractImage.h"
2022
#include "SEFramework/Image/WriteableImage.h"
23+
#include "SEFramework/Frame/Frame.h"
2124

2225

2326
namespace SExtractor {
@@ -30,10 +33,6 @@ class CheckImages : public Configurable {
3033

3134
void saveImages();
3235

33-
std::shared_ptr<WriteableImage<DetectionImage::PixelType>> getModelFittingCheckImage() const {
34-
return m_check_image_model_fitting;
35-
}
36-
3736
std::shared_ptr<WriteableImage<unsigned int>> getSegmentationImage() const {
3837
return m_segmentation_image;
3938
}
@@ -59,10 +58,13 @@ class CheckImages : public Configurable {
5958
}
6059

6160
std::shared_ptr<WriteableImage<unsigned int>>
62-
getAutoApertureImage(unsigned instance, int width, int height, const std::shared_ptr<CoordinateSystem> &);
61+
getAutoApertureImage(std::shared_ptr<const MeasurementImageFrame> frame);
6362

6463
std::shared_ptr<WriteableImage<unsigned int>>
65-
getApertureImage(unsigned instance, int width, int height, const std::shared_ptr<CoordinateSystem> &);
64+
getApertureImage(std::shared_ptr<const MeasurementImageFrame> frame);
65+
66+
std::shared_ptr<WriteableImage<MeasurementImage::PixelType>>
67+
getModelFittingImage(std::shared_ptr<const MeasurementImageFrame> frame);
6668

6769
void setBackgroundCheckImage(std::shared_ptr<Image<SeFloat>> background_image) {
6870
m_background_image = background_image;
@@ -80,8 +82,8 @@ class CheckImages : public Configurable {
8082
m_thresholded_image = thresholded_image;
8183
}
8284

83-
std::shared_ptr<WriteableImage<SeFloat>> getWriteableCheckImage(std::string id, int width, int height);
84-
void setCustomCheckImage(std::string id, std::shared_ptr<Image<SeFloat>> image);
85+
//std::shared_ptr<WriteableImage<SeFloat>> getWriteableCheckImage(std::string id, int width, int height);
86+
//void setCustomCheckImage(std::string id, std::shared_ptr<Image<SeFloat>> image);
8587

8688
virtual void reportConfigDependencies(Euclid::Configuration::ConfigManager& manager) const override;
8789
virtual void configure(Euclid::Configuration::ConfigManager& manager) override;
@@ -108,15 +110,15 @@ class CheckImages : public Configurable {
108110
static std::unique_ptr<CheckImages> m_instance;
109111

110112
// check image
111-
std::shared_ptr<WriteableImage<DetectionImage::PixelType>> m_check_image_model_fitting;
112113
std::shared_ptr<WriteableImage<unsigned int>> m_segmentation_image;
113114
std::shared_ptr<WriteableImage<unsigned int>> m_partition_image;
114115
std::shared_ptr<WriteableImage<unsigned int>> m_group_image;
115116
std::shared_ptr<WriteableImage<unsigned int>> m_auto_aperture_image;
116117
std::shared_ptr<WriteableImage<unsigned int>> m_aperture_image;
117118
std::shared_ptr<WriteableImage<SeFloat>> m_moffat_image;
118-
std::map<int, decltype(m_aperture_image)> m_measurement_aperture_images;
119-
std::map<int, decltype(m_auto_aperture_image)> m_measurement_auto_aperture_images;
119+
std::map<std::shared_ptr<const MeasurementImageFrame>, decltype(m_aperture_image)> m_measurement_aperture_images;
120+
std::map<std::shared_ptr<const MeasurementImageFrame>, decltype(m_auto_aperture_image)> m_measurement_auto_aperture_images;
121+
std::map<std::shared_ptr<const MeasurementImageFrame>, std::shared_ptr<WriteableImage<MeasurementImage::PixelType>>> m_check_image_model_fitting;
120122

121123
std::shared_ptr<DetectionImage> m_detection_image;
122124
std::shared_ptr<Image<SeFloat>> m_background_image;
@@ -125,20 +127,20 @@ class CheckImages : public Configurable {
125127
std::shared_ptr<WeightImage> m_variance_image;
126128
std::shared_ptr<CoordinateSystem> m_coordinate_system;
127129

128-
std::string m_model_fitting_image_filename;
129-
std::string m_residual_filename;
130-
std::string m_model_background_filename;
131-
std::string m_model_variance_filename;
132-
std::string m_segmentation_filename;
133-
std::string m_partition_filename;
134-
std::string m_group_filename;
135-
std::string m_filtered_filename;
136-
std::string m_thresholded_filename;
137-
std::string m_auto_aperture_filename;
138-
std::string m_aperture_filename;
139-
std::string m_moffat_filename;
140-
141-
std::map<std::string, std::tuple<std::shared_ptr<Image<SeFloat>>, bool>> m_custom_images;
130+
boost::filesystem::path m_model_fitting_image_filename;
131+
boost::filesystem::path m_residual_filename;
132+
boost::filesystem::path m_model_background_filename;
133+
boost::filesystem::path m_model_variance_filename;
134+
boost::filesystem::path m_segmentation_filename;
135+
boost::filesystem::path m_partition_filename;
136+
boost::filesystem::path m_group_filename;
137+
boost::filesystem::path m_filtered_filename;
138+
boost::filesystem::path m_thresholded_filename;
139+
boost::filesystem::path m_auto_aperture_filename;
140+
boost::filesystem::path m_aperture_filename;
141+
boost::filesystem::path m_moffat_filename;
142+
143+
std::map<boost::filesystem::path, std::tuple<std::shared_ptr<Image<SeFloat>>, bool>> m_custom_images;
142144

143145
std::mutex m_access_mutex;
144146
};

SEImplementation/SEImplementation/Configuration/DetectionImageConfig.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class DetectionImageConfig : public Euclid::Configuration::Configuration {
3232
std::map<std::string, Configuration::OptionDescriptionList> getProgramOptions() override;
3333

3434
void initialize(const UserValues& args) override;
35-
35+
36+
std::string getDetectionImagePath() const;
3637
std::shared_ptr<DetectionImage> getDetectionImage() const;
3738
std::shared_ptr<CoordinateSystem> getCoordinateSystem() const;
3839

@@ -41,6 +42,7 @@ class DetectionImageConfig : public Euclid::Configuration::Configuration {
4142
int getInterpolationGap() const { return m_interpolation_gap; }
4243

4344
private:
45+
std::string m_detection_image_path;
4446
std::shared_ptr<DetectionImage> m_detection_image;
4547
std::shared_ptr<CoordinateSystem> m_coordinate_system;
4648
double m_gain;

SEImplementation/SEImplementation/Plugin/FlexibleModelFitting/FlexibleModelFittingTask.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ class FlexibleModelFittingTask : public GroupTask {
6363
std::vector<std::shared_ptr<FlexibleModelFittingParameter>> m_parameters;
6464
std::vector<std::shared_ptr<FlexibleModelFittingFrame>> m_frames;
6565
std::vector<std::shared_ptr<FlexibleModelFittingPrior>> m_priors;
66-
67-
std::string m_checkimage_prefix;
6866
};
6967

7068
}

SEImplementation/src/lib/CheckImages/CheckImages.cpp

Lines changed: 74 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void CheckImages::reportConfigDependencies(Euclid::Configuration::ConfigManager
2323
manager.registerConfiguration<CheckImagesConfig>();
2424
}
2525

26-
std::shared_ptr<WriteableImage<SeFloat>> CheckImages::getWriteableCheckImage(std::string id, int width, int height) {
26+
/*std::shared_ptr<WriteableImage<SeFloat>> CheckImages::getWriteableCheckImage(std::string id, int width, int height) {
2727
if (m_custom_images.count(id) != 0) {
2828
auto image = std::dynamic_pointer_cast<WriteableImage<SeFloat>>(std::get<0>(m_custom_images[id]));
2929
if (image != nullptr) {
@@ -41,7 +41,7 @@ std::shared_ptr<WriteableImage<SeFloat>> CheckImages::getWriteableCheckImage(std
4141
4242
void CheckImages::setCustomCheckImage(std::string id, std::shared_ptr<Image<SeFloat>> image) {
4343
m_custom_images[id] = std::make_tuple(image, true);
44-
}
44+
}*/
4545

4646
void CheckImages::configure(Euclid::Configuration::ConfigManager& manager) {
4747
m_detection_image = manager.getConfiguration<DetectionImageConfig>().getDetectionImage();
@@ -62,91 +62,115 @@ void CheckImages::configure(Euclid::Configuration::ConfigManager& manager) {
6262

6363
m_coordinate_system = manager.getConfiguration<DetectionImageConfig>().getCoordinateSystem();
6464

65-
if (m_model_fitting_image_filename != "") {
66-
m_check_image_model_fitting = FitsWriter::newImage<DetectionImage::PixelType>(m_model_fitting_image_filename,
67-
m_detection_image->getWidth(), m_detection_image->getHeight(), m_coordinate_system);
68-
}
69-
else if (m_residual_filename != "") {
70-
m_check_image_model_fitting = FitsWriter::newTemporaryImage<DetectionImage::PixelType>(
71-
"sextractor_check_model_%%%%%%.fits", m_detection_image->getWidth(), m_detection_image->getHeight());
72-
}
73-
7465
if (m_segmentation_filename != "") {
75-
m_segmentation_image = FitsWriter::newImage<unsigned int>(m_segmentation_filename,
66+
m_segmentation_image = FitsWriter::newImage<unsigned int>(m_segmentation_filename.native(),
7667
m_detection_image->getWidth(), m_detection_image->getHeight(), m_coordinate_system);
7768
}
7869

7970
if (m_partition_filename != "") {
80-
m_partition_image = FitsWriter::newImage<unsigned int>(m_partition_filename,
71+
m_partition_image = FitsWriter::newImage<unsigned int>(m_partition_filename.native(),
8172
m_detection_image->getWidth(), m_detection_image->getHeight(), m_coordinate_system);
8273
}
8374

8475
if (m_group_filename != "") {
85-
m_group_image = FitsWriter::newImage<unsigned int>(m_group_filename,
76+
m_group_image = FitsWriter::newImage<unsigned int>(m_group_filename.native(),
8677
m_detection_image->getWidth(), m_detection_image->getHeight(), m_coordinate_system);
8778
}
8879

8980
if (m_auto_aperture_filename != "") {
90-
m_auto_aperture_image = FitsWriter::newImage<unsigned int>(m_auto_aperture_filename,
81+
m_auto_aperture_image = FitsWriter::newImage<unsigned int>(m_auto_aperture_filename.native(),
9182
m_detection_image->getWidth(), m_detection_image->getHeight(), m_coordinate_system);
9283
}
9384

9485
if (m_aperture_filename != "") {
95-
m_aperture_image = FitsWriter::newImage<unsigned int>(m_aperture_filename,
86+
m_aperture_image = FitsWriter::newImage<unsigned int>(m_aperture_filename.native(),
9687
m_detection_image->getWidth(), m_detection_image->getHeight(), m_coordinate_system
9788
);
9889
}
9990

10091
if (m_moffat_filename != "") {
101-
m_moffat_image = FitsWriter::newImage<SeFloat>(m_moffat_filename,
92+
m_moffat_image = FitsWriter::newImage<SeFloat>(m_moffat_filename.native(),
10293
m_detection_image->getWidth(), m_detection_image->getHeight(), m_coordinate_system
10394
);
10495
}
10596
}
10697

10798
std::shared_ptr<WriteableImage<unsigned int>>
108-
CheckImages::getAutoApertureImage(unsigned instance, int width, int height, const std::shared_ptr<CoordinateSystem> &cs) {
99+
CheckImages::getAutoApertureImage(std::shared_ptr<const MeasurementImageFrame> frame) {
109100
if (m_auto_aperture_filename.empty()) {
110101
return nullptr;
111102
}
112103

113104
std::lock_guard<std::mutex> lock{m_access_mutex};
114105

115-
auto i = m_measurement_auto_aperture_images.find(instance);
106+
auto i = m_measurement_auto_aperture_images.find(frame);
116107
if (i == m_measurement_auto_aperture_images.end()) {
117-
auto frame_filename = m_auto_aperture_filename + "." + std::to_string(instance);
108+
auto filename = m_auto_aperture_filename.stem();
109+
filename += "_" + frame->getLabel();
110+
filename.replace_extension(m_auto_aperture_filename.extension());
111+
auto frame_filename = m_auto_aperture_filename.parent_path() / filename;
118112
i = m_measurement_auto_aperture_images.emplace(
119113
std::make_pair(
120-
instance,
114+
frame,
121115
FitsWriter::newImage<unsigned int>(
122-
frame_filename,
123-
width,
124-
height,
125-
cs
116+
frame_filename.native(),
117+
frame->getOriginalImage()->getWidth(),
118+
frame->getOriginalImage()->getHeight(),
119+
frame->getCoordinateSystem()
126120
))).first;
127121
}
128122
return i->second;
129123
}
130124

131125
std::shared_ptr<WriteableImage<unsigned int>>
132-
CheckImages::getApertureImage(unsigned instance, int width, int height, const std::shared_ptr<CoordinateSystem> &cs) {
126+
CheckImages::getApertureImage(std::shared_ptr<const MeasurementImageFrame> frame) {
133127
if (m_aperture_filename.empty()) {
134128
return nullptr;
135129
}
136130

137131
std::lock_guard<std::mutex> lock{m_access_mutex};
138132

139-
auto i = m_measurement_aperture_images.find(instance);
133+
auto i = m_measurement_aperture_images.find(frame);
140134
if (i == m_measurement_aperture_images.end()) {
141-
auto frame_filename = m_aperture_filename + "." + std::to_string(instance);
135+
auto filename = m_aperture_filename.stem();
136+
filename += "_" + frame->getLabel();
137+
filename.replace_extension(m_aperture_filename.extension());
138+
auto frame_filename = m_aperture_filename.parent_path() / filename;
142139
i = m_measurement_aperture_images.emplace(
143140
std::make_pair(
144-
instance,
141+
frame,
145142
FitsWriter::newImage<unsigned int>(
146-
frame_filename,
147-
width,
148-
height,
149-
cs
143+
frame_filename.native(),
144+
frame->getOriginalImage()->getWidth(),
145+
frame->getOriginalImage()->getHeight(),
146+
frame->getCoordinateSystem()
147+
))).first;
148+
}
149+
return i->second;
150+
}
151+
152+
std::shared_ptr<WriteableImage<MeasurementImage::PixelType>>
153+
CheckImages::getModelFittingImage(std::shared_ptr<const SExtractor::MeasurementImageFrame> frame) {
154+
if (m_model_fitting_image_filename.empty()) {
155+
return nullptr;
156+
}
157+
158+
std::lock_guard<std::mutex> lock{m_access_mutex};
159+
160+
auto i = m_check_image_model_fitting.find(frame);
161+
if (i == m_check_image_model_fitting.end()) {
162+
auto filename = m_model_fitting_image_filename.stem();
163+
filename += "_" + frame->getLabel();
164+
filename.replace_extension(m_model_fitting_image_filename.extension());
165+
auto frame_filename = m_model_fitting_image_filename.parent_path() / filename;
166+
i = m_check_image_model_fitting.emplace(
167+
std::make_pair(
168+
frame,
169+
FitsWriter::newImage<MeasurementImage::PixelType>(
170+
frame_filename.native(),
171+
frame->getOriginalImage()->getWidth(),
172+
frame->getOriginalImage()->getHeight(),
173+
frame->getCoordinateSystem()
150174
))).first;
151175
}
152176
return i->second;
@@ -157,33 +181,42 @@ void CheckImages::saveImages() {
157181

158182
// if possible, save the background image
159183
if (m_background_image != nullptr && m_model_background_filename != "") {
160-
FitsWriter::writeFile(*m_background_image, m_model_background_filename, m_coordinate_system);
184+
FitsWriter::writeFile(*m_background_image, m_model_background_filename.native(), m_coordinate_system);
161185
}
162186

163187
// if possible, save the variance image
164188
if (m_variance_image != nullptr && m_model_variance_filename != "") {
165-
FitsWriter::writeFile(*m_variance_image, m_model_variance_filename, m_coordinate_system);
189+
FitsWriter::writeFile(*m_variance_image, m_model_variance_filename.native(), m_coordinate_system);
166190
}
167191

168192
// if possible, save the filtered image
169193
if (m_filtered_image != nullptr && m_filtered_filename != "") {
170-
FitsWriter::writeFile(*m_filtered_image, m_filtered_filename, m_coordinate_system);
194+
FitsWriter::writeFile(*m_filtered_image, m_filtered_filename.native(), m_coordinate_system);
171195
}
172196

173197
// if possible, save the thresholded image
174198
if (m_thresholded_image != nullptr && m_thresholded_filename != "") {
175-
FitsWriter::writeFile(*m_thresholded_image, m_thresholded_filename, m_coordinate_system);
199+
FitsWriter::writeFile(*m_thresholded_image, m_thresholded_filename.native(), m_coordinate_system);
176200
}
177201

178202
// if possible, create and save the residual image
179-
if (m_check_image_model_fitting != nullptr && m_residual_filename != "") {
180-
auto residual_image = SubtractImage<SeFloat>::create(m_detection_image, m_check_image_model_fitting);
181-
FitsWriter::writeFile(*residual_image, m_residual_filename, m_coordinate_system);
203+
if (m_residual_filename != "") {
204+
for (auto &ci : m_check_image_model_fitting) {
205+
auto residual_image = SubtractImage<SeFloat>::create(ci.first->getSubtractedImage(), ci.second);
206+
auto filename = m_residual_filename.stem();
207+
filename += "_" + ci.first->getLabel();
208+
filename.replace_extension(m_residual_filename.extension());
209+
auto frame_filename = m_residual_filename.parent_path() / filename;
210+
FitsWriter::writeFile(*residual_image, filename.native(), ci.first->getCoordinateSystem());
211+
}
182212
}
183213

184214
for (auto const& entry : m_custom_images) {
185215
if (std::get<1>(entry.second)) {
186-
FitsWriter::writeFile(*std::get<0>(entry.second), entry.first + ".fits");
216+
auto filename = entry.first;
217+
if (!filename.has_extension())
218+
filename.replace_extension(".fits");
219+
FitsWriter::writeFile(*std::get<0>(entry.second), filename.native());
187220
}
188221
}
189222

0 commit comments

Comments
 (0)