py4sci

Previous topic

datfile

Next topic

vtkutils

This Page

surface

Note

Functions for calculating surfaces and analyzing them.

Module author: Adam Gagorik <adam.gagorik@gmail.com>

surface.make_3D(array)[source]

Force the numpy array passed to be 3D via np.expand_dims().

Parameters:array (numpy.ndarray) – numpy array
surface.load_ascii(handle, square=False, cube=False, shape=None, **kwargs)[source]

Wrapper around np.loadtxt. Forces data to be at least 3 dimensions.

Parameters:
  • square – reshape as if data is NxN
  • cube – reshape as if data is NxNxN
  • square – bool
  • cube – bool
  • shape – list
Parm shape:

reshape data

surface.load_chk(handle)[source]

Load checkpoint file and convert traps into a surface.

surface.load(handle, rot90=-1, **kwargs)[source]

Load surface from file. Takes into account the file extension.

ext func
pkl common.load_pkl()
npy numpy.load()
chk surface.load_chk()
inp surface.load_chk()
csv surface.load_ascii()
txt surface.load_ascii()
dat surface.load_ascii()
png scipy.ndimage.imread()
jpg scipy.ndimage.imread()
jpeg scipy.ndimage.imread()
Parameters:
  • handle (str) – filename
  • rot90 (int) – number of times to rotate image by 90 degrees
Returns:

image

Return type:

numpy.ndarray

Warning

image file (png, jpg, etc) data is forced into range [0,255].

Warning

data is always made 3D via numpy.expand_dims()

Warning

image data is rotated by -90 degrees.

surface.save_vti(handle, array, **kwargs)[source]

Save numpy array to vtkImageData XML file. You can open it in paraview.

Parameters:
surface.save_chk(handle, array)[source]

Save numpy array to Langmuir checkpoint file.

Parameters:
surface.save(handle, obj, zlevel=0, **kwargs)[source]

Save object to a file. Takes into account the file extension.

ext func
pkl common.load_pkl()
npy numpy.load()
vti surface.save_cti()
csv np.savetxt()
txt np.savetxt()
dat np.savetxt()
png scipy.misc.imsave()
jpg scipy.misc.imsave()
jpeg scipy.misc.imsave()
Parameters:
  • handle (str) – filename
  • obj – object to save
  • zlevel (int) – slice z-index

Warning

image file (png, jpg, etc) data is forced into range [0,255].

Warning

if ndims is 3 and an image file is being saved, only a slice is saved.

surface.threshold(a, v=0, v0=0, v1=1, copy=False)[source]

Set values in array above {v} to {v1}, and below {v} to {v0}.

Parameters:
  • v (float) – threshold value
  • v0 (float) – lower value
  • v1 (float) – upper value
  • copy (bool) – copy array
surface.linear_mapping(array, n=0.0, m=1.0)[source]

Map values in array to fall in the range [n,m].

Parameters:
  • array – array like object
  • n (float) – lower bound
  • m (float) – upper bound
surface.rfunc(size=None)[source]

Produces numbers in the range [-0.5, 0.5].

Parameters:size – shape of output
Type:int
class surface.WaveDimensions(L=6.283185307179586, n=1)[source]

Compute wavelength, wavenumber, etc from an interval length (L) and number of waves (n).

Parameters:
  • L (float) – interval length
  • n (int) – number of waves in interval
>>> wx = WaveDimensions(10, 2)
>>> print wx
[Wave Dimensions]
    L      = 10
    n      = 2
    lambda = 5.00000e+00
    nubar  = 2.00000e-01
    k      = 1.25664e+00
calc(L=None, n=None)[source]

Perform calculations to compute wavelength, wavenumber, etc. Called automatically in constructor.

Parameters:
  • L (float) – interval length
  • n (int) – number of waves in interval
surface.f_gyroid(x, y, z, kx, ky, kz)[source]

Surface function f(x,y,z) for gyroid.

Parameters:
  • x (float) – x-value(s)
  • y (float) – y-value(s)
  • z (float) – z-value(s)
  • kx (float) – 2 pi nx / Lx
  • ky (float) – 2 pi ny / Ly
  • kz (float) – 2 pi nz / Lz
>>> w = WaveDimensions(10, 2)
>>> x, y, z = np.mgrid[0:10:100j,0:10:100j,0:10:100j]
>>> gyroid(x, y, z, w.k, w.k, w.k)
surface.gyroid(x, y, z, wx, wy, wz)[source]

Wrapper around f_* that uses WaveDimensions.

surface.f_scherk_first_surface(x, y, z, kx, ky, kz)[source]

Surface function f(x,y,z) for scherk.

Parameters:
  • x (float) – x-value(s)
  • y (float) – y-value(s)
  • z (float) – z-value(s)
  • kx (float) – 2 pi nx / Lx
  • ky (float) – 2 pi ny / Ly
  • kz (float) – 2 pi nz / Lz
>>> w = WaveDimensions(10, 2)
>>> x, y, z = np.mgrid[0:10:100j,0:10:100j,0:10:100j]
>>> scherk_first_surface(x, y, z, w.k, w.k, w.k)
surface.scherk_first_surface(x, y, z, wx, wy, wz)[source]

Wrapper around f_* that uses WaveDimensions.

surface.f_schwarz_p_surface(x, y, z, kx, ky, kz)[source]

Surface function f(x,y,z) for psurface.

Parameters:
  • x (float) – x-value(s)
  • y (float) – y-value(s)
  • z (float) – z-value(s)
  • kx (float) – 2 pi nx / Lx
  • ky (float) – 2 pi ny / Ly
  • kz (float) – 2 pi nz / Lz
