31#include "moo_create_s1d.h"
34#include "moo_badpix.h"
51_moo_create_s1d_single(moo_sci_single *sci_single,
57 cpl_propertylist *sci_header)
59 cpl_propertylist *pheader = NULL;
60 cpl_propertylist *header = NULL;
61 cpl_table *data = NULL;
62 cpl_image *iflux = NULL;
63 cpl_image *ierr = NULL;
64 cpl_image *isky = NULL;
65 moo_s1d *result = NULL;
67 cpl_ensure(sci_single != NULL, CPL_ERROR_NULL_INPUT, NULL);
71 char *filename = cpl_strdup(sci_single->filename);
73 char *basename = strrchr(filename,
'/');
74 if (basename == NULL) {
78 basename = basename + 1;
80 int len = strlen(basename);
81 basename[len - 5] =
'\0';
83 cpl_sprintf(
"%s_%s_%s.fits", basename, sci_single->extname, targname);
84 pheader = cpl_propertylist_duplicate(sci_header);
87 cpl_propertylist_set_double(pheader, MOO_PFITS_EXPTIME, exptime);
89 result->primary_header = pheader;
90 header = cpl_propertylist_duplicate(sci_single->header);
91 result->header = header;
96 double wmin = crval1 + (1 - crpix1) * cd1_1;
97 double wmax = crval1 + (naxis1 - crpix1) * cd1_1;
98 cpl_propertylist_set_string(header, MOO_PFITS_EXTNAME,
99 MOO_S1D_SPETCRUM_EXTNAME);
100 cpl_propertylist_append_string(header,
"VOCLASS",
"SPECTRUM v2.0");
101 cpl_propertylist_append_double(header,
"TDMIN", wmin);
102 cpl_propertylist_append_double(header,
"TDMAX", wmax);
103 cpl_propertylist_append_string(header,
"TUTYP1",
104 "spec:Data.SpectralAxis.Value");
105 cpl_propertylist_append_string(header,
"TUCD1",
"em.wl;obs.atmos");
106 cpl_propertylist_append_string(header,
"TUTYP2",
107 "spec:Data.FluxAxis.Value");
108 cpl_propertylist_append_string(header,
"TUCD2",
109 "phot.flux.density;em.wl;src.net;meta.main");
110 cpl_propertylist_append_string(header,
"TUTYP3",
111 "Spectrum.Data.FluxAxis.Accuracy.StatError");
112 cpl_propertylist_append_string(header,
"TUCD3",
113 "phot.flux.density;em.wl;src.net;meta.main");
114 cpl_propertylist_append_string(header,
"TUTYP4",
115 "meta.code.qual;meta.main");
116 cpl_propertylist_append_string(header,
"TUCD4",
117 "spec:Data.FluxAxis.Accuracy.QualityStatus");
118 cpl_propertylist_append_string(header,
"TUTYP5",
119 "spec:Data.FluxAxis.Value");
120 cpl_propertylist_append_string(header,
"TUCD5",
121 "phot.flux.density;em.wl;src.net;meta.main");
122 data = cpl_table_new(naxis1);
124 moo_try_check(cpl_table_new_column(data, MOO_S1D_WAVE, CPL_TYPE_DOUBLE),
126 moo_try_check(cpl_table_new_column(data, MOO_S1D_FLUX, CPL_TYPE_DOUBLE),
128 moo_try_check(cpl_table_new_column(data, MOO_S1D_ERR, CPL_TYPE_DOUBLE),
130 moo_try_check(cpl_table_new_column(data, MOO_S1D_QUAL, CPL_TYPE_INT),
" ");
132 moo_try_check(cpl_table_new_column(data, MOO_S1D_BGFLUX, CPL_TYPE_DOUBLE),
135 iflux = hdrl_image_get_image(himg);
136 ierr = hdrl_image_get_error(himg);
140 for (
int i = 1; i <= naxis1; i++) {
142 double flux = cpl_image_get(iflux, i, indextarg, &rej);
143 double err = cpl_image_get(ierr, i, indextarg, &rej);
144 int qual = (int)cpl_image_get(iqual, i, indextarg, &rej);
145 double sky = cpl_image_get(isky, i, indextarg, &rej);
146 cpl_table_set_double(data, MOO_S1D_WAVE, i - 1,
147 crval1 + (i - crpix1) * cd1_1);
148 cpl_table_set_double(data, MOO_S1D_FLUX, i - 1, flux);
149 cpl_table_set_double(data, MOO_S1D_ERR, i - 1, err);
150 cpl_table_set_int(data, MOO_S1D_QUAL, i - 1, qual);
151 cpl_table_set_double(data, MOO_S1D_BGFLUX, i - 1, sky);
178 moo_create_s1d_params *params,
180 moo_products *products)
183 cpl_ensure_code(sci_frame != NULL, CPL_ERROR_NULL_INPUT);
184 cpl_ensure_code(params != NULL, CPL_ERROR_NULL_INPUT);
188 cpl_errorstate prestate = cpl_errorstate_get();
189 cpl_msg_info(__func__,
"Create S1D");
191 if (params->do_s1d) {
193 cpl_table *table = ttable->table;
194 int nrow = cpl_table_get_nrow(table);
196 for (
int t = 0; t < nrow; t++) {
198 cpl_table_get_int(table, MOO_TARGET_TABLE_INDEXTARG, t, NULL);
199 const char *targname =
200 cpl_table_get_string(table, MOO_TARGET_TABLE_TARGNAME, t);
202 cpl_table_get_double(table, MOO_TARGET_TABLE_TARGALPHA, t,
205 cpl_table_get_double(table, MOO_TARGET_TABLE_TARGDELTA, t,
207 for (
int j = 0; j < 3; j++) {
210 if (sci_single != NULL) {
214 s1d = _moo_create_s1d_single(sci_single, indextarg,
215 targname, talpha, tdelta,
216 exptime, sci->primary_header);
218 if (products != NULL) {
230 if (!cpl_errorstate_is_equal(prestate)) {
231 cpl_msg_error(__func__,
"Error in create_s1d");
232 cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one);
235 return CPL_ERROR_NONE;
moo_s1d * moo_s1d_new(void)
Create a new moo_cube.
void moo_s1d_save(moo_s1d *self)
Save a moo_s1d to a FITS file.
void moo_s1d_delete(moo_s1d *self)
Delete a moo_s1d.
cpl_image * moo_sci_single_get_sky(moo_sci_single *self)
Get sky of sci single.
hdrl_image * moo_sci_single_get_image(moo_sci_single *self)
Get image of SCI_SINGLE.
cpl_image * moo_sci_single_get_qual(moo_sci_single *self)
Get image of qual.
moo_sci_single * moo_sci_load_single(moo_sci *self, moo_detector_type type, int level)
Load the type part in SCI and return it.
void moo_sci_delete(moo_sci *self)
Delete a moo_sci.
moo_sci * moo_sci_create(const cpl_frame *frame)
Create a new empty SCI filename.
moo_sci_single * moo_sci_get_single(moo_sci *self, moo_detector_type type)
Get the type part in SCI and return it.
moo_target_table * moo_sci_get_target_table(moo_sci *self)
Get the target table of SCI file.
double moo_target_table_get_exptime(moo_target_table *self, int i, int j)
rget the exptime of a target
cpl_error_code moo_create_s1d(cpl_frame *sci_frame, moo_create_s1d_params *params, const char *tag, moo_products *products)
Apply the telluric correction to SCI.
double moo_pfits_get_cd1_1(const cpl_propertylist *plist)
find out the CD1_1 value
int moo_pfits_get_naxis1(const cpl_propertylist *plist)
find out the NAXIS1 value
cpl_error_code moo_pfits_update_dec(cpl_propertylist *plist, double value)
Set the DEC value.
double moo_pfits_get_crval1(const cpl_propertylist *plist)
find out the CRVAL1 value
cpl_error_code moo_pfits_update_ra(cpl_propertylist *plist, double value)
Set the RA value.
double moo_pfits_get_crpix1(const cpl_propertylist *plist)
find out the CRPIX1 value
cpl_frame * moo_products_add_s1d(moo_products *self, moo_s1d *s1d, const char *tag, const cpl_frame *inherit_frame)
create a product from a MOLECTABLE object
the different type of detectors