Exemplo n.º 1
0
void wninit()
{
    int i;
    static int done = 0;
    void do_init(), readfnames();


    if (done)
	return;
    do_init();
    for (i = 1; i < NUMPARTS + 1; i++)
	readfnames(i);
    morphinit();
    done = 1;
}
Exemplo n.º 2
0
void re_wninit()
{
    int i;
    void readfnames();

    for (i = 1; i < NUMPARTS + 1; i++) {
	fclose(datafps[i]);
	fclose(indexfps[i]);
    }
    fclose(sensefp);
    do_init();
    for (i = 1; i < NUMPARTS + 1; i++)
	readfnames(i);

    re_morphinit();
}
Exemplo n.º 3
0
Arquivo: phot.c Projeto: krzul/dia
/*--------------------------------------------------------*/
int main(int argc, char *argv[])
{
        char        **newheader,
                    *imffname, *parfname, *psffname, *reffname,
                    *instrname,
                    *fieldname,
                    *outfname,
                    *coofname,
                    **diffiles,
                    **imfiles,
                    **kerfiles;
        int         nx0, ny0, k, *sector, nim, iim, npsf, ipsf, hsize,
                    isec_x, isec_y, *cx, *cy, psfn, kern, irad,
//                  ofs,
                    *vnum,
                    i;
        float       *im, *difim, *refim;
        double      **wxy, *x, *y, *xs, *ys, **psfs, *psfim, *kerim, ratio;
        STAR        **obj, *objp;
        PSF_STRUCT  psf;
        KER_STRUCT  ker;
        PAR_STRUCT  par;

/*** IO stuff ***/

  if (argc != 7)
  {
    printf("\n\tUSAGE: phot  parameter_file instrument_file");
    printf(" ref_image psf_fit_file image_data_list field_name\n");
    exit(1);
  }

  parfname= argv[1];
  instrname=argv[2];
  reffname= argv[3];
  psffname= argv[4];
  imffname= argv[5];
  fieldname=argv[6];

  get_params(parfname, instrname, &par);

  if (par.verbose)
    printf("\n\n*** Profile photometry with variable PSF and kernel ***\n\n");

  if (!(outfname=(char *)calloc(strlen(fieldname)+5, sizeof(char))))
    errmess("calloc(outfname)");
  strcpy(outfname, fieldname);
  strcat(outfname, ".db");

  if (!(coofname=(char *)calloc(strlen(fieldname)+5, sizeof(char))))
    errmess("calloc(coofname)");
  strcpy(coofname, fieldname);
  strcat(coofname, ".coo");


/***  read filenames for difference images, images and kernel fits  ***/
  nim=readfnames(imffname, &diffiles, &imfiles, &kerfiles);
  if (par.verbose)  printf("%d images to process\n", nim);

/***  read coordinates of variables  ***/
  npsf=readcoo(coofname, &vnum, &x, &y);
  if (par.verbose)  printf("%d variables to measure\n\n", npsf);

/***  read in psf fit and get a sample kernel from the first image  ***/
  read_psf(psffname, &psf);
  read_kernel(kerfiles[0], &ker, 1, par.verbose);

  psf.normrad = par.normrad;
  psf.hw += ker.hw;

  psfn = 2*psf.hw + 1;
  kern = 2*ker.hw + 1;

/*** get memory ***/
  if (!(ker.vecs = (double **)malloc(ker.nvecs*sizeof(double *))))
    errmess("malloc(ker.vecs)");
  for (k=0; k<ker.nvecs; k++)
    if (!(ker.vecs[k] = (double *)malloc(kern*kern*sizeof(double))))
      errmess("malloc(ker.vecs[k])");

  if (!(sector=(int *)malloc(npsf*sizeof(int)))) errmess("malloc(sector)");
  if (!(cx= (int *)malloc(npsf*sizeof(int))))          errmess("malloc(cx)");
  if (!(cy= (int *)malloc(npsf*sizeof(int))))          errmess("malloc(cy)");
  if (!(xs= (double *)malloc(npsf*sizeof(double))))    errmess("malloc(xs)");
  if (!(ys= (double *)malloc(npsf*sizeof(double))))    errmess("malloc(ys)");
  if (!(wxy=(double **)malloc(npsf*sizeof(double *)))) errmess("malloc(wxy)");

  if (!(psfs=(double **)malloc(npsf*sizeof(double *))))
    errmess("malloc(psfs)");
  if (!(kerim=(double *)malloc(kern*kern*sizeof(double))))
    errmess("malloc(kerim)");
  if (!(psfim=(double *)malloc(psfn*psfn*sizeof(double))))
    errmess("malloc(psfim)");

  if (!(obj=(STAR **)malloc(npsf*sizeof(STAR *)))) errmess("malloc(obj)");

/***********************************************************************/
/** get things that can be done once for all: spatial coeffs and psfs **/
/***********************************************************************/

  for (ipsf=0; ipsf<npsf; ipsf++)
  {
    if (!(obj[ipsf]=(STAR *)malloc(nim*sizeof(STAR))))
      errmess("malloc(obj[ipsf])");
    if (!(wxy[ipsf]=(double *)malloc(ker.nwxy*sizeof(double))))
      errmess("malloc(wxy[ipsf])");
    if (!(psfs[ipsf]=(double *)malloc(psfn*psfn*sizeof(double))))
      errmess("malloc(psfs[ipsf])");

/* offsets for image sectors from kernel fit */

    cx[ipsf]=(int)floor(x[ipsf]+0.5);
    cy[ipsf]=(int)floor(y[ipsf]+0.5);

    isec_x=(cx[ipsf] - ker.hw)/(ker.nx - 2*ker.hw);
    isec_y=(cy[ipsf] - ker.hw)/(ker.ny - 2*ker.hw);

    xs[ipsf]=x[ipsf] - isec_x*(ker.nx - 2*ker.hw);
    ys[ipsf]=y[ipsf] - isec_y*(ker.ny - 2*ker.hw);

    sector[ipsf]=isec_y + ker.nsec_y*isec_x;

    spatial_coeffs(&ker, xs[ipsf], ys[ipsf], wxy[ipsf]);

    init_psf(&psf, x[ipsf], y[ipsf]);
    make_psf(&psf, x[ipsf], y[ipsf], cx[ipsf], cy[ipsf], psfs[ipsf]);
  }

  refim=read_FITS_2D1file(reffname, 's', &hsize, &newheader, &nx0, &ny0);
  for (i=0; i<hsize; i++) free(newheader[i]);
  free(newheader);

  make_vectors(&ker);

  par.nx0=nx0;
  par.ny0=ny0;
  par.psfhw=psf.hw;
  par.psfn=psfn;

  irad=(int)par.anrad2 + 2;

/*******************************/
/***  main loop over images  ***/
/*******************************/

  for (iim=0; iim<nim; iim++)
  {
    if (par.verbose > 2) printf("%d: %s\n", iim, diffiles[iim]);

    difim=read_FITS_2D1file(diffiles[iim], 's', &hsize, &newheader, &nx0, &ny0);

    for (i=0; i<hsize; i++) free(newheader[i]);
    free(newheader);

    if ((nx0 != par.nx0) || (ny0 != par.ny0))
    {
      printf("ERROR! phot: wrong size of the image %s\n", diffiles[iim]);
      exit(2);
    }

    im=read_FITS_2D1file(imfiles[iim], 's', &hsize, &newheader, &nx0, &ny0);
    for (i=0; i<hsize; i++) free(newheader[i]);
    free(newheader);

    if ((nx0 != par.nx0) || (ny0 != par.ny0))
    {
      printf("ERROR! phot: wrong size of the image %s\n", imfiles[iim]);
      exit(3);
    }


/* read kernel into tables allocated before */
    read_kernel(kerfiles[iim], &ker, 0, par.verbose);


/*** loop over stars ***/
    for (ipsf=0; ipsf<npsf; ipsf++)
    {
      objp = &obj[ipsf][iim];

      if ((cx[ipsf] < irad) || (cy[ipsf] < irad) ||
          (cx[ipsf] >= nx0-irad) || (cy[ipsf] >= ny0-irad))
      {
        if (par.verbose)
          printf("%s warning: object %4d too close to edge: ignored!\n",
                  diffiles[iim], ipsf);

        objp->a_flux   = par.bad_value;
        objp->a_err    = par.bad_value;
        objp->p_flux   = par.bad_value;
        objp->p_err    = par.bad_value;
        objp->chi2_n   = par.bad_value;
        objp->ker_chi2 = par.bad_value;
        objp->corr     = par.bad_value;
        objp->nbad     = -1;

        continue;
      }

/*** prepare local psf ***/
      make_kernel(&ker, wxy[ipsf], kerim, sector[ipsf]);

      im_convolve(psfs[ipsf], psfim, psfn, psfn, kerim, ker.hw);

      objp->ker_chi2=(float)ker.chi2_n[sector[ipsf]];

      objp->fwhm=(float)get_fwhm(psfim, x[ipsf], y[ipsf], cx[ipsf], cy[ipsf],
                                 &par, &ratio);

      if (par.bkg_mode) objp->bg = bkg(difim, cx[ipsf], cy[ipsf], &par);
      else              objp->bg = 0.0;

/*** actual profile and aperture photometry ***/
      get_phot(difim, im, refim, x[ipsf], y[ipsf], cx[ipsf], cy[ipsf], psfim,
               objp, &par);

      if (par.verbose > 1)
        printf("%s  star: %5d  flux= %9g +- %8g   nbad: %d\n",
                diffiles[iim], ipsf, objp->p_flux, objp->p_err, objp->nbad);
    }

    free(difim);
    free(im);
  }

/*** write photometry to the output file  ***/
  if (par.verbose) printf("\nWriting photometry to:  %s\n", outfname);

  if (par.dbf == 'A')
    writedba(outfname, diffiles, nim, npsf, vnum, obj);
  else
    writedbb(outfname, diffiles, nim, npsf, vnum, obj);

  if (par.verbose)  printf("\nPhotometry done!\n");

  return(0);
}