slim4.post
Post-processing functions
Enums
- class slim4.post.RasterInterpType(IntEnum)
Interpolation of the raster
Values
nodes:0— Interpret a N pixels over an interval as the boundaries of N-1 cellscells:1— Interpret a N pixels over an interval as the centers of N cells. Should be used for imshow
- class slim4.post.RenderType(IntEnum)
type of raster render
Values
auto:-1— Auto-selects render typeslim2d:0— For 2D datasurface:1— Surface of 3D meshz:2— Constant-z transectbottom:3— Bottomcgbottom:4— Bottom but continuous over steps in z-like meshesvertical:5— Vertical transect
Classes
- class slim4.post.Rasterizer
slim4::slim::Data from array of values
Properties
geotransform: NDArray[np.float64] | None — The geotransform (only for horizontal type renders)projection: str — The projectionConstructor
- __init__(mesh, projection='', interp_type='cells', merge_mpi=True)
create a new slim4::post::Rasterizer
Parameters
mesh: slim.Mesh — The mesh of data(s) to rasterizeprojection: str — The projection of the output raster. If not provided, the mesh projection is used.interp_type: RasterInterpType | str — The interpolation type of the rastermerge_mpi: bool — If true, combines the renders of all MPI ranks. Else each rank acts independantly
Methods
- set_bbox(x0, x1, y0, y1, width=-1, height=-1)
Set the bounding box for a horizontal transect. The bounding box is defined by its minimum and maximum x and y coordinates. The rasterizer then computes the coordinates of the pixels in the bounding box, which can be used for interpolation and rendering. If either width or height is left unspecified (negative), the rasterizer automatically adjusts the other dimension to preserve square pixels in physical space. If both are left unspecified, the target image will be around 1M pixels, with an aspect ratio adapted to the bounding box and projection.
Parameters
x0: float — The minimum x coordinatex1: float — The maximum x coordinatey0: float — The minimum y coordinatey1: float — The maximum y coordinatewidth: int — The width of the output imageheight: int — The height of the output imageReturns
x: NDArray[np.float64] — The x coordinate of the pixels (width)y: NDArray[np.float64] — The y coordinate of the pixels (height)
- set_vertical_transect(xy, zmin, zmax, width, height)
Set the transect for a vertical transect render. The transect is defined by a set of points in the horizontal plane, which are connected by straight lines.
Parameters
xy: NDArray[np.float64] — Points defining the transect. Shape (2, n) with n >= 2zmin: float — The minimum z coordinatezmax: float — The maximum z coordinatewidth: int — The width of the output imageheight: int — The height of the output imageReturns
xyp: NDArray[np.float64] — The horizontal coordinates of the transect. Shape (2, width)length: float — The total length of the transect in meters.
- interpolate(x, field, t=-31536000000, z=None)
Set points for generic interpolation
Parameters
x: slim.ScalarArrayDevice — The coordinates, shape (2, n) (2D) or (3, n) (3D)field: Union[slim.ScalarArrayDevice, slim.Data] — The data to interpolatet: float — The time (if field or z is provided as slim4::slim::Data)z: Union[slim.ScalarArrayDevice, slim.Data] | None — The vertical coordinate of the mesh. Required for 3D interpolationsReturns
out: slim.ScalarArrayDevice — The interpolated data
- render(field, t=-31536000000, zcut=0, z=None, render_type='auto')
Render the data at time t and depth z
Parameters
field: Union[slim.ScalarArrayDevice, slim.Data] — The data to rendert: float — The time (if field or z is provided as slim4::slim::Data)zcut: float — For 3D z-type renders : The depth at which the data is rendered. Returns NAN if below the ocean floor or above the ocean surfacez: Union[slim.ScalarArrayDevice, slim.Data] | None — The vertical coordinate of the mesh. Required for 3D z-type and vertical rendersrender_type: RenderType | str — The type of render.Returns
out: slim.ScalarArrayDevice — The rendered data : shape = (n_fields, height, width)
- particle_density(pos)
Render the particle density of a set of particles. For 3D meshes, only the horizontal position is considered, and the density is integrated over the vertical.
Parameters
pos: slim.ScalarArrayDevice — The position of the particles. Shape (2, n_particles) or (3, n_particles)Returns
out: slim.ScalarArrayDevice — The rendered particle density : shape = (height, width)
- class slim4.post.Swan
a class to handle swan mesh The local nodes and local triangles are the same as the slim mesh but all triangles ghosts by node are collected
Properties
triangles: NDArray[np.int32] — The triangles of the meshtriangles_global_id: NDArray[np.int32] — The global id of the trianglesnodes_global_id: NDArray[np.int32] — The global id of the nodesConstructor
- __init__(mesh)
Constructor
Parameters
mesh: slim2d.Mesh — The slim mesh to be used
Methods
- scatter(data)
Scatter data from the slim mesh to the swan mesh
Parameters
data: NDArray[np.float64] — The data to scatter (should be of rank 2 and the size of the first dimension should be >= than the number of local nodes)Returns
swandata: NDArray[np.float64] — The scattered data
- n_neighbour_partitions()
Get the number of neighbour partitions
Returns
n: int — The number of neighbour partitions
- neighbour_partition(i)
Get the neighbour partition
Parameters
i: int — The index of the neighbour partitionReturns
rank: int — The rank of the neighbour partitionscatter_send: NDArray[np.int32] — The local id of the nodes to sendscatter_recv: NDArray[np.int32] — The local id of the nodes to receive
- write_node_global_ids(fname)
Write the global ids of the nodes to a file
Parameters
fname: str — The file name
Functions
- slim4.post.compute_rpe(mesh, z, z0, rho, g, nbins=500000)
Computes the relative potential energy (RPE) for a given 3D mesh, depth array, density array, and gravitational acceleration.
Parameters
mesh: slim3d.Mesh — The 3D mesh representing the volume.z: NDArray[np.float64] — The depth array (1, 6, n_prisms).z0: NDArray[np.float64] — The depth array of the rest state (1, 6, n_prisms).rho: NDArray[np.float64] — The density array (1, 6, n_prisms).g: float — The gravitational acceleration.nbins: int — the number of bins to use in rho and z histograms (use 0 for not using histograms, more precise but much slower)Returns
rpe: float — The computed relative potential energy.
- slim4.post.get_boundary_segments(mesh2d, tags)
Get the segments of the boundaries of a 2D mesh with given tags. Segments are represented by a contiguous set of points. For loops, the first and last point are the same.
Parameters
mesh2d: slim2d.Mesh — The 2D meshtags: List[str] — The tags of the boundaries to returnReturns
points: NDArray[np.float64] — The points of the segments (2, npoints)segments: NDArray[np.int32] — The range of each segment in points (nsegments, 2). The i-th segment is points[:, segments[i,0]:segments[i,1]]