35 #include "muse_exp_align_z.h" 54 static const char *muse_exp_align_help =
55 "Compute the coordinate offset for each input field-of-view image with respect to a reference. The created list of coordinate offsets can then be used in muse_exp_combine as the field coordinate offsets to properly align the exposures during their combination.";
57 static const char *muse_exp_align_help_esorex =
58 "\n\nInput frames for raw frame tag \"IMAGE_FOV\":\n" 59 "\n Frame tag Type Req #Fr Description" 60 "\n -------------------- ---- --- --- ------------" 61 "\n IMAGE_FOV raw Y >=2 Input field-of-view images" 62 "\n\nProduct frames for raw frame tag \"IMAGE_FOV\":\n" 63 "\n Frame tag Level Description" 64 "\n -------------------- -------- ------------" 65 "\n SOURCE_LIST final List of parameters of the detected point sources." 66 "\n OFFSET_LIST final List of computed coordinate offsets.";
77 static cpl_recipeconfig *
78 muse_exp_align_new_recipeconfig(
void)
80 cpl_recipeconfig *recipeconfig = cpl_recipeconfig_new();
82 cpl_recipeconfig_set_tag(recipeconfig,
"IMAGE_FOV", 2, -1);
83 cpl_recipeconfig_set_output(recipeconfig,
"IMAGE_FOV",
"SOURCE_LIST");
84 cpl_recipeconfig_set_output(recipeconfig,
"IMAGE_FOV",
"OFFSET_LIST");
100 static cpl_error_code
101 muse_exp_align_prepare_header(
const char *aFrametag, cpl_propertylist *aHeader)
103 cpl_ensure_code(aFrametag, CPL_ERROR_NULL_INPUT);
104 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
105 if (!strcmp(aFrametag,
"SOURCE_LIST")) {
108 "Number of detected sources.");
111 "Median value of background pixels.");
114 "Median absolute deviation of the background pixels.");
117 "Detection threshold used for detecting sources.");
118 }
else if (!strcmp(aFrametag,
"OFFSET_LIST")) {
121 "Number of detected sources for input image i");
124 "Median number of matches of input image i with other images");
127 "Minimum of the median number of matches for all input images");
130 "Number of input images that do not have any matches with other images");
133 "[arcsec] RA minimum offset.");
136 "[arcsec] RA maximum offset.");
139 "[arcsec] RA mean offset.");
142 "[arcsec] Standard deviation of RA offsets.");
145 "[arcsec] DEC minimum offset.");
148 "[arcsec] DEC maximum offset.");
151 "[arcsec] DEC mean offset.");
154 "[arcsec] Standard deviation of DEC offsets.");
156 cpl_msg_warning(__func__,
"Frame tag %s is not defined", aFrametag);
157 return CPL_ERROR_ILLEGAL_INPUT;
159 return CPL_ERROR_NONE;
172 static cpl_frame_level
173 muse_exp_align_get_frame_level(
const char *aFrametag)
176 return CPL_FRAME_LEVEL_NONE;
178 if (!strcmp(aFrametag,
"SOURCE_LIST")) {
179 return CPL_FRAME_LEVEL_FINAL;
181 if (!strcmp(aFrametag,
"OFFSET_LIST")) {
182 return CPL_FRAME_LEVEL_FINAL;
184 return CPL_FRAME_LEVEL_NONE;
198 muse_exp_align_get_frame_mode(
const char *aFrametag)
203 if (!strcmp(aFrametag,
"SOURCE_LIST")) {
206 if (!strcmp(aFrametag,
"OFFSET_LIST")) {
224 muse_exp_align_create(cpl_plugin *aPlugin)
228 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
229 recipe = (cpl_recipe *)aPlugin;
237 muse_exp_align_new_recipeconfig(),
238 muse_exp_align_prepare_header,
239 muse_exp_align_get_frame_level,
240 muse_exp_align_get_frame_mode);
245 cpl_msg_set_time_on();
249 recipe->parameters = cpl_parameterlist_new();
256 p = cpl_parameter_new_value(
"muse.muse_exp_align.rsearch",
258 "Search radius (in arcsec) for each iteration of the offset computation.",
259 "muse.muse_exp_align",
260 (
const char *)
"30.,4.,2.,0.8");
261 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"rsearch");
262 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"rsearch");
264 cpl_parameterlist_append(recipe->parameters, p);
270 p = cpl_parameter_new_value(
"muse.muse_exp_align.nbins",
272 "Number of bins to use for 2D histogram on the first iteration of the offset computation.",
273 "muse.muse_exp_align",
275 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"nbins");
276 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nbins");
278 cpl_parameterlist_append(recipe->parameters, p);
281 p = cpl_parameter_new_value(
"muse.muse_exp_align.weight",
284 "muse.muse_exp_align",
286 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"weight");
287 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"weight");
289 cpl_parameterlist_append(recipe->parameters, p);
292 p = cpl_parameter_new_value(
"muse.muse_exp_align.fwhm",
294 "FWHM in pixels of the convolution filter.",
295 "muse.muse_exp_align",
297 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"fwhm");
298 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"fwhm");
300 cpl_parameterlist_append(recipe->parameters, p);
308 p = cpl_parameter_new_value(
"muse.muse_exp_align.threshold",
310 "Initial intensity threshold for detecting point sources. If the value is negative or zero the threshold is taken as sigma above median background MAD. If it is larger than zero the threshold is taken as absolute background level.",
311 "muse.muse_exp_align",
313 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"threshold");
314 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"threshold");
316 cpl_parameterlist_append(recipe->parameters, p);
321 p = cpl_parameter_new_value(
"muse.muse_exp_align.bkgignore",
323 "Fraction of the image to be ignored.",
324 "muse.muse_exp_align",
326 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"bkgignore");
327 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"bkgignore");
329 cpl_parameterlist_append(recipe->parameters, p);
335 p = cpl_parameter_new_value(
"muse.muse_exp_align.bkgfraction",
337 "Fraction of the image (without the ignored part) to be considered as background.",
338 "muse.muse_exp_align",
340 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"bkgfraction");
341 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"bkgfraction");
343 cpl_parameterlist_append(recipe->parameters, p);
346 p = cpl_parameter_new_value(
"muse.muse_exp_align.step",
348 "Increment/decrement of the threshold value in subsequent iterations.",
349 "muse.muse_exp_align",
351 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"step");
352 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"step");
354 cpl_parameterlist_append(recipe->parameters, p);
357 p = cpl_parameter_new_value(
"muse.muse_exp_align.iterations",
359 "Maximum number of iterations used for detecting sources.",
360 "muse.muse_exp_align",
362 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"iterations");
363 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"iterations");
365 cpl_parameterlist_append(recipe->parameters, p);
368 p = cpl_parameter_new_value(
"muse.muse_exp_align.srcmin",
370 "Minimum number of sources which must be found.",
371 "muse.muse_exp_align",
373 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"srcmin");
374 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"srcmin");
376 cpl_parameterlist_append(recipe->parameters, p);
379 p = cpl_parameter_new_value(
"muse.muse_exp_align.srcmax",
381 "Maximum number of sources which may be found.",
382 "muse.muse_exp_align",
384 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"srcmax");
385 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"srcmax");
387 cpl_parameterlist_append(recipe->parameters, p);
390 p = cpl_parameter_new_value(
"muse.muse_exp_align.roundmin",
392 "Lower limit of the allowed point-source roundness.",
393 "muse.muse_exp_align",
395 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"roundmin");
396 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"roundmin");
398 cpl_parameterlist_append(recipe->parameters, p);
401 p = cpl_parameter_new_value(
"muse.muse_exp_align.roundmax",
403 "Upper limit of the allowed point-source roundness.",
404 "muse.muse_exp_align",
406 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"roundmax");
407 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"roundmax");
409 cpl_parameterlist_append(recipe->parameters, p);
412 p = cpl_parameter_new_value(
"muse.muse_exp_align.sharpmin",
414 "Lower limit of the allowed point-source sharpness.",
415 "muse.muse_exp_align",
417 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"sharpmin");
418 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sharpmin");
420 cpl_parameterlist_append(recipe->parameters, p);
423 p = cpl_parameter_new_value(
"muse.muse_exp_align.sharpmax",
425 "Upper limit of the allowed point-source sharpness.",
426 "muse.muse_exp_align",
428 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CFG,
"sharpmax");
429 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sharpmax");
431 cpl_parameterlist_append(recipe->parameters, p);
451 cpl_ensure_code(aParams, CPL_ERROR_NULL_INPUT);
452 cpl_ensure_code(aParameters, CPL_ERROR_NULL_INPUT);
455 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.rsearch");
456 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
457 aParams->
rsearch = cpl_parameter_get_string(p);
459 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.nbins");
460 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
461 aParams->
nbins = cpl_parameter_get_int(p);
463 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.weight");
464 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
465 aParams->
weight = cpl_parameter_get_bool(p);
467 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.fwhm");
468 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
469 aParams->
fwhm = cpl_parameter_get_double(p);
471 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.threshold");
472 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
473 aParams->
threshold = cpl_parameter_get_double(p);
475 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.bkgignore");
476 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
477 aParams->
bkgignore = cpl_parameter_get_double(p);
479 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.bkgfraction");
480 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
481 aParams->
bkgfraction = cpl_parameter_get_double(p);
483 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.step");
484 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
485 aParams->
step = cpl_parameter_get_double(p);
487 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.iterations");
488 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
489 aParams->
iterations = cpl_parameter_get_int(p);
491 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.srcmin");
492 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
493 aParams->
srcmin = cpl_parameter_get_int(p);
495 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.srcmax");
496 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
497 aParams->
srcmax = cpl_parameter_get_int(p);
499 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.roundmin");
500 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
501 aParams->
roundmin = cpl_parameter_get_double(p);
503 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.roundmax");
504 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
505 aParams->
roundmax = cpl_parameter_get_double(p);
507 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.sharpmin");
508 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
509 aParams->
sharpmin = cpl_parameter_get_double(p);
511 p = cpl_parameterlist_find(aParameters,
"muse.muse_exp_align.sharpmax");
512 cpl_ensure_code(p, CPL_ERROR_DATA_NOT_FOUND);
513 aParams->
sharpmax = cpl_parameter_get_double(p);
527 muse_exp_align_exec(cpl_plugin *aPlugin)
529 if (cpl_plugin_get_type(aPlugin) != CPL_PLUGIN_TYPE_RECIPE) {
533 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
534 cpl_msg_set_threadid_on();
536 cpl_frameset *usedframes = cpl_frameset_new(),
537 *outframes = cpl_frameset_new();
539 muse_exp_align_params_fill(¶ms, recipe->parameters);
541 cpl_errorstate prestate = cpl_errorstate_get();
545 int rc = muse_exp_align_compute(proc, ¶ms);
546 cpl_frameset_join(usedframes, proc->
usedframes);
547 cpl_frameset_join(outframes, proc->
outframes);
550 if (!cpl_errorstate_is_equal(prestate)) {
554 cpl_msg_set_level(CPL_MSG_INFO);
565 cpl_frameset_join(recipe->frames, usedframes);
566 cpl_frameset_join(recipe->frames, outframes);
567 cpl_frameset_delete(usedframes);
568 cpl_frameset_delete(outframes);
581 muse_exp_align_destroy(cpl_plugin *aPlugin)
585 if (cpl_plugin_get_type(aPlugin) == CPL_PLUGIN_TYPE_RECIPE) {
586 recipe = (cpl_recipe *)aPlugin;
592 cpl_parameterlist_delete(recipe->parameters);
609 cpl_plugin_get_info(cpl_pluginlist *aList)
611 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
612 cpl_plugin *plugin = &recipe->interface;
616 helptext = cpl_sprintf(
"%s%s", muse_exp_align_help,
617 muse_exp_align_help_esorex);
619 helptext = cpl_sprintf(
"%s", muse_exp_align_help);
623 cpl_plugin_init(plugin, CPL_PLUGIN_API, MUSE_BINARY_VERSION,
624 CPL_PLUGIN_TYPE_RECIPE,
626 "Create a coordinate offset table to be used to align exposures during exposure combination.",
631 muse_exp_align_create,
633 muse_exp_align_destroy);
634 cpl_pluginlist_append(aList, plugin);
int srcmin
Minimum number of sources which must be found.
void muse_processing_delete(muse_processing *aProcessing)
Free the muse_processing structure.
double fwhm
FWHM in pixels of the convolution filter.
muse_cplframework_type muse_cplframework(void)
Return the CPL framework the recipe is run under.
double roundmax
Upper limit of the allowed point-source roundness.
double step
Increment/decrement of the threshold value in subsequent iterations.
cpl_frameset * usedframes
muse_processing * muse_processing_new(const char *aName, cpl_recipe *aRecipe)
Create a new processing structure.
double bkgfraction
Fraction of the image (without the ignored part) to be considered as background.
double sharpmax
Upper limit of the allowed point-source sharpness.
const char * muse_get_license(void)
Get the pipeline copyright and license.
Structure to hold the parameters of the muse_exp_align recipe.
int srcmax
Maximum number of sources which may be found.
double threshold
Initial intensity threshold for detecting point sources. If the value is negative or zero the thresho...
int iterations
Maximum number of iterations used for detecting sources.
int nbins
Number of bins to use for 2D histogram on the first iteration of the offset computation.
double bkgignore
Fraction of the image to be ignored.
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
void muse_processinginfo_delete(cpl_recipe *)
Clear all information from the processing info and from the recipe config.
cpl_error_code muse_cplframeset_erase_duplicate(cpl_frameset *aFrames)
Erase all duplicate frames from a frameset.
const char * rsearch
Search radius (in arcsec) for each iteration of the offset computation.
cpl_error_code muse_cplframeset_erase_all(cpl_frameset *aFrames)
Erase all frames in a frameset.
double roundmin
Lower limit of the allowed point-source roundness.
void muse_processinginfo_register(cpl_recipe *, cpl_recipeconfig *, muse_processing_prepare_header_func *, muse_processing_get_frame_level_func *, muse_processing_get_frame_mode_func *)
Register extended functionalities for MUSE recipes.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.
double sharpmin
Lower limit of the allowed point-source sharpness.
cpl_error_code muse_processing_prepare_property(cpl_propertylist *, const char *, cpl_type, const char *)
Prepare and check the specified property.