static int SumGrps (AcsSumInfo *acs, char *mtype) { extern int status; SingleGroup x; /* first imset */ SingleGroupLine y; /* line from Nth imset */ double exptime; /* exposure time of current image */ double sumexptime = 0.; /* accumulated exposure time */ char *message; /* for printtime info */ int extver; /* imset number */ int i; /* counter for current image */ int chip, ychip; /*Chip being summed */ int extchip; /* Extension of chip being summed */ int line; /* Line of chip being summed */ char uroot[CHAR_FNAME_LENGTH]; /* Upper case version of rootname */ int doStat (SingleGroup *, short); void TimeStamp (char *, char *); void PrGrpBegin (char *, int); void PrGrpEnd (char *, int); void PrSwitch (char *, int); void UCalVer (Hdr *); void UFilename (char *, Hdr *); void UMemType (char *, Hdr *); void UExpname (char *, Hdr *); int DetCCDChip (char *, int, int, int *); void UpperAll (char *, char *, int); int GetKeyInt (Hdr *, char *, int, int, int *); int GetKeyDbl (Hdr *, char *, int, double, double *); int PutKeyStr (Hdr *, char *, char *, char *); initSingleGroup (&x); initSingleGroupLine (&y); if (acs->printtime) { if ((message = calloc (CHAR_LINE_LENGTH+1, sizeof (char))) == NULL) return (status = OUT_OF_MEMORY); } for (extver = 1; extver <= acs->nimsets; extver++) { PrGrpBegin ("imset", extver); getSingleGroup (acs->input[0], extver, &x); if (hstio_err()) return (status = OPEN_FAILED); if (acs->printtime) TimeStamp ("first imset read", acs->input[0]); /* get from x */ if (GetKeyInt (&x.sci.hdr, "CCDCHIP", USE_DEFAULT, 1, &chip)) return (status); if (GetKeyDbl (x.globalhdr, "EXPEND", NO_DEFAULT, 0., &acs->expend)) return (status); sumexptime = acs->exptime; /* Square the errors to convert to variance. */ SquareErr (&x); /* operate on x */ /* For each imset/extver, loop over all images */ for (i = 1; i < acs->nimages; i++) { /* Determine which extension corresponds to desired chip ** for the remainder of the images. */ extchip = 0; if (DetCCDChip(acs->input[i], chip, acs->nimsets, &extchip) ) { return (status); } /* Get the first line of bias image data. */ openSingleGroupLine (acs->input[i], extchip, &y); if (hstio_err()) return (status = OPEN_FAILED); /* Update exposure time info. */ /* get from y */ if (GetKeyInt (&y.sci.hdr, "CCDCHIP", USE_DEFAULT, 1, &ychip)) return (status); if (GetKeyDbl (y.globalhdr, "EXPTIME", NO_DEFAULT, 0., &exptime)) return (status); if (GetKeyDbl (y.globalhdr, "EXPEND", NO_DEFAULT, 0., &acs->expend)) return (status); sumexptime += exptime; /*Loop over lines in each subsequent image */ for (line = 0; line < x.sci.data.ny; line++) { status = getSingleGroupLine (acs->input[i], line, &y); if (status) { sprintf(MsgText,"Could not read line %d from image %d.",line+1,i+1); trlerror(MsgText); return (status = OPEN_FAILED); } SquareErrLine (&y); /* operate on y */ /* Add current imset to sum (i.e. add y to x). This differs from add2d in that RptSum adds variances, rather than adding errors in quadrature. */ if (RptSumLine (&x, line, &y)) return (status); } /*End loop over lines */ if (acs->printtime) { if (i == 1) strcpy (message, "1st imset added"); else if (i == 2) strcpy (message, "2nd imset added"); else if (i == 3) strcpy (message, "3rd imset added"); else sprintf (message, "%dth imset added", i); TimeStamp (message, acs->input[i]); } closeSingleGroupLine (&y); } /* End loop over images */ freeSingleGroupLine (&y); /* Take the square root of variance to convert back to errors. */ SqrtErr (&x); /* Compute statistics and update keywords in output headers. */ trlmessage ("\n"); if (doStat (&x, acs->sdqflags)) return (status); if (acs->printtime) TimeStamp ("Image statistics computed", acs->rootname); /* Update header info in output. */ if (PutSumHdrInfo (&x, sumexptime, acs->expend, acs->nimages, acs->nimsets)) return (status); /* Update CAL_VER and FILENAME, then write output file. EXPNAME values modified for all extensions in a SingleGroup. WJH 7 July 1999 */ UCalVer (x.globalhdr); UFilename (acs->output, x.globalhdr); UMemType (mtype, x.globalhdr); UExpname (acs->rootname, &x.sci.hdr); UExpname (acs->rootname, &x.err.hdr); UExpname (acs->rootname, &x.dq.hdr); UpperAll (acs->rootname, uroot, strlen(acs->rootname)+1 ); PutKeyStr (x.globalhdr, "ROOTNAME", uroot,"Rootname of the observation set"); putSingleGroup (acs->output, extver, &x, 0); if (hstio_err()) return (status = 1001); freeSingleGroup (&x); PrGrpEnd ("imset", extver); if (acs->printtime) TimeStamp ("Output written to disk", acs->rootname); } /* End loop over imsets */ if (acs->printtime) free (message); return (status); }
static int GetSumKeyInfo (AcsSumInfo *acs, Hdr *phdr) { /* arguments: AcsSumInfo *acs io: calibration switches and info Hdr *phdr i: primary header */ extern int status; int sdqflags; /* "serious" data quality flags */ int nextend; /* number of FITS extensions */ int nrptexp; /* number of exposures */ int no_def = 0; /* missing keyword is fatal error */ int GetKeyInt (Hdr *, char *, int, int, int *); int GetKeyStr (Hdr *, char *, int, char *, char *, int); int GetKeyDbl (Hdr *, char *, int, double, double *); /* Have the data been converted from counts to absolute flux? */ if (GetKeyStr (phdr, "APERTURE", no_def, "", acs->aperture, ACS_CBUF)) return (status); if (GetKeyStr (phdr, "DETECTOR", no_def, "", acs->det, ACS_CBUF)) return (status); if (strcmp (acs->det, "SBC") == 0) { acs->detector = MAMA_DETECTOR; } else if (strcmp (acs->det, "HRC") == 0) { acs->detector = HRC_CCD_DETECTOR; } else if (strcmp (acs->det, "WFC") == 0) { acs->detector = WFC_CCD_DETECTOR; } else { sprintf (MsgText, "DETECTOR = %s is invalid", acs->det); trlerror (MsgText); return (status = HEADER_PROBLEM); } /* Filter names. */ if (GetKeyStr (phdr, "FILTER1", USE_DEFAULT, "", acs->filter1, ACS_CBUF)) return (status); if (GetKeyStr (phdr, "FILTER2", USE_DEFAULT, "", acs->filter2, ACS_CBUF)) return (status); if (GetKeyDbl (phdr, "EXPTIME", NO_DEFAULT, 0., &acs->exptime)) return (status); if (GetKeyInt (phdr, "SDQFLAGS", USE_DEFAULT, MAX_DQ, &sdqflags)) return (status); acs->sdqflags = sdqflags; /* Find out how many extensions there are in this file. */ if (GetKeyInt (phdr, "NEXTEND", USE_DEFAULT, EXT_PER_GROUP, &nextend)) return (status); /* Convert number of extensions to number of SingleGroups. */ acs->nimsets = nextend / EXT_PER_GROUP; /* Get NRPTEXP and compare with nimages. */ if (GetKeyInt (phdr, "NRPTEXP", no_def, 0, &nrptexp)) return (status); if (nrptexp != acs->nimages) { sprintf (MsgText, "%d exposures will be summed, however, NRPTEXP was %d.", acs->nimages, nrptexp); trlwarn (MsgText); } if (acs->nimages <= 1) { trlwarn ("ACSSUM: Can not continue. There is only one input image!"); return (status = NOTHING_TO_DO); } return (status); }
/* acsrej_do -- Perform the cosmic ray rejection for ACS images Description: ------------ This is mostly a file bookkeeping routine for the cosmic ray rejection task. It takes care of input/output files open/close, check for dimensions, read/ write data from/to files, allocate memory spaces etc. Date Author Description ---- ------ ----------- 06-May-1996 J.-C. Hsu Adapt from the SPP code crrej_do.x 05-Aug-1998 W. Hack Modified to handle ACS data 11-Feb-1999 W. Hack EXPTIME now in Pri. Hdr. 18-Mar-1999 W.J. Hack Revised to read EXPTIMEs from Primary headers for cr_scaling using tpin directly 14-Sep-1999 W.J. Hack Cleaned up SHADCORR usage. Added check for max number of files here. */ int acsrej_do (IRAFPointer tpin, char *outfile, char *mtype, clpar *par, int newpar[]) { extern int status; IODescPtr ipsci[MAX_FILES]; /* science image descriptor */ IODescPtr ipdq[MAX_FILES]; /* data quality image descriptor */ float skyval[MAX_FILES]; /* background DN values */ float efac[MAX_FILES]; /* exposure factors */ multiamp noise; /* readout noise */ multiamp gain; /* A-to-D gain factors */ float exptot; float texpt; int nimgs; SingleGroup sg; int niter = 0; float sigma[MAX_ITER]; Hdr phdr; /* primary header */ int extver; /* Current extension being processed*/ int numext; /* Number of extensions in each image */ int nextend; /* Number of output extensions */ char imgname[MAX_FILES][CHAR_FNAME_LENGTH]; char fimage[CHAR_FNAME_LENGTH]; /* Name of first image in list */ char root[CHAR_FNAME_LENGTH]; /* ROOTNAME for output CRJ file */ char uroot[CHAR_FNAME_LENGTH]; /* Upper case version of rootname */ char *shadrefname; int ext[MAX_FILES]; int dim_x, dim_y; /* image dimensions */ int i, j, n; /* loop indices */ float *efacsum, *work; int nrej; /* total number of rejected pixels */ float skysum; /* total sky level */ int logit; RefImage shadref; int shadswitch; double expend, expstart; int non_zero; /* number of input images with EXPTIME>0.*/ int found; char imgdefault[CHAR_FNAME_LENGTH]; /* name of first input image with EXPTIME > 0. */ int GetSwitch (Hdr *, char *, int *); int UpdateSwitch (char *, int, Hdr *, int *); void InitRefImg (RefImage *); int ImgHistory (const RefImage *, Hdr *); int ImgPedigree (RefImage *); int acsrej_check (IRAFPointer, int, int, clpar *, int [], char [][CHAR_FNAME_LENGTH], int [], IODescPtr [], IODescPtr [], multiamp *, multiamp *, int *, int *, int); int cr_scaling (char *, IRAFPointer, float [], int *, double *, double *); int rejpar_in(clpar *, int [], int, float, int *, float []); void acsrej_sky (char *, IODescPtr [], IODescPtr [], int, short, float []); void cr_history (SingleGroup *, clpar *, int); int acsrej_init (IODescPtr [], IODescPtr [], clpar *, int, int, int, multiamp, multiamp, float [], float [], SingleGroup *, float *); int acsrej_loop (IODescPtr [], IODescPtr [], char [][CHAR_FNAME_LENGTH], int [], int, clpar *, int, int, int, float [], multiamp, multiamp, float [], float [], FloatTwoDArray *, FloatTwoDArray *, float *, ShortTwoDArray *, int *, char *); int PutKeyFlt (Hdr *, char *, float, char *); int PutKeyDbl (Hdr *, char *, double, char *); int PutKeyStr (Hdr *, char *, char *, char *); int GetKeyStr (Hdr *, char *, int, char *, char *, int); int PutKeyInt (Hdr *, char *, int, char *); int GetKeyInt (Hdr *, char *, int, int, int *); void UFilename (char *, Hdr *); void UMemType (char *, Hdr *); void UExpname (char *, Hdr *); int LoadHdr (char *, Hdr *); void UpperAll (char *, char *, int); void TimeStamp (char *, char *); void WhichError (int); void PrSwitch (char *, int); void FindAsnRoot (char *, char *); void initmulti (multiamp *); /* -------------------------------- begin ---------------------------------- */ /* Initialize necessary structures */ InitRefImg (&shadref); root[0] = '\0'; uroot[0] = '\0'; initmulti (&noise); initmulti (&gain); numext = 0; nextend = 0; /* Since CR-SPLIT images are in separate files, we need to combine the same chip's exposure from each file. Therefore we will loop over each extension in the first image, determine what chip that corresponds to, and get the same chip from the rest of the images (which could be in any arbitrary extension in each of the images). */ /* First, let's determine how many extensions/chips in each file */ c_imtgetim (tpin, fimage, CHAR_FNAME_LENGTH); if (LoadHdr (fimage, &phdr) ) return (status = ERROR_RETURN); if (GetKeyInt (&phdr, "NEXTEND", NO_DEFAULT, 0, &nextend) == 0) numext = nextend / EXT_PER_GROUP; else numext = 1; shadswitch = 0; /* Check to see if SHADCORR was set to PERFORM in image header */ if (GetSwitch (&phdr, "SHADCORR", &shadswitch) ) return(status); /* If shadcorr was set either by the user on the command line or in the image header, initialize shadcorr processing. */ if (par->shadcorr == PERFORM || shadswitch == PERFORM) { /* Use par->shadcorr as switch for performing shading correction */ par->shadcorr = PERFORM; shadrefname = calloc(CHAR_FNAME_LENGTH, sizeof(char)); if (GetKeyStr (&phdr, "SHADFILE", NO_DEFAULT, "", shadrefname, CHAR_FNAME_LENGTH) ) return(status); strcpy (shadref.name, shadrefname); /* Read in PEDIGREE and DESCRIPTION for SHADFILE */ if (ImgPedigree (&shadref) ) return (status); /* If a DUMMY shadfile was specified, turn off shadcorr */ if (shadref.goodPedigree == DUMMY) par->shadcorr = OMIT; free (shadrefname); } freeHdr (&phdr); /* Initialize efac */ for (n = 0; n < MAX_FILES; n++) efac[n] = 1.0; /* calculate the scaling factors due to different exposure time */ strcpy (par->expname, "EXPTIME"); if (cr_scaling (par->expname, tpin, efac, &nimgs, &expend, &expstart) ){ WhichError (status); return (status); } /* make sure there is more than one image to process */ if (nimgs < 2) { trlmessage ("Needs more than one input image."); return (status = NOTHING_TO_DO); } /* calculate the total exposure time */ exptot = 0.; non_zero = 0; for (n = 0; n < nimgs; ++n) { exptot += efac[n]; /* Count how many inputs have non-zero(valid) EXPTIME */ if (efac[n] > 0.) non_zero++; } /* for the case of all images have zero exposure time, use equal exposure time of 1. */ if (exptot == 0.) { for (n = 0; n < nimgs; ++n) { efac[n] = 1.; } texpt = (float) nimgs; non_zero = nimgs; } else { texpt = exptot; } /* Now, start the loop. */ for (extver = 1; extver <= numext; extver++) { if (par->printtime) { TimeStamp ("Start cosmic ray rejection",""); } /* open input files and temporary files, check the parameters */ if (acsrej_check (tpin, extver, numext, par, newpar, imgname, ext, ipsci, ipdq, &noise, &gain, &dim_x, &dim_y, nimgs)) { WhichError (status); return(status); } /* Now that we have read in SHADCORR, report if it will be performed */ PrSwitch ("shadcorr", par->shadcorr); /* read in the parameters */ if (rejpar_in (par, newpar, nimgs, exptot, &niter, sigma) ) return(status); /* allocate array space */ efacsum = calloc (dim_x*dim_y, sizeof(float)); work = calloc (nimgs*dim_x, sizeof(float)); /* calculate the sky levels */ acsrej_sky (par->sky, ipsci, ipdq, nimgs, par->badinpdq, skyval); if (status != ACS_OK) { WhichError (status); return (status); } if (par->verbose) { for (n = 0; n < nimgs; n++) { sprintf (MsgText, "sky of '%s[sci,%d]' is %0.3f DN", imgname[n], ext[n], skyval[n]); trlmessage (MsgText); } } /* use the first input image to set up the data structure */ initSingleGroup (&sg); /* Find the first image in the input list which has an EXPTIME > 0. to use for initializing the output SingleGroup. */ found = 0; n = 0; /* By default, simply use the first one, so initialize accordingly.*/ strcpy (imgdefault, imgname[0]); do { if (efac[n] > 0.) { strcpy(imgdefault,imgname[n]); found = 1; } n++; } while (found == 0); getSingleGroup (imgdefault, extver, &sg); if (non_zero > 1){ /* compute the initial pixel values to be used to compare against all images. */ if (non_zero < nimgs){ trlwarn ("Some input exposures had EXPTIME = 0."); } if (acsrej_init (ipsci, ipdq, par, nimgs, dim_x, dim_y, noise, gain, efac, skyval, &sg, work) ) { WhichError(status); closeSciDq(nimgs, ipsci, ipdq, par); return (status); } if (par->printtime) TimeStamp ("Calculated initial guess for extension", ""); /* do the iterative cosmic ray rejection calculations */ if (acsrej_loop (ipsci, ipdq, imgname, ext, nimgs, par, niter, dim_x, dim_y, sigma, noise, gain, efac, skyval, &sg.sci.data, &sg.err.data, efacsum, &sg.dq.data, &nrej, shadref.name) ) { WhichError(status); closeSciDq(nimgs, ipsci, ipdq, par); return (status); } } else { trlwarn ("Cosmic-ray rejection NOT performed!"); if (non_zero > 0) { trlwarn ("Some input exposures had EXPTIME = 0."); trlwarn ("Output product will not be cosmic-ray cleaned!"); } /*else { trlwarn ("ALL input exposures had EXPTIME = 0."); trlwarn ("Output product will be BLANK!"); } */ } /* End if(non_zero) block */ /* must close all images, now that we are done reading them */ closeSciDq(nimgs, ipsci, ipdq, par); /* calculate the total sky ... */ skysum = 0.; for (n = 0; n < nimgs; ++n) { skysum += skyval[n]; } /* ... and force it to be non-negative */ if (skysum < 0.) skysum = 0.; if (par->printtime){ if (non_zero > 1){ TimeStamp ("Finished detecting cosmic rays on extension", ""); } else { TimeStamp ("Done checking this extension",""); } } /* write to the output image */ if (non_zero > 0){ for (j = 0; j < dim_y; ++j) { for (i = 0; i < dim_x; ++i) { PPix(&sg.sci.data,i,j) = PPix(&sg.sci.data,i,j)*texpt + skysum; PPix(&sg.err.data,i,j) *= texpt; } } } else { for (j = 0; j < dim_y; ++j) { for (i = 0; i < dim_x; ++i) { PPix(&sg.sci.data,i,j) = par->fillval; PPix(&sg.err.data,i,j) = 0.; /* Set DQ value to one which will always be considered BAD */ PPix(&sg.dq.data,i,j) = 1; } } /* Set at least one pixel to a different value to insure that an image array actually gets produced. */ PPix(&sg.err.data,0,0) = -1.; PPix(&sg.dq.data,0,0) = 8; } /* update the exposure time of the output images */ PutKeyFlt (sg.globalhdr, "TEXPTIME", exptot, ""); PutKeyFlt (sg.globalhdr, "SKYSUM", skysum, "Total sky level (DN)"); PutKeyDbl (sg.globalhdr, "EXPSTART", expstart, "computed exposure start time (Modified Julian Date)"); PutKeyDbl (sg.globalhdr, "EXPEND", expend, "exposure end time (Modified Julian Date)"); /* Updated REJ_RATE to use 'texpt' as a safe value when EXPTIME=0 for all members. WJH, 24 Feb 2003 */ PutKeyFlt (sg.globalhdr, "REJ_RATE", (float)nrej/texpt, "Cosmic ray impact rate (pixels/sec)"); PutKeyFlt (sg.globalhdr, "EXPTIME", exptot, ""); if (par->shadcorr) { logit = 0; if (UpdateSwitch ("SHADCORR", par->shadcorr, sg.globalhdr, &logit) ) return (status); PrSwitch ("shadcorr", COMPLETE); if (logit) { /*Records SHADFILE information in header comments... */ if (ImgHistory (&shadref, sg.globalhdr)) return (status); } } /* record parameters to the output file */ cr_history (&sg, par, nextend); PutKeyInt (&sg.sci.hdr, "NCOMBINE", nimgs, ""); UFilename (outfile, sg.globalhdr); UMemType (mtype, sg.globalhdr); FindAsnRoot (outfile, root); UpperAll (root, uroot, strlen(root)+1 ); /* EXPNAME values modified for all extensions in a SingleGroup. WJH 7 July 1999 */ UExpname (root, &sg.sci.hdr); UExpname (root, &sg.err.hdr); UExpname (root, &sg.dq.hdr); PutKeyStr (sg.globalhdr, "ROOTNAME", uroot,"Rootname of the observation set"); /* Output CHIP to the same EXTVER as the CHIP ID */ putSingleGroup (outfile, extver, &sg, 0); freeSingleGroup (&sg); if (par->printtime) TimeStamp ("Finished writing out extension", ""); /* deallocate memories */ free (efacsum); free (work); } /* Set status to a value which will be understood by CALACS to turn off subsequent processing. */ if (non_zero == 0) status = NO_GOOD_DATA; return (status); }
int GetCCDInfo (WF3Info *wf3, CCD_Switch *sci_sw, RefFileInfo *sciref) { /* arguments: WF3Info *wf3 i: calibration flags and other info CCD_Switch *sci_sw o: all calibration switches (0 or 1) for science file RefFileInfo *sciref io: list of keyword,filename pairs for science file */ extern int status; IODescPtr im; /* descriptor for an image */ Hdr phdr; /* primary header */ int nextend; /* number of FITS extensions in rawfile */ int GetKeyInt (Hdr *, char *, int, int, int *); int GetKeyFlt (Hdr *, char *, int, float, float *); int GetCCDSws (CCD_Switch *, Hdr *); int GetCCDRef (WF3Info *, CCD_Switch *, Hdr *, RefFileInfo *); /* Open input raw data file. */ initHdr (&phdr); im = openInputImage (wf3->rawfile, "", 0); if (hstio_err()) { sprintf (MsgText, "Member \"%s\" is not present", wf3->rawfile); trlerror (MsgText); freeHdr(&phdr); return (status = OPEN_FAILED); } /* Read primary header into pdhr. */ getHeader (im, &phdr); if (hstio_err()) { sprintf (MsgText, "Could not open PRIMARY header for \"%s\" ", wf3->rawfile); trlmessage (MsgText); closeImage(im); freeHdr(&phdr); return (status = OPEN_FAILED); } closeImage (im); /* Get generic parameters: */ /* Find out how many extensions there are in this file. */ if (GetKeyInt (&phdr, "NEXTEND", USE_DEFAULT, EXT_PER_GROUP, &nextend)){ freeHdr(&phdr); closeImage(im); return (status = KEYWORD_MISSING); } wf3->nchips = nextend / EXT_PER_GROUP; /* Get binning and gain info. We really only need this for the CCD. */ if (GetKeyInt (&phdr, "BINAXIS1", USE_DEFAULT, 1, &wf3->scibin[0])) { closeImage(im); freeHdr(&phdr); return (status = KEYWORD_MISSING); } if (GetKeyInt (&phdr, "BINAXIS2", USE_DEFAULT, 1, &wf3->scibin[1])){ closeImage(im); freeHdr(&phdr); return (status = KEYWORD_MISSING); } if (GetKeyFlt (&phdr, "CCDGAIN", USE_DEFAULT, 1.5, &wf3->scigain)){ closeImage(im); freeHdr(&phdr); return (status = KEYWORD_MISSING); } wf3->samebin = 1; /* default */ /* Get calibration switches, and check that reference files exist. */ if (GetCCDSws (sci_sw, &phdr)) return (status = KEYWORD_MISSING); if (GetCCDRef (wf3, sci_sw, &phdr, sciref)) return (status = CAL_FILE_MISSING); freeHdr (&phdr); return (status); }
int getCTEParsFromImageHeader(SingleGroup *group, CTEParamsFast *pars) { extern int status; double rn_amp = 0; int cte_len = 0; int n_forward = 0; int n_par = 0; int fix_rocr = 0; int noise_mit = 0; int tempStatus = HSTCAL_OK; /*check the PCTENSMD keyword in the header*/ tempStatus = GetKeyInt(group->globalhdr, "PCTENSMD", NO_DEFAULT, -999, &noise_mit); if (tempStatus == HSTCAL_OK) pars->noise_mit = noise_mit; else if (tempStatus != KEYWORD_MISSING) { trlerror("(pctecorr) Error reading PCTENSMD keyword from header"); return (status = tempStatus); } else if (tempStatus == KEYWORD_MISSING) status = HSTCAL_OK; /*check the PCTEDIM keyword in header*/ tempStatus = GetKeyInt(group->globalhdr, "PCTETLEN", NO_DEFAULT, -999, &cte_len); if (tempStatus == HSTCAL_OK) { if (cte_len > 1) pars->cte_len = cte_len; } else if (tempStatus != KEYWORD_MISSING) { trlerror("(pctecorr) Error reading PCTETLEN keyword from header"); return (status = tempStatus); } else if (tempStatus == KEYWORD_MISSING) status = HSTCAL_OK; /*check the PCTERNOI keyword in header*/ tempStatus = GetKeyDbl(group->globalhdr, "PCTERNOI", NO_DEFAULT, -999, &rn_amp); if (tempStatus == HSTCAL_OK) { if (rn_amp > 1.) pars->rn_amp = rn_amp; } else if (tempStatus != KEYWORD_MISSING) { trlerror("(pctecorr) Error reading PCTERNOI keyword from header"); return (status = tempStatus); } else if (tempStatus == KEYWORD_MISSING) status = HSTCAL_OK; /* get number of iterations used in forward model */ tempStatus = GetKeyInt(group->globalhdr, "PCTENFOR", NO_DEFAULT, -999, &n_forward); if (tempStatus == HSTCAL_OK) { if (n_forward > 1) pars->n_forward = n_forward; } else if (tempStatus != KEYWORD_MISSING) { trlerror("(pctecorr) Error reading PCTENFOR keyword from header"); return (status = tempStatus); } else if (tempStatus == KEYWORD_MISSING) status = HSTCAL_OK; /* get number of iterations used in parallel transfer*/ tempStatus = GetKeyInt(group->globalhdr, "PCTENPAR", NO_DEFAULT, -999, &n_par); if (tempStatus == HSTCAL_OK) { if (n_par > 1) pars->n_par = n_par; } else if (tempStatus != KEYWORD_MISSING) { trlerror("(pctecorr) Error reading PCTENPAR keyword from header"); return (status = tempStatus); } else if (tempStatus == KEYWORD_MISSING) status = HSTCAL_OK; /*fix the readout Cr's? */ tempStatus = GetKeyInt(group->globalhdr, "FIXROCR", NO_DEFAULT, -999, &fix_rocr); if (tempStatus == HSTCAL_OK) { if (fix_rocr == 0 || fix_rocr == 1) pars->fix_rocr = fix_rocr; else { char msgBuffer[256]; *msgBuffer = '\0'; sprintf(msgBuffer, "(pctecorr) FIXROCR keyword from header has invalid value, '%d'. Only 0 or 1 accepted.", fix_rocr); trlerror(msgBuffer); return (status = INVALID_VALUE); } } else if (tempStatus != KEYWORD_MISSING) { trlerror("(pctecorr) Error reading FIXROCR keyword from header"); return (status = tempStatus); } else if (tempStatus == KEYWORD_MISSING) status = HSTCAL_OK; return HSTCAL_OK; }
int loadPCTETAB (char *filename, CTEParamsFast *pars) { /* Read the cte parameters from the reference table PCTETAB These are taken from the PCTETAB global header: CTE_NAME - name of cte algorithm CTE_VER - version number of cte algorithm CTEDATE0 - date of instrument installation in HST, in fractional years CTEDATE1 - reference date of CTE model pinning, in fractional years PCTETLEN - max length of CTE trail PCTERNOI - readnoise amplitude and clipping level PCTESMIT - number of iterations used in CTE forward modeling PCTESHFT - number of iterations used in the parallel transfer PCTENSMD - readnoise mitigation algorithm PCTETRSH - over-subtraction threshold The table has 4 extensions: Filename: wfc3_cte.fits No. Name Type Cards Dimensions Format 0 PRIMARY PrimaryHDU 21 () 1 QPROF BinTableHDU 16 <pars->nTraps>R x 3C ['i', 'i', 'i'] 2 SCLBYCOL BinTableHDU 20 <pars->nScaleTableColumns> x 5C ['i', 'e', 'e', 'e', 'e'] 3 RPROF ImageHDU 12 (<pars->nTraps>, 100) float32 4 CPROF ImageHDU 12 (<pars->nTraps>, 100) float32 */ extern int status; /* variable for return status */ /* VARIABLE FOR FILENAME + EXTENSION NUMBER. */ char filename_wext[strlen(filename) + 4]; /* NAMES OF DATA COLUMNS WE WANT FROM THE FILE, DATA WILL BE STORED IN THE PARS STRUCTURE */ const char wcol[] = "W"; const char qlevq[] = "QLEV_Q"; const char dpdew[] = "DPDE_W"; const char iz[] = "IZ"; const char sens512[]= "SENS_0512"; const char sens1024[] = "SENS_1024"; const char sens1536[] = "SENS_1536"; const char sens2048[] = "SENS_2048"; /* HSTIO VARIABLES */ Hdr hdr_ptr; initHdr(&hdr_ptr); /* LOAD PRIMARY HEADER */ if (LoadHdr(filename, &hdr_ptr)) { sprintf(MsgText,"(pctecorr) Error loading header from %s",filename); cteerror(MsgText); status = OPEN_FAILED; return status; } /* GET CTE_NAME KEYWORD */ if (GetKeyStr (&hdr_ptr, "CTE_NAME", NO_DEFAULT, "", pars->cte_name, SZ_CBUF)) { cteerror("(pctecorr) Error reading CTE_NAME keyword from PCTETAB"); status = KEYWORD_MISSING; return status; } sprintf(MsgText,"\nCTE_NAME: %s",pars->cte_name); trlmessage(MsgText); /* GET VERSION NUMBER */ if (GetKeyStr(&hdr_ptr, "CTE_VER", NO_DEFAULT, "", pars->cte_ver, SZ_CBUF)) { cteerror("(pctecorr) Error reading CTE_VER keyword from PCTETAB"); status = KEYWORD_MISSING; return status; } sprintf(MsgText,"CTE_VER: %s",pars->cte_ver); trlmessage(MsgText); /* GET DATE OF INSTRUMENT INSTALLATION IN HST */ if (GetKeyDbl(&hdr_ptr, "CTEDATE0", NO_DEFAULT, -999, &pars->cte_date0)) { cteerror("(pctecorr) Error reading CTEDATE0 keyword from PCTETAB"); status = KEYWORD_MISSING; return status; } sprintf(MsgText,"CTEDATE0: %g",pars->cte_date0); trlmessage(MsgText); /* GET REFRENCE DATE OF CTE MODEL PINNING */ if (GetKeyDbl(&hdr_ptr, "CTEDATE1", NO_DEFAULT, -999, &pars->cte_date1)) { cteerror("(pctecorr) Error reading CTEDATE1 keyword from PCTETAB"); status = KEYWORD_MISSING; return status; } sprintf(MsgText,"CTEDATE1: %g",pars->cte_date1); trlmessage(MsgText); /* READ MAX LENGTH OF CTE TRAIL */ if (GetKeyInt(&hdr_ptr, "PCTETLEN", NO_DEFAULT, -999, &pars->cte_len)) { cteerror("(pctecorr) Error reading PCTETLEN keyword from PCTETAB"); status = KEYWORD_MISSING; return status; } sprintf(MsgText,"PCTETLEN: %d",pars->cte_len); trlmessage(MsgText); /* GET READ NOISE CLIPPING LEVEL */ if (GetKeyDbl(&hdr_ptr, "PCTERNOI", NO_DEFAULT, -999, &pars->rn_amp)) { cteerror("(pctecorr) Error reading PCTERNOI keyword from PCTETAB"); status = KEYWORD_MISSING; return status; } sprintf(MsgText,"PCTERNOI: %f",pars->rn_amp); trlmessage(MsgText); /* GET NUMBER OF ITERATIONS USED IN FORWARD MODEL */ if (GetKeyInt(&hdr_ptr, "PCTENFOR", NO_DEFAULT, -999, &pars->n_forward)) { cteerror("(pctecorr) Error reading PCTENFOR keyword from PCTETAB"); status = KEYWORD_MISSING; return status; } sprintf(MsgText,"PCTERNFOR: %d",pars->n_forward); trlmessage(MsgText); /* GET NUMBER OF ITERATIONS USED IN PARALLEL TRANSFER*/ if (GetKeyInt(&hdr_ptr, "PCTENPAR", NO_DEFAULT, -999, &pars->n_par)) { cteerror("(pctecorr) Error reading PCTENPAR keyword from PCTETAB"); status = KEYWORD_MISSING; return status; } sprintf(MsgText,"PCTERNPAR: %d",pars->n_par); trlmessage(MsgText); /* GET READ NOISE MITIGATION ALGORITHM*/ if (GetKeyInt(&hdr_ptr, "PCTENSMD", NO_DEFAULT, -999, &pars->noise_mit)) { cteerror("(pctecorr) Error reading PCTENSMD keyword from PCTETAB"); status = KEYWORD_MISSING; return status; } sprintf(MsgText,"PCTENSMD: %d",pars->noise_mit); trlmessage(MsgText); /* GET OVER SUBTRACTION THRESHOLD */ if (GetKeyDbl(&hdr_ptr, "PCTETRSH", NO_DEFAULT, -999, &pars->thresh)) { cteerror("(pctecorr) Error reading PCTETRSH keyword from PCTETAB"); status = KEYWORD_MISSING; return status; } sprintf(MsgText,"PCTETRSH: %g",pars->thresh); trlmessage(MsgText); /*FIX THE READOUT CR'S? */ if (GetKeyInt(&hdr_ptr, "FIXROCR", NO_DEFAULT, -999, &pars->fix_rocr)){ cteerror("(pctecorr) Error reading FIXROCR keyword from PCTETAB"); status = KEYWORD_MISSING; return status; } sprintf(MsgText,"FIXROCR: %d",pars->fix_rocr); trlmessage(MsgText); /* DONE READING STUFF FROM THE PRIMARY HEADER */ freeHdr(&hdr_ptr); /****************************************************************************/ /* READ DATA FROM FIRST TABLE EXTENSIONS */ sprintf(filename_wext, "%s[%i]", filename, 1); /* OPEN PARAMETERS FILE TO EXTENSION NUMBER 1 */ IRAFPointer tbl_ptr = c_tbtopn(filename_wext, IRAF_READ_ONLY, 0); // xtables table pointer if (c_iraferr()) { sprintf(MsgText,"(pctecorr) Error opening %s with xtables",filename_wext); cteerror(MsgText); status = OPEN_FAILED; c_tbtclo(tbl_ptr); return status; } /* READ DATA FROM TABLE */ /* get column pointer for w */ IRAFPointer w_ptr = c_tbcfnd1_retPtr(tbl_ptr, wcol); if (c_iraferr() || !w_ptr) { sprintf(MsgText,"(pctecorr) Error getting column %s of PCTETAB",wcol); cteerror(MsgText); status = COLUMN_NOT_FOUND; return status; } /* GET COLUMN POINTER FOR QLEVQ */ IRAFPointer qlevq_ptr = c_tbcfnd1_retPtr(tbl_ptr, qlevq); if (c_iraferr() || !qlevq_ptr) { sprintf(MsgText,"(pctecorr) Error getting column %s of PCTETAB",qlevq); cteerror(MsgText); status = COLUMN_NOT_FOUND; return status; } /* GET COLUMN POINTER FOR DPDEW */ IRAFPointer dpdew_ptr = c_tbcfnd1_retPtr(tbl_ptr, dpdew); if (c_iraferr() || !dpdew_ptr) { sprintf(MsgText,"(pctecorr) Error getting column %s of PCTETAB",dpdew); cteerror(MsgText); status = COLUMN_NOT_FOUND; return status; } // LOOP OVER TABLE ROWS UP TO SIZE TRAPS int ctraps = 0; // actual usable traps, i.e. see if more traps were added to reference file {unsigned j; for (j = 0; j < pars->nTraps; ++j) { /* GET W FROM THIS ROW */ pars->wcol_data[j] = c_tbeGetInt(tbl_ptr, w_ptr, j+1); if (c_iraferr()) { sprintf(MsgText,"(pctecorr) Error reading row %d of column %s in PCTETAB",j+1, wcol); cteerror(MsgText); status = TABLE_ERROR; return status; } /* GET QLEVQ FROM THIS ROW */ pars->qlevq_data[j] = c_tbeGetDouble(tbl_ptr, qlevq_ptr, j+1); if (c_iraferr()) { sprintf(MsgText,"(pctecorr) Error reading row %d of column %s in PCTETAB",j+1, qlevq); cteerror(MsgText); status = TABLE_ERROR; return status; } if (pars->qlevq_data[j] < 999999.) ctraps+=1; /* GET DPDEW FROM THIS ROW */ pars->dpdew_data[j] = c_tbeGetDouble(tbl_ptr, dpdew_ptr, j+1); if (c_iraferr()) { sprintf(MsgText,"(pctecorr) Error reading row %d of column %s in PCTETAB",j+1, dpdew); cteerror(MsgText); status = TABLE_ERROR; return status; } if (ctraps > pars->nTraps){ sprintf(MsgText,"More TRAPS in reference file than available, update TRAPS: %i -> %i",pars->nTraps,(int)ctraps); trlmessage(MsgText); } }} /*IF CTRAPS EVER OVERFLOWS INT THIS NEEDS TO BE CHANGED*/ pars->cte_traps = ctraps; /* sprintf(MsgText,"(pctecorr) data check for PCTETAB QPROF, row %i, %i\t%g\t%g\ttraps=%i\n",20, pars->wcol_data[19],pars->qlevq_data[19], pars->dpdew_data[19], pars->cte_traps); trlmessage(MsgText); */ /* CLOSE CTE PARAMETERS FILE FOR EXTENSION 1*/ c_tbtClose((void*)&tbl_ptr); assert(!tbl_ptr); /****************************************************************************/ /****************************************************************************/ /* READ CTE SCALING DATA FROM SECOND TABLE EXTENSION */ sprintf(filename_wext, "%s[%i]", filename, 2); tbl_ptr = c_tbtopn(filename_wext, IRAF_READ_ONLY, 0); if (c_iraferr()) { sprintf(MsgText,"(pctecorr) Error opening %s with xtables",filename_wext); cteerror(MsgText); status = OPEN_FAILED; c_tbtclo(tbl_ptr); return status; } /*get column pointer for iz column*/ IRAFPointer iz_ptr = c_tbcfnd1_retPtr(tbl_ptr, iz); if (c_iraferr() || iz_ptr == 0) { sprintf(MsgText,"(pctecorr) Error getting column %s of PCTETAB",iz); cteerror(MsgText); status = COLUMN_NOT_FOUND; return status; } /* get column pointer for sens512 */ IRAFPointer sens512_ptr = c_tbcfnd1_retPtr(tbl_ptr, sens512); if (c_iraferr() || w_ptr == 0) { sprintf(MsgText,"(pctecorr) Error getting column %s of PCTETAB",sens512); cteerror(MsgText); status = COLUMN_NOT_FOUND; return status; } /* get column pointer for sens1024 */ IRAFPointer sens1024_ptr = c_tbcfnd1_retPtr(tbl_ptr, sens1024); if (c_iraferr() || w_ptr == 0) { sprintf(MsgText,"(pctecorr) Error getting column %s of PCTETAB",sens1024); cteerror(MsgText); status = COLUMN_NOT_FOUND; return status; } /* get column pointer for sens1536 */ IRAFPointer sens1536_ptr = c_tbcfnd1_retPtr(tbl_ptr, sens1536); if (c_iraferr() || w_ptr == 0) { sprintf(MsgText,"(pctecorr) Error getting column %s of PCTETAB",sens1536); cteerror(MsgText); status = COLUMN_NOT_FOUND; return status; } /* get column pointer for sens2048 */ IRAFPointer sens2048_ptr = c_tbcfnd1_retPtr(tbl_ptr, sens2048); if (c_iraferr() || w_ptr == 0) { sprintf(MsgText,"(pctecorr) Error getting column %s of PCTETAB",sens2048); cteerror(MsgText); status = COLUMN_NOT_FOUND; return status; } /* read data from table */ /* loop over table rows */ {unsigned j; for (j = 0; j < pars->nScaleTableColumns; ++j) { /* get trap from this row */ pars->iz_data[j] = c_tbeGetInt(tbl_ptr, iz_ptr, j+1); if (c_iraferr()) { sprintf(MsgText,"(pctecorr) Error reading row %d of column %s in PCTETAB",j+1, iz); cteerror(MsgText); return (status = TABLE_ERROR); } pars->scale512[j] = c_tbeGetDouble(tbl_ptr, sens512_ptr, j+1); if (c_iraferr()) { sprintf(MsgText,"(pctecorr) Error reading row %d of column %s in PCTETAB",j+1, sens512); cteerror(MsgText); return (status = TABLE_ERROR); } pars->scale1024[j] = c_tbeGetDouble(tbl_ptr, sens1024_ptr, j+1); if (c_iraferr()) { sprintf(MsgText,"(pctecorr) Error reading row %d of column %s in PCTETAB",j+1, sens1024); cteerror(MsgText); return (status = TABLE_ERROR); } pars->scale1536[j] = c_tbeGetDouble(tbl_ptr, sens1536_ptr, j+1); if (c_iraferr()) { sprintf(MsgText,"(pctecorr) Error reading row %d of column %s in PCTETAB",j+1, sens1536); cteerror(MsgText); return (status = TABLE_ERROR); } pars->scale2048[j] = c_tbeGetDouble(tbl_ptr, sens2048_ptr, j+1); if (c_iraferr()) { sprintf(MsgText,"(pctecorr) Error reading row %d of column %s in PCTETAB",j+1, sens2048); cteerror(MsgText); return (status = TABLE_ERROR); } }} // for testing /*{ unsigned j = pars->nColumns; sprintf(MsgText,"(pctecorr) data check for PCTETAB SCLBYCOL row %d, %d %g\t%g\t%g\t%g\ntotal traps = %i", j,pars->iz_data[j-1],pars->scale512[j-1],pars->scale1024[j-1],pars->scale1536[j-1],pars->scale2048[j-1],pars->cte_traps); trlmessage(MsgText); } */ /* close CTE parameters file for extension 2*/ c_tbtClose((void*)&tbl_ptr); assert(!tbl_ptr); /****************************************************************************/ /* extension 3: differential trail profile as image */ ctemessage("Reading in image from extension 3"); /* Get the coefficient images from the PCTETAB */ pars->rprof = malloc(sizeof(*pars->rprof)); if (pars->rprof == NULL){ sprintf (MsgText, "Can't allocate memory for RPROF ref data"); trlerror (MsgText); return (status = 1); } initFloatHdrData(pars->rprof); pars->rprof->data.storageOrder = COLUMNMAJOR; if (getFloatHD (filename, "RPROF", 1, pars->rprof)){ return (status=1); } /****************************************************************************/ /* ext number 4 : cummulative trail profile as image */ ctemessage("Reading in image from extension 4"); pars->cprof = malloc(sizeof(*pars->cprof)); if (pars->cprof == NULL){ sprintf (MsgText, "Can't allocate memory for CPROF ref data"); trlerror (MsgText); return (status = 1); } /* Get the coefficient images from the PCTETAB */ initFloatHdrData (pars->cprof); pars->cprof->data.storageOrder = COLUMNMAJOR; if (getFloatHD (filename, "CPROF", 1, pars->cprof)){ return (status=1); } return(status); }