X-shooter Pipeline Reference Manual 3.8.15
xsh_lingain.c
Go to the documentation of this file.
1/* $Id: xsh_lingain.c,v 1.51 2012-12-18 15:25:21 amodigli Exp $
2 *
3 * This file is part of the DETMON Pipeline
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: amodigli $
23 * $Date: 2012-12-18 15:25:21 $
24 * $Revision: 1.51 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32/*----------------------------------------------------------------------------
33 Includes and Defines
34 ----------------------------------------------------------------------------*/
35#include <cpl.h>
36#include "xsh_detmon.h"
37#include "xsh_detmon_lg.h"
38
39//#include "uves_plugin.h"
40//#include "uves_chip_type.h"
41#include "xsh_dfs.h"
42#include "xsh_drl.h"
43#include "xsh_msg.h"
44#include "xsh_error.h"
45#include "xsh_utils.h"
46#include <xsh_data_instrument.h>
47#include "xsh_parameters.h"
48#include "xsh_badpixelmap.h"
49
50/* Define here the DO.CATG keywords */
51
52#define XSH_LINGAIN_ON_RAW(it) ((it) == 0 ? XSH_LINEARITY_UVB_ON : \
53 (it) == 1 ? XSH_LINEARITY_VIS_ON : \
54 (it) == 2 ? XSH_LINEARITY_NIR_ON : \
55 "???")
56
57#define XSH_LINGAIN_OFF_RAW(it) ((it) == 0 ? XSH_LINEARITY_UVB_OFF : \
58 (it) == 1 ? XSH_LINEARITY_VIS_OFF : \
59 (it) == 2 ? XSH_LINEARITY_NIR_OFF : \
60 "???")
61
62#define XSH_LINGAIN_DET_LIN_INFO(it) ((it) == 0 ? XSH_DET_LIN_INFO_UVB : \
63 (it) == 1 ? XSH_DET_LIN_INFO_VIS : \
64 (it) == 2 ? XSH_DET_LIN_INFO_NIR : \
65 "???")
66
67#define XSH_LINGAIN_GAIN_INFO(it) ((it) == 0 ? XSH_GAIN_INFO_UVB : \
68 (it) == 1 ? XSH_GAIN_INFO_VIS : \
69 (it) == 2 ? XSH_GAIN_INFO_NIR : \
70 "???")
71
72#define XSH_LINGAIN_COEFFS_CUBE(it) ((it) == 0 ? XSH_COEFFS_CUBE_UVB : \
73 (it) == 1 ? XSH_COEFFS_CUBE_VIS : \
74 (it) == 2 ? XSH_COEFFS_CUBE_NIR : \
75 "???")
76
77#define XSH_LINGAIN_BP_MAP_NL(it) ((it) == 0 ? XSH_BP_MAP_NL_UVB : \
78 (it) == 1 ? XSH_BP_MAP_NL_VIS : \
79 (it) == 2 ? XSH_BP_MAP_NL_NIR : \
80 "???")
81
82#define XSH_LINGAIN_RAW_BP_MAP_NL(it) ((it) == 0 ? XSH_RAW_BP_MAP_NL_UVB : \
83 (it) == 1 ? XSH_RAW_BP_MAP_NL_VIS : \
84 (it) == 2 ? XSH_RAW_BP_MAP_NL_NIR : \
85 "???")
86
87#define XSH_LINGAIN_AUTOCORR(it) ((it) == 0 ? XSH_AUTOCORR_UVB : \
88 (it) == 1 ? XSH_AUTOCORR_VIS : \
89 (it) == 2 ? XSH_AUTOCORR_NIR : \
90 "???")
91
92#define XSH_LINGAIN_DIFF_FLAT(it) ((it) == 0 ? XSH_DIFF_FLAT_UVB : \
93 (it) == 1 ? XSH_DIFF_FLAT_VIS : \
94 (it) == 2 ? XSH_DIFF_FLAT_NIR : \
95 "???")
96
97#define RECIPE_ID "xsh_lingain"
98#define RECIPE_AUTHOR "Lander de Bilbao,A.Modigliani"
99#define RECIPE_CONTACT "amodigli@eso.org"
100
101/* Copy here instrument specific keywords which need to be in the PAF file */
102#define INSTREGEXP "ESO INS SETUP ID"
103
104#define PAFREGEXP "^(" REGEXP "|" INSTREGEXP ")$"
105#define NIR TRUE
106#define OPT FALSE
107#define XSH_PIX2PIX CPL_TRUE
108#define XSH_EXTS_RED -1
109#define XSH_BPMBIN 1
110#define XSH_TOL 0.1
111/*----------------------------------------------------------------------------
112 Functions prototypes
113 ----------------------------------------------------------------------------*/
114static int xsh_lingain_create(cpl_plugin *);
115static int xsh_lingain_exec(cpl_plugin *);
116static int xsh_lingain_destroy(cpl_plugin *);
117static int
118xsh_lingain(cpl_frameset * frameset,
119 cpl_parameterlist * parlist);
120
121cpl_error_code
122xsh_lingain_fill_parlist_default_opt(cpl_parameterlist * parlist);
123cpl_error_code
124xsh_lingain_fill_parlist_default_nir(cpl_parameterlist * parlist);
125static cpl_error_code
126xsh_lingain_set_saturation_limit(cpl_parameterlist * parlist,
128
129/* AMO: not used.
130static cpl_error_code
131xsh_lingain_pre_format(const cpl_frameset* raws,
132 xsh_instrument* instrument,
133 cpl_frame* bpmap,
134 const int arm_id,
135 cpl_frameset** frameset);
136*/
137/*----------------------------------------------------------------------------
138 Static variables
139 ----------------------------------------------------------------------------*/
140static char xsh_lingain_description_short[] = "Computes detector's gain/linearity-map";
141
143 "This recipe computes detector linearity coefficients and gain\n\
144Input Frames : \n\
145 arm = UVB-VIS: \n\
146 - A set of n RAW linearity frames (Format=RAW, n >=8, Tag = LINEARITY_arm_ON)\n\
147 - A set of n RAW bias frames (Format=RAW, n >=1, Tag = LINEARITY_arm_OFF)\n\
148 arm = NIR:\n\
149 - A set of n RAW linearity on frames (Format=RAW, n >=8, Tag = LINEARITY_arm_ON)\n\
150 - A set of n RAW linearity off frames (Format=RAW, n >=8, Tag = LINEARITY_arm_OFF)\n\
151 - [OPTIONAL] a static bad pixel map (PRO.CATG=BP_MAP_RP_arm) \n\
152 Note: on and off frames are taken in pairs sequence: OFF-ON-ON-OFF, \n\
153 at least 16 frames.\n\
154Products : \n\
155 - A linearity map table, PRO.CATG = BP_MAP_LIN_NIR\n\
156 - A gain table, PRO.CATG = GAIN_INFO\n\
157 - A cube cointaining the linearity coefficients, PRO.CATG = COEFFS_CUBE_arm\n\
158 - A linearity map image (RAW format), PRO.CATG = RAW_BP_MAP_NL_arm\n\
159 - A linearity map image (PRE format), PRO.CATG = BP_MAP_NL_arm\n";
160
161/*----------------------------------------------------------------------------
162 Functions code
163 ----------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
175int cpl_plugin_get_info(cpl_pluginlist * list)
176{
177 cpl_recipe *recipe = NULL;
178 cpl_plugin *plugin = NULL;
179
180 recipe = cpl_calloc(1, sizeof(*recipe));
181 if (recipe == NULL) {
182 return -1;
183 }
184
185 plugin = &recipe->interface;
186
187 cpl_plugin_init(plugin, CPL_PLUGIN_API, /* Plugin API */
188 XSH_BINARY_VERSION, /* Plugin version */
189 CPL_PLUGIN_TYPE_RECIPE, /* Plugin type */
190 RECIPE_ID, /* Plugin name */
191 xsh_lingain_description_short, /* Short help */
192 xsh_lingain_description, /* Detailed help */
193 RECIPE_AUTHOR, /* Author name */
194 RECIPE_CONTACT, /* Contact address */
195 xsh_get_license(), /* Copyright */
199
200 cpl_pluginlist_append(list, plugin);
201
202 return (cpl_error_get_code() != CPL_ERROR_NONE);
203}
204
205/*---------------------------------------------------------------------------*/
215/*--------------------------------------------------------------------------*/
216
217static int xsh_lingain_create(cpl_plugin * plugin)
218{
219 cpl_recipe *recipe = NULL;
220 /* Reset library state */
221 xsh_init();
222
223 /* Check input */
224 assure(plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
225
226 /* Get the recipe out of the plugin */
227 assure(cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
228 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
229
230 recipe = (cpl_recipe *) plugin;
231
232 /* Create the parameter list in the cpl_recipe object */
233 recipe->parameters = cpl_parameterlist_new();
234 assure(recipe->parameters != NULL,
235 CPL_ERROR_ILLEGAL_OUTPUT, "Memory allocation failed!");
236
237 /* Set generic parameters (common to all recipes) */
238 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
239 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
240 check(xsh_lingain_fill_parlist_default_opt(recipe->parameters));
241
242 cleanup:
243 if (cpl_error_get_code() != CPL_ERROR_NONE) {
244 xsh_error_dump(CPL_MSG_ERROR);
245 return 1;
246 } else {
247 return 0;
248 }
249}
250
251
252/*---------------------------------------------------------------------------*/
258/*---------------------------------------------------------------------------*/
259
260static int xsh_lingain_exec(cpl_plugin * plugin)
261{
262 cpl_recipe *recipe = NULL;
263
264 /* Check parameter */
265 assure(plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
266
267 /* Get the recipe out of the plugin */
268 assure(cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
269 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
270
271 recipe = (cpl_recipe *) plugin;
272
273 /* Check recipe */
274 xsh_lingain(recipe->frames,recipe->parameters);
275
276 cleanup:
277 if (cpl_error_get_code() != CPL_ERROR_NONE) {
278 xsh_error_dump(CPL_MSG_ERROR);
279 cpl_error_reset();
280 return 1;
281 } else {
282 return 0;
283 }
284}
285
286/*---------------------------------------------------------------------------*/
292/*---------------------------------------------------------------------------*/
293static int xsh_lingain_destroy(cpl_plugin * plugin)
294{
295 cpl_recipe *recipe = NULL;
296
298 /* Check parameter */
299 assure(plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
300
301 /* Get the recipe out of the plugin */
302 assure(cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
303 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
304
305 recipe = (cpl_recipe *) plugin;
306
307 xsh_free_parameterlist(&recipe->parameters);
308
309 cleanup:
310 if (cpl_error_get_code() != CPL_ERROR_NONE) {
311 return 1;
312 } else {
313 return 0;
314 }
315}
316
317static cpl_error_code
318xsh_params_set_defaults(cpl_parameterlist* pars,
319 xsh_instrument* inst)
320{
321 cpl_parameter* p=NULL;
322
324
325 p=cpl_parameterlist_find(pars, "xshoo.xsh_lingain.kappa");
326
328 //if( fabs(val-def) > DBL_MIN ) {
329 /* if the user has not set the parameter use default */
330 cpl_parameter_set_double(p,5.);
331 }
332 }
333
334 //cleanup:
335
336 return cpl_error_get_code();
337
338}
339
340/*---------------------------------------------------------------------------*/
341/*
342 @brief Interpret the command line options and execute the data processing
343 @param frameset the frames list
344 @param parlist the parameters list
345 @return 0 if everything is ok
346*/
347/*---------------------------------------------------------------------------*/
348
349static int
350xsh_lingain(cpl_frameset * frameset,
351 cpl_parameterlist * parlist)
352{
353
354 const char* recipe_tags[6] = {XSH_LINEARITY_UVB_ON,XSH_LINEARITY_UVB_OFF,
357 int recipe_tags_size = 6;
358
359 cpl_error_code error=0;
360 int processed=0;
361 cpl_parameterlist* plist=NULL;
363 cpl_frameset* raws=NULL;
364 cpl_frameset* calib=NULL;
365 cpl_frameset* pros=NULL;
366
367 cpl_propertylist * lintbl = NULL;
368 cpl_propertylist * gaintbl = NULL;
369 cpl_propertylist * coeffscube = NULL;
370 cpl_propertylist * bpm = NULL;
371 cpl_propertylist * corr = NULL;
372 cpl_propertylist * diff_flat =NULL;
373 cpl_frame* bpmap_nl=NULL;
374 cpl_image* ima=NULL;
375 char name[256];
376 cpl_propertylist* head=NULL;
377 cpl_frame *bpmap = NULL;
378 cpl_frame* coadd_bp_map=NULL;
379 cpl_image* crox=NULL;
380
381
382 char* bp_nl_tag=NULL;
383 char* bp_nl_name=NULL;
384 xsh_pre* pre_bp_nl = NULL;
385 cpl_frame* bp_nl_frame = NULL;
386
387
388 /**************************************************************************/
389 /* DFS management */
390 /**************************************************************************/
391 check( xsh_begin( frameset, parlist, &instrument, &raws, &calib,
392 recipe_tags, recipe_tags_size,
393 RECIPE_ID, XSH_BINARY_VERSION,
395 if((bpmap=xsh_find_frame_with_tag(calib,XSH_BP_MAP_RP,instrument))==NULL) {
396 xsh_msg("%s not provided",XSH_BP_MAP_RP);
397 }
398 check(plist=xsh_parameterlist_duplicate(parlist));
399
401
402 //xsh_lingain_pre_format(raws,instrument,bpmap,2,&frameset);
403
406
407 processed++;
408
409 lintbl=xsh_detmon_fill_prolist("DET_LIN_INFO_NIR","TYPE","TECH",CPL_FALSE);
410
411 gaintbl=xsh_detmon_fill_prolist("GAIN_INFO_NIR","TYPE","TECH",CPL_FALSE);
412
413 coeffscube=xsh_detmon_fill_prolist("COEFFS_CUBE_NIR","TYPE","TECH",CPL_FALSE);
414
415 bpm=xsh_detmon_fill_prolist("RAW_BP_MAP_NL_NIR","TYPE","TECH",CPL_FALSE);
416
417 corr=xsh_detmon_fill_prolist("AUTOCORR_NIR","TYPE","TECH",CPL_FALSE);
418
419 diff_flat=xsh_detmon_fill_prolist("DIFF_FLAT_NIR","TYPE","TECH",CPL_FALSE);
420
421 check(error = xsh_detmon_lg(raws,
422 plist,
425 RECIPE_ID,
426 "xshoo",
427 PAFREGEXP,
428 lintbl,
429 gaintbl,
430 coeffscube,
431 bpm,
432 corr,
433 diff_flat,
434 PACKAGE "/" PACKAGE_VERSION,
435 NULL, NULL, NIR));
436
438
439 //xsh_lingain_pre_format(raws,instrument,bpmap,0,&frameset);
440
444
445 processed++;
446
447 lintbl=xsh_detmon_fill_prolist("DET_LIN_INFO_UVB","TYPE","TECH",CPL_FALSE);
448
449 gaintbl=xsh_detmon_fill_prolist("GAIN_INFO_UVB","TYPE","TECH",CPL_FALSE);
450
451 coeffscube=xsh_detmon_fill_prolist("COEFFS_CUBE_UVB","TYPE","TECH",CPL_FALSE);
452
453 bpm=xsh_detmon_fill_prolist("RAW_BP_MAP_NL_UVB","TYPE","TECH",CPL_FALSE);
454
455 corr=xsh_detmon_fill_prolist("AUTOCORR_UVB","TYPE","TECH",CPL_FALSE);
456
457 diff_flat=xsh_detmon_fill_prolist("DIFF_FLAT_UVB","TYPE","TECH",CPL_FALSE);
458 check(error = xsh_detmon_lg(raws,
459 plist,
462 RECIPE_ID,
463 "xshoo",
464 PAFREGEXP,
465 lintbl,
466 gaintbl,
467 coeffscube,
468 bpm,
469 corr,
470 diff_flat,
471 PACKAGE "/" PACKAGE_VERSION,
472 NULL, NULL, OPT));
473
474
475
477
478 //xsh_lingain_pre_format(raws,instrument,bpmap,1,&frameset);
479
481
483
484 processed++;
485
486 lintbl=xsh_detmon_fill_prolist("DET_LIN_INFO_VIS","TYPE","TECH",CPL_FALSE);
487
488 gaintbl=xsh_detmon_fill_prolist("GAIN_INFO_VIS","TYPE","TECH",CPL_FALSE);
489
490 coeffscube=xsh_detmon_fill_prolist("COEFFS_CUBE_VIS","TYPE","TECH",CPL_FALSE);
491
492 bpm=xsh_detmon_fill_prolist("RAW_BP_MAP_NL_VIS","TYPE","TECH",CPL_FALSE);
493
494 corr=xsh_detmon_fill_prolist("AUTOCORR_VIS","TYPE","TECH",CPL_FALSE);
495
496 diff_flat=xsh_detmon_fill_prolist("DIFF_FLAT_VIS","TYPE","TECH",CPL_FALSE);
497
498 check(error = xsh_detmon_lg(raws,
499 plist,
502 RECIPE_ID,
503 "xshoo",
504 PAFREGEXP,
505 lintbl,
506 gaintbl,
507 coeffscube,
508 bpm,
509 corr,
510 diff_flat,
511 PACKAGE "/" PACKAGE_VERSION,
512 NULL, NULL, OPT));
513
514
515
516 }
517
518 pros=cpl_frameset_new();
520 check(xsh_frameset_merge(frameset,pros));
521 xsh_free_frameset(&pros);
523
524 /* special put in PRE format */
525 check( pre_bp_nl = xsh_pre_create(bpmap_nl , NULL, NULL, instrument,0,CPL_FALSE));
526 bp_nl_tag=cpl_sprintf("%s_%s",XSH_BP_MAP_NL,
528 bp_nl_name=cpl_sprintf("%s.fits",bp_nl_tag);
529 check( bp_nl_frame = xsh_pre_save( pre_bp_nl, bp_nl_name,bp_nl_tag,1 ));
530 cpl_frameset_insert(frameset, bp_nl_frame);
531
532
533 check(sprintf(name,cpl_frame_get_filename(bp_nl_frame)));
534 check(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
535 check(head=cpl_propertylist_load(name,0));
536 cpl_propertylist_erase_regexp(head, "NPIXSAT",0);
537 cpl_propertylist_erase_regexp(head, "FPIXSAT",0);
539 /* Flag NIR bad pixels with a crox */
542 check(cpl_image_save(crox,name,CPL_BPP_IEEE_FLOAT,head,CPL_IO_DEFAULT));
543 xsh_free_image(&crox);
544 } else {
545 check(cpl_image_save(ima,name,CPL_BPP_IEEE_FLOAT,head,CPL_IO_DEFAULT));
546 }
547 xsh_free_image(&ima);
549
550/* Reflex analisis decided to remove generation of MASTER_BP_MAP_ARM
551 if(bpmap!=NULL) {
552 xsh_msg( "Master bp map is bit-wise OR combination of input with non-linear pixels" ) ;
553 check(coadd_bp_map=cpl_frame_duplicate(bpmap));
554 sprintf(name,cpl_frame_get_filename(bpmap));
555 } else {
556 xsh_msg( "Master bp map is given by non-linear pixels" ) ;
557 check(coadd_bp_map=cpl_frame_duplicate(bp_nl_frame));
558 sprintf(name,cpl_frame_get_filename(bp_nl_frame));
559 }
560 check(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
561 check(head=cpl_propertylist_load(name,0));
562 check(pro_catg=XSH_GET_TAG_FROM_ARM(XSH_MASTER_BP_MAP_NLIN,instrument));
563 sprintf(name,"%s.fits",pro_catg);
564 check(cpl_image_save(ima,name,CPL_BPP_IEEE_FLOAT,head,CPL_IO_DEFAULT));
565 xsh_free_image(&ima);
566 xsh_free_propertylist(&head);
567
568
569 if(bpmap!=NULL) {
570 check(xsh_badpixelmap_coadd(coadd_bp_map,bp_nl_frame));
571 }
572 check(cpl_frame_set_tag(coadd_bp_map,pro_catg));
573 check( xsh_add_product_bpmap(coadd_bp_map, frameset, parlist,
574 RECIPE_ID, instrument, NULL ));
575
576 xsh_free_frame(&coadd_bp_map);
577*/
578
579
580 if(processed>0) {
581 /* Propagate the error, if any */
582 cpl_ensure_code(!error, error);
583 } else {
584 xsh_msg("No data has been processed.");
585 xsh_msg("Pls check if input frame set contains valid tags");
586 }
587
588
589 cleanup:
590
591 xsh_free_frame(&coadd_bp_map);
592 xsh_free_frameset(&pros);
593 xsh_free_image(&ima);
595 xsh_free_propertylist(&lintbl);
596 xsh_free_propertylist(&gaintbl);
597 xsh_free_propertylist(&coeffscube);
600 xsh_free_propertylist(&diff_flat);
601 xsh_pre_free(&pre_bp_nl);
602 return CPL_ERROR_NONE;
603}
604
605/* AMO not used
606static cpl_error_code
607xsh_lingain_pre_format(const cpl_frameset* raws,
608 xsh_instrument* instrument,
609 cpl_frame* bpmap,
610 const int arm_id,
611 cpl_frameset** frameset)
612{
613
614 cpl_frameset* lin_pre_set=NULL;
615 cpl_frameset* bias_pre_set=NULL;
616 cpl_frameset* bias_set=NULL;
617 cpl_frameset* lin_set=NULL;
618
619 cpl_frame* frm=NULL;
620 int pre_overscan_corr=0;
621
622
623 int i=0;
624 int n=0;
625
626
627 check(bias_set=xsh_frameset_extract(*frameset,XSH_LINGAIN_OFF_RAW(arm_id)));
628 check(lin_set=xsh_frameset_extract(raws,XSH_LINGAIN_ON_RAW(arm_id)));
629
630 check(xsh_prepare(lin_set, bpmap, NULL, XSH_LINEARITY, instrument,pre_overscan_corr,CPL_TRUE));
631 check(lin_pre_set=xsh_frameset_extract_pre(lin_set,XSH_LINEARITY));
632 xsh_free_frameset(&lin_set);
633
634 check(xsh_prepare(bias_set, bpmap, NULL, XSH_BIAS, instrument,pre_overscan_corr,CPL_TRUE));
635 check(bias_pre_set=xsh_frameset_extract_pre(bias_set,XSH_BIAS));
636 xsh_free_frameset(&bias_set);
637
638 check(n=cpl_frameset_get_size(bias_pre_set));
639 xsh_free_frameset(frameset);
640 *frameset=cpl_frameset_new();
641 for(i=0;i<n;i++) {
642 check(frm=cpl_frameset_get_frame(bias_pre_set,i));
643 check(cpl_frameset_insert(*frameset,cpl_frame_duplicate(frm)));
644 }
645
646 check(n=cpl_frameset_get_size(lin_pre_set));
647 for(i=0;i<n;i++) {
648 check(frm=cpl_frameset_get_frame(lin_pre_set,i));
649 check(cpl_frameset_insert(*frameset,cpl_frame_duplicate(frm)));
650 }
651
652 cleanup:
653
654 xsh_free_frameset(&bias_set);
655 xsh_free_frameset(&lin_set);
656
657 xsh_free_frameset(&bias_pre_set);
658 xsh_free_frameset(&lin_pre_set);
659
660 return cpl_error_get_code();
661
662}
663*/
664
665cpl_error_code
666xsh_lingain_fill_parlist_default_opt(cpl_parameterlist * parlist)
667{
668
669 cpl_error_code error =
671 cpl_parameter * p;
672
673 cpl_ensure_code(!error, error);
674
675 /* FIXME: Put the parameter names and their new default values in two arrays
676 and iterate through them */
677 p = cpl_parameterlist_find(parlist, PACKAGE "." RECIPE_ID ".pix2pix");
678
679 cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
680
681 error = cpl_parameter_set_default_bool(p, XSH_PIX2PIX);
682
683 p = cpl_parameterlist_find(parlist, PACKAGE "." RECIPE_ID ".tolerance");
684
685 cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
686
687 error = cpl_parameter_set_default_double(p, XSH_TOL);
688
689 cpl_ensure_code(!error, error);
690
691 return CPL_ERROR_NONE;
692}
693
694
695cpl_error_code
696xsh_lingain_fill_parlist_default_nir(cpl_parameterlist * parlist)
697{
698
699
700
701 cpl_error_code error =
703 PACKAGE_TARNAME);
704 cpl_parameter * p;
705
706 cpl_ensure_code(!error, error);
707
708
709 p = cpl_parameterlist_find(parlist, PACKAGE_TARNAME "." RECIPE_ID ".bpmbin");
710
711 cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
712
713 error = cpl_parameter_set_default_bool(p, XSH_BPMBIN);
714
715 cpl_ensure_code(!error, error);
716
717
718 return CPL_ERROR_NONE;
719
720}
721
722
723
724static cpl_error_code
725xsh_lingain_set_saturation_limit(cpl_parameterlist * parlist,
727{
728
729 cpl_error_code error =0;
730 cpl_parameter * p;
731 double val=0;
732 double thresh_max=65000; /* UVB/VIS */
733
735 thresh_max=42000;
736 }
737
738 cpl_ensure_code(!error, error);
739
740 p = cpl_parameterlist_find(parlist, PACKAGE "." RECIPE_ID ".saturation_limit");
741
742 cpl_ensure_code(p != NULL, CPL_ERROR_DATA_NOT_FOUND);
743 val=cpl_parameter_get_double(p);
744
745 if( fabs(val+1.) < 0.00001) {
746 error = cpl_parameter_set_default_double(p, thresh_max);
747 }
748 cpl_ensure_code(!error, error);
749
750 return CPL_ERROR_NONE;
751
752}
753
static xsh_instrument * instrument
cpl_image * xsh_image_flag_bptype_with_crox(cpl_image *ima)
void xsh_bpmap_bitwise_to_flag(cpl_image *bpmap, int flag)
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
Definition: xsh_data_pre.c:823
xsh_pre * xsh_pre_create(cpl_frame *raw, cpl_frame *bpmap, cpl_image *bias_data, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
Create a XSH_PRE from a raw frame.
Definition: xsh_data_pre.c:450
cpl_frame * xsh_pre_save(const xsh_pre *pre, const char *filename, const char *tag, int temp)
Save PRE on disk.
#define assure(CONDITION, ERROR_CODE,...)
Definition: xsh_error.h:54
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_dump(level)
Definition: xsh_error.h:92
#define xsh_error_reset()
Definition: xsh_error.h:87
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
void xsh_free_parameterlist(cpl_parameterlist **p)
Deallocate a parameter list and set the pointer to NULL.
Definition: xsh_utils.c:2224
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
Definition: xsh_utils.c:2116
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
Definition: xsh_utils.c:2269
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
Definition: xsh_utils.c:2254
const char * xsh_get_license(void)
Get the pipeline copyright and license.
Definition: xsh_utils.c:1193
void xsh_init(void)
Reset library state.
Definition: xsh_utils.c:1160
cpl_error_code xsh_begin(cpl_frameset *frames, const cpl_parameterlist *parameters, xsh_instrument **instrument, cpl_frameset **raws, cpl_frameset **calib, const char *tag_list[], int tag_list_size, const char *recipe_id, unsigned int binary_version, const char *short_descr)
Recipe initialization.
Definition: xsh_utils.c:1244
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
cpl_parameterlist * xsh_parameterlist_duplicate(const cpl_parameterlist *pin)
Extract frames with given tag from frameset.
Definition: xsh_utils.c:771
#define QFLAG_NON_LINEAR_PIXEL
@ XSH_ARM_UVB
@ XSH_ARM_NIR
@ XSH_ARM_VIS
cpl_propertylist * xsh_detmon_fill_prolist(const char *procatg, const char *protype, const char *protech, cpl_boolean proscience)
Definition: xsh_detmon.c:291
cpl_error_code xsh_detmon_lg_fill_parlist_opt_default(cpl_parameterlist *parlist, const char *recipe_name, const char *pipeline_name)
Parlist filling with OPT required parameters and its default values.
cpl_error_code xsh_detmon_lg_fill_parlist_nir_default(cpl_parameterlist *parlist, const char *recipe_name, const char *pipeline_name)
Parlist filling with NIR required parameters and its default values.
cpl_error_code xsh_detmon_lg(cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *tag_on, const char *tag_off, const char *recipe_name, const char *pipeline_name, const char *pafregexp, const cpl_propertylist *pro_lintbl, const cpl_propertylist *pro_gaintbl, const cpl_propertylist *pro_coeffscube, const cpl_propertylist *pro_bpm, const cpl_propertylist *pro_corr, const cpl_propertylist *pro_diff, const char *package, int(*compare)(const cpl_frame *, const cpl_frame *), int(*load_fset)(const cpl_frameset *, cpl_type, cpl_imagelist *), const cpl_boolean opt_nir)
cpl_error_code xsh_frameset_merge(cpl_frameset *set1, cpl_frameset *set2)
Extracts raw frames.
Definition: xsh_dfs.c:1014
int xsh_parameter_get_default_flag(const cpl_parameter *p)
Check if an input parameter has been changed by the user.
Definition: xsh_dfs.c:115
cpl_error_code xsh_dfs_extract_pro_frames(cpl_frameset *input, cpl_frameset *pros)
split input sof in groups: raw and calib
Definition: xsh_dfs.c:1173
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
Definition: xsh_dfs.c:3347
#define XSH_LINEARITY_VIS_OFF
Definition: xsh_dfs.h:389
#define XSH_LINEARITY_NIR_ON
Definition: xsh_dfs.h:390
#define XSH_LINEARITY_UVB_OFF
Definition: xsh_dfs.h:387
#define XSH_BP_MAP_RP
Definition: xsh_dfs.h:355
#define XSH_LINEARITY_NIR_OFF
Definition: xsh_dfs.h:391
#define XSH_LINEARITY_UVB_ON
Definition: xsh_dfs.h:386
#define XSH_RAW_BP_MAP_NL
Definition: xsh_dfs.h:365
#define XSH_LINEARITY_VIS_ON
Definition: xsh_dfs.h:388
#define XSH_BP_MAP_NL
Definition: xsh_dfs.h:360
static char xsh_lingain_description_short[]
Definition: xsh_lingain.c:140
#define RECIPE_CONTACT
Definition: xsh_lingain.c:99
cpl_error_code xsh_lingain_fill_parlist_default_opt(cpl_parameterlist *parlist)
Definition: xsh_lingain.c:666
#define OPT
Definition: xsh_lingain.c:106
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
Definition: xsh_lingain.c:175
static char xsh_lingain_description[]
Definition: xsh_lingain.c:142
#define XSH_BPMBIN
Definition: xsh_lingain.c:109
static int xsh_lingain(cpl_frameset *frameset, cpl_parameterlist *parlist)
Definition: xsh_lingain.c:350
cpl_error_code xsh_lingain_fill_parlist_default_nir(cpl_parameterlist *parlist)
Definition: xsh_lingain.c:696
#define PAFREGEXP
Definition: xsh_lingain.c:104
static cpl_error_code xsh_lingain_set_saturation_limit(cpl_parameterlist *parlist, xsh_instrument *instrument)
Definition: xsh_lingain.c:725
static int xsh_lingain_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
Definition: xsh_lingain.c:260
#define XSH_PIX2PIX
Definition: xsh_lingain.c:107
#define NIR
Definition: xsh_lingain.c:105
static int xsh_lingain_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
Definition: xsh_lingain.c:293
#define RECIPE_ID
Definition: xsh_lingain.c:97
#define RECIPE_AUTHOR
Definition: xsh_lingain.c:98
#define XSH_TOL
Definition: xsh_lingain.c:110
static cpl_error_code xsh_params_set_defaults(cpl_parameterlist *pars, xsh_instrument *inst)
Definition: xsh_lingain.c:318
static int xsh_lingain_create(cpl_plugin *)
Setup the recipe options.
Definition: xsh_lingain.c:217
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)