>>> w = WaveDimensions(10, 2)
>>> x, y, z = np.mgrid[0:10:100j,0:10:100j,0:10:100j]
>>> schwarz_p_surface(x, y, z, w.k, w.k, w.k)
surface.schwarz_p_surface(x, y, z, wx, wy, wz)[source]

Wrapper around f_* that uses WaveDimensions.

surface.f_schwarz_d_surface(x, y, z, kx, ky, kz)[source]

Surface function f(x,y,z) for dsurface.

Parameters:
  • x (float) – x-value(s)
  • y (float) – y-value(s)
  • z (float) – z-value(s)
  • kx (float) – 2 pi nx / Lx
  • ky (float) – 2 pi ny / Ly
  • kz (float) – 2 pi nz / Lz
>>> w = WaveDimensions(10, 2)
>>> x, y, z = np.mgrid[0:10:100j,0:10:100j,0:10:100j]
>>> schwarz_d_surface(x, y, z, w.k, w.k, w.k)
surface.schwarz_d_surface(x, y, z, wx, wy, wz)[source]

Wrapper around f_* that uses WaveDimensions.

surface.f_bandXY(x, y, z, kx, ky, kz)[source]

Surface function f(x,y,z) for bands that run along z-direction.

Parameters:
  • x (float) – x-value(s)
  • y (float) – y-value(s)
  • z (float) – z-value(s)
  • kx (float) – 2 pi nx / Lx
  • ky (float) – 2 pi ny / Ly
  • kz (float) – 2 pi nz / Lz
>>> w = WaveDimensions(10, 2)
>>> x, y, z = np.mgrid[0:10:100j,0:10:100j,0:10:100j]
>>> bandXY(x, y, z, w.k, w.k, w.k)
surface.bandXY(x, y, z, wx, wy, wz)[source]

Wrapper around f_* that uses WaveDimensions.

surface.f_bandXZ(x, y, z, kx, ky, kz)[source]

Surface function f(x,y,z) for bands that run along y-direction.

Parameters:
  • x (float) – x-value(s)
  • y (float) – y-value(s)
  • z (float) – z-value(s)
  • kx (float) – 2 pi nx / Lx
  • ky (float) – 2 pi ny / Ly
  • kz (float) – 2 pi nz / Lz
>>> w = WaveDimensions(10, 2)
>>> x, y, z = np.mgrid[0:10:100j,0:10:100j,0:10:100j]
>>> bandXZ(x, y, z, w.k, w.k, w.k)
surface.bandXZ(x, y, z, wx, wy, wz)[source]

Wrapper around f_* that uses WaveDimensions.

surface.f_bandYZ(x, y, z, kx, ky, kz)[source]

Surface function f(x,y,z) for bands that run along x-direction.

Parameters:
  • x (float) – x-value(s)
  • y (float) – y-value(s)
  • z (float) – z-value(s)
  • kx (float) – 2 pi nx / Lx
  • ky (float) – 2 pi ny / Ly
  • kz (float) – 2 pi nz / Lz
>>> w = WaveDimensions(10, 2)
>>> x, y, z = np.mgrid[0:10:100j,0:10:100j,0:10:100j]
>>> bandYZ(x, y, z, w.k, w.k, w.k)
surface.bandYZ(x, y, z, wx, wy, wz)[source]

Wrapper around f_* that uses WaveDimensions.

class surface.Kernel(xmin, xmax, ymin, ymax, zmin, zmax, spacing=1.0)[source]

An x, y, z, v mgrid.

Parameters:
  • xmin (float) – lower x
  • xmax (float) – upper x
  • ymin (float) – lower y
  • ymax (float) – upper y
  • zmin (float) – lower z
  • zmax (float) – upper z
  • spacing (float) – grid spacing
class surface.FuncKernel(func, *args, **kwargs)[source]

An x, y, z, v mgrid. Computes v using the function = f(x, y, z) passed. See Kernel for more parameters.

class surface.SimpleKernel(func, nx=3, ny=3, nz=3, spacing=1.0)[source]

An x, y, z, v mgrid. Computes v using the function = f(x, y, z) passed. Creates x, y, z domain using spacing and number of points.

Parameters:
  • func (func) – function of x, y, z
  • nx (int) – x-direction has 2*nx + 1 points
  • ny (int) – y-direction has 2*ny + 1 points
  • nz (int) – z-direction has 2*nz + 1 points
  • spacing (double) – grid spacing
class surface.RandomKernel(*args, **kwargs)[source]

An x, y, z, v mgrid. Computes v using random noise. Creates x, y, z domain using spacing and number of points. See SimpleKernel for more parameters.

class surface.GaussianKernel(sx, sy, sz, mx=0.0, my=0.0, mz=0.0, spacing=1.0)[source]

An x, y, z, v mgrid. The size of the grid is determined using the stdev of the Gaussian PDF.

Parameters:
class surface.Isotropic(grid, kernel, rfunc=<function rfunc at 0x7fef9ab9dc80>, v=0.0, mode='same', verbose=False)[source]

Performs convolution of random noise with a kernel to make morphology.

Parameters:
  • grid (surface.Grid) – grid
  • kernel (Kernel) – Kernel instance
  • rfunc (func) – function that produces random numbers in range [-0.5,0.5]
surface.f_isotropic(x, y, z, sx, sy, sz, full=False)[source]

Surface function f(x,y,z) for isotropic morphology according to Jake.

Parameters:
>>> x, y, z = np.mgrid[0:10:100j,0:10:100j,0:10:100j]
>>> isotropic(x, y, z, 1, 1, 1)