BHAC Python tools
Classes | Functions | Variables
amrplot Namespace Reference

Classes

class  polyplot
 Simple 2D plotter class using matplotlib, plots every cell in one patch. More...
 
class  rgplot
 As polyplot, but use regridded data to display. More...
 

Functions

def velovect (u1, u2, d, nvect=None, scalevar=None, scale=100, color='k', ax=None, alpha=1.)
 Plots normalized velocity vectors. More...
 
def contour (var, d, levels=None, nmax=600, colors='k', linestyles='solid', ax=None, linewidths=1, smooth=1., alpha=1.)
 
def streamlines (u1, u2, d, x0=None, y0=None, nmax=600, density=1, fig=None, color='b', linewidth=1, arrowsize=1, alpha=1., smooth=0)
 plots streamlines from a vector field. More...
 
def streamline (u1, u2, d, x1_0, x2_0, dl=1., fig=None, nmax=600)
 
def gridvar (var, d, xrange, yrange, nmax=600, smooth=0)
 

Variables

 default_timer = time.clock
 

Function Documentation

◆ contour()

def amrplot.contour (   var,
  d,
  levels = None,
  nmax = 600,
  colors = 'k',
  linestyles = 'solid',
  ax = None,
  linewidths = 1,
  smooth = 1.,
  alpha = 1. 
)

Definition at line 475 of file amrplot.py.

475 def contour(var,d,levels=None,nmax=600,colors='k',linestyles='solid',ax=None,linewidths=1,smooth=1.,alpha=1.):
476  if ax==None:
477  ax=plt.gca()
478 
479  xrange=[ax.get_xlim()[0],ax.get_xlim()[1]]
480  yrange=[ax.get_ylim()[0],ax.get_ylim()[1]]
481 
482  # Aspect ratio:
483  r=(xrange[1]-xrange[0])/(yrange[1]-yrange[0])
484  if r<1:
485  ny=nmax
486  nx=int(r*nmax)
487  else:
488  nx=nmax
489  ny=int(nmax/r)
490  nregrid = [nx,ny]
491 
492  CC=d.getCenterPoints()
493  tmp0=np.complex(0,nregrid[0])
494  tmp1=np.complex(0,nregrid[1])
495  grid_x, grid_y = np.mgrid[xrange[0]:xrange[1]:tmp0, yrange[0]:yrange[1]:tmp1]
496  gridvar = griddata(CC, var, (grid_x, grid_y), method='linear')
497  isnan=np.isnan(gridvar)
498  gridvar[isnan] = griddata(CC, var, (grid_x[isnan], grid_y[isnan]), method='nearest')
499 
500 # smooth the data slightly:
501  blurred_gridvar = ndimage.gaussian_filter(gridvar, sigma=smooth)
502 
503 
504  if levels == None:
505  cs = ax.contour(grid_x,grid_y,blurred_gridvar,16,alpha=alpha)
506  else:
507  cs = ax.contour(grid_x,grid_y,blurred_gridvar,levels=levels,colors=colors,linestyles=linestyles,linewidths=linewidths,alpha=alpha)
508 
509  plt.draw()
510  return cs
511 
512 #=============================================================================
def contour(var, d, levels=None, nmax=600, colors='k', linestyles='solid', ax=None, linewidths=1, smooth=1., alpha=1.)
Definition: amrplot.py:475

◆ gridvar()

def amrplot.gridvar (   var,
  d,
  xrange,
  yrange,
  nmax = 600,
  smooth = 0 
)

Definition at line 629 of file amrplot.py.

629 def gridvar(var,d,xrange,yrange,nmax=600,smooth=0):
630 
631  # Aspect ratio:
632  r=(xrange[1]-xrange[0])/(yrange[1]-yrange[0])
633  if r<1:
634  ny=nmax
635  nx=int(r*nmax)
636  else:
637  nx=nmax
638  ny=int(nmax/r)
639  nregrid = [nx,ny]
640 
641  CC=d.getCenterPoints()
642  tmp0=np.complex(0,nregrid[0])
643  tmp1=np.complex(0,nregrid[1])
644  grid_x, grid_y = np.mgrid[xrange[0]:xrange[1]:tmp0, yrange[0]:yrange[1]:tmp1]
645  gridvar = griddata(CC, var, (grid_x, grid_y), method='linear')
646  isnan=np.isnan(gridvar)
647  gridvar[isnan] = griddata(CC, var, (grid_x[isnan], grid_y[isnan]), method='nearest')
648 
649 # smooth the data slightly:
650  blurred_gridvar = ndimage.gaussian_filter(gridvar, sigma=smooth)
651 
652  return blurred_gridvar,grid_x,grid_y
653 
def gridvar(var, d, xrange, yrange, nmax=600, smooth=0)
Definition: amrplot.py:629

