Пример #1
0
int doDark (ACSInfo *acs2d, SingleGroup *x, float *meandark) {
  
  /* arguments:
   ACSInfo *acs     i: calibration switches, etc
   SingleGroup *x    io: image to be calibrated; written to in-place
   float *meandark    o: mean of dark image values subtracted
   */
  
  extern int status;

  const float darkscaling = 3.0;  /* Extra idle time */
  
  SingleGroupLine y, z;	/* y and z are scratch space */
  int extver = 1;		/* get this imset from dark image */
  int rx, ry;		/* for binning dark down to size of x */
  int x0, y0;		/* offsets of sci image */
  int same_size;		/* true if no binning of ref image required */
  int avg = 0;		/* bin2d should sum values within each bin */
  int scilines; 			/* number of lines in science image */
  int i, j;
  float mean, dark;
  float weight, wdark;    /* weights for line averages */
  int update;
  float darktime;
  
  int FindLine (SingleGroup *, SingleGroupLine *, int *, int *, int *, int *, int *);
  int sub1d (SingleGroup *, int, SingleGroupLine *);
  int trim1d (SingleGroupLine *, int, int, int, int, int, SingleGroupLine *);
  int DetCCDChip (char *, int, int, int *);
  void AvgSciValLine (SingleGroupLine *, short, float *, float *);
  int multk1d (SingleGroupLine *, float);
  
  
	initSingleGroupLine (&y);
	
	scilines = x->sci.data.ny;

  /* Compute DARKTIME */
  /* SBC does not have FLASH keywords */
  if (acs2d->detector == MAMA_DETECTOR)
    darktime = acs2d->exptime;
  else {
    darktime = acs2d->exptime + acs2d->flashdur;

    /* Post-SM4 non-BIAS WFC only */
    /* TARGNAME unavailable, assume EXPTIME=0 means BIAS */
    if (acs2d->detector == WFC_CCD_DETECTOR && acs2d->expstart > SM4MJD && acs2d->exptime > 0)
      darktime += darkscaling;
  }
  
	/* Compute correct extension version number to extract from
   reference image to correspond to CHIP in science data.
   */
	if (acs2d->pctecorr == PERFORM) {
    if (DetCCDChip (acs2d->darkcte.name, acs2d->chip, acs2d->nimsets, &extver) )
      return (status);
  } else {
    if (DetCCDChip (acs2d->dark.name, acs2d->chip, acs2d->nimsets, &extver) )
      return (status);
  }
	
	if (acs2d->verbose) {
		sprintf(MsgText,"Performing dark subtraction on chip %d in imset %d",acs2d->chip, extver);
		trlmessage(MsgText);
	}
  
	/* Get the dark image data. */
  if (acs2d->pctecorr == PERFORM) {
    openSingleGroupLine (acs2d->darkcte.name, extver, &y);
  } else {
    openSingleGroupLine (acs2d->dark.name, extver, &y);
  }
	if (hstio_err())
    return (status = OPEN_FAILED);
  
  
	/* Compare binning of science image and reference image;
   get same_size and high_res flags, and get info about
   binning and offset for use by bin2d.
   */
	if (FindLine (x, &y, &same_size, &rx, &ry, &x0, &y0))
    return (status);
  
  if (rx != 1 || ry != 1) {
		sprintf(MsgText,"Reference image and input are not binned to the same pixel size!");
		trlmessage(MsgText);
  }
	if (acs2d->verbose){
		sprintf(MsgText,"Image has an offset of %d,%d",x0,y0);
		trlmessage(MsgText);
	}
  
	mean = 0.0;
  weight = 0.0;
  
	/* Bin the dark image down to the actual size of x. */
  
	initSingleGroupLine (&z);
	allocSingleGroupLine (&z, x->sci.data.nx);
	for (i=0, j=y0; i < scilines; i++,j++) { 
    
    /* We are working with a sub-array and need to apply the
     proper section from the reference image to the science image.
     */
		if (acs2d->pctecorr == PERFORM) {
      getSingleGroupLine (acs2d->darkcte.name, j, &y);
    } else {
      getSingleGroupLine (acs2d->dark.name, j, &y);
    }
    
    /*
     rx = 1;
     */
    update = NO;
    
    if (trim1d (&y, x0, y0, rx, avg, update, &z)) {
			trlerror ("(darkcorr) size mismatch.");
			return (status);
    }
    
    multk1d(&z, darktime);
    
    AvgSciValLine (&z, acs2d->sdqflags, &dark, &wdark);
    
		/* Sum the contribution from each line */			
		mean += dark * wdark;
		weight += wdark;
    
    status = sub1d (x, i, &z);
		if (status)
			return (status);
	}
	freeSingleGroupLine (&z);			/* done with z */
  
  /*	} */
  
	closeSingleGroupLine (&y);
	freeSingleGroupLine (&y);
  
	/* Compute the mean for the entire image */	
	if (scilines > 0) 
		*meandark = mean / weight; 
	else 
		*meandark = 0.;
	
	return (status);
}
Пример #2
0
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);
}
Пример #3
0
int doDark (WF3Info *wf32d, SingleGroup *x, float *meandark) {

/* arguments:
WF3Info *wf3       i: calibration switches, etc
SingleGroup *x    io: image to be calibrated; written to in-place
float *meandark	   o: mean of dark image values subtracted
*/

    extern int status;

    SingleGroupLine y, z;	/* y and z are scratch space */
    int extver = 1;		/* get this imset from dark image */
    int rx, ry;			/* for binning dark down to size of x */
    int x0, y0;			/* offsets of sci image */
    int same_size;		/* true if no binning of ref image required */
    int avg = 0;		/* bin2d should sum values within each bin */
    int scilines; 		/* number of lines in science image */
    int i, j;
    float mean, dark;
    float weight, wdark;    	/* weights for line averages */
    int update;
    float gain[NAMPS];
    float rn2[NAMPS];       	/* only need this to call get_nsegn */

    int FindLine (SingleGroup *, SingleGroupLine *, int *, int *, int *,
		  int *, int *);
    int sub1d (SingleGroup *, int, SingleGroupLine *);
    int trim1d (SingleGroupLine *, int, int, int, int, int, SingleGroupLine *);
    int DetCCDChip (char *, int, int, int *);
    void get_nsegn (int, int, int, int, float *, float*, float *, float *);
    void AvgSciValLine (SingleGroupLine *, short, float *, float *);
    void multgn1d (SingleGroupLine *, int, int, int, float *, float);


	initSingleGroupLine (&y);
	
	scilines = x->sci.data.ny;

	/* Compute correct extension version number to extract from
	   reference image to correspond to CHIP in science data.  */
	if (DetCCDChip(wf32d->dark.name, wf32d->chip, wf32d->nimsets, &extver))
	    return (status);	
	
	if (wf32d->verbose) {
	    sprintf (MsgText,
		     "Performing dark subtraction on chip %d in imset %d",
		     wf32d->chip, extver);
	    trlmessage(MsgText);
	}

	/* Get the dark image data. */
	openSingleGroupLine (wf32d->dark.name, extver, &y);
	if (hstio_err())
	    return (status = OPEN_FAILED);

	/* Compare binning of science image and reference image;
	   get same_size flag, and get info about binning and offset
	   for use by bin2d.
	*/
	if (FindLine (x, &y, &same_size, &rx, &ry, &x0, &y0))
	    return (status);
    
	/* Return with error if reference data not binned same as input */
	if (rx != 1 || ry != 1) {
	    closeSingleGroupLine (&y);
	    freeSingleGroupLine (&y);
	    sprintf (MsgText,
	    "DARK image and input are not binned to the same pixel size!");
	    trlerror(MsgText);
	    return (status = SIZE_MISMATCH);
	}
	if (wf32d->verbose){
	    sprintf(MsgText,"Image has an offset of %d,%d",x0,y0);
	    trlmessage(MsgText);
	}

	mean = 0.0;
	weight = 0.0;
    
	/* Multiply the dark image by the exposure time and divide by the
	   atodgain (or just by exposure time for the MAMAs), and
	   subtract it from x.
	*/
    
	for (i = 0; i < NAMPS; i++) {
	     gain[i] = 0.;
	     rn2[i] = 0.;
	}
	get_nsegn (wf32d->detector, wf32d->chip, wf32d->ampx, wf32d->ampy,
		   wf32d->atodgain, wf32d->readnoise, gain, rn2);

	initSingleGroupLine (&z);
	allocSingleGroupLine (&z, x->sci.data.nx);
	for (i=0, j=y0; i < scilines; i++,j++) { 

	     /* We are working with a sub-array and need to apply the
		proper section from the reference image to the science image.
	     */
	     getSingleGroupLine (wf32d->dark.name, j, &y);

             update = NO;

	     if (trim1d (&y, x0, y0, rx, avg, update, &z)) {
		 trlerror ("(darkcorr) size mismatch.");
		 return (status);
	     }

	     multgn1d(&z, j, wf32d->ampx, wf32d->ampy, gain, wf32d->exptime[0]);

	     AvgSciValLine (&z, wf32d->sdqflags, &dark, &wdark);

	     /* Sum the contribution from each line */			
	     mean += dark * wdark;
	     weight += wdark;

	     status = sub1d (x, i, &z);
	     if (status)
		 return (status);
	}
	freeSingleGroupLine (&z);			/* done with z */

	closeSingleGroupLine (&y);
	freeSingleGroupLine (&y);

	/* Compute the mean for the entire image */	
	if (scilines > 0) 
	    *meandark = mean / weight; 
	else 
	    *meandark = 0.;
	
	return (status);
}