40 #include "irplib_oddeven.h"
42 #include "isaac_utils.h"
43 #include "isaac_pfits.h"
64 const char * isaac_license =
65 "This file is part of the ISAAC Instrument Pipeline\n"
66 "Copyright (C) 2002,2003 European Southern Observatory\n"
68 "This program is free software; you can redistribute it and/or modify\n"
69 "it under the terms of the GNU General Public License as published by\n"
70 "the Free Software Foundation; either version 2 of the License, or\n"
71 "(at your option) any later version.\n"
73 "This program is distributed in the hope that it will be useful,\n"
74 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
75 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
76 "GNU General Public License for more details.\n"
78 "You should have received a copy of the GNU General Public License\n"
79 "along with this program; if not, write to the Free Software\n"
80 "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, \n"
94 cpl_bivector * offsets;
97 const cpl_frame * frame;
98 cpl_propertylist * plist;
103 if (fset == NULL)
return NULL;
106 nfiles = cpl_frameset_get_size(fset);
107 offsets = cpl_bivector_new(nfiles);
108 offsets_x = cpl_bivector_get_x_data(offsets);
109 offsets_y = cpl_bivector_get_y_data(offsets);
110 for (i=0; i<nfiles; i++) {
111 if (cpl_error_get_code()) {
112 cpl_bivector_delete(offsets);
116 frame = cpl_frameset_get_position_const(fset, i);
117 plist=cpl_propertylist_load(cpl_frame_get_filename(frame),0);
120 cpl_propertylist_delete(plist);
121 if (cpl_error_get_code()) {
122 cpl_msg_error(cpl_func,
"Cannot get offsets from header");
123 cpl_bivector_delete(offsets);
128 for (i=1; i<nfiles; i++) {
129 offsets_x[i] -= offsets_x[0];
130 offsets_y[i] -= offsets_y[0];
132 offsets_x[0] = offsets_y[0] = 0.00;
146 if (!strcmp(f,
"J"))
return ISAAC_BAND_J;
147 if (!strcmp(f,
"J+Block"))
return ISAAC_BAND_J;
148 if (!strcmp(f,
"Js"))
return ISAAC_BAND_J;
149 if (!strcmp(f,
"Z"))
return ISAAC_BAND_J;
150 if (!strcmp(f,
"SZ"))
return ISAAC_BAND_J;
151 if (!strcmp(f,
"SH"))
return ISAAC_BAND_H;
152 if (!strcmp(f,
"H"))
return ISAAC_BAND_H;
153 if (!strcmp(f,
"Ks"))
return ISAAC_BAND_KS;
154 if (!strcmp(f,
"K"))
return ISAAC_BAND_K;
155 if (!strcmp(f,
"SK"))
return ISAAC_BAND_K;
156 if (!strcmp(f,
"L"))
return ISAAC_BAND_L;
157 if (!strcmp(f,
"L-new"))
return ISAAC_BAND_L;
158 if (!strcmp(f,
"SL"))
return ISAAC_BAND_L;
159 if (!strcmp(f,
"M"))
return ISAAC_BAND_M;
160 if (!strcmp(f,
"M_NB"))
return ISAAC_BAND_M;
161 if (!strcmp(f,
"M_NB-new"))
return ISAAC_BAND_M;
162 if (!strcmp(f,
"NB_1.06"))
return ISAAC_BAND_J;
163 if (!strcmp(f,
"NB_1.08"))
return ISAAC_BAND_J;
164 if (!strcmp(f,
"NB_1.19"))
return ISAAC_BAND_J;
165 if (!strcmp(f,
"NB_1.21"))
return ISAAC_BAND_J;
166 if (!strcmp(f,
"NB_1.26"))
return ISAAC_BAND_J;
167 if (!strcmp(f,
"NB_1.28"))
return ISAAC_BAND_J;
168 if (!strcmp(f,
"NB_1.64"))
return ISAAC_BAND_H;
169 if (!strcmp(f,
"NB_1.71"))
return ISAAC_BAND_H;
170 if (!strcmp(f,
"NB_2.07"))
return ISAAC_BAND_KS;
171 if (!strcmp(f,
"NB_2.09"))
return ISAAC_BAND_KS;
172 if (!strcmp(f,
"NB_2.13"))
return ISAAC_BAND_KS;
173 if (!strcmp(f,
"NB_2.17"))
return ISAAC_BAND_KS;
174 if (!strcmp(f,
"NB_2.19"))
return ISAAC_BAND_KS;
175 if (!strcmp(f,
"NB_2.25"))
return ISAAC_BAND_KS;
176 if (!strcmp(f,
"NB_2.29"))
return ISAAC_BAND_KS;
177 if (!strcmp(f,
"NB_2.34"))
return ISAAC_BAND_KS;
178 if (!strcmp(f,
"NB_3.21"))
return ISAAC_BAND_L;
179 if (!strcmp(f,
"NB_3.28"))
return ISAAC_BAND_L;
180 if (!strcmp(f,
"NB_3.80"))
return ISAAC_BAND_L;
181 if (!strcmp(f,
"NB_4.07"))
return ISAAC_BAND_L;
183 (void)cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE,
"%s", f);
185 return ISAAC_BAND_UNKNOWN;
197 if (!strcmp(f,
"J"))
return ISAAC_BAND_J;
198 if (!strcmp(f,
"Js"))
return ISAAC_BAND_JS;
199 if (!strcmp(f,
"Z"))
return ISAAC_BAND_Z;
200 if (!strcmp(f,
"SZ"))
return ISAAC_BAND_SZ;
201 if (!strcmp(f,
"SH"))
return ISAAC_BAND_SH;
202 if (!strcmp(f,
"H"))
return ISAAC_BAND_H;
203 if (!strcmp(f,
"Ks"))
return ISAAC_BAND_KS;
204 if (!strcmp(f,
"K"))
return ISAAC_BAND_K;
205 if (!strcmp(f,
"SK"))
return ISAAC_BAND_SK;
206 if (!strcmp(f,
"L"))
return ISAAC_BAND_L;
207 if (!strcmp(f,
"SL"))
return ISAAC_BAND_SL;
208 if (!strcmp(f,
"M"))
return ISAAC_BAND_M;
209 if (!strcmp(f,
"M_NB"))
return ISAAC_BAND_M;
210 if (!strcmp(f,
"NB_1.06"))
return ISAAC_BAND_J;
211 if (!strcmp(f,
"NB_1.08"))
return ISAAC_BAND_J;
212 if (!strcmp(f,
"NB_1.19"))
return ISAAC_BAND_J;
213 if (!strcmp(f,
"NB_1.21"))
return ISAAC_BAND_J;
214 if (!strcmp(f,
"NB_1.26"))
return ISAAC_BAND_J;
215 if (!strcmp(f,
"NB_1.28"))
return ISAAC_BAND_J;
216 if (!strcmp(f,
"NB_1.64"))
return ISAAC_BAND_H;
217 if (!strcmp(f,
"NB_1.71"))
return ISAAC_BAND_H;
218 if (!strcmp(f,
"NB_2.07"))
return ISAAC_BAND_KS;
219 if (!strcmp(f,
"NB_2.09"))
return ISAAC_BAND_KS;
220 if (!strcmp(f,
"NB_2.13"))
return ISAAC_BAND_KS;
221 if (!strcmp(f,
"NB_2.17"))
return ISAAC_BAND_KS;
222 if (!strcmp(f,
"NB_2.19"))
return ISAAC_BAND_KS;
223 if (!strcmp(f,
"NB_2.25"))
return ISAAC_BAND_KS;
224 if (!strcmp(f,
"NB_2.29"))
return ISAAC_BAND_KS;
225 if (!strcmp(f,
"NB_2.34"))
return ISAAC_BAND_KS;
226 if (!strcmp(f,
"NB_3.21"))
return ISAAC_BAND_L;
227 if (!strcmp(f,
"NB_3.28"))
return ISAAC_BAND_L;
228 if (!strcmp(f,
"NB_3.80"))
return ISAAC_BAND_L;
229 if (!strcmp(f,
"NB_4.07"))
return ISAAC_BAND_L;
231 (void)cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE,
"%s", f);
233 return ISAAC_BAND_UNKNOWN;
246 case ISAAC_BAND_J:
return "J";
247 case ISAAC_BAND_JS:
return "Js";
248 case ISAAC_BAND_JBLOCK:
return "J+Block";
249 case ISAAC_BAND_H:
return "H";
250 case ISAAC_BAND_K:
return "K";
251 case ISAAC_BAND_KS:
return "Ks";
252 case ISAAC_BAND_L:
return "L";
253 case ISAAC_BAND_M:
return "M";
254 case ISAAC_BAND_LP:
return "Lp";
255 case ISAAC_BAND_MP:
return "Mp";
256 case ISAAC_BAND_Z:
return "Z";
257 case ISAAC_BAND_SZ:
return "SZ";
258 case ISAAC_BAND_SH:
return "SH";
259 case ISAAC_BAND_SK:
return "SK";
260 case ISAAC_BAND_SL:
return "SL";
262 (void)cpl_error_set_message(cpl_func, CPL_ERROR_UNSUPPORTED_MODE,
281 cpl_image * quad1_corr;
282 cpl_image * quad2_corr;
283 cpl_image * quad3_corr;
284 cpl_image * quad4_corr;
292 int i, j, pos1, pos2, pos3, pos4;
295 if (in == NULL)
return NULL;
298 nx = cpl_image_get_size_x(in);
299 ny = cpl_image_get_size_y(in);
302 quad1 = cpl_image_extract(in, 1, 1, nx/2, ny/2);
303 quad2 = cpl_image_extract(in, (nx/2)+1, 1, nx, ny/2);
304 quad3 = cpl_image_extract(in, 1, (ny/2)+1, nx/2, ny);
305 quad4 = cpl_image_extract(in, (nx/2)+1, (ny/2)+1, nx, ny);
308 quad1_corr = irplib_oddeven_correct(quad1);
309 quad2_corr = irplib_oddeven_correct(quad2);
310 quad3_corr = irplib_oddeven_correct(quad3);
311 quad4_corr = irplib_oddeven_correct(quad4);
313 cpl_image_delete(quad1);
314 cpl_image_delete(quad2);
315 cpl_image_delete(quad3);
316 cpl_image_delete(quad4);
319 out = cpl_image_duplicate(in);
320 pout = cpl_image_get_data_float(out);
321 pin1 = cpl_image_get_data_float(quad1_corr);
322 pin2 = cpl_image_get_data_float(quad2_corr);
323 pin3 = cpl_image_get_data_float(quad3_corr);
324 pin4 = cpl_image_get_data_float(quad4_corr);
326 for (j=0; j<ny/2; j++) {
327 for (i=0; i<nx/2; i++) {
329 pos2 = (i+(nx/2)) + j * nx;
330 pos3 = i + (j+(ny/2)) * nx;
331 pos4 = (i+(nx/2)) + (j+(ny/2)) * nx;
332 pout[pos1] = pin1[i+j*(nx/2)];
333 pout[pos2] = pin2[i+j*(nx/2)];
334 pout[pos3] = pin3[i+j*(nx/2)];
335 pout[pos4] = pin4[i+j*(nx/2)];
339 cpl_image_delete(quad1_corr);
340 cpl_image_delete(quad2_corr);
341 cpl_image_delete(quad3_corr);
342 cpl_image_delete(quad4_corr);
359 const cpl_size nframes = cpl_frameset_get_size(
self);
360 cpl_frameset * newset = NULL;
363 if (
self == NULL)
return NULL;
364 if (tag == NULL)
return NULL;
366 for (cpl_size i = 0; i < nframes; i++) {
367 const cpl_frame * frame = cpl_frameset_get_position_const(
self, i);
368 const char * mytag = cpl_frame_get_tag(frame);
370 if (mytag != NULL && !strcmp(mytag, tag)) {
371 cpl_frame * newframe = cpl_frame_duplicate(frame);
374 if (newset == NULL) newset = cpl_frameset_new();
376 if (cpl_frameset_insert(newset, newframe)) {
377 cpl_frame_delete(newframe);
378 cpl_frameset_delete(newset);
379 (void)cpl_error_set(cpl_func, cpl_error_get_code());
400 const cpl_frame * frame;
402 if (
self == NULL)
return NULL;
403 if (tag == NULL)
return NULL;
406 frame = cpl_frameset_find_const(
self, tag);
408 return frame == NULL ? NULL : cpl_frame_get_filename(frame);
double isaac_pfits_get_cumoffsety(const cpl_propertylist *plist)
find out the cumulative offset in Y
double isaac_pfits_get_cumoffsetx(const cpl_propertylist *plist)
find out the cumulative offset in X
const char * isaac_extract_filename(const cpl_frameset *self, const char *tag)
Extract the filename of the first frame of the given tag.
const char * isaac_std_band_name(isaac_band band)
Return a band name.
cpl_image * isaac_oddeven_correct(const cpl_image *in)
Correct the odd/even in an image.
isaac_band isaac_get_bbfilter(const char *f)
Get the broad band filter.
cpl_bivector * isaac_get_offsets(const cpl_frameset *fset)
Get the offsets from a set of frames.
cpl_frameset * isaac_extract_frameset(const cpl_frameset *self, const char *tag)
Extract the frames with the given tag from a frameset.
const char * isaac_get_license(void)
Get the pipeline copyright and license.
isaac_band isaac_get_associated_filter(const char *f)
Get the broad band filter.