◆ streamline()

def amrplot.streamline (   u1,
  u2,
  d,
  x1_0,
  x2_0,
  dl = 1.,
  fig = None,
  nmax = 600 
)

Definition at line 571 of file amrplot.py.

571 def streamline(u1,u2,d,x1_0,x2_0,dl=1.,fig=None,nmax=600):
572 
573  if fig==None:
574  ax=plt.gca()
575  else:
576  ax=fig.figure.gca()
577 
578  xrange=[ax.get_xlim()[0],ax.get_xlim()[1]]
579  yrange=[ax.get_ylim()[0],ax.get_ylim()[1]]
580 
581  if nmax == 600 and fig != None:
582  nmax = fig.dpi * max([fig.fig_w,fig.fig_h])
583 
584 
585  # Aspect ratio:
586  r=(xrange[1]-xrange[0])/(yrange[1]-yrange[0])
587  if r<1:
588  ny=nmax
589  nx=int(r*nmax)
590  else:
591  nx=nmax
592  ny=int(nmax/r)
593  nregrid = [nx,ny]
594 
595  CC=d.getCenterPoints()
596  tmp0=np.complex(0,nregrid[0])
597  tmp1=np.complex(0,nregrid[1])
598  x=np.linspace(xrange[0],xrange[1],nregrid[0])
599  y=np.linspace(yrange[0],yrange[1],nregrid[1])
600  grid_x, grid_y = np.mgrid[xrange[0]:xrange[1]:tmp0, yrange[0]:yrange[1]:tmp1]
601 
602  u = griddata(CC, u1, (grid_x, grid_y), method='linear')
603  v = griddata(CC, u2, (grid_x, grid_y), method='linear')
604  uisnan=np.isnan(u)
605  visnan=np.isnan(v)
606  un = np.empty(np.shape(u))
607  vn = np.empty(np.shape(v))
608  un[uisnan] = griddata(CC, u1, (grid_x[uisnan], grid_y[uisnan]), method='nearest')
609  vn[visnan] = griddata(CC, u2, (grid_x[visnan], grid_y[visnan]), method='nearest')
610  u[uisnan]=un[uisnan]
611  v[visnan]=vn[visnan]
612 # Normalize:
613  mag=np.sqrt(u**2+v**2)
614  u=u/mag
615  v=v/mag
616 
617  fu = interpolate.interp2d(grid_x, grid_y, u, kind='cubic')
618  fv = interpolate.interp2d(grid_x, grid_y, v, kind='cubic')
619  x1=[x1_0]
620  x2=[x2_0]
621  while(x1[-1] >= xrange[0] and x1[-1] <= xrange[1] and
622  x2[-1] >= yrange[0] and x2[-1] <= yrange[1]):
623  dt=dl
624  x1.append(x1[-1]+fu(x1[-1],x2[-1])*dt)
625  x2.append(x2[-1]+fv(x1[-1],x2[-1])*dt)
626  return [np.array(x1),np.array(x2)]
627 
628 #=============================================================================
def streamline(u1, u2, d, x1_0, x2_0, dl=1., fig=None, nmax=600)
Definition: amrplot.py:571

◆ streamlines()

def amrplot.streamlines (   u1,
  u2,
  d,
  x0 = None,
  y0 = None,
  nmax = 600,
  density = 1,
  fig = None,
  color = 'b',
  linewidth = 1,
  arrowsize = 1,
  alpha = 1.,
  smooth = 0 
)

plots streamlines from a vector field.

Use density=[densx,densy] to control how close streamlines are allowed to get.

Definition at line 514 of file amrplot.py.

