Skip to content

Commit 77ba254

Browse files
committed
propagate renormalization configuration from MeasurementImage
1 parent 9db6de7 commit 77ba254

File tree

12 files changed

+43
-29
lines changed

12 files changed

+43
-29
lines changed

SEImplementation/SEImplementation/Configuration/MeasurementImageConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class MeasurementImageConfig : public Euclid::Configuration::Configuration {
6565
bool m_is_data_cube;
6666
int m_image_layer;
6767
int m_weight_layer;
68+
69+
bool m_psf_renormalize;
6870
};
6971

7072
explicit MeasurementImageConfig(long manager_id);

SEImplementation/SEImplementation/Plugin/Psf/PsfPluginConfig.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,8 @@ class PsfPluginConfig: public Euclid::Configuration::Configuration {
4545
static std::shared_ptr<Psf> readPsf(const std::string &filename, int hdu_number = 1);
4646
static std::shared_ptr<Psf> generateGaussianPsf(SeFloat fwhm, SeFloat pixel_sampling);
4747

48-
bool shouldNormalizePsf() const {
49-
return m_psf_normalization;
50-
}
51-
5248
private:
5349
std::shared_ptr<Psf> m_vpsf;
54-
bool m_psf_normalization { true };
5550
};
5651

5752
} // end SourceXtractor

SEImplementation/SEImplementation/Plugin/SourcePsf/SourcePsfTask.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class SourcePsfTask: public SourceTask {
2727
public:
2828
virtual ~SourcePsfTask() = default;
2929

30-
SourcePsfTask(unsigned instance, const std::shared_ptr<Psf> &vpsf);
30+
SourcePsfTask(unsigned instance, const std::shared_ptr<Psf>& vpsf, bool normalize_psf = true)
31+
: m_instance(instance), m_vpsf(vpsf), m_normalize_psf(normalize_psf) {
32+
}
3133

3234
void computeProperties(SourceInterface& source) const override;
3335

SEImplementation/SEImplementation/Plugin/SourcePsf/SourcePsfTaskFactory.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ class SourcePsfTaskFactory: public TaskFactory {
3737
std::shared_ptr<Task> createTask(const PropertyId& property_id) const override;
3838

3939
private:
40-
std::map<int, std::shared_ptr<Psf>> m_vpsf;
40+
41+
struct PsfInfo {
42+
std::shared_ptr<Psf> m_psf;
43+
bool m_normalize_psf;
44+
};
45+
46+
std::map<int, PsfInfo> m_psf_infos;
4147
};
4248

4349
} // end SourceXtractor

SEImplementation/SEImplementation/PythonConfig/PyMeasurementImage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class PyMeasurementImage : public PyId {
5454
bool is_data_cube;
5555
int image_layer;
5656
int weight_layer;
57+
58+
bool psf_renormalize;
5759
};
5860

5961
}

