35 #include "muse_ampl_z.h" 54 char *keyword = cpl_sprintf(
"ESO QC AMPL INPUT%d "QC_BASIC_NSATURATED, k+1);
57 cpl_propertylist_update_int(aImage->
header, keyword, nsaturated);
71 muse_ampl_table_new(
const double aAmpl[][2])
73 cpl_ensure(aAmpl, CPL_ERROR_NULL_INPUT, NULL);
75 while (aAmpl[++i][0] > 0.) n++;
76 cpl_msg_debug(__func__,
"creating table with %d entries", n);
77 cpl_table *tampl = cpl_table_new(n);
78 cpl_table_new_column(tampl,
"lambda", CPL_TYPE_DOUBLE);
79 cpl_table_new_column(tampl,
"throughput", CPL_TYPE_DOUBLE);
80 for (i = 0; i < n; i++) {
81 cpl_table_set_double(tampl,
"lambda", i, aAmpl[i][0]);
82 cpl_table_set_double(tampl,
"throughput", i, aAmpl[i][1]);
85 cpl_table_dump(tampl, 0, 100000, stdout);
107 if (!trace || !wave) {
108 cpl_msg_error(__func__,
"Calibration could not be loaded:%s%s",
109 !trace ?
" "MUSE_TAG_TRACE_TABLE :
"",
110 !wave ?
" "MUSE_TAG_WAVECAL_TABLE :
"");
112 cpl_table_delete(trace);
113 cpl_table_delete(wave);
123 cpl_error_set_message(__func__, cpl_error_get_code(),
124 "Loading and processing raw data failed!");
125 cpl_table_delete(trace);
126 cpl_table_delete(wave);
131 cpars->scale = CPL_TRUE;
135 cpl_msg_error(__func__,
"Combining input frames failed!");
137 cpl_table_delete(trace);
138 cpl_table_delete(wave);
143 muse_ampl_qc_header(image, images);
154 cpl_msg_error(__func__,
"Filter \"%s\" could not be loaded from FILTER_LIST" 161 cpl_table_delete(trace);
162 cpl_table_delete(wave);
164 cpl_msg_error(__func__,
"pixel table was not created: %s",
165 cpl_error_get_message());
171 MUSE_TAG_GEOMETRY_TABLE, 0);
174 ifuarea = pow(fpsize / 10., 2) / kMuseNumIFUs;
180 ifuarea /= pow(kMuseSpaxelSizeX_WFM / kMuseSpaxelSizeX_NFM, 2);
182 cpl_msg_warning(__func__,
"assuming constant per-IFU area of %f cm**2 " 183 "(mode %s)", ifuarea, modestring);
187 cpl_msg_info(__func__,
"computed area of IFU %d in focal plane: %.3f cm**2 " 188 "(mode %s)", aParams->
nifu, ifuarea, modestring);
189 cpl_table_delete(geotable);
211 cpl_table_unselect_all(pt->
table);
212 cpl_msg_debug(__func__,
"Using black body correction with T = %.1f K",
216 double dsum = 0., esum = 0., lwmean = 0., wsum = 0.;
217 cpl_size irow, nrow = cpl_table_get_nrow(pt->
table);
218 for (irow = 0; irow < nrow; irow++) {
222 cpl_table_select_row(pt->
table, irow);
230 stat[irow] = CPL_PHYS_H * CPL_PHYS_C / lbda[irow] * 1e10 * data[irow];
235 double lbda_m = lbda[irow] / 1e10,
236 fb = (CPL_PHYS_H * CPL_PHYS_C) / (CPL_PHYS_K * aParams->
temp * lbda_m),
237 Bn = 15. / lbda_m * pow(fb / CPL_MATH_PI, 4) / (exp(fb) - 1.);
238 wsum += data[irow] / Bn;
239 lwmean += lbda[irow] * data[irow] / Bn;
242 cpl_msg_info(__func__,
"%"CPL_SIZE_FORMAT
" of %"CPL_SIZE_FORMAT
" pixel table " 243 "rows (%.2f%%) unused", cpl_table_count_selected(pt->
table), nrow,
244 100. * cpl_table_count_selected(pt->
table) / nrow);
245 cpl_table_erase_selected(pt->
table);
248 power = esum / exptime;
250 double pdensity = power / ifuarea;
251 cpl_msg_info(__func__,
"Summed flux: %e ph, energy: %e J, power: %e W, power " 252 "density: %e W/cm**2", dsum, esum, power, pdensity);
257 cpl_table *tampl1 = muse_ampl_table_new(kMuseAmpl1),
258 *tampl2 = muse_ampl_table_new(kMuseAmpl2);
261 * kMuseAmplPhysicalSize,
264 * kMuseAmplPhysicalSize;
265 cpl_table_delete(tampl1);
266 cpl_table_delete(tampl2);
267 cpl_msg_info(__func__,
"mean photo diode sensitivities at weighted mean " 268 "wavelength %.2f Angstrom: %f A/W*cm**2, %f A/W*cm**2", lwmean,
271 cpl_msg_debug(__func__,
"using beam widening factor %.3f for photo diode 2",
273 sens2 /= aParams->
fbeam;
277 cpl_errorstate state = cpl_errorstate_get();
280 if (!cpl_errorstate_is_equal(state)) {
281 cpl_msg_error(__func__,
"Pico-amplifier measurement(s) not found in header: %s",
282 cpl_error_get_message());
290 p1density = pam1 / sens1,
291 p2density = pam2 / sens2;
292 cpl_msg_info(__func__,
"amplifiers: AMPL1 %.3e +/- %.3e A, %.2e W/cm**2, " 293 "AMPL2 %.3e +/- %.3e A, %.2e W/cm**2", pam1, pam1stdev,
294 p1density, pam2, pam2stdev, p2density);
301 double thru1 = pdensity / p1density * 100.,
302 thru2 = pdensity / p2density * 100.,
304 filterr = lwmean > 5000 && lwmean < 8000 ? 0.01 : 0.02,
306 thru2err = sqrt(areaerr*areaerr + beamerr*beamerr + filterr*filterr);
307 cpl_msg_info(__func__,
"throughput values: to AMPL1 %.3f %%, to " 308 "AMPL2 %.3f +/- %.3f %%", thru1, thru2, thru2err * thru2);
311 cpl_propertylist_erase_regexp(pt->
header,
"ESO QC", 0);
312 cpl_propertylist_append_float(pt->
header,
"ESO QC AMPL PHOTONS", dsum);
313 cpl_propertylist_append_float(pt->
header,
"ESO QC AMPL POWER", power);
314 cpl_propertylist_append_float(pt->
header,
"ESO QC AMPL THRU1", thru1);
315 cpl_propertylist_append_float(pt->
header,
"ESO QC AMPL THRU2", thru2);
316 cpl_propertylist_append_float(pt->
header,
"ESO QC AMPL THRU2ERR", thru2 * thru2err);
320 double slicearea = ifuarea / kMuseSlicesPerCCD;
321 cpl_msg_warning(__func__,
"assuming constant per-slice area of %f cm**2",
331 * cpl_table_get_nrow(pts[ipt]->table) / exptime,
332 spdensity = spower / slicearea,
333 sthru2 = spdensity / p2density * 100.;
334 char *keyword = cpl_sprintf(
"ESO QC AMPL SLICE%d THRU2", slice);
335 cpl_propertylist_append_float(pt->
header, keyword, sthru2);
337 cpl_msg_info(__func__,
"slice %2d: power %.3e W, throughput %.3f %%",
338 slice, spower, sthru2);
354 cpl_propertylist_copy_property_regexp(outimage->
header, image->
header,
356 cpl_propertylist_copy_property_regexp(outimage->
header, pt->
header,
359 cpl_propertylist_erase_regexp(outimage->
header,
"^ESO DRS MUSE SLICE.* CENTER", 0);
368 "AMPL_CONVOLVED", aParams->
nifu);
369 const char *fn = cpl_frame_get_filename(outframe);
370 cpl_propertylist *hext = cpl_propertylist_new();
371 cpl_propertylist_append_string(hext,
"EXTNAME",
"PHOTONS");
372 cpl_propertylist_set_comment(hext,
"EXTNAME",
"This extension contains photon counts");
373 cpl_propertylist_append_string(hext,
"BUNIT", cpl_table_get_column_unit(pt->
table,
375 cpl_image_save(outimage->
data, fn, CPL_TYPE_UNSPECIFIED, hext, CPL_IO_EXTEND);
376 cpl_propertylist_update_string(hext,
"EXTNAME",
"ENERGY");
377 cpl_propertylist_set_comment(hext,
"EXTNAME",
"This extension contains per-pixel energy");
378 cpl_propertylist_update_string(hext,
"BUNIT", cpl_table_get_column_unit(pt->
table,
380 cpl_image_save(outimage->
stat, fn, CPL_TYPE_UNSPECIFIED, hext, CPL_IO_EXTEND);
382 cpl_propertylist_update_string(hext,
"EXTNAME", EXTNAME_DQ);
383 cpl_propertylist_set_comment(hext,
"EXTNAME", EXTNAME_DQ_COMMENT);
384 cpl_propertylist_erase(hext,
"BUNIT");
385 cpl_image_save(outimage->
dq, fn, CPL_TYPE_UNSPECIFIED, hext, CPL_IO_EXTEND);
387 cpl_frame_delete(outframe);
388 cpl_propertylist_delete(hext);
muse_imagelist * muse_basicproc_load(muse_processing *aProcessing, unsigned char aIFU, muse_basicproc_params *aBPars)
Load the raw input files from disk and do basic processing.
Structure definition for a collection of muse_images.
void muse_image_delete(muse_image *aImage)
Deallocate memory associated to a muse_image object.
void muse_pixtable_extracted_delete(muse_pixtable **aPixtables)
Delete a pixel table array.
unsigned short muse_pixtable_origin_get_slice(uint32_t aOrigin)
Get the slice number from the encoded 32bit origin number.
int nifu
IFU to handle. If set to 0, all IFUs are processed serially. If set to -1, all IFUs are processed in ...
cpl_size muse_pixtable_extracted_get_size(muse_pixtable **aPixtables)
Get the size of an array of extracted pixel tables.
muse_pixtable ** muse_pixtable_extracted_get_slices(muse_pixtable *aPixtable)
Extract one pixel table per IFU and slice.
cpl_image * data
the data extension
Structure to hold the parameters of the muse_ampl recipe.
cpl_image * stat
the statistics extension
double muse_geo_table_ifu_area(const cpl_table *aTable, const unsigned char aIFU, double aScale)
Compute the area of an IFU in the VLT focal plane.
void muse_imagelist_delete(muse_imagelist *aList)
Free the memory of the MUSE image list.
muse_basicproc_params * muse_basicproc_params_new(cpl_parameterlist *aParameters, const char *aPrefix)
Create a new structure of basic processing parameters.
muse_image * muse_combine_images(muse_combinepar *aCPars, muse_imagelist *aImages)
Combine several images into one.
Structure definition of MUSE three extension FITS file.
double muse_pfits_get_focu_scale(const cpl_propertylist *aHeaders)
find out the scale in the VLT focal plane
cpl_table * table
The pixel table.
void muse_basicproc_params_delete(muse_basicproc_params *aBPars)
Free a structure of basic processing parameters.
cpl_propertylist * header
the FITS header
double temp
Lamp temperature [K] used to create the black body function.
#define MUSE_PIXTABLE_DATA
unsigned int muse_imagelist_get_size(muse_imagelist *aList)
Return the number of stored images.
muse_imagelist * muse_pixtable_to_imagelist(muse_pixtable *aPixtable)
Project a pixel table with data from one IFU back onto its image.
void muse_combinepar_delete(muse_combinepar *aCPars)
Clear the combination parameters.
cpl_image * dq
the data quality extension
const char * muse_pfits_get_pam2_filter(const cpl_propertylist *aHeaders)
query the filter set up in front of photo diode (pico amplifier) 2
double muse_flux_response_interpolate(const cpl_table *aResponse, double aLambda, double *aError, muse_flux_interpolation_type aType)
Compute linearly interpolated response of some kind at given wavelength.
cpl_error_code muse_processing_save_header(muse_processing *aProcessing, int aIFU, cpl_propertylist *aHeader, const char *aTag)
Save a FITS header to disk.
Structure definition of MUSE pixel table.
#define MUSE_WCS_KEYS
regular expression for WCS properties
muse_image * muse_imagelist_get(muse_imagelist *aList, unsigned int aIdx)
Get the muse_image of given list index.
double muse_pfits_get_pam_intensity(const cpl_propertylist *aHeaders, int aDiode)
query the intensity measured by one photo diode (pico amplifier)
int savetable
Save the table with all the processed pixel values.
double muse_pfits_get_pam_stdev(const cpl_propertylist *aHeaders, int aDiode)
query the intensity std. dev. of one photo diode (pico amplifier)
cpl_table * table
The table.
muse_combinepar * muse_combinepar_new(cpl_parameterlist *aParameters, const char *aPrefix)
Create a new set of combination parameters.
muse_table * muse_table_load_filter(muse_processing *aProcessing, const char *aFilterName)
Load a table for a given filter name.
Structure to store a table together with a property list.
muse_pixtable * muse_pixtable_create(muse_image *aImage, cpl_table *aTrace, cpl_table *aWave, cpl_table *aGeoTable)
Create the pixel table for one CCD.
void muse_table_delete(muse_table *aTable)
Deallocate memory associated to a muse_table object.
#define MUSE_PIXTABLE_ORIGIN
double fbeam
Factor to describe the widening of the beam from the focal plane to photo diode 2.
int muse_processing_save_image(muse_processing *aProcessing, int aIFU, muse_image *aImage, const char *aTag)
Save a computed MUSE image to disk.
cpl_table * muse_processing_load_ctable(muse_processing *aProcessing, const char *aTag, unsigned char aIFU)
Load a CPL table according to its tag and IFU/channel number.
#define MUSE_PIXTABLE_STAT
#define MUSE_PIXTABLE_LAMBDA
double muse_pfits_get_exptime(const cpl_propertylist *aHeaders)
find out the exposure time
int savemaster
Save the processed and combined master image before any concolution is done.
cpl_error_code muse_processing_save_table(muse_processing *aProcessing, int aIFU, void *aTable, cpl_propertylist *aHeader, const char *aTag, muse_table_type aType)
Save a computed table to disk.
Structure of basic processing parameters.
void muse_pixtable_delete(muse_pixtable *aPixtable)
Deallocate memory associated to a pixel table object.
cpl_error_code muse_pixtable_compute_limits(muse_pixtable *aPixtable)
(Re-)Compute the limits of the coordinate columns of a pixel table.
cpl_frame * muse_frameset_find_master(const cpl_frameset *aFrames, const char *aTag, unsigned char aIFU)
find the master frame according to its CCD number and tag
muse_ins_mode muse_pfits_get_mode(const cpl_propertylist *aHeaders)
find out the observation mode
cpl_parameterlist * parameters
cpl_propertylist * header
The FITS header.
cpl_error_code muse_basicproc_qc_saturated(muse_image *aImage, const char *aPrefix)
Add QC parameter about saturated pixels to a muse_image.