Reference for flowtracks.graphics

Various specialized graphing routines. The Probability Density Function graphing is best accessed by calling pdf_graph() on the raw data, but you can generate the PDF from the data separately (e.g. using pdf_bins()) and calling generalized_histogram_disp() on the result.

The other facility here is a function to plot a time-dependent 3D vector as 3 component subplots, which is another customary presentation in fluid dynamics circles. See plot_vectors().

3D trajectories: select_trajectories() picks the longest or fastest tracks of a store, plot_trajectories_3d() draws them interactively with PyVista (VTK, GPU-rendered polylines – the vtk extra), from the same PolyData the .vtp ParaView writer saves.

flowtracks.graphics.pdf_bins(data, num_bins, log_bins=False)[source]

Generate a PDF of the given data possibly with logarithmic bins, ready for using in a histogram plot.

Arguments

  • data: the samples to histogram.

  • bins: the number of bins in the histogram.

  • log_bins: if True, the bin edges are equally spaced on the log scale, otherwise they are linearly spaced (a normal histogram). If True, data should not contain zeros.

Returns

  • hist: num_bins-lenght array of density values for each bin.

  • bin_edges: array of size num_bins + 1 with the edges of the bins including the ending limit of the bins.

flowtracks.graphics.generalized_histogram_disp(hist, bin_edges, log_bins=False, log_density=False, marker='o')[source]

Draws a given histogram according to the visual custom of the fluid dynamics community.

Arguments

  • hist: an array containing the number of values (or density) for each bin.

  • bin_edges: the start value of each bin, same length as hist.

  • log_bins: indicates that the bin edges are log-spaced.

  • log_densify: Show the log of the probability density value. May cause problems if log_bins is True.

  • marker: marker style for matplotlib.

Returns

the list of lines drawn, Matplotlib objects.

flowtracks.graphics.pdf_graph(data, num_bins, log=False, log_density=False, marker='o')[source]

Draw a PDF of the given data, according to the visual custom of the fluid dynamics community, and possibly with logarithmic bins.

Arguments

  • data: the samples to histogram.

  • bins: the number of bins in the histogram.

  • log: if True, the bin edges are equally spaced on the log scale, otherwise they are linearly spaced (a normal histogram). If True, data should not contain zeros.

  • log_density: Show the log of the probability density value. Only if log is False.

  • marker: override the circle marker with any string acceptable to matplotlib.

flowtracks.graphics.plot_vectors(vecs, indep, xlabel, fig=None, marker='-', ytick_dens=None, yticks_format=None, unit_str='', common_scale=None, arrows=None, arrow_color=None)[source]

Plot 3D vectors as 3 subplots sharing the same independent axis.

Arguments

  • vecs: an (n,3) array, with n vectors to plot against the independent variable.

  • indep: the corresponding n values of the independent variable.

  • xlabel: label for the independent axis.

  • fig: an optional figure object to use. If None, one will be created.

  • ytick_dens: if not None, place this many yticks on each subplot, instead of the automatic tick marks.

  • yticks_format: a pyplot formatter object.

  • unit_str: a string to add to the Y labels representing the vector’s units.

  • arrows: an (n,3) array of values to represent as vertical arrows attached to each trajectory point.

  • arrow_color: a matplotlib color spec for the arrow bodies.

Returns

  • fig: the figure object used for plotting.

flowtracks.graphics.trajectory_summary(source)[source]

Per-trajectory table: ids, points, mean position, mean velocity, spatial extent (bounding-box diagonal), path length (sum of step lengths: distance actually travelled, back-and-forth motion included) and largest jump – the largest one-frame spike: |step_k - (step_(k-1) + step_(k+1)) / 2|, a step that disagrees with its two neighbours (a smooth speed-up is not a jump), in position units per time unit of time (frames), so a step across a bridged gap is not mistaken for one. Rows sorted by trajid.

flowtracks.graphics.select_trajectories(source, by='length', n=10, min_points=20, min_extent=0.0, seed=0)[source]

Trajectory ids of n trajectories chosen by:

“length” - longest (points), best first. “speed” - fastest (max point speed), best first. “path” - longest path travelled (sum of step lengths), best first: long AND moving – back-and-forth motion counts in full, tracks that sit still (wall points) rank low. “typical” - one per main flow pattern: k-means (k = n) of the tracks’ standardized mean position + mean velocity; from each cluster the track nearest its centre, largest cluster first – the “most common” tracks in position and velocity. “coverage” - fill the flow: k-means (k = n) of the tracks’ mean positions splits the volume into n regions; the longest track of each region. “jumps” - largest one-frame spike (see trajectory_summary()), largest first.

typical / coverage / jumps only consider tracks with at least min_points points and a spatial extent of at least min_extent (position units) – e.g. to leave out points on a solid, reflecting wall that never move. source: anything trajectory_summary() reads.

flowtracks.graphics.plot_trajectories_3d(source, trajids=None, scalars='speed', context=0, plotter=None, cmap='plasma', clim=None, line_width=3, point_size=6, title=None, bar_title=None, show=True, units=None)[source]

Interactive 3D trajectory view (PyVista): polylines coloured by a point array (speed, time, trajid), points drawn as spheres so short tracks stay visible.

  • trajids: draw only these (e.g. from select_trajectories()); None draws every trajectory.

  • context: also draw this many randomly sampled points of ALL trajectories, faint grey, to show where the selection sits.

  • plotter: draw into an existing pyvista.Plotter (or a subplot of one); a new one is created otherwise.

  • bar_title: colour-bar title (default: scalars). PyVista merges bars with the same title into one shared colour range, so give each subplot its own title to keep its own range.

  • show: call plotter.show(); pass False to compose or screenshot.

  • units: {"pos": "m", "vel": "m s-1", "time": "frame"} for axis and colour-bar titles (x [m], speed [m s-1]). When omitted and source is a Zarr path, whatever the writer recorded is used; otherwise titles stay bare rather than guessed.

Returns the plotter.

flowtracks.graphics.animate_trajectories_3d(source, out_dir, frames=None, *, component=1, tail=20, pos_scale=1.0, bounds=None, cmap='coolwarm', clim=(-0.5, 0.5), bar_title=None, bar_labels=21, bar_fmt='%.2f', view_direction=(-1.0, 1.0, 1.0), view_up=(0.0, 1.0, 0.0), zoom=1.0, window_center=(0.0, 0.0), window_size=(1920, 1080), point_size=6.0, grid_step=500.0, axis_titles=('x', 'y', 'z'), wall_color=(0.54, 0.54, 0.54), background='white', font_size=20, font_file=None, outlines=(), outline_color='black', outline_width=3.0, movie=None, fps=10, label=None)[source]

Off-screen movie frames of trajectories as trailing beads (PyVista).

Every frame shows each particle’s last tail positions as shaded spheres coloured by one velocity component (component: 0, 1, 2), in a box with grey back walls, a grid_step grid and labelled axes, seen with a fixed parallel-projection camera – the usual ParaView look.

  • source: zarr path / ZarrScene / Scene, as plot_trajectories_3d().

  • out_dir: PNG frames are written as frame_0000.png …

  • frames: frame numbers to render (default: every frame of the source).

  • pos_scale: multiplies positions (e.g. 1000 for m -> mm axes).

  • bounds: (x0, x1, y0, y1, z0, z1) of the box, in scaled units (default: the data’s 0.5-99.5 percentile box).

  • view_direction: from the scene towards the camera; view_up the screen’s up; zoom > 1 enlarges; window_center shifts the projection centre in normalized window units (VTK SetWindowCenter).

  • movie: if given, the frames are also encoded to this .mp4 with ffmpeg.

  • label: optional str.format text drawn bottom-left, given frame.

  • font_file: TrueType file for all text (VTK’s built-in font has no square brackets).

  • outlines: (N, 3) point arrays in scaled units, each drawn as a closed line (e.g. the top and bottom rims of a cylindrical vessel).

Returns the list of PNG paths.