514  '''plots streamlines from a vector field. Use density=[densx,densy] to control how close streamlines are allowed to get.'''
515  if fig==None:
516  ax=plt.gca()
517  else:
518  ax=fig.ax
519 
520  xrange=[ax.get_xlim()[0],ax.get_xlim()[1]]
521  yrange=[ax.get_ylim()[0],ax.get_ylim()[1]]
522 
523  if nmax == 600 and fig != None:
524  nmax = fig.dpi * max([fig.fig_w,fig.fig_h])
525 
526 
527  # Aspect ratio:
528  r=(xrange[1]-xrange[0])/(yrange[1]-yrange[0])
529  if r<1:
530  ny=nmax
531  nx=int(r*nmax)
532  else:
533  nx=nmax
534  ny=int(nmax/r)
535  nregrid = [nx,ny]
536  print(nregrid)
537 
538  CC=d.getCenterPoints()
539  tmp0=np.complex(0,nregrid[0])
540  tmp1=np.complex(0,nregrid[1])
541  x=np.linspace(xrange[0],xrange[1],nregrid[0])
542  y=np.linspace(yrange[0],yrange[1],nregrid[1])
543  grid_x, grid_y = np.mgrid[xrange[0]:xrange[1]:tmp0, yrange[0]:yrange[1]:tmp1]
544 
545  u = griddata(CC, u1, (grid_x, grid_y), method='linear')
546  v = griddata(CC, u2, (grid_x, grid_y), method='linear')
547  uisnan=np.isnan(u)
548  visnan=np.isnan(v)
549  un = np.empty(np.shape(u))
550  vn = np.empty(np.shape(v))
551  un[uisnan] = griddata(CC, u1, (grid_x[uisnan], grid_y[uisnan]), method='nearest')
552  vn[visnan] = griddata(CC, u2, (grid_x[visnan], grid_y[visnan]), method='nearest')
553  u[uisnan]=un[uisnan]
554  v[visnan]=vn[visnan]
555 
556  if (smooth != 0):
557  u = ndimage.gaussian_filter(u, sigma=smooth)
558  v = ndimage.gaussian_filter(v, sigma=smooth)
559 
560  if (x0 != None and y0!= None):
561  for myx in zip(x0,y0):
562  streamplot(x, y, u.transpose(), v.transpose(), x_0=myx[0],
563  y_0=myx[1], density=density, linewidth=linewidth,
564  INTEGRATOR='RK4', color=color, arrowsize=arrowsize,alpha=alpha)
565  else:
566  streamplot(x, y, u.transpose(), v.transpose(),
567  density=density, linewidth=linewidth,
568  INTEGRATOR='RK4', color=color, arrowsize=arrowsize,alpha=alpha)
569 
570 #=============================================================================

◆ velovect()

def amrplot.velovect (   u1,
  u2,
  d,
  nvect = None,
  scalevar = None,
  scale = 100,
  color = 'k',
  ax = None,
  alpha = 1. 
)

Plots normalized velocity vectors.

Definition at line 442 of file amrplot.py.

442  '''Plots normalized velocity vectors'''
443 
444  minvel=1e-40
445 
446  if ax==None:
447  ax=plt.gca()
448 
449  CC=d.getCenterPoints()
450  n=np.sqrt(u1**2+u2**2)
451  # remove zero velocity:
452  m=n<minvel
453  vr=np.ma.filled(np.ma.masked_array(u1/n,m),0.)
454  vz=np.ma.filled(np.ma.masked_array(u2/n,m),0.)
455  if scalevar is not None:
456  vr = vr*scalevar
457  vz = vz*scalevar
458  if nvect==None:
459  Q=ax.quiver(CC[:,0],CC[:,1],vr,vz,pivot='middle',width=1e-3,minlength=0.,scale=scale,
460  headwidth=6,alpha=alpha)
461  else:
462  # regrid the data:
463  tmp0=np.complex(0,nvect[0])
464  tmp1=np.complex(0,nvect[1])
465  grid_r, grid_z = np.mgrid[ax.get_xlim()[0]:ax.get_xlim()[1]:tmp0, ax.get_ylim()[0]:ax.get_ylim()[1]:tmp1]
466  grid_vr = griddata(CC, vr, (grid_r, grid_z), method='nearest')
467  grid_vz = griddata(CC, vz, (grid_r, grid_z), method='nearest')
468  Q=ax.quiver(grid_r,grid_z,grid_vr,grid_vz,pivot='middle',width=2e-3,minlength=minvel,scale=scale,
469  headwidth=10,headlength=10,color=color,edgecolor=color,rasterized=True,alpha=alpha)
470 
471  plt.draw()
472  return Q
473 
474 #=============================================================================

Variable Documentation

◆ default_timer

amrplot.default_timer = time.clock

Definition at line 19 of file amrplot.py.