loadcartesianfields.py¶
-
jcmwave.
loadcartesianfields
(file_name, format='squeeze')¶ Loads a tensor fields given on a Cartesian grid stored in .jcm format.
Parameters: - file_name (filepath) – path to a Cartesian fieldbag in .jcm format.
- format (str) –
format of the table after load.
Allowed values are: ‘squeeze’ (default) and ‘full’. For details the “Results”.
Returns: Dictionary with the following entries:
- ’X’, ‘Y’, ‘Z’ (numpy arrays):
x, y, z-coordinates of the Cartesian grid. Each
X
,Y
,Z
has the shape[nx, ny, nz]
, wherenx
,ny
,nz
are the number of grid points in each direction.X[ix, iy, iz]
is the value of sampling vector in x-direction at positionix
,0<=ix<nx
, irrespective ofiy
,iz
. Accordingly, we haveY[ix, iy, iz]=y[iy]
andZ[ix, iy, iz]=z[iz]
. For a Cartesian field in polar coordinates, XYZ arrays are changed to R, Theta and Phi holding the corresponding coordinate values.
- ’field’ (list of numpy arrays):
Fj=['field'][j]
contains the field values of the (j+1)’th field of the fieldbag.Fj[ix, iy, iz, k]
gives the k’th field component at the point with coordinates[x(ix), y(iy), z(iz)]
of the (j+1)’th field.- When ‘format’ is ‘squeeze’, singleton dimensions are removed accordingly to the commands
>>> X = X.squeeze() >>> Y = Y.squeeze() >>> Z = Z.squeeze() >>> Fj = Fj.squeeze()
Example:
Plot Cartesian fieldbag on xy-mesh. Real part of the z-component of the first field is plotted. (matplotlib required): >>> cfb = jcmwave.loadcartesianfields('./project_results/cartesian_xy.jcm'); >>> pcolormesh(cfb['X'], cfb['Y'], cfb['field'][0][:, :, 2].real, shading='gouraud')