@@ -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
4242void CheckImages::setCustomCheckImage(std::string id, std::shared_ptr<Image<SeFloat>> image) {
4343 m_custom_images[id] = std::make_tuple(image, true);
44- }
44+ }*/
4545
4646void 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+
161179void 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) {
0 commit comments