Ejemplo n.º 1
0
def sample_vectors(vec, mask=None, narrows=800, x0=None, x1=None):
  """Samples a vector field for plotting purposes.

  :param vec:     Vector to sample.
  :type vec:      2D vector of 2D :py:class:`~.RegData`  
  :param mask:    Optional mask for the data.
  :type mask:     :py:class:`~.RegData` or numpy array 
  :param narrows: Desired number of arrows.
  :type narrows:  int
  :param x0:      Sample region lower left coordinate. Default: use data 
                  coordinate range.
  :type x0:       length-2 float list/array or None
  :param x1:      Sample region upper right coordinate. Default: use data 
                  coordinate range.
  :type x1:       length-2 float list/array or None

  The results of this function are      
  
  cd : length-2 tuple of lists or arrays 
    x- and y-coordinates of the samples.
  d : length-2 tuple of lists or arrays
    x- and y-components of sampled vectors.
  vmax : float
    Maximum length of all sampled vectors.
  l : float
    Average distance between sampled vectors.

  
  :returns:       A tuple (cd,d,vmax,l)
  """
  if (x0 is None):
    x0=vec[0].x0()
  #
  if (x1 is None):
    x1=vec[0].x1()
  #
  s  = x1-x0
  a  = s[0]*s[1]
  l  = math.sqrt(a/narrows)
  n  = (s/l).astype(np.int32)
  sg = grid_data.RegGeom(n, x0, x1=x1)
  sv = [v.sample(sg, order=1) for v in vec]
  d  = [v.data for v in sv]
  cd = sv[0].coords2d()
  if (mask is not None): 
    m   = np.logical_not(mask.sample(sg, order=0).data)
    cd  = [cd[0][m],cd[1][m]]
    d   = [d[0][m],d[1][m]]
  #
  a = np.sqrt(d[0]**2 + d[1]**2)
  vmax = a.max() #max(np.abs(d[0]).max(),np.abs(d[1]).max())
  
  return cd, d, vmax, l
Ejemplo n.º 2
0
def get_geometry_xz_xy(sd, opt):
  def full_domain():
    xmax    = float(sd.initial_params.coordbase.xmax)
    ymax    = float(sd.initial_params.coordbase.ymax)
    zmax    = float(sd.initial_params.coordbase.zmax)
    return (np.array([xmax, ymax]), np.array([xmax,zmax]))
  #
  def manual_domain():
    return (np.array([opt.xmax, opt.ymax]),
            np.array([opt.xmax, opt.zmax]))
  #
  
  dd = {'full':full_domain, 
        'manual':manual_domain}
  exy,exz   = dd[opt.domain]()
  sampres   = int(opt.xres*0.8)
  sampresxy = [sampres, int(sampres*exy[1]/exy[0])]
  sampresxz = [sampres, int(sampres*0.5*exz[1]/exz[0])]
  
  grxy = grid_data.RegGeom(sampresxy, -exy, x1=exy)
  grxz = grid_data.RegGeom(sampresxz, [-exz[0],0], x1=exz)
  geom = [grxz, grxy]
  return geom
Ejemplo n.º 3
0
def get_geometry_xz(sd, opt):
  def full_domain():
    xmax    = float(sd.initial_params.coordbase.xmax)
    zmax    = float(sd.initial_params.coordbase.zmax)
    return xmax, zmax
  #
  def manual_domain():
    return (opt.xmax, opt.zmax)
  #
  
  sampres         = int(opt.xres*0.8)
  sampres         = [sampres, sampres]
  dd = {'full':full_domain, 
        'manual':manual_domain}
  x1 = np.array(dd[opt.domain]())
  
  geom = grid_data.RegGeom(sampres, -x1, x1=x1)
  return geom 
Ejemplo n.º 4
0
#!/usr/bin/env python
"""This demonstrates the volume rendering of Cactus data using VTK."""
import numpy as np
from postcactus import grid_data as gd
from postcactus import viz_vtk as viz
from math import *
 
geom = gd.RegGeom([200,210,180], [-100.0]*3, x1=[100.]*3)
x,y,z = geom.coords1d()
x3,y3,z3 = x[:,None, None], y[None, :, None], z[None, None, :]
d  = np.sqrt(x3**2 + y3**2) 
r  = np.sqrt(d**2 + z3**2) 
phi = np.arctan2(x3, y3)
th = np.arctan2(z3,d)
k = 2*pi/50.
l = 70.
data = (l/(l+r)) * np.cos(phi-k*r) * np.cos(th)**2
data2 = (l/(l+r)) * np.cos(phi-k*r) * np.sin(th)**2

data = gd.RegData(geom.x0(), geom.dx(), data)
data2 = gd.RegData(geom.x0(), geom.dx(), data2)


renderer = viz.make_renderer(bgcolor='k')

vmax = data.max()
vmin = data.min()
vmin,vmax,numlbl = viz.align_range_decimal(vmin,vmax)

otf = viz.OpacityMap(vmin=vmin, vmax=vmax)
otf.add_steps([-0.5,  0.5], [0.1]*2, [.1]*2, color=['r','g'])
Ejemplo n.º 5
0
from postcactus import visualize as viz
from postcactus import grid_data as gd

# Sim dir:
sd = SimDir("<simulation directory here>")

# Func to plot:
func = 'rho'
minf = -9
maxf = 0
# Options:
dolog = 1
AMRboundaries = 1
cm = viz.get_color_map('viridis')
# Grid where to plot:
g = gd.RegGeom([400, 400], [-10, -10], x1=[10, 10])

# Get iterations and times, and loop
iters = sd.grid.xy.get_iters(func)
times = sd.grid.xy.get_times(func)
i = 0
for it in iters:
    print("Plotting it = ", it)
    plt.clf()
    # Get data
    func_plot = sd.grid.xy.read(func, it, geom=g, order=1)
    if dolog != 0:
        func_plot = func_plot.log10()
    if AMRboundaries != 0:
        rlvl = sd.grid.xy.read(func, it, geom=g, order=1, level_fill=True)
        lvl = -0.5 + np.arange(0, 6)