63 #define PRINT_USAGE(rc) \ 64 fprintf(stderr, "Usage: %s [ -x ] [ -f filter,names ] CUBE FILTER_LIST\n", \ 66 cpl_end(); return (rc); 68 int main(
int argc,
char **argv)
70 const char *idstring =
"muse_cube_filter";
71 cpl_init(CPL_INIT_DEFAULT);
72 cpl_msg_set_time_on();
74 cpl_msg_set_level(CPL_MSG_DEBUG);
75 cpl_msg_set_component_on();
76 cpl_errorstate state = cpl_errorstate_get();
83 cpl_array *filters = NULL;
86 cpl_boolean extended = CPL_FALSE;
90 for (i = 1; i < argc; i++) {
91 if (strncmp(argv[i],
"-f", 3) == 0) {
99 }
else if (strncmp(argv[i],
"-x", 3) == 0) {
101 }
else if (strncmp(argv[i],
"-", 1) == 0) {
114 if (!iname || !list) {
119 cpl_msg_info(idstring,
"No filter names given, will use all from \"%s\"",
122 filters = cpl_array_new(0, CPL_TYPE_STRING);
123 cpl_errorstate es = cpl_errorstate_get();
126 cpl_propertylist *header = cpl_propertylist_load(list, iext);
130 if (!cpl_propertylist_has(header,
"EXTNAME")) {
134 cpl_array_set_size(filters, cpl_array_get_size(filters) + 1);
135 cpl_array_set_string(filters, cpl_array_get_size(filters) - 1, extname);
136 cpl_msg_info(idstring,
"Added filter \"%s\"", extname);
137 cpl_propertylist_delete(header);
138 }
while (cpl_errorstate_is_equal(es));
139 cpl_errorstate_set(es);
142 cpl_array_dump(filters, 0, 10000, stdout);
146 cpl_msg_info(idstring,
"Loading cube \"%s\"", iname);
149 cpl_msg_error(idstring,
"MUSE cube could not be loaded from \"%s\"!", iname);
154 int nx = cpl_image_get_size_x(cpl_imagelist_get(cube->
data, 0)),
155 ny = cpl_image_get_size_y(cpl_imagelist_get(cube->
data, 0)),
156 nl = cpl_imagelist_get_size(cube->
data);
157 cpl_msg_info(idstring,
"Loaded cube \"%s\" (%dx%dx%d)", iname, nx, ny, nl);
160 cpl_array *names = cpl_array_new(0, CPL_TYPE_STRING);
161 int idx, n = cpl_array_get_size(filters);
162 for (i = 0, idx = 0; i < n; i++) {
163 const char *fname = cpl_array_get_string(filters, i);
165 if (fname && strncmp(fname,
"white", 6)) {
166 iext = cpl_fits_find_extension(list, fname);
168 cpl_msg_warning(idstring,
"No filter \"%s\" found in table \"%s\"", fname,
172 cpl_msg_info(idstring,
"Integrating over filter \"%s\" (from %s)", fname,
173 MUSE_TAG_FILTER_LIST);
175 ftable->
table = cpl_table_load(list, iext, 1);
176 ftable->
header = cpl_propertylist_load(list, 0);
177 cpl_propertylist *hext = cpl_propertylist_load(list, iext);
178 cpl_propertylist_copy_property_regexp(ftable->
header, hext,
179 "^EXTNAME$|^Z|^COMMENT", 0);
180 cpl_propertylist_delete(hext);
182 cpl_msg_info(idstring,
"Integrating over filter \"%s\" (builtin)", fname);
190 cpl_array_set_size(names, cpl_array_get_size(names) + 1);
191 cpl_array_set_string(names, cpl_array_get_size(names) - 1, fname);
193 cpl_array_delete(filters);
197 cpl_array_dump(names, 0, n, stdout);
204 cpl_errorstate es = cpl_errorstate_get();
206 if (rc == CPL_ERROR_NONE && cpl_errorstate_is_equal(es)) {
207 cpl_msg_info(idstring,
"Appended %d images into cube \"%s\"", n, iname);
209 cpl_msg_error(idstring,
"Appending %d images into cube \"%s\" failed: %s",
210 n, iname, cpl_error_get_message());
214 char *fn = cpl_sprintf(
"%s", iname),
215 *basename = strstr(fn,
".fits");
217 for (i = 0; i < n; i++) {
218 const char *fname = cpl_array_get_string(names, i);
220 char *outname = cpl_sprintf(
"%s_%s.fits", fn, fname);
223 cpl_msg_info(idstring,
"Saved image for filter \"%s\" into \"%s\"", fname,
229 cpl_array_delete(names);
232 if (!cpl_errorstate_is_equal(state)) {
Structure definition of a MUSE datacube.
Structure definition for a collection of muse_images.
const char * muse_pfits_get_extname(const cpl_propertylist *aHeaders)
find out the extension name
muse_datacube * muse_datacube_load(const char *aFilename)
Load header, DATA and optionally STAT and DQ extensions as well as the reconstructed images of a MUSE...
void muse_datacube_delete(muse_datacube *aCube)
Deallocate memory associated to a muse_datacube object.
void muse_imagelist_delete(muse_imagelist *aList)
Free the memory of the MUSE image list.
muse_table * muse_table_new(void)
Allocate memory for a new muse_table object.
Structure definition of MUSE three extension FITS file.
unsigned int muse_imagelist_get_size(muse_imagelist *aList)
Return the number of stored images.
cpl_array * muse_cplarray_new_from_delimited_string(const char *aString, const char *aDelim)
Convert a delimited string into an array of strings.
muse_image * muse_imagelist_get(muse_imagelist *aList, unsigned int aIdx)
Get the muse_image of given list index.
cpl_table * table
The table.
cpl_error_code muse_datacube_save_recimages(const char *aFilename, muse_imagelist *aImages, cpl_array *aNames)
Save reconstructed images of a cube in extra extensions.
void muse_cplerrorstate_dump_some(unsigned aCurrent, unsigned aFirst, unsigned aLast)
Dump some CPL errors.
muse_table * muse_table_load_filter(muse_processing *aProcessing, const char *aFilterName)
Load a table for a given filter name.
cpl_imagelist * data
the cube containing the actual data values
Structure to store a table together with a property list.
void muse_table_delete(muse_table *aTable)
Deallocate memory associated to a muse_table object.
cpl_propertylist * header
the header
cpl_error_code muse_image_save(muse_image *aImage, const char *aFilename)
Save the three image extensions and the FITS headers of a MUSE image to a file.
muse_imagelist * muse_imagelist_new(void)
Create a new (empty) MUSE image list.
muse_image * muse_datacube_collapse(muse_datacube *aCube, const muse_table *aFilter)
Integrate a FITS NAXIS=3 datacube along the wavelength direction.
void muse_processing_recipeinfo(cpl_plugin *)
Output main pipeline configuration, inputs, and parameters.
cpl_error_code muse_imagelist_set(muse_imagelist *aList, muse_image *aImage, unsigned int aIdx)
Set the muse_image of given list index.
cpl_error_code muse_image_dq_to_nan(muse_image *aImage)
Convert pixels flagged in the DQ extension to NANs in DATA (and STAT, if present).