示例#1
0
文件: image.c 项目: jobovy/nemo
int sub_image (imageptr iptr, regionptr rptr, imageptr *optr)
{
  int nx,ny,nz, nx1,ny1,nz1, ix,iy,iz, ix0,iy0,iz0;
  size_t np, np1;

  nx  = Nx(iptr);
  ny  = Ny(iptr);
  nz  = Nz(iptr);
  np = nx*ny*nz;
  /* grab the bounding box */
  ix0 = BLC(rptr)[0];
  iy0 = BLC(rptr)[1];
  iz0 = BLC(rptr)[2];
  nx1 = TRC(rptr)[0] - ix0;
  ny1 = TRC(rptr)[1] - iy0;
  nz1 = TRC(rptr)[2] - iz0;
  np1 = nx1*ny1*nz1;

  *optr = (imageptr ) allocate(sizeof(image));
  dprintf (DLEV,"copy_image:Allocated image @ %d size=%d * %d * %d",*optr,nx1,ny1,nz1);
    	
  Frame(*optr) = (real *) allocate(np1*sizeof(real));	
  dprintf (DLEV,"Frame allocated @ %d ",Frame(*optr));
  Nx(*optr) = nx1;
  Ny(*optr) = ny1;
  Nz(*optr) = nz1;
  Xmin(*optr) = Xmin(iptr) + ix0*Dx(iptr);
  Ymin(*optr) = Ymin(iptr) + iy0*Dy(iptr);
  Zmin(*optr) = Zmin(iptr) + iz0*Dz(iptr);
  Dx(*optr) = Dx(iptr);
  Dy(*optr) = Dy(iptr);
  Dz(*optr) = Dz(iptr);
  Namex(*optr) = mystrcpy(Namex(iptr));
  Namey(*optr) = mystrcpy(Namey(iptr));
  Namez(*optr) = mystrcpy(Namez(iptr));
  Xref(*optr) = Xref(iptr) + ix0;
  Yref(*optr) = Yref(iptr) + iy0;
  Zref(*optr) = Zref(iptr) + iz0;
  for (iz=0; iz<nz1; iz++)
    for (iy=0; iy<ny1; iy++)
      for (ix=0; ix<nx1; ix++)
	CubeValue(*optr,ix,iy,iz) = CubeValue(iptr,ix-ix0,iy-iy0,iz-iy0);
  Storage(*optr) = matdef[idef];
  Axis(*optr) = Axis(iptr);
  set_iarray(*optr);
  
  return 1;		/* succes return code  */
}
示例#2
0
文件: image.c 项目: jobovy/nemo
static void set_iarray(imageptr iptr)
{
  int i;
  int nx, ny, nz;

#ifdef USE_IARRAY
  nx = Nx(iptr);
  ny = Ny(iptr);
  nz = Nz(iptr);
  warning("USE_IARRAY (%d,%d,%d)",nx,ny,nz);
  IDx(iptr) = (int *) allocate( nx * sizeof(int));
  IDy(iptr) = (int *) allocate( ny * sizeof(int));
  IDz(iptr) = (int *) allocate( nz * sizeof(int));
  if (idef == 1) { // CDEF
    for (i=0; i<nz; i++) IDz(iptr)[i] = i;
    for (i=0; i<ny; i++) IDy(iptr)[i] = nz*i;
    for (i=0; i<nx; i++) IDx(iptr)[i] = nz*ny*i;
  } else if (idef == 0) { // FORDEF
    for (i=0; i<nx; i++) IDx(iptr)[i] = i;
    for (i=0; i<ny; i++) IDy(iptr)[i] = nx*i;
    for (i=0; i<nz; i++) IDz(iptr)[i] = nx*ny*i;
  } else // ILLEGAL
    error("set_iarray: idef=%d\n",idef);
#endif
}
示例#3
0
nemo_main()
{
  int n = 0;
  setparams();                    /* set globals */

  instr = stropen (infile, "r");
  plinit ("***", 0.0, 20.0, 0.0, 20.0);       /* init yapp */
  while (read_image(instr,&iptr)) {   /* loop while more images found */
    dprintf(1,"Time= %g MinMax= %g %g\n",Time(iptr),MapMin(iptr),MapMax(iptr));
    nx=Nx(iptr);			
    ny=Ny(iptr);
    nz=Nz(iptr);
    if (nz > 1) error("Cannot handle 3D images [%d,%d,%d]",nx,ny,nz);
    xmin=Xmin(iptr);
    ymin=Ymin(iptr);
    dx=Dx(iptr);
    dy=Dy(iptr);
    xsize = nx * dx;
    ysize = ny * dy;
    if (n>0) {
      sleep(1);
      plframe();
    }
    plot_map();                                 /* plot the map */
    n++;
  }
  plstop();                                   /* end of yapp */
  strclose(instr);
}
示例#4
0
local void object_noise(int npars, real *pars)
{
  int i,j;
  int nx = Nx(iptr);
  int ny = Ny(iptr);
  double m = 1.0;
  double s = 1.0;

  if (npar > 0) m = pars[0];
  if (npar > 1) s = pars[1];

  dprintf(0,"noise:%g %g\n",m,s);

  if (s==0) return;

  if (Qtotflux) {
    m /= (nx*ny);
    s /= (nx*ny);
    dprintf(0,"noise: m->%g  s->%g\n",m,s);
  }
  
  for (j=0; j<ny; j++)
    for (i=0; i<nx; i++)
      MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + grandom(m,s);
}
示例#5
0
local void object_gauss(int npars, real *pars)
{
  int i,nx = Nx(iptr);
  int j,ny = Ny(iptr);
  real A = 1.0;
  real h = 1.0;
  real x1,y1,x2,y2,r,arg,value;

  if (npar > 0) A = pars[0];
  if (npar > 1) h = pars[1];
  dprintf(0,"gauss: %g %g\n",A,h);

  if (A==0) return;

  if (Qtotflux) {
    A /= (PI*h*h/surface);
    dprintf(0,"gauss: A->%g\n",A);
  }

  for (j=0; j<ny; j++) {
    y1 = (j-center[1])*Dy(iptr) + Ymin(iptr);
    for (i=0; i<nx; i++) {
      x1 = (i-center[0])*Dx(iptr) + Xmin(iptr);
      x2 =  -x1*sinp - y1*cosp;
      y2 =   x1*cosp - y1*sinp;
      r = sqrt(x2*x2 + sqr(y2/cosi));
      arg = r/h;
      dprintf(2,"%d %d : %g %g %g %g   %g\n",i,j,x1,y1,x2,y2,arg);
      value = (arg < 13) ?  A * exp(-0.5*arg*arg) : 0.0;
      MapValue(iptr,i,j)  = factor*MapValue(iptr,i,j) + value;
    }
  }
}
示例#6
0
local void object_ferrers(int npars, real *pars)
{
  int i,nx = Nx(iptr);
  int j,ny = Ny(iptr);
  int l, lmax;
  real A = 1.0;   /* peak */
  real h = 1.0;   /* size */
  real e = 0.0;   /* 1-b/a */
  real b = 0.0;   /* phi */
  real p = 1.0;   /* power factor */
  real x1,y1,x2,y2,x3,y3,r,arg,value;
  real amp,phi,sum;
  real sinb,cosb;

  if (npar > 0) A = pars[0];
  if (npar > 1) h = pars[1];
  if (npar > 2) e = pars[2];
  if (npar > 3) b = pars[3];
  if (npar > 4) p = pars[4];
  dprintf(0,"ferrers: %g %g %g %g %g\n",A,h,e,b,p);

  if (A==0) return;

  lmax = Qtotflux ? 2 : 1;

  sinb = sin(b*PI/180.0);
  cosb = cos(b*PI/180.0);

  for (l=0; l<lmax; l++) {     /* 1st loop: sum up the flux   if in 2nd loop: normalize */
    if (l==0) 
      sum = 0.0;
    else {
      A /= sum;
      dprintf(0,"ferrers: A->%g\n",A);
    } 
    for (j=0; j<ny; j++) {
      y1 = (j-center[1])*Dy(iptr) + Ymin(iptr);
      for (i=0; i<nx; i++) {
	x1 = (i-center[0])*Dx(iptr) + Xmin(iptr);
	
	x2 =  -x1*sinp - y1*cosp;
	y2 =  (x1*cosp - y1*sinp)/cosi;

	x3 =   x2*cosb - y2*sinb;
	y3 = (x2*sinb  + y2*cosb)/(1-e);

	r = (x3*x3+y3*y3)/(h*h);
	value = r < 1 ? A * pow(1.0-r, p) : 0.0;

	if (Qtotflux) {   
	  if (l==0) 
	    sum += value;
	  else
	    MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
	} else
	  MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
      } /* i */
    } /* j */
  } /* k */
}
示例#7
0
文件: ccdsmooth.c 项目: jobovy/nemo
void nemo_main ()
{
    setparams();			/* set par's in globals */

    instr = stropen (infile, "r");
    read_image (instr,&iptr);
				/* set some global paramters */
    nx = Nx(iptr);	
    ny = Ny(iptr);
    nz = Nz(iptr);
    xmin = Xmin(iptr);
    ymin = Ymin(iptr);
    zmin = Zmin(iptr);
    dx = Dx(iptr);
    dy = Dy(iptr);
    dz = Dz(iptr);

    if(hasvalue("gauss"))
        make_gauss_beam(getparam("dir"));

    outstr = stropen (outfile,"w");
    if (hasvalue("wiener"))
      wiener();
    else
      smooth_it();
    write_image (outstr,iptr);

    strclose(instr);
    strclose(outstr);
}
示例#8
0
void nemo_main()
{
    stream  instr, outstr;
    int     nx, ny, nz;        /* size of scratch map */
    int     nx1,ny1,nz1;
    int     nxaver, nyaver,nzaver;
    int     i,j,k, i0,j0,k0, i1,j1,k1;
    imageptr iptr=NULL, iptr1=NULL;      /* pointer to images */
    real    sum, tmp, zzz;
    bool    Qreorder = FALSE;
    bool    Qdummy, Qsample;
    string  reorder;

    instr = stropen(getparam("in"), "r");
    nxaver=getiparam("nxaver");
    nyaver=getiparam("nyaver");
    nzaver=getiparam("nzaver");
    Qdummy = getbparam("dummy");

    nx1 = nemoinpi(getparam("x"),ix,MAXDIM);
    ny1 = nemoinpi(getparam("y"),iy,MAXDIM);
    nz1 = nemoinpi(getparam("z"),iz,MAXDIM);
    if (nx1<0 || ny1<0 || nz1<0) error("Error parsing x,y,z=");
    Qsample = nx1>0 || ny1>0 || nz1>0;
    if (Qsample) warning("Sampling will be done");

    read_image( instr, &iptr);

    nx = Nx(iptr);	                   /* old cube size */
    ny = Ny(iptr);      
    nz = Nz(iptr);      
    nx1 = ax_index("x",nx,nx1,ix);         /* initialize new cube axes */
    ny1 = ax_index("y",ny,ny1,iy);         /* before any reordering */
    nz1 = ax_index("z",nz,nz1,iz);

    Qreorder = hasvalue("reorder");
    if (Qreorder) {
      reorder = getparam("reorder");
      if (strlen(reorder) != 3) error("Reorder must have 3 letters");
    } 

    outstr = stropen(getparam("out"), "w");

    if (nxaver>1 || nyaver>1 || nzaver>1) {  /*  averaging, but retaining size */
        dprintf(0,"Averaging map %d * %d * %d pixels; mapsize %d * %d * %d\n",
                   nxaver,nyaver,nzaver,nx,ny,nz);
        nx1 = nx/nxaver;  if (nx % nxaver) warning("X binning not even");
        ny1 = ny/nyaver;  if (ny % nyaver) warning("Y binning not even");
        nz1 = nz/nzaver;  if (nz % nzaver) warning("X binning not even");
	LOOP(k1,nz1) {
	  k = k1*nzaver;
	  LOOP(j1,ny1) {
            j = j1*nyaver;
	    LOOP(i1,nx1) {
	      i = i1*nxaver;
	      sum = 0.0;
	      LOOP(k0,nzaver) LOOP(j0,nyaver) LOOP(i0,nxaver) sum += CV(iptr, i+i0, j+j0, k+k0);
	      sum /= (real) (nxaver*nyaver*nzaver);
	      LOOP(k0,nzaver) LOOP(j0,nyaver) LOOP(i0,nxaver) CV(iptr, i+i0, j+j0, k+k0) = sum;
            }
示例#9
0
文件: image.c 项目: jobovy/nemo
void ini_matrix(imageptr *iptr, int nx, int ny)
{
  int ix,iy;
	
  printf ("iptr @ %d    (sizeof = %d)\n",*iptr,sizeof(image));
	
  if (*iptr==0) {
    *iptr = (imageptr ) allocate((sizeof(image)));
    printf ("allocated image 'iptr' @ %d\n",*iptr);
    Frame(*iptr) = (real *) allocate (nx*ny*sizeof(real));
    printf ("Allocated frame @ %d\n",Frame(*iptr));
  } else {
    printf ("Image already allocated @ %d\n",*iptr);
    printf ("with Frame @ %d\n",Frame(*iptr));
  }
  Nx(*iptr) = nx;
  Ny(*iptr) = ny;
  Nz(*iptr) = 1;
  Xmin(*iptr) = 1.0;
  Ymin(*iptr) = 2.0;
  Zmin(*iptr) = 3.0;
  Dx(*iptr) = 0.1;
  Dy(*iptr) = 0.1;
  Dz(*iptr) = 0.1;
  Namex(*iptr) = NULL;        /* no axis names */
  Namey(*iptr) = NULL;
  Namez(*iptr) = NULL;
  Unit(*iptr)  = NULL;        /* no units */
  Mask(*iptr)  = NULL;

  set_iarray(*iptr);
  for (ix=0; ix<nx; ix++)
    for (iy=0; iy<ny; iy++)
      MapValue(*iptr,ix,iy)  = (ix*ny+iy)*0.1;
}
示例#10
0
文件: image.c 项目: jobovy/nemo
int write_image (stream outstr, imageptr iptr)
{
  put_history(outstr);
  put_set (outstr,ImageTag);
    put_set (outstr,ParametersTag);
      put_data (outstr,NxTag,  IntType,  &(Nx(iptr)),   0);
      put_data (outstr,NyTag,  IntType,  &(Ny(iptr)),   0);
      put_data (outstr,NzTag,  IntType,  &(Nz(iptr)),   0);
      put_data (outstr,XminTag,RealType, &(Xmin(iptr)), 0);
      put_data (outstr,YminTag,RealType, &(Ymin(iptr)), 0);
      put_data (outstr,ZminTag,RealType, &(Zmin(iptr)), 0);
      put_data (outstr,DxTag,  RealType, &(Dx(iptr)),   0);
      put_data (outstr,DyTag,  RealType, &(Dy(iptr)),   0);
      put_data (outstr,DzTag,  RealType, &(Dz(iptr)),   0);
      put_data (outstr,XrefTag,RealType, &(Xref(iptr)), 0);
      put_data (outstr,YrefTag,RealType, &(Yref(iptr)), 0);
      put_data (outstr,ZrefTag,RealType, &(Zref(iptr)), 0);
      put_data (outstr,MapMinTag, RealType, &(MapMin(iptr)), 0);
      put_data (outstr,MapMaxTag, RealType, &(MapMax(iptr)), 0);
      put_data (outstr,BeamTypeTag, IntType, &(BeamType(iptr)), 0);
      put_data (outstr,BeamxTag, RealType, &(Beamx(iptr)), 0);
      put_data (outstr,BeamyTag, RealType, &(Beamy(iptr)), 0);
      put_data (outstr,BeamzTag, RealType, &(Beamz(iptr)), 0);
      if (Namex(iptr))
         put_string (outstr,NamexTag,Namex(iptr));
      if (Namey(iptr))
         put_string (outstr,NameyTag,Namey(iptr));
      if (Namez(iptr))
         put_string (outstr,NamezTag,Namez(iptr));
      if (Unit(iptr))
         put_string (outstr,UnitTag,Unit(iptr));
      put_data (outstr,TimeTag,  RealType, &(Time(iptr)), 0);
      put_string(outstr,StorageTag,matdef[idef]);
      put_data (outstr,AxisTag,  IntType, &(Axis(iptr)), 0);
    put_tes (outstr, ParametersTag);
         
    put_set (outstr,MapTag);
    if (Nz(iptr)==1)
      put_data (outstr,MapValuesTag,RealType,
		Frame(iptr),Nx(iptr),Ny(iptr),0);
    else
      put_data (outstr,MapValuesTag,RealType,
		Frame(iptr),Nx(iptr),Ny(iptr),Nz(iptr),0);
    put_tes (outstr, MapTag);
  put_tes (outstr, ImageTag);
  return 1;
}
示例#11
0
文件: ccdhist.c 项目: jobovy/nemo
local void read_data()
{
  int   i, k, ndata, n;
  real *data;
  stream instr;
  imageptr iptr=NULL;	


  instr = stropen (input, "r");
  read_image (instr,&iptr);
  strclose(instr);

  ndata = Nx(iptr) * Ny(iptr) * Nz(iptr);
  data = Frame(iptr);
  x = (real *) allocate(ndata*sizeof(real));

  if (scale != 1.0) {
    for (i=0; i<ndata; i++)
      data[i] *= scale;
  }

  if (Qdual) {
    /* pass over the data, finding the mean */
    dual_mean = 0.0;
    n = 0;
    for (i=0; i<ndata; i++) {
      if (Qblank && data[i]==blankval) continue;
      dual_mean += data[i];
      n++;
    }
    dual_mean /= n;
    dprintf(0,"Dual pass mean       : %g\n",dual_mean);
  } else
    dual_mean = 0.0;

  Nunder = Nover = Nblank = 0;
  for (i=0, k=0; i<ndata; i++) {
    if (Qblank && data[i]==blankval) { Nblank++; continue;}
    data[i] -= dual_mean;
    if (Qmin && data[i] < xrange[0]) { Nunder++; continue;}
    if (Qmax && data[i] > xrange[1]) { Nover++;  continue;}
    /* should now copy data into new array for later work */
    x[k++] = data[i];
  }
  npt = k;
  dprintf(0,"Under/Over flow: %d %d\n",Nunder,Nover);
  dprintf(0,"Blanked:         %d\n",Nblank);


  minmax(npt, x, &xmin, &xmax);
  if (!Qmin) xrange[0] = xmin;
  if (!Qmax) xrange[1] = xmax;

  /*  allocate index arrray , and compute sorted index for median */
  if (Qmedian) 
    (mysort)(x,npt,sizeof(real),compar_real);
  free_image(iptr);

}
示例#12
0
inline void IsingLattice::initialize(){
	// initialize the grid (all up)
	set_all(spin_up);
	
	m_total_magnetization = Nx() * Ny() * Nz(); // initial total magnetization = number of sites
	// As the energy of this initial configuration is the lowest possible for the system anyway,
	// it is conveniant to just set it to zero:
	m_total_energy = 0;
}
示例#13
0
文件: image.c 项目: jobovy/nemo
int create_image_mask(imageptr iptr, image_maskptr *mptr)
{
  int nx = Nx(iptr);
  int ny = Ny(iptr);
  int nz = Nz(iptr);
  size_t np = nx*ny*nz;

  *mptr = (image_maskptr ) allocate(sizeof(image_mask));
  dprintf (DLEV,"create_image_mask:Allocated image_mask @ %d size=%d * %d * %d",*mptr,nx,ny,nz);
  if (*mptr == NULL) return 0;	/* no memory available */
    	
  Frame(*mptr) = (bool *) allocate(np*sizeof(bool));	
  dprintf (DLEV,"Frame allocated @ %d ",Frame(*mptr));
  if (Frame(*mptr)==NULL) {
    printf ("CREATE_IMAGE_MASK: Not enough memory to allocate image\n");
    return 0;
  }
  Nx(*mptr) = nx;
  Ny(*mptr) = ny;
  Nz(*mptr) = nz;
  return 1;
}
示例#14
0
local void object_isothermal(int npars, real *pars)
{
  int i,nx = Nx(iptr);
  int j,ny = Ny(iptr);
  int l, lmax;
  real A = 1.0;   /* peak */
  real h = 1.0;   /* size */
  real p = -0.5;  /* power factor */
  real x1,y1,x2,y2,x3,y3,r,arg,value;
  real amp,phi,sum;
  real sinb,cosb;

  if (npar > 0) A = pars[0];
  if (npar > 1) h = pars[1];
  if (npar > 2) p = pars[2];
  dprintf(0,"isothermal: %g %g %g \n",A,h,p);

  if (A==0) return;

  lmax = Qtotflux ? 2 : 1;

  for (l=0; l<lmax; l++) {     /* 1st loop: sum up the flux   if in 2nd loop: normalize */
    if (l==0) 
      sum = 0.0;
    else {
      A /= sum;
      dprintf(0,"isothermal: A->%g\n",A);
    } 
    for (j=0; j<ny; j++) {
      y1 = (j-center[1])*Dy(iptr) + Ymin(iptr);
      for (i=0; i<nx; i++) {
	x1 = (i-center[0])*Dx(iptr) + Xmin(iptr);
	
	x2 =  -x1*sinp - y1*cosp;
	y2 =  (x1*cosp - y1*sinp)/cosi;

	r = (x2*x2+y2*y2)/(h*h);
	value = A * pow(1.0+r, p);

	if (Qtotflux) {   
	  if (l==0) 
	    sum += value;
	  else
	    MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
	} else
	  MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
      } /* i */
    } /* j */
  } /* k */
}
示例#15
0
文件: image.c 项目: jobovy/nemo
int copy_image (imageptr iptr, imageptr *optr)
{
  int nx,ny,nz;
  size_t np;
  nx = Nx(iptr);
  ny = Ny(iptr);
  nz = Nz(iptr);
  np = nx*ny*nz;
  

  *optr = (imageptr ) allocate(sizeof(image));
  dprintf (DLEV,"copy_image:Allocated image @ %d size=%d * %d * %d",*optr,nx,ny,nz);
    	
  Frame(*optr) = (real *) allocate(np*sizeof(real));	
  dprintf (DLEV,"Frame allocated @ %d ",Frame(*optr));
  Nx(*optr) = nx;
  Ny(*optr) = ny;
  Nz(*optr) = nz;
  Xmin(*optr) = Xmin(iptr);
  Ymin(*optr) = Ymin(iptr);
  Zmin(*optr) = Zmin(iptr);
  Dx(*optr) = Dx(iptr);
  Dy(*optr) = Dy(iptr);
  Dz(*optr) = Dz(iptr);
  Namex(*optr) = mystrcpy(Namex(iptr));
  Namey(*optr) = mystrcpy(Namey(iptr));
  Namez(*optr) = mystrcpy(Namez(iptr));
  Xref(*optr) = Xref(iptr);
  Yref(*optr) = Yref(iptr);
  Zref(*optr) = Zref(iptr);
  Storage(*optr) = matdef[idef];
  Axis(*optr) = Axis(iptr);
  set_iarray(*optr);
  
  return 1;		/* succes return code  */
}
示例#16
0
nemo_main()
{
    imageptr iptr=NULL, optr=NULL;
    string *filename;
    stream instr, outstr;
    int i, j, i0, j0, nfiles;
    int nx, ny, nx1, ny1, ix, iy, n;

    nx = hasvalue("nx") ? getiparam("nx") : 0;
    ny = hasvalue("ny") ? getiparam("ny") : 0;
    
    filename = burststring(getparam("in")," ,\n");
    nfiles = xstrlen(filename,sizeof(string))-1;
    if (nx==0 && ny==0)
      error("Need at least one of nx= or ny=");
    else if (nx==0) {
      nx = nfiles/ny;
      dprintf(0,"nx=%d ny=%d nfiles=%d\n",nx,ny,nfiles);
      if (nfiles % ny) error("nfiles=%d/ny=%d does not divide evenly",nfiles,ny);
    } else if (ny==0) {
      ny = nfiles/nx;
      dprintf(0,"nx=%d ny=%d nfiles=%d\n",nx,ny,nfiles);
      if (nfiles % nx) error("nfiles=%d/nx=%d does not divide evenly",nfiles,nx);
    }

    for (iy=0, n=0; iy<ny; iy++) {
      for (ix=0; ix<nx; ix++, n++) {
	instr = stropen (filename[n],"r");
	read_image (instr,&iptr);               /* read image */
	strclose(instr);                        /* close image file */
	if (n==0) {
	  nx1 = Nx(iptr);
	  ny1 = Ny(iptr);
	  create_image(&optr,nx*nx1,ny*ny1);
	}
	i0 = ix*nx1;
	j0 = iy*ny1;
	for (j=0; j<ny1; j++)
	  for (i=0; i<nx1; i++)
	    MapValue(optr,i+i0,j+j0) = MapValue(iptr,i,j);
	i++;
      }
    }
    outstr = stropen(getparam("out"),"w");
    write_image(outstr,optr);
    strclose(outstr);
}
const arma::vec& CylindricalBirefringentMaterial::centerOfMass()
{
  com.set_size(3);
  com.fill(0.0);
  double mass = 0.0;
  for ( unsigned int z=0;z<Nz();z++ )
  for ( unsigned int y=0;y<Ny();y++ )
  for ( unsigned int x=0;x<Nx();x++ )
  {
    com(0) += x*get(x,y,z);
    com(1) += y*get(x,y,z);
    com(2) += z*get(x,y,z);
    mass += get(x,y,z);
  }
  com /= mass;
  return com;
}
示例#18
0
local void object_bar(int npars, real *pars)
{
  int i,nx = Nx(iptr);
  int j,ny = Ny(iptr);
  real A = 1.0;
  real h = 1.0;
  real e = 0.0;
  real b = 0.0;
  real x1,y1,x2,y2,x3,y3,r,arg,value;
  real sinb,cosb,omba;

  if (npar > 0) A = pars[0];
  if (npar > 1) h = pars[1];
  if (npar > 2) e = pars[2];
  if (npar > 3) b = pars[3];
  dprintf(0,"bar: %g %g %g %g\n",A,h,e,b);

  sinb = sin(b*PI/180.0);
  cosb = cos(b*PI/180.0);

  if (A==0) return;

  if (Qtotflux) {
    A /= (PI*h*h*(1-e)/surface);
    dprintf(0,"bar: A->%g\n",A);
  }
  dprintf(1,"bar b=%g\n",b);

  for (j=0; j<ny; j++) {
    y1 = (j-center[1])*Dy(iptr) + Ymin(iptr);
    for (i=0; i<nx; i++) {
      x1 = (i-center[0])*Dx(iptr) + Xmin(iptr);

      x2 =  -x1*sinp - y1*cosp;
      y2 =   (x1*cosp - y1*sinp)/cosi;

      x3 =   x2*cosb - y2*sinb;
      y3 = (x2*sinb  + y2*cosb)/(1-e);

      r = sqrt(x3*x3+y3*y3);
      arg = r/h;
      value = (arg < 100) ? A * exp(-arg) : 0.0;
      MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + value;
    }
  }
}
示例#19
0
local void object_flat(int npars, real *pars)
{
  int i,j;
  int nx = Nx(iptr);
  int ny = Ny(iptr);
  real A = 1.0;

  if (A==0) return;

  if (npar > 0) A = pars[0];

  if (Qtotflux) A /= (nx*ny);

  for (j=0; j<ny; j++)
    for (i=0; i<nx; i++)
      MapValue(iptr,i,j) = factor*MapValue(iptr,i,j) + A;

}
示例#20
0
void report_minmax(string t)
{
    real m_min, m_max, brightness, total;
    int    i, ix, iy, iz, kounter, idir;
    char   *cp;

    m_max = -HUGE;                      /* determine new min/max */
    m_min =  HUGE;
    for (ix=0; ix<Nx(iptr); ix++)   	
    for (iy=0; iy<Ny(iptr); iy++)
    for (iz=0; iz<Nz(iptr); iz++) {
          brightness = CubeValue(iptr,ix,iy,iz);
	  total += brightness;
          m_max = MAX(m_max, brightness);
          m_min = MIN(m_min, brightness);
    }
    dprintf (0,"%s min and max in map are: %f %f\n",t,m_min,m_max);
    dprintf (0,"%s total values: %f\n",t,total);
    dprintf (0,"%s total surden: %f\n",t,total*Dx(iptr)*Dy(iptr));
}
示例#21
0
文件: image.c 项目: jobovy/nemo
/*
 * CREATE_CUBE: create a blank cube Nx by Ny by Nz in size
 */
int create_cube (imageptr *iptr, int nx, int ny, int nz)
{
    *iptr = (imageptr ) allocate(sizeof(image));
    dprintf (DLEV,"CREATE_CUBE: Allocated image @ cube %d size=%d * %d * %d",
		*iptr,nx,ny,nz);
    if (*iptr == NULL)
	return 0;	/* no memory available */
    	
    Frame(*iptr) = (real *) allocate(nx*ny*nz*sizeof(real));	
    dprintf (DLEV,"Frame allocated @ %d ",Frame(*iptr));
    Nx(*iptr) = nx;             /* cube dimension */
    Ny(*iptr) = ny;
    Nz(*iptr) = nz;
    Xmin(*iptr) = 0.0;          /* start lower left corner at 0.0 */
    Ymin(*iptr) = 0.0;
    Zmin(*iptr) = 0.0;
    Xref(*iptr) = 0.0;
    Yref(*iptr) = 0.0;
    Zref(*iptr) = 0.0;
    Dx(*iptr) = 1.0;            /* unity pixels */
    Dy(*iptr) = 1.0;
    Dz(*iptr) = 1.0;
    MapMin(*iptr) = 0.0;
    MapMax(*iptr) = 0.0;
    BeamType(*iptr) = 0;
    Beamx(*iptr) = 0.0;         /* name beams */
    Beamy(*iptr) = 0.0;
    Beamz(*iptr) = 0.0;
    Namex(*iptr) = NULL;        /* no axis names yet */
    Namey(*iptr) = NULL;
    Namez(*iptr) = NULL;
    Unit(*iptr)  = NULL;        /* no units */
    Time(*iptr)  = 0.0;
    Storage(*iptr) = matdef[idef];
    Axis(*iptr) = 0;
    Mask(*iptr) = NULL;
    set_iarray(*iptr);
    
    return 1;		/* succes return code  */
}
示例#22
0
void takeStep(ADDvector&  x, ADDvector&  lambda, ADDvector&  nu, 
		           ADDvector& Dx, ADDvector& Dlambda, ADDvector& Dnu) {

	ADD s = mgr.addOne();
	ADD alpha = mgr.constant(.9);
	ADDvector Nx(Dx.count());
	ADDvector Nlambda(Dlambda.count());
	ADDvector Nnu(Dnu.count());

	//Start with a full step
	for(int i = 0; i < x.count(); i++) {
		Nx[i] = Dx[i] * s;
	}
	for(int i = 0; i < lambda.count(); i++) {
		Nlambda[i] = Dlambda[i] * s;
	}
	for(int i = 0; i < nu.count(); i++) {
		Nnu[i] = Dnu[i] * s;
	}

	//Decay step size while instances are not feasible...
	ADD feasible = Valid(Nx, Nlambda, Nnu);
	while (feasible != mgr.addOne()) {
		s *= alpha;
		for(int i = 0; i < x.count(); i++) {
			Nx[i] = Nx[i] * feasible + (x[i] + Dx[i] * s) * feasible.Cmpl();
		}
		for(int i = 0; i < lambda.count(); i++) {
			Nlambda[i] = Nlambda[i] * feasible + (lambda[i] + Dlambda[i] * s) * feasible.Cmpl();
		}
		for(int i = 0; i < nu.count(); i++) {
			Nnu[i] = Nnu[i] * feasible + (nu[i] + Dnu[i] * s) * feasible.Cmpl();
		}
		feasible = Valid(Nx, Nlambda, Nnu);
	}
	x = Nx;
	lambda = Nlambda;
	nu = Nnu;
}
示例#23
0
文件: image.c 项目: jobovy/nemo
int create_image (imageptr *iptr, int nx, int ny)
{
    *iptr = (imageptr ) allocate(sizeof(image));
    dprintf (DLEV,"create_image:Allocated image @ %d size=%d * %d",*iptr,nx,ny);
    Frame(*iptr) = (real *) allocate(nx*ny*sizeof(real));	
    dprintf (DLEV,"Frame allocated @ %d ",Frame(*iptr));
    Axis(*iptr) = 0;            /* old style axis with no reference pixel */
    Nx(*iptr) = nx;             /* old style ONE map, no cube */
    Ny(*iptr) = ny;
    Nz(*iptr) = 1;
    Xmin(*iptr) = 0.0;          /* start lower left corner at 0.0 */
    Ymin(*iptr) = 0.0;
    Zmin(*iptr) = 0.0;
    Dx(*iptr) = 1.0;            /* unity pixels */
    Dy(*iptr) = 1.0;
    Dz(*iptr) = 1.0;
    Xref(*iptr) = 0.0;
    Yref(*iptr) = 0.0;
    Zref(*iptr) = 0.0;
    MapMin(*iptr) = 0.0;
    MapMax(*iptr) = 0.0;
    BeamType(*iptr) = 0;
    Beamx(*iptr) = 0.0;         /* name beams */
    Beamy(*iptr) = 0.0;
    Beamz(*iptr) = 0.0;
    Namex(*iptr) = NULL;        /* no axis names */
    Namey(*iptr) = NULL;
    Namez(*iptr) = NULL;
    Unit(*iptr)  = NULL;        /* no units */
    Time(*iptr)  = 0.0;
    Storage(*iptr) = matdef[idef];
    Axis(*iptr) = 0;
    Mask(*iptr) = NULL;
    set_iarray((*iptr));

    return 1;		/* succes return code  */
}
const arma::mat& CylindricalBirefringentMaterial::inertiaTensor()
{
  centerOfMass();
  inertia.set_size(3,3);
  inertia.fill(0.0);
  for ( unsigned int z=0;z<Nz();z++ )
  for ( unsigned int y=0;y<Ny();y++ )
  for ( unsigned int x=0;x<Nx();x++ )
  {
    double xcrd = static_cast<int>(x)-com(0);
    double ycrd = static_cast<int>(y)-com(1);
    double zcrd = static_cast<int>(z)-com(2);
    inertia(0,0) += (ycrd*ycrd + zcrd*zcrd)*get(x,y,z);
    inertia(0,1) -= xcrd*ycrd*get(x,y,z);
    inertia(0,2) -= xcrd*zcrd*get(x,y,z);
    inertia(1,1) += (xcrd*xcrd+zcrd*zcrd)*get(x,y,z);
    inertia(1,2) -= ycrd*zcrd*get(x,y,z);
    inertia(2,2) += (xcrd*xcrd+ycrd*ycrd)*get(x,y,z);
  }
  inertia(1,0) = inertia(0,1);
  inertia(2,1) = inertia(1,2);
  inertia(2,0) = inertia(0,2);
  return inertia;
}
示例#25
0
void make_rawheader(FITS *fitsfile, imageptr iptr, bool Qrel)
{
    int ndim, n;
    double tmpr[3];
    
    ndim = (Nz(iptr) > 1) ? 3 : 2;

    n = nemoinpd(getparam("cdelt"),tmpr,3);
    if (n == 0) {
        Dx(iptr) = 2.0/Nx(iptr);
        Dy(iptr) = 2.0/Ny(iptr);
        Dz(iptr) = 2.0/Nz(iptr);
    } else if (n == 3) {
        Dx(iptr) = tmpr[0];
        Dy(iptr) = tmpr[1];
        Dz(iptr) = tmpr[2];
    } else
        error("cdelt= needs either 3 or 0 entries");

    Xmin(iptr) = 0.0;
    Ymin(iptr) = 0.0;
    Zmin(iptr) = 0.0;

}
示例#26
0
文件: ccdsmooth.c 项目: jobovy/nemo
void smooth_it()
{
    real m_min, m_max, brightness, total;
    int    i, ix, iy, iz, kounter, idir;
    char   *cp;

    m_min = HUGE;
    m_max = -HUGE;
    total = 0.0;

    kounter = nsmooth;
    while (kounter-- > 0) {
     	dprintf (1,"Convolving %s with %d-length beam: ",dir,lsmooth);
	for (i=0; i<lsmooth; i++)
		dprintf (1," %f ",smooth[i]);
	cp = dir;			/* point to direction again */
        while (*cp) {
            if (*cp=='x')
	        idir=1;
	    else if (*cp=='y')
                idir=2;
            else if (*cp=='z')
                idir=3;
            else
	        error("Wrong direction %c for beamsmoothing\n",*cp);
	    convolve_cube (Frame(iptr),nx,ny,nz,smooth,lsmooth,idir);
            cp++;
	}
    }

    m_max = -HUGE;                      /* determine new min/max */
    m_min =  HUGE;
    for (ix=0; ix<Nx(iptr); ix++)   	
    for (iy=0; iy<Ny(iptr); iy++)
    for (iz=0; iz<Nz(iptr); iz++) {
          brightness = CubeValue(iptr,ix,iy,iz);
	  total += brightness;
          m_max = MAX(m_max, brightness);
          m_min = MIN(m_min, brightness);
    }
    MapMin(iptr) = m_min; 		/* update map headers */
    MapMax(iptr) = m_max;
    if (hasvalue("gauss")) {
    	BeamType(iptr)=GAUSS;
	if (strchr(getparam("dir"),'x'))
    	   Beamx(iptr)=gauss_fwhm;
 	if (strchr(getparam("dir"),'y'))
    	   Beamy(iptr)=gauss_fwhm;
	if (strchr(getparam("dir"),'z'))
    	   Beamz(iptr)=gauss_fwhm;
     } else {
    	BeamType(iptr)=ANYBEAM;
	/*  factor (3+nsmooth)/2   is very roughly ok for nsmooth=1,2,3,4 */
	Beamx(iptr) = (1.5+0.5*nsmooth) * ABS(Dx(iptr));
	Beamy(iptr) = (1.5+0.5*nsmooth) * ABS(Dy(iptr));
	Beamz(iptr) = (1.5+0.5*nsmooth) * ABS(Dz(iptr));
     }
    	
    dprintf (1,"New min and max in map are: %f %f\n",m_min,m_max);
    dprintf (1,"New total brightness/mass is %f\n",total*Dx(iptr)*Dy(iptr));
}
示例#27
0
文件: velfitpatch.c 项目: jobovy/nemo
nemo_main()
{
  bool Qsample, Qtab, Qout, Qxy;
  stream velstr, tabstr, outstr0, outstr1, outstr2;
  real scale;
  real *x, *y, *v, sol[3];
  int i, j, id, jd, nx, ny, nd, d, d2;
  string outmode = getparam("mode");
  string bname, oname;
  int mode = -1;
  int npt = 0;

  /* output mode */

  Qtab = hasvalue("tab");
  Qxy  = (*outmode == 'x' || *outmode == 'X');

  scale = getdparam("scale");

  /* read velocity field */

  velstr = stropen(getparam("in"),"r");
  read_image(velstr,&velptr);
  nx = Nx(velptr);
  ny = Ny(velptr);

  Qout = hasvalue("out");
  if (Qout) {
    copy_image(velptr, &outptr0);
    copy_image(velptr, &outptr1);
    copy_image(velptr, &outptr2);
    bname = getparam("out");
    oname = (string) allocate(strlen(bname) + 5);
    sprintf(oname,"%s.%s", bname, "vc");
    outstr0 = stropen(oname,"w");
    sprintf(oname,"%s.%s", bname, Qxy ? "ox" : "om");
    outstr1 = stropen(oname,"w");
    sprintf(oname,"%s.%s", bname, Qxy ? "oy" : "pa");
    outstr2 = stropen(oname,"w");
  }

  /* needed arrays */

  d = getiparam("patch");
  d2 = 2*d + 1;
  x = (real *) allocate(d2*d2*sizeof(real));
  y = (real *) allocate(d2*d2*sizeof(real));
  v = (real *) allocate(d2*d2*sizeof(real));

  for (i=d; i<nx-d; i++) {
    for (j=d; j<ny-d; j++) {
      nd = 0;
      for (id=-d; id<=d; id++) {
	for (jd=-d; jd<=d; jd++) {
	  x[nd] = id;
	  y[nd] = jd;
	  v[nd] = MapValue(velptr, i+id, j+jd);
	  if (v[nd] != 0.0) nd++;
	}
      }
      fit_patch(nd, x, y, v, sol, scale);
      if (!Qxy) xy2rt(sol);
      if (Qtab) printf("%d %d   %g %g %g\n",i,j,sol[0],sol[1],sol[2]);
      npt++;
      if (Qout) {
	MapValue(outptr0,i,j) = sol[0];
	MapValue(outptr1,i,j) = sol[1];
	MapValue(outptr2,i,j) = sol[2];
      }
    }
  }
  dprintf(0,"Processed %d points with patch area %d x %d\n",npt,d2,d2);
  if (Qout) {
    write_image(outstr0,outptr0);
    write_image(outstr1,outptr1);
    write_image(outstr2,outptr2);
  }
}
示例#28
0
void write_fits(string name,imageptr iptr)
{
    FLOAT tmpr,xmin[3],xref[3],dx[3],mapmin,mapmax;   /* fitsio FLOAT !!! */
    FITS *fitsfile;
    char *cp, origin[80];
    string *hitem, axname[3];
    float *buffer, *bp;
    int i, j, k, axistype, bitpix, keepaxis[3], nx[3], p[3], nx_out[3], ndim=3;
    double bscale, bzero;
    
    if (hasvalue("ndim")) ndim = getiparam("ndim");
    nx[0] = Nx(iptr);
    nx[1] = Ny(iptr);
    nx[2] = Nz(iptr);   if (nx[2] <= 0) nx[2] = 1;
    xmin[0] = Xmin(iptr)*scale[0];
    xmin[1] = Ymin(iptr)*scale[1];
    xmin[2] = Zmin(iptr)*scale[2];
    dx[0] = Dx(iptr)*scale[0];
    dx[1] = Dy(iptr)*scale[1];
    dx[2] = Dz(iptr)*scale[2];
    xref[0] = Xref(iptr)+1.0;
    xref[1] = Yref(iptr)+1.0;
    xref[2] = Zref(iptr)+1.0;
    axistype = Axis(iptr);
    axname[0] = (Namex(iptr) ? Namex(iptr) : xyz[0]);
    axname[1] = (Namey(iptr) ? Namey(iptr) : xyz[1]);
    axname[2] = (Namez(iptr) ? Namez(iptr) : xyz[2]);
    mapmin = MapMin(iptr);
    mapmax = MapMax(iptr);
    if (Qdummy) 
      for (i=0; i<3; i++) p[i] = i;
    else {
      if (Qrefmap) warning("dummy=f and usage of refmap will result in bad headers");
      permute(nx,p,3);
      dprintf(0,"Reordering axes: %d %d %d\n",p[0],p[1],p[2]);
    }
#if 1
    for (i=0; i<3; i++)  nx_out[i] = nx[p[i]];
    /* fix this so CubeValue works */
    Nx(iptr) = nx_out[0];
    Ny(iptr) = nx_out[1];
    Nz(iptr) = nx_out[2];
#else
    for (i=0; i<3; i++)  nx_out[i] = nx[i];
#endif
    sprintf(origin,"NEMO ccdfits %s",getparam("VERSION"));

    dprintf(1,"NEMO Image file written to FITS disk file\n");
    dprintf(1,"%d %d %d   %f %f %f   %f %f %f  %f %f %f   %f %f \n",
	    nx[0],nx[1],nx[2],xmin[0],xmin[1],xmin[2],dx[0],dx[1],dx[2],xref[0],xref[1],xref[2],
	    mapmin,mapmax);
    dprintf(1,"keepaxis(%d,%d,%d)\n",keepaxis[0],keepaxis[1],keepaxis[2]);
    
    fit_setblocksize(2880*getiparam("blocking"));
    bitpix = getiparam("bitpix");
    fit_setbitpix(bitpix);
    if (bitpix == 16) {      /* scale from -2^(bitpix-1) .. 2^(bitpix-1)-1 */
        bscale = (mapmax - mapmin) / (2.0*32768.0 - 1.0);
        bzero = mapmax - bscale*32767.0;
        fit_setscale(bscale,bzero);
    } else if (bitpix == 32) {
        bscale = (mapmax - mapmin) / (2.0*2147483648.0 - 1.0);
        bzero = mapmax - bscale*2147483647.0;
        fit_setscale(bscale,bzero);
    } else if (bitpix == 8) {
    	bscale = (mapmax - mapmin) / (2.0*128.0 - 1.0);
    	bzero = mapmin;
    	fit_setscale(bscale,bzero);
    }
    dprintf(1,"bscale,bzero=%g %g\n",bscale,bzero);

    fitsfile = fitopen(name,"new",ndim,nx_out);
    if (fitsfile==NULL) error("Could not open fitsfile %s for writing\n",name);

    if (Qrefmap || Qcrpix) {
      fitwrhdr(fitsfile,"CRPIX1",ref_crpix[0]);       
      fitwrhdr(fitsfile,"CRPIX2",ref_crpix[1]);       
      if (ndim>2) fitwrhdr(fitsfile,"CRPIX3",ref_crpix[2]);
    } else {
      if (axistype==1) {
	fitwrhdr(fitsfile,"CRPIX1",xref[0]);      
	fitwrhdr(fitsfile,"CRPIX2",xref[1]);
	if (ndim>2) fitwrhdr(fitsfile,"CRPIX3",xref[2]);
      } else {
	fitwrhdr(fitsfile,"CRPIX1",1.0);        /* CRPIX = 1 by Nemo definition */
	fitwrhdr(fitsfile,"CRPIX2",1.0);
	if (ndim>2) fitwrhdr(fitsfile,"CRPIX3",1.0);
      }
    }
    if (Qrefmap || Qcrval) {
      fitwrhdr(fitsfile,"CRVAL1",ref_crval[0]);
      fitwrhdr(fitsfile,"CRVAL2",ref_crval[1]);
      if (ndim>2) fitwrhdr(fitsfile,"CRVAL3",ref_crval[2]);
    } else {
      fitwrhdr(fitsfile,"CRVAL1",xmin[p[0]]);
      fitwrhdr(fitsfile,"CRVAL2",xmin[p[1]]);
      if (ndim>2) fitwrhdr(fitsfile,"CRVAL3",xmin[p[2]]);
    }

    if (Qcdmatrix) {
      fitwrhdr(fitsfile,"CD1_1",dx[p[0]]);    
      fitwrhdr(fitsfile,"CD2_2",dx[p[1]]);    
      if (ndim>2) fitwrhdr(fitsfile,"CD3_3",dx[p[2]]);    
    } else {
      if (Qrefmap || Qcdelt) {
	fitwrhdr(fitsfile,"CDELT1",ref_cdelt[0]*scale[0]);
	fitwrhdr(fitsfile,"CDELT2",ref_cdelt[1]*scale[1]);
	if (ndim>2) fitwrhdr(fitsfile,"CDELT3",ref_cdelt[2]*scale[2]);
      } else {
	fitwrhdr(fitsfile,"CDELT1",dx[p[0]]);    
	fitwrhdr(fitsfile,"CDELT2",dx[p[1]]);    
	if (ndim>2) fitwrhdr(fitsfile,"CDELT3",dx[p[2]]);
      }
    }

    if (Qradecvel) {
      dprintf(0,"[Axes names written as %s, %s, %s\n",
	      radeve[p[0]],radeve[p[1]],radeve[p[2]]);
      fitwrhda(fitsfile,"CTYPE1",radeve[p[0]]);
      fitwrhda(fitsfile,"CTYPE2",radeve[p[1]]);
      if (ndim>2) fitwrhda(fitsfile,"CTYPE3",radeve[p[2]]);
    } else {
      if (Qrefmap) {
        fitwrhda(fitsfile,"CTYPE1",ref_ctype[0]);
        fitwrhda(fitsfile,"CTYPE2",ref_ctype[1]);
        if (ndim>2) fitwrhda(fitsfile,"CTYPE3",ref_ctype[2]);
      } else {
	fitwrhda(fitsfile,"CTYPE1",axname[p[0]]);
	fitwrhda(fitsfile,"CTYPE2",axname[p[1]]);
	if (ndim>2) fitwrhda(fitsfile,"CTYPE3",axname[p[2]]);
      }
    }

    fitwrhdr(fitsfile,"DATAMIN",mapmin);
    fitwrhdr(fitsfile,"DATAMAX",mapmax);
    fitwrhda(fitsfile,"ORIGIN",origin);

    cp = getenv("USER");                                /* AUTHOR */
    if (cp)
        fitwrhda(fitsfile,"AUTHOR",cp);
    else
        fitwrhda(fitsfile,"AUTHOR","NEMO");

    if (object)                                        /* OBJECT */
        fitwrhda(fitsfile,"OBJECT",object);

    if (comment)                                       /* COMMENT */
        stuffit(fitsfile,"COMMENT",comment);
    if (headline)
        stuffit(fitsfile,"COMMENT",headline);

    hitem = ask_history();                              /* HISTORY */
    fitwra(fitsfile,"HISTORY","NEMO: History in reversed order");
    for (i=0, cp=hitem[0]; cp != NULL; i++) {
    	stuffit(fitsfile,"HISTORY",cp);
        cp = hitem[i+1];
    }

    for(i=0; i<nfill; i++)   /* debugging header I/O */
        fitwra(fitsfile,"COMMENT","Dummy filler space");

    buffer = (float *) allocate(nx[p[0]]*sizeof(float));

    for (k=0; k<nx_out[2]; k++) {          /* loop over all planes */
        fitsetpl(fitsfile,1,&k);
        for (j=0; j<nx_out[1]; j++) {      /* loop over all rows */
            for (i=0, bp=buffer; i<nx_out[0]; i++, bp++)
                *bp =  iscale[0] * CubeValue(iptr,i,j,k) + iscale[1];
            fitwrite(fitsfile,j,buffer);
        }
    }
    free(buffer);
    fitclose(fitsfile);
}
示例#29
0
plot_map ()
{
    real m_range, brightness, dcm;
    real m_min, m_max;
    int    i, ix, iy;
    int    cnt;		/* counter of pixels */

    nsize = Nx(iptr);  /* old method forced square .. */			
    cell = Dx(iptr);   /* and forced so for gray scale due to LW mem-problems */
    size = nsize*cell;
    
    m_min = MapMin(iptr);	/* get min- and max from header */
    m_max = MapMax(iptr);
    dprintf (1,"Min and max in map from map-header are: %f %f\n",m_min,m_max);
 
    if (mmax==UNDEF)	/* reset default autoscales to user supplied if necessary */
	mmax=m_max;
    if (mmin==UNDEF)
    	mmin=m_min;
    m_range = mmax-mmin;
    if (m_range==0) {
    	mmax=mmin+1.0;
	if (gray) warning("%g; Plot-range was zero, mmax increased by 1",mmin);
    }
        
    dprintf (1,"User reset Min and max are: %f %f\n",mmin,mmax);

    
    sprintf (plabel,"File: %s",infile);			/* filename */
    sprintf (clabel,"Contours: %s",cntstr);             /* contour levels */
    sprintf (glabel,"Gray MinMax: %g %g",mmin,mmax);    /* grey scale minmax */
    sprintf (tlabel,"Time: %g",Time(iptr));             /* time of orig snapshot */

	/* set scales and labels along axes */
    if (xplot[0]==UNDEF || xplot[1]==UNDEF) {
    	xplot[0] = Xmin(iptr) - 0.5*Dx(iptr);
    	xplot[1] = xplot[0] + Nx(iptr)*Dx(iptr);
    }
    if (Namex(iptr))
        strncpy(xlabel,Namex(iptr),80);
    else
        strcpy (xlabel,"");

    if (yplot[0]==UNDEF || yplot[1]==UNDEF) {
    	yplot[0] = Ymin(iptr) - 0.5*Dy(iptr);
    	yplot[1] = yplot[0] + Ny(iptr)*Dy(iptr);
    }
    if (Namey(iptr))
        strncpy(ylabel,Namey(iptr),80);
    else
        strcpy (ylabel,"");
	
    dprintf (1,"Plotting area x=%f:%f y=%f:%f\n",
    	xplot[0], xplot[1], yplot[0], yplot[1]);

    if (gray) {		
				/* gray-scale */
       dcm = Dx(iptr) / (xplot[1]-xplot[0]) * 16.0;
       pl_matrix (Frame(iptr), nx, ny, 
		  xtrans(Xmin(iptr)), ytrans(Ymin(iptr)), dcm , mmin, mmax, power, blankval);
           /*  color_bar (100.0,500.0,32);  */
     } 
     		/* OLD ROUTINE, has to call relocate/frame ---> plcontour */
     plltype(lwidth,ltype);
     if (cmode==0) 
        contour (Frame(iptr),nx,ny,cntval,ncntval,
		Xmin(iptr), 
		Ymin(iptr), 
		Xmin(iptr)+(Nx(iptr)-1)*Dx(iptr),
		Ymin(iptr)+(Ny(iptr)-1)*Dy(iptr), lineto);
    
     else if (cmode==1)
         pl_contour (Frame(iptr),nx,ny,ncntval,cntval);
     plltype(1,1);

	/* draw axes and their labels */
    xaxis ( 2.0, 2.0, 16.0, xplot, -7, xtrans,  xlabel);
    xaxis ( 2.0,18.0, 16.0, xplot, -7, xtrans,  NULL);
    yaxis ( 2.0, 2.0, 16.0, yplot, -7, ytrans, ylabel);
    yaxis (18.0, 2.0, 16.0, yplot, -7, ytrans, NULL);

    pltext (plabel,2.0,18.4, 0.32, 0.0);	/* plot header with file name */
    pltext (clabel,2.0,19.0, 0.32, 0.0);        /* plot header with contour levels */
    pltext (glabel,2.0,19.6, 0.32, 0.0);        /* plot header with greyscale info */
    pltext (tlabel,10.0,19.6,0.32, 0.0);        /* time info */

    pljust(1);
    pltext (headline,10.0,18.4, 0.26, 0.0);     /* plot extra user suplied header */
    pljust(-1);
}
示例#30
0
nemo_main()
{
    int  i, j, k;
    real x, xmin, xmax, mean, sigma, skew, kurt, median, bad, w, *data;
    real sum, sov;
    Moment m;
    bool Qmin, Qmax, Qbad, Qw, Qmedian, Qmmcount = getbparam("mmcount");
    real nu, nppb = getdparam("nppb");
    int npar = getiparam("npar");
    int ngood = 0;
    int min_count, max_count;

    instr = stropen (getparam("in"), "r");
    read_image (instr,&iptr);
    strclose(instr);

    if (hasvalue("win")) {
      instr = stropen (getparam("win"), "r");
      read_image (instr,&wptr);
      strclose(instr);
      if (Nx(iptr) != Nx(wptr)) error("X sizes of in/win don't match");
      if (Ny(iptr) != Ny(wptr)) error("X sizes of in/win don't match");
      if (Nz(iptr) != Nz(wptr)) error("X sizes of in/win don't match");
      Qw = TRUE;
    } else
      Qw = FALSE;

    nx = Nx(iptr);	
    ny = Ny(iptr);
    nz = Nz(iptr);
    Qmin = hasvalue("min");
    if (Qmin) xmin = getdparam("min");
    Qmax = hasvalue("max");
    if (Qmax) xmax = getdparam("max");
    Qbad = hasvalue("bad");
    if (Qbad) bad = getdparam("bad");
    Qmedian = getbparam("median");
    if (Qmedian)
      data = (real *) allocate(nx*ny*nz*sizeof(real));

    sov = Dx(iptr)*Dy(iptr)*Dz(iptr);   /* voxel volume; TODO: should we do 2D vs. 3D ? */
    
    ini_moment(&m,4,0);
    for (i=0; i<nx; i++) {
      for (j=0; j<ny; j++) {
        for (k=0; k<nz; k++) {
            x =  CubeValue(iptr,i,j,k);
            if (Qmin && x<xmin) continue;
            if (Qmax && x>xmax) continue;
            if (Qbad && x==bad) continue;
	    w = Qw ? CubeValue(wptr,i,j,k) : 1.0;
            accum_moment(&m,x,w);
	    if (Qmedian) data[ngood++] = x;
        }
      }
    }
    if (npar > 0) {
      nu = n_moment(&m)/nppb - npar;
      if (nu < 1) error("%g: No degrees of freedom",nu);
      printf("chi2= %g\n", show_moment(&m,2)/nu/nppb);
      printf("df= %g\n", nu);
    } else {
      nsize = nx * ny * nz;
    
      mean = mean_moment(&m);
      sigma = sigma_moment(&m);
      skew = skewness_moment(&m);
      kurt = kurtosis_moment(&m);
      sum = show_moment(&m,1);
      
      printf ("Min=%f  Max=%f\n",min_moment(&m), max_moment(&m));
      printf ("Number of points      : %d\n",n_moment(&m));
      printf ("Mean and dispersion   : %f %f\n",mean,sigma);
      printf ("Skewness and kurtosis : %f %f\n",skew,kurt);
      printf ("Sum and Sum*Dx*Dy*Dz  : %f %f\n",sum, sum*sov);
      if (Qmedian)
	printf ("Median                : %f\n",get_median(ngood,data));

      if (Qmmcount) {
	min_count = max_count = 0;
	xmin = min_moment(&m);
	xmax = max_moment(&m);
	for (i=0; i<nx; i++) {
	  for (j=0; j<ny; j++) {
	    for (k=0; k<nz; k++) {
	      x =  CubeValue(iptr,i,j,k);
	      if (x==xmin) min_count++;
	      if (x==xmax) max_count++;
	    }
	  }
	} /* i */
	printf("Min_Max_count         : %d %d\n",min_count,max_count);
      }
      printf ("%d/%d out-of-range points discarded\n",nsize-n_moment(&m), nsize);
    }
}