169 po::options_description config_options {
"TestImage options" };
172 config_options.add_options()
173 (
"output", po::value<string>()->required(),
"filename to save the created test image")
174 (
"output-weight", po::value<string>()->default_value(
""),
"filename to save the created weight map image")
175 (
"size", po::value<double>()->default_value(512.0),
"image size")
176 (
"bg-level", po::value<double>()->default_value(0.0),
"background level")
177 (
"bg-sigma", po::value<double>()->default_value(20.0),
"standard deviation of background gaussian noise")
178 (
"gain", po::value<double>()->default_value(0.0),
"gain in e-/adu, 0 for infinite gain")
179 (
"saturation", po::value<double>()->default_value(0.0),
"image saturation level, 0 for no saturation")
180 (
"psf-file", po::value<string>()->default_value(
""),
"Psf file for convolution")
181 (
"psf-fwhm", po::value<double>()->default_value(5.0),
182 "Full width half maximum for generated gaussian psf (used when no psf file is provided)")
183 (
"psf-scale", po::value<double>()->default_value(0.2),
"Pixel scale for generated gaussian psf")
184 (
"disable-psf", po::bool_switch(),
"Disable psf convolution")
185 (
"random-sources", po::value<int>()->default_value(0),
"Nb of random sources to add")
186 (
"source-list", po::value<string>()->default_value(
""),
"Use sources from file")
187 (
"source-catalog", po::value<string>()->default_value(
""),
"Use sources from file (skymaker format)")
188 (
"zero-point", po::value<double>()->default_value(0.0),
"Zero point for magnitudes in catalog")
189 (
"exposure-time", po::value<double>()->default_value(300.),
"Exposure time for objects in catalog")
190 (
"save-sources", po::value<string>()->default_value(
""),
"Filename to save final list of sources")
191 (
"bad-pixels", po::value<double>()->default_value(0.0),
"Probability for a pixel to be a bad pixel")
192 (
"bad-columns", po::value<double>()->default_value(0.0),
"Probability for a column of pixels to be bad")
193 (
"rotation", po::value<double>()->default_value(0.0),
"Rotate sources around middle point")
194 (
"scale", po::value<double>()->default_value(1.0),
"Scale factor")
195 (
"shift-x", po::value<double>()->default_value(0.0),
"Shift X")
196 (
"shift-y", po::value<double>()->default_value(0.0),
"Shift Y")
197 (
"model-size", po::value<double>()->default_value(0.0),
"Model size for the rasterization of sources, defaults to size")
198 (
"max-tile-memory", po::value<int>()->default_value(512),
"Maximum memory used for image tiles cache in megabytes")
199 (
"tile-size", po::value<int>()->default_value(256),
"Image tiles size in pixels")
200 (
"copy-coordinate-system", po::value<string>()->default_value(
""),
"Copy the coordinate system from another FITS file")
203 return config_options;
226 component_list.
clear();
229 std::move(component_list), xs, ys, rot, size, size, x_param, y_param, jacobian));
245 component_list.
clear();
248 std::move(component_list), xs, ys, rot, size, size, x_param, y_param, jacobian));
253 point_models.
emplace_back(x_param, y_param, flux_param);
328 double x_min,
double y_min,
double x_max,
double y_max) {
333 boost::random::uniform_real_distribution<> random_x(x_min, x_max);
334 boost::random::uniform_real_distribution<> random_y(y_min, y_max);
338 for (
int i = 0; i < number_of_sources; i++) {
343 gal_exp_random_i0(
m_rng),
344 boost::random::uniform_real_distribution<>(.5, 6)(
m_rng),
345 boost::random::uniform_real_distribution<>(.2, .8)(
m_rng),
346 boost::random::uniform_real_distribution<>(-M_PI/2, M_PI/2)(
m_rng),
488 auto max_tile_memory = args[
"max-tile-memory"].as<
int>();
489 auto tile_size = args[
"tile-size"].as<
int>();
492 auto image_size = args[
"size"].as<
double>();
493 auto rot_angle = args[
"rotation"].as<
double>() / 180.0 * M_PI;
494 auto scale = args[
"scale"].as<
double>();
495 auto shift_x = args[
"shift-x"].as<
double>();
496 auto shift_y = args[
"shift-y"].as<
double>();
497 auto model_size = args[
"model-size"].as<
double>();
498 if (model_size <= 0.) {
499 model_size = image_size;
503 m_exp_time = args[
"exposure-time"].as<
double>();
511 auto psf_filename = args[
"psf-file"].as<
std::string>();
512 if (psf_filename !=
"") {
513 logger.info() <<
"Loading psf file: " << psf_filename;
520 auto copy_coordinate_system = args[
"copy-coordinate-system"].as<
std::string>();
521 if (copy_coordinate_system !=
"") {
527 auto raster_model_size = model_size / vpsf->getPixelSampling() +
std::max(vpsf->getWidth(), vpsf->getHeight());
529 logger.fatal() <<
"The expected required memory for model rasterization exceeds the maximum size for an integer";
530 logger.fatal() <<
"Please, either reduce the model size, the image size, or increase the PSF pixel scale";
536 const auto& vpsf_components = vpsf->getComponents();
538 for (
auto i = 0u; i < psf_vals.
size(); ++i) {
539 if (vpsf_components[i] ==
"X_IMAGE" || vpsf_components[i] ==
"Y_IMAGE") {
540 psf_vals[i] = image_size / 2 - 1;
548 auto p = vpsf->getPsf(psf_vals);
549 auto psf_sum =
std::accumulate(p->getData().begin(), p->getData().end(), 0.);
556 if (sources_filename !=
"") {
557 logger.info() <<
"Loading sources from < " << sources_filename <<
" >...";
559 sources.
insert(sources.
end(), loaded_sources.begin(), loaded_sources.end());
563 if (sources_cat_filename !=
"") {
564 logger.info() <<
"Loading source catalog from < " << sources_cat_filename <<
" >...";
566 sources.
insert(sources.
end(), loaded_sources.begin(), loaded_sources.end());
569 int nb_of_random_sources = args[
"random-sources"].as<
int>();
570 if (nb_of_random_sources > 0) {
571 logger.info() <<
"Adding " << nb_of_random_sources <<
" random source" << (nb_of_random_sources>1 ?
"s" :
"") <<
"...";
572 auto random_sources =
generateRandomSources(nb_of_random_sources, image_size * .1, image_size * .1, image_size * .9, image_size * .9);
573 sources.
insert(sources.
end(), random_sources.begin(), random_sources.end());
577 if (sources_save_filename !=
"") {
578 logger.info() <<
"Saving sources to < " << sources_save_filename <<
" >...";
582 logger.info(
"Transforming sources...");
585 logger.info(
"Creating source models...");
586 for (
const auto& source : sources) {
590 logger.info(
"Rendering...");
597 if (args[
"disable-psf"].as<bool>()) {
619 logger.info(
"Adding noise...");
622 addBackgroundNoise(target_image, args[
"bg-level"].as<double>(), args[
"bg-sigma"].as<double>());
624 logger.info(
"Adding saturation...");
626 auto saturation_level = args[
"saturation"].as<
double>();
627 saturate(target_image, saturation_level);
629 logger.info(
"Creating weight map...");
631 auto weight_filename = args[
"output-weight"].as<
std::string>();
632 if (weight_filename !=
"") {
635 for (
int y = 0; y < image_size; ++y) {
636 for (
int x = 0; x < image_size; ++x) {
637 weight_map->setValue(x, y, 1);
641 logger.info(
"Adding bad pixels...");
643 addBadPixels(weight_map, args[
"bad-pixels"].as<double>());
647 for (
int y = 0; y < target_image->getHeight(); y++) {
648 for (
int x = 0; x < target_image->getWidth(); x++) {
649 if (weightAccessor.
getValue(x, y) == 0) {
650 target_image->setValue(x, y, saturation_level);
656 logger.info(
"All done ^__^");