Skip to content

Commit 2109b75

Browse files
committed
Use CheckImages for the debug and residuals
Copy WCS headers, and use the original file name to make it easier to track.
1 parent b7d15e1 commit 2109b75

File tree

4 files changed

+54
-41
lines changed

4 files changed

+54
-41
lines changed

SEImplementation/SEImplementation/CheckImages/CheckImages.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ class CheckImages : public Configurable {
3333

3434
void saveImages();
3535

36-
std::shared_ptr<WriteableImage<DetectionImage::PixelType>> getModelFittingCheckImage() const {
37-
return m_check_image_model_fitting;
38-
}
39-
4036
std::shared_ptr<WriteableImage<unsigned int>> getSegmentationImage() const {
4137
return m_segmentation_image;
4238
}
@@ -67,6 +63,9 @@ class CheckImages : public Configurable {
6763
std::shared_ptr<WriteableImage<unsigned int>>
6864
getApertureImage(std::shared_ptr<const MeasurementImageFrame> frame);
6965

66+
std::shared_ptr<WriteableImage<MeasurementImage::PixelType>>
67+
getModelFittingImage(std::shared_ptr<const MeasurementImageFrame> frame);
68+
7069
void setBackgroundCheckImage(std::shared_ptr<Image<SeFloat>> background_image) {
7170
m_background_image = background_image;
7271
}
@@ -83,8 +82,8 @@ class CheckImages : public Configurable {
8382
m_thresholded_image = thresholded_image;
8483
}
8584

86-
std::shared_ptr<WriteableImage<SeFloat>> getWriteableCheckImage(std::string id, int width, int height);
87-
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);
8887

8988
virtual void reportConfigDependencies(Euclid::Configuration::ConfigManager& manager) const override;
9089
virtual void configure(Euclid::Configuration::ConfigManager& manager) override;
@@ -111,7 +110,6 @@ class CheckImages : public Configurable {
111110
static std::unique_ptr<CheckImages> m_instance;
112111

113112
// check image
114-
std::shared_ptr<WriteableImage<DetectionImage::PixelType>> m_check_image_model_fitting;
115113
std::shared_ptr<WriteableImage<unsigned int>> m_segmentation_image;
116114
std::shared_ptr<WriteableImage<unsigned int>> m_partition_image;
117115
std::shared_ptr<WriteableImage<unsigned int>> m_group_image;
@@ -120,6 +118,7 @@ class CheckImages : public Configurable {
120118
std::shared_ptr<WriteableImage<SeFloat>> m_moffat_image;
121119
std::map<std::shared_ptr<const MeasurementImageFrame>, decltype(m_aperture_image)> m_measurement_aperture_images;
122120
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;
123122

124123
std::shared_ptr<DetectionImage> m_detection_image;
125124
std::shared_ptr<Image<SeFloat>> m_background_image;

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: 38 additions & 14 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,15 +62,6 @@ 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.native(),
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 != "") {
7566
m_segmentation_image = FitsWriter::newImage<unsigned int>(m_segmentation_filename.native(),
7667
m_detection_image->getWidth(), m_detection_image->getHeight(), m_coordinate_system);
@@ -158,6 +149,33 @@ CheckImages::getApertureImage(std::shared_ptr<const MeasurementImageFrame> frame
158149
return i->second;
159150
}
160151

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()
174+
))).first;
175+
}
176+
return i->second;
177+
}
178+
161179
void CheckImages::saveImages() {
162180
lock();
163181

@@ -182,9 +200,15 @@ void CheckImages::saveImages() {
182200
}
183201

184202
// if possible, create and save the residual image
185-
if (m_check_image_model_fitting != nullptr && m_residual_filename != "") {
186-
auto residual_image = SubtractImage<SeFloat>::create(m_detection_image, m_check_image_model_fitting);
187-
FitsWriter::writeFile(*residual_image, m_residual_filename.native(), 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+
}
188212
}
189213

190214
for (auto const& entry : m_custom_images) {

SEImplementation/src/lib/Plugin/FlexibleModelFitting/FlexibleModelFittingTask.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -323,29 +323,21 @@ void FlexibleModelFittingTask::updateCheckImages(SourceGroupInterface& group,
323323
auto final_stamp = frame_model.getImage();
324324

325325
auto stamp_rect = group.getProperty<MeasurementFrameGroupRectangle>(frame_index);
326-
327-
CheckImages::getInstance().lock();
328326
auto frame = group.begin()->getProperty<MeasurementFrame>(frame_index).getFrame();
329327

330-
std::stringstream checkimage_id;
331-
checkimage_id << m_checkimage_prefix << "_debug_" << frame_id;
332-
auto debug_image = CheckImages::getInstance().getWriteableCheckImage(checkimage_id.str(),
333-
frame->getSubtractedImage()->getWidth(), frame->getSubtractedImage()->getHeight());
334-
335-
for (int x=0; x<final_stamp->getWidth(); x++) {
336-
for (int y=0; y<final_stamp->getHeight(); y++) {
337-
auto x_coord = stamp_rect.getTopLeft().m_x + x;
338-
auto y_coord = stamp_rect.getTopLeft().m_y + y;
339-
debug_image->setValue(x_coord, y_coord, debug_image->getValue(x_coord, y_coord) + final_stamp->getValue(x,y));
328+
auto debug_image = CheckImages::getInstance().getModelFittingImage(frame);
329+
if (debug_image) {
330+
CheckImages::getInstance().lock();
331+
for (int x = 0; x < final_stamp->getWidth(); x++) {
332+
for (int y = 0; y < final_stamp->getHeight(); y++) {
333+
auto x_coord = stamp_rect.getTopLeft().m_x + x;
334+
auto y_coord = stamp_rect.getTopLeft().m_y + y;
335+
debug_image->setValue(x_coord, y_coord,
336+
debug_image->getValue(x_coord, y_coord) + final_stamp->getValue(x, y));
337+
}
340338
}
341339
}
342340

343-
auto residual_image = SubtractImage<SeFloat>::create(frame->getSubtractedImage(), debug_image);
344-
345-
std::stringstream checkimage_residual_id;
346-
checkimage_residual_id << m_checkimage_prefix << "_residual_" << frame_id;
347-
CheckImages::getInstance().setCustomCheckImage(checkimage_residual_id.str(), residual_image);
348-
349341
CheckImages::getInstance().unlock();
350342
}
351343
frame_id++;

0 commit comments

Comments
 (0)