SEImplementation/python/sourcextractor/config/measurement_images.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class MeasurementImage(cpp.MeasurementImage):
107107
For multi-extension FITS file specifies the HDU number for the psf. Defaults to the same value as image_hdu
108108
weight_hdu : int
109109
For multi-extension FITS file specifies the HDU number for the weight. Defaults to the same value as image_hdu
110+
psf_renormalize : bool
111+
If True, the PSF will be renormalized to have a total flux of 1.0. Default True
110112
"""
111113

112114
def _set_checked(self, attr_name, value):
@@ -122,7 +124,7 @@ def __init__(self, fits_file, psf_file=None, weight_file=None, gain=None,
122124
flux_scale=None, flux_scale_keyword='FLXSCALE',
123125
weight_type='none', weight_absolute=False, weight_scaling=1.,
124126
weight_threshold=None, constant_background=None,
125-
image_hdu=0, psf_hdu=None, weight_hdu=None
127+
image_hdu=0, psf_hdu=None, weight_hdu=None, psf_renormalize=True
126128
):
127129
"""
128130
Constructor.
@@ -201,6 +203,9 @@ def __init__(self, fits_file, psf_file=None, weight_file=None, gain=None,
201203
self._set_checked('weight_hdu', image_hdu)
202204
else:
203205
self._set_checked('weight_hdu', weight_hdu)
206+
207+
self.psf_renormalize = psf_renormalize
208+
print(self.psf_renormalize)
204209

205210
def __str__(self):
206211
"""

SEImplementation/src/lib/Configuration/MeasurementImageConfig.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ void MeasurementImageConfig::initialize(const UserValues&) {
220220
info.m_psf_hdu = py_image.psf_hdu + 1;
221221
info.m_weight_hdu = py_image.weight_hdu + 1;
222222

223+
info.m_psf_renormalize = py_image.psf_renormalize;
224+
223225
m_image_infos.emplace_back(std::move(info));
224226
}
225227
} else {
@@ -252,10 +254,14 @@ void MeasurementImageConfig::initialize(const UserValues&) {
252254

253255
0, // id
254256

255-
1,1,1 // HDUs
256-
});
257+
1,1,1, // HDUs
257258

259+
false, // is_data_cube
260+
0, // image_layer
261+
0, // weight_layer
258262

263+
true // psf_renormalize
264+
});
259265
}
260266
}
261267

SEImplementation/src/lib/Plugin/Psf/PsfPluginConfig.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ namespace SourceXtractor {
4242
static const std::string PSF_FILE{"psf-filename"};
4343
static const std::string PSF_FWHM {"psf-fwhm" };
4444
static const std::string PSF_PIXEL_SAMPLING {"psf-pixel-sampling" };
45-
static const std::string PSF_NORMALIZATION {"psf-normalization" };
4645

4746
/*
4847
* Reading in a stacked PSF as it is being developed for co-added images in Euclid
@@ -232,9 +231,7 @@ std::map<std::string, Configuration::OptionDescriptionList> PsfPluginConfig::get
232231
{PSF_FWHM.c_str(), po::value<double>(),
233232
"Generate a gaussian PSF with the given full-width half-maximum (in pixels)"},
234233
{PSF_PIXEL_SAMPLING.c_str(), po::value<double>(),
235-
"Generate a gaussian PSF with the given pixel sampling step size"},
236-
{PSF_NORMALIZATION.c_str(), po::value<bool>()->default_value(true),
237-
"Whether PSFs should be normalized"}
234+
"Generate a gaussian PSF with the given pixel sampling step size"}
238235
}}};
239236
}
240237

@@ -259,7 +256,6 @@ void PsfPluginConfig::initialize(const UserValues &args) {
259256
m_vpsf = generateGaussianPsf(args.find(PSF_FWHM)->second.as<double>(),
260257
args.find(PSF_PIXEL_SAMPLING)->second.as<double>());
261258
}
262-
m_psf_normalization = args.find(PSF_NORMALIZATION)->second.as<bool>();
263259
}
264260

265261
const std::shared_ptr<Psf>& PsfPluginConfig::getPsf() const {

SEImplementation/src/lib/Plugin/SourcePsf/SourcePsfTask.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ std::map<std::string, SourcePsfTask::ValueGetter> SourcePsfTask::component_value
4545
{"YMODEL_IMAGE", getCoordY}
4646
};
4747

48-
SourcePsfTask::SourcePsfTask(unsigned instance, const std::shared_ptr<Psf> &vpsf)
49-
: m_instance(instance), m_vpsf(vpsf) {
50-
}
51-
5248
void SourcePsfTask::computeProperties(SourceXtractor::SourceInterface &source) const {
5349
if (m_vpsf != nullptr) {
5450
std::vector<double> component_values;
@@ -57,15 +53,14 @@ void SourcePsfTask::computeProperties(SourceXtractor::SourceInterface &source) c
5753
component_values.push_back(component_value_getters[component](source, m_instance));
5854
}
5955

60-
auto psf = m_vpsf->getPsf(component_values);
61-
std::shared_ptr<VectorImage<SeFloat>> psf_normalized = psf;
56+
std::shared_ptr<VectorImage<SeFloat>> psf = m_vpsf->getPsf(component_values);
6257

6358
if (m_normalize_psf) {
6459
// The result may not be normalized!
6560
auto psf_sum = std::accumulate(psf->getData().begin(), psf->getData().end(), 0.);
66-
psf_normalized = VectorImage<SeFloat>::create(*MultiplyImage<SeFloat>::create(psf, 1. / psf_sum));
61+
psf = VectorImage<SeFloat>::create(*MultiplyImage<SeFloat>::create(psf, 1. / psf_sum));
6762
}
68-
source.setIndexedProperty<SourcePsfProperty>(m_instance, m_vpsf->getPixelSampling(), psf_normalized);
63+
source.setIndexedProperty<SourcePsfProperty>(m_instance, m_vpsf->getPixelSampling(), psf);
6964

7065
// Check image
7166
auto check_image = CheckImages::getInstance().getPsfImage(m_instance);
@@ -74,7 +69,7 @@ void SourcePsfTask::computeProperties(SourceXtractor::SourceInterface &source) c
7469
auto y = component_value_getters["Y_IMAGE"](source, m_instance);
7570

7671
ModelFitting::ImageTraits<ModelFitting::WriteableInterfaceTypePtr>::addImageToImage(
77-
check_image, psf_normalized, m_vpsf->getPixelSampling(), x, y);
72+
check_image, psf, m_vpsf->getPixelSampling(), x, y);
7873
}
7974
} else {
8075
source.setIndexedProperty<SourcePsfProperty>(m_instance, 1.0, nullptr);

SEImplementation/src/lib/Plugin/SourcePsf/SourcePsfTaskFactory.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,27 @@ void SourcePsfTaskFactory::configure(Euclid::Configuration::ConfigManager& manag
3434

3535
for (unsigned int i = 0; i < image_infos.size(); i++) {
3636
if (!image_infos[i].m_psf_path.empty()) {
37-
m_vpsf[image_infos[i].m_id] = PsfPluginConfig::readPsf(image_infos[i].m_psf_path, image_infos[i].m_psf_hdu);
37+
m_psf_infos[image_infos[i].m_id] = {
38+
PsfPluginConfig::readPsf(image_infos[i].m_psf_path, image_infos[i].m_psf_hdu),
39+
image_infos[i].m_psf_renormalize
40+
};
3841
}
3942
else if (default_psf) {
40-
m_vpsf[image_infos[i].m_id] = default_psf;
43+
m_psf_infos[image_infos[i].m_id] = { default_psf, true };
4144
}
4245
}
4346
}
4447

4548
std::shared_ptr<Task> SourcePsfTaskFactory::createTask(const SourceXtractor::PropertyId& property_id) const {
4649
auto instance = property_id.getIndex();
4750

48-
if (m_vpsf.find(instance) == m_vpsf.end()) {
51+
if (m_psf_infos.find(instance) == m_psf_infos.end()) {
4952
throw Elements::Exception() << "Missing PSF. Make sure every frame has a PSF";
5053
}
5154

5255
try {
53-
return std::make_shared<SourcePsfTask>(instance, m_vpsf.at(instance));
56+
return std::make_shared<SourcePsfTask>(
57+
instance, m_psf_infos.at(instance).m_psf, m_psf_infos.at(instance).m_normalize_psf);
5458
} catch (const std::out_of_range&) {
5559
return nullptr;
5660
}

0 commit comments

Comments
 (0)