Ejemplo n.º 1
0
int main(int argc,char**argv) {
   int i,j;
   ftype mask,data;
   float DMIN,DMINe;

   if (argc<3) {
      printf("Usage: %s <mask> <images>\n",*argv);
      printf("  mask image defined such that zero = bad pixel\n");
      return -1;
   }
   readfits(argv[1],&mask,1);
   for (i=2;i<argc;i++) {
      readfits(argv[i],&data,1);
      if (mask.Next!=data.Next || !eqimg(&(mask.img),&(data.img))) {
	 printf("FITS images are not the same size\n");
      }
      else {
	 int sOK=1;
	 parsecards(&data.img,NULL,NULL,NULL,&DMIN,NULL,NULL,NULL,NULL,0,1);
	 if (isimage(&(mask.img))) {
	    applymask(&(mask.img),&(data.img),DMIN);
	 }
	 for (j=0;j<mask.Next;j++) {
	    DMINe=DMIN;
	    if (!eqimg(mask.ext+j,data.ext+j)) {
	       printf("FITS images are not the same size\n");
	       sOK=0;
	    }
	    else if (isimage(mask.ext+j)) {
	       parsecards(data.ext+j,NULL,NULL,NULL,&DMINe,NULL,NULL,NULL,NULL,0,0);
	       applymask(mask.ext+j,data.ext+j,DMINe);
	    }
	 }
	 if (sOK) {
	    writefits(argv[i],&data,1);
	 }
      }
   }
   return 0;
}
Ejemplo n.º 2
0
void mrqcof(float **y, float **sig, struct image *psf, float a[], 
	int ia[], int ma, double **alpha, double beta[], double *chisq,
	void (*funcs)(int x, int y, float *, float [], int [], int, 
	struct fitpars *), struct fitpars *fpar, struct convpars *cpar)
{
	extern struct image *mask;
        extern struct sampars sample;
        extern struct image model;
        extern unsigned long *pos;
        extern struct derivs df;

	struct fitpars *fptr;
	struct derivs *dptr;
        char name[80];

	int ix, iy, j,k,l,m,mfit=0;
	float ymod,wt,sig2i,dy,*dyda;

	dyda=vector(1,ma);
	for (j=1;j<=ma;j++)
		if (ia[j]==1) mfit++;
	for (j=1;j<=mfit;j++) {
		for (k=1;k<=j;k++) alpha[j][k]=0.0;
		beta[j]=0.0;
	}

	mkmodel (&model, &df, fpar, cpar, 0);

#if CKIMG
    sprintf (model.name, "gal+psf-model.fits");            /*  Output image */
    writefits ("test.fits", &model, "gal + PSF", 0);

    fptr = fpar;
    dptr = &df; 
    while (fptr != NULL) {
        for (j=0; j<= NPARS; j++){
            if (fptr->ia[j] == 1 || j==0) {
                sprintf (name, "deriv%d.fits", j);
                mkimg (dptr->dpm[j], dptr->naxes, name, "small.fits");
            };
        };
        fptr = fptr->next;
        dptr = dptr->next;
    };
#endif

	sample.nmask = 0;
	*chisq=0.0;
	for (iy=1; iy<= model.naxes[2]; iy++) {
	    for (ix=1;ix<=model.naxes[1];ix++) {
	        if (mask->z[iy][ix] < 1.) {        /* Calculate chi^2 only   */
		    (*funcs)(ix,iy,&ymod,dyda,ia,ma,fpar);  /* for unflagged */
		    sig2i=1.0/(sig[iy][ix]*sig[iy][ix]);           /* pixels */
		    dy=y[iy][ix]-ymod;
		    for (j=0,l=1;l<=ma;l++) {
			if (ia[l]==1) {
			    wt=dyda[l]*sig2i;
			    for (j++,k=0,m=1;m<=l;m++)
				if (ia[m]==1) alpha[j][++k] += wt*dyda[m]; 
			    beta[j] += dy*wt;
			};
		    };
		    *chisq += dy*dy*sig2i;
	        } else
		    sample.nmask++;	   /* count up the number of flagged pixels */
	    };
	};
	for (j=2;j<=mfit;j++)
		for (k=1;k<j;k++) alpha[k][j]=alpha[j][k];
	free_vector(dyda,1,ma);
}