55 "This recipe computes phase and amplitude referencing for astrometric observations.\n"
56 "It supports on- and off-axis observing strategies, as well as the use of swaps.\n"
58 "* If swaps are present: obtain astrometric solution and compute swap phase reference\n"
59 "* Compute phase reference for the target.\n"
60 "* Write output product with correctly referenced phase.\n"
64 GRAVI_ASTRO_SWAP":\talternating star/planet frames for swap observing mode\n"
86 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
87 cpl_plugin * plugin = &recipe->interface;
89 if (cpl_plugin_init(plugin,
92 CPL_PLUGIN_TYPE_RECIPE,
96 "Calvin Sykes, Mathias Nowak, Sebastian Hoenig",
102 cpl_msg_error(cpl_func,
"Plugin initialization failed");
103 (void)cpl_error_set_where(cpl_func);
107 if (cpl_pluginlist_append(list, plugin)) {
108 cpl_msg_error(cpl_func,
"Error adding plugin to list");
109 (void)cpl_error_set_where(cpl_func);
130 if (cpl_error_get_code() != CPL_ERROR_NONE) {
131 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
132 cpl_func, __LINE__, cpl_error_get_where());
133 return (
int)cpl_error_get_code();
136 if (plugin == NULL) {
137 cpl_msg_error(cpl_func,
"Null plugin");
138 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
142 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
143 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
144 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
148 recipe = (cpl_recipe *)plugin;
151 recipe->parameters = cpl_parameterlist_new();
152 if (recipe->parameters == NULL) {
153 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
154 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
178 cpl_errorstate initial_errorstate = cpl_errorstate_get();
182 if (cpl_error_get_code() != CPL_ERROR_NONE) {
183 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
184 cpl_func, __LINE__, cpl_error_get_where());
185 return (
int)cpl_error_get_code();
188 if (plugin == NULL) {
189 cpl_msg_error(cpl_func,
"Null plugin");
190 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
194 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
195 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
196 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
200 recipe = (cpl_recipe *)plugin;
203 if (recipe->parameters == NULL) {
204 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
205 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
207 if (recipe->frames == NULL) {
208 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
209 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
216 if (cpl_dfs_update_product_header(recipe->frames)) {
218 recipe_status = (int)cpl_error_get_code();
222 if (!cpl_errorstate_is_equal(initial_errorstate)) {
225 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
228 return recipe_status;
242 if (plugin == NULL) {
243 cpl_msg_error(cpl_func,
"Null plugin");
244 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
248 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
249 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
250 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
254 recipe = (cpl_recipe *)plugin;
256 cpl_parameterlist_delete(recipe->parameters);
272 cpl_frame *frame = NULL;
276 cpl_size nframes = cpl_frameset_get_size(frameset);
278 data = cpl_calloc(nframes,
sizeof(
astro_data *));
279 for (
int i = 0; i < nframes; i++) {
280 frame = cpl_frameset_get_position(frameset, i);
285 out_data[i] = tmp_data;
306 cpl_parameterlist * parlist)
308 cpl_frameset *target_frameset=NULL, *swap_frameset=NULL, *phaseref_frameset=NULL,
311 cpl_frame *frame=NULL;
312 cpl_size n_target = 0, n_swap = 0, n_phaseref = 0;
313 gravi_data **tgt_data = NULL, **swap_data = NULL;
314 astro_data **tgt_astro = NULL, **swap_astro=NULL, **phaseref_astro=NULL;
318 cpl_msg_set_time_on();
319 cpl_msg_set_component_on();
322 cpl_boolean debug = cpl_parameter_get_bool(
323 cpl_parameterlist_find(parlist,
"gravity.astrometry.wait-for-debugger"));
326 fprintf(stderr,
"PID is: %d\n", getpid());
327 fprintf(stderr,
"Waiting for debugger to attach...\n");
328 volatile int attach = 1;
330 if (attach == 0)
break;
341 double ft_mean_flux_threshold = cpl_parameter_get_double(
342 cpl_parameterlist_find(parlist,
"gravity.astrometry.ft-mean-flux"));
345 cpl_error_get_code()) ;
369 used_frameset = cpl_frameset_new();
372 n_target = cpl_frameset_get_size(target_frameset);
373 tgt_data = cpl_malloc(n_target *
sizeof(
gravi_data*));
374 tgt_astro =
load_data(target_frameset, used_frameset, tgt_data);
375 cpl_msg_debug(cpl_func,
"There are %lld ASTRO_TARGET frames", n_target);
379 n_swap = cpl_frameset_get_size(swap_frameset);
380 swap_data = cpl_malloc(n_swap *
sizeof(
gravi_data*));
381 swap_astro =
load_data(swap_frameset, used_frameset, swap_data);
382 cpl_msg_debug(cpl_func,
"There are %lld ASTRO_SWAP frames", n_swap);
386 n_phaseref = cpl_frameset_get_size(phaseref_frameset);
387 phaseref_astro =
load_data(phaseref_frameset, used_frameset, NULL);
388 cpl_msg_debug(cpl_func,
"There are %lld ASTRO_CAL_PHASEREF frames", n_phaseref);
401 double ft_mean_flux_tgt = 0.0;
402 for (
int i = 0; i < n_target; i++)
404 ft_mean_flux_tgt /= n_target;
405 cpl_msg_debug(cpl_func,
"ftOnPlanetMeanFlux=%f", ft_mean_flux_tgt);
407 double ft_mean_flux_ref = 0.0;
408 for (
int i = 0; i < n_phaseref; i++)
410 ft_mean_flux_ref /= n_phaseref;
411 cpl_msg_debug(cpl_func,
"ftOnStarMeanFlux=%f", ft_mean_flux_ref);
414 for (
int i = 0; i < n_target; i++) {
419 for (
int i = 0; i < n_phaseref; i++) {
424 cpl_msg_info(cpl_func,
"Creating visibility reference from %lld observations", n_phaseref);
425 for (
int i = 0; i < n_target; i++)
429 for (
int i = 0; i < n_target; i++) {
432 frame = cpl_frameset_get_position(target_frameset, i);
435 used_frameset, frame,
"gravity_astrometry",
448 FREE(cpl_frameset_delete, target_frameset);
449 FREE(cpl_frameset_delete, phaseref_frameset);
450 FREE(cpl_frameset_delete, used_frameset);
457 return (
int)cpl_error_get_code();
void gravi_astrometry_delete(astro_data *self)
cpl_error_code gravi_astrometry_create_phase_reference(astro_data *self, astro_data **phase_refs, cpl_size nphase, astro_data **swaps, cpl_size nswap, cpl_parameterlist *parlist)
Compute the final astrometric phase reference.
cpl_table * gravi_astrometry_get_phase_reference(astro_data *self)
double gravi_astrometry_get_mean_ftflux(astro_data *self)
cpl_error_code gravi_astrometry_filter_ftflux(astro_data *self, double threshold)
Filter based on FT flux threshold and normalise.
cpl_error_code gravi_astrometry_normalise_to_ft(astro_data *self)
Normalise visibilities to average FT flux.
astro_data * gravi_astrometry_load(gravi_data *data)
Load data for astrometry from a gravi_data.
cpl_error_code gravi_astrometry_reduce_swaps(astro_data **swap_data, cpl_size nswap, cpl_parameterlist *parlist)
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
#define GRAVI_RECIPE_OUTPUT
#define GRAVI_ASTRO_TARGET
#define GRAVI_RECIPE_FLOW
#define GRAVI_ASTRO_PHASE_CALIBRATED
#define GRAVI_RECIPE_INPUT
#define GRAVI_ASTRO_CAL_PHASEREF
cpl_msg_debug(cpl_func, "Spectra has <50 pixels -> don't flat")
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
#define CPLCHECK_CLEAN(msg)
#define gravi_msg_function_exit(flag)
#define FREE(function, variable)
#define gravi_msg_function_start(flag)
#define FREELOOP(function, variable, n)
static astro_data ** load_data(cpl_frameset *frameset, cpl_frameset *used_frameset, gravi_data **out_data)
Load input astrometric quantities from ASTROREDUCED file(s).
static char gravity_astro_short[]
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int gravity_astrometry_create(cpl_plugin *)
Setup the recipe options
static int gravity_astrometry_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int gravity_astrometry_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int gravity_astrometry(cpl_frameset *, cpl_parameterlist *)
TODO.
static char gravity_astro_description[]
cpl_error_code gravi_data_add_table(gravi_data *self, cpl_propertylist *plist, const char *extname, cpl_table *table)
Add a BINTABLE extension in gravi_data.
gravi_data * gravi_data_load_frame(cpl_frame *frame, cpl_frameset *used_frameset)
Load a FITS file and create a gravi_data.
cpl_error_code gravi_data_save_new(gravi_data *self, cpl_frameset *allframes, const char *filename, const char *suffix, const cpl_parameterlist *parlist, cpl_frameset *usedframes, cpl_frame *frame, const char *recipe, cpl_propertylist *applist, const char *proCatg)
Save a gravi data in a CPL-complian FITS file.
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
cpl_parameter * gravi_parameter_add_static_name(cpl_parameterlist *self)
cpl_error_code gravi_parameter_add_astrometry(cpl_parameterlist *self)
cpl_frameset * gravi_frameset_extract_astro_target(cpl_frameset *frameset)
cpl_frameset * gravi_frameset_extract_astro_swap(cpl_frameset *frameset)
cpl_error_code gravi_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
cpl_frameset * gravi_frameset_extract_astro_phaseref(cpl_frameset *frameset)
void gravity_print_banner(void)
const char * gravi_get_license(void)
Get the pipeline copyright and license.