squarenet.artist
Functions
|
|
|
|
|
Render a structured grid as either a static figure or a morphing animation. |
|
- class squarenet.artist.Path(*args, **kwargs)[source]
Bases:
PurePathPurePath subclass that can make system calls.
Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.
- absolute()[source]
Return an absolute version of this path by prepending the current working directory. No normalization or symlink resolution is performed.
Use resolve() to get the canonical path to a file.
- exists(*, follow_symlinks=True)[source]
Whether this path exists.
This method normally follows symlinks; to check whether a symlink exists, add the argument follow_symlinks=False.
- expanduser()[source]
Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)
- glob(pattern, *, case_sensitive=None)[source]
Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.
- hardlink_to(target)[source]
Make this path a hard link pointing to the same file as target.
Note the order of arguments (self, target) is the reverse of os.link’s.
- classmethod home()[source]
Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).
- is_file()[source]
Whether this path is a regular file (also True for symlinks pointing to regular files).
- iterdir()[source]
Yield path objects of the directory contents.
The children are yielded in arbitrary order, and the special entries ‘.’ and ‘..’ are not included.
- lchmod(mode)[source]
Like chmod(), except if the path points to a symlink, the symlink’s permissions are changed, rather than its target’s.
- lstat()[source]
Like stat(), except if the path points to a symlink, the symlink’s status information is returned, rather than its target’s.
- open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)[source]
Open the file pointed to by this path and return a file object, as the built-in open() function does.
- read_text(encoding=None, errors=None)[source]
Open the file in text mode, read it, and close the file.
- rename(target)[source]
Rename this path to the target path.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- replace(target)[source]
Rename this path to the target path, overwriting if that path exists.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- resolve(strict=False)[source]
Make the path absolute, resolving all symlinks on the way and also normalizing it.
- rglob(pattern, *, case_sensitive=None)[source]
Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.
- samefile(other_path)[source]
Return whether other_path is the same or not as this file (as returned by os.path.samefile()).
- stat(*, follow_symlinks=True)[source]
Return the result of the stat() system call on this path, like os.stat() does.
- symlink_to(target, target_is_directory=False)[source]
Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink.
- touch(mode=438, exist_ok=True)[source]
Create this file with the given access mode, if it doesn’t exist.
- unlink(missing_ok=False)[source]
Remove this file or link. If the path is a directory, use rmdir() instead.
- squarenet.artist.default_config()[source]
I. MAIN ARGUMENTS — passed directly to sqplot()
- stylerendering style. One of:
‘checkerboard’ — points coloured in a 2-colour tile pattern ‘mesh’ — grid lines drawn at 4 levels of density, ‘scatter’ — plain point cloud; depth-coloured (cmap) in
3-D, black in 2-D.
- animateFalse → single static PNG.
- True → GIF that morphs continuously from the input grid
to the identity grid and back.
save : whether to write the output to disk. save_path : destination path.
II. EXTRA ARGUMENTS — passed as cfg = {…}
All keys are optional. Only specify what you want to override; everything else is filled from the defaults shown here.
- Layout
figsize : (width, heigth) size of the base figure
- Projection
- projection3-tuple of axis indices, e.g. (0, 1, 2).
Used if ndim >= 3. this selects both which axes to keep AND in what order
- Scale & density
scale_factor : positive integer. bigger -> finer details pointsize : base size for a single point linewidth : base width for a mesh lines. mesh_long_edge : length ratio (relative to the median) above wich an edge will not be ploted in ‘mesh’ style
- Colours
colors_checkerboard : 2 colors for the ‘checkerboard’ style. cmap_scatter : colormap e.g. ‘plasma’, ‘coolwarm’ used in ‘scatter’ to encode the depth.
- Animation
frames : number of frames in the animation interval : inter-frame delay in milliseconds (for interactive sessions). fps : frames per second written (for the saved GIF).
- Display
- showif True, calls plt.show().
Will fail if session is not interactive
- squarenet.artist.sqplot(grid, verbose, style='checkerboard', animate=False, save=True, save_path='sqrnet/plot', cfg=None)[source]
Render a structured grid as either a static figure or a morphing animation.
The input grid is displayed using one of several rendering styles and may optionally be animated by continuously interpolating between the input grid and the corresponding identity grid.
- Parameters:
grid (ndarray) – Structured grid of shape
(..., D), whereDis either 2 or 3.verbose (bool) – If
True, prints progress information while rendering or exporting.style ({"checkerboard", "mesh", "scatter"}, default="checkerboard") –
Rendering style.
"checkerboard": alternating colours on adjacent grid cells."mesh": draw the grid connectivity as a wireframe."scatter": draw only the grid points. In 3-D, points are coloured
according to their depth after projection; in 2-D they are drawn in black.
animate (bool, default=False) – If
True, generate an animation interpolating between the input grid and the identity grid. Otherwise, produce a single static figure.save (bool, default=True) – If
True, save the generated figure or animation to disk.save_path (str, default="sqrnet/plot") – Output path used when
save=True.cfg (dict, optional) – Rendering configuration. Any omitted entries are filled with the default values returned by
default_config(). Seehelp(default_config)for the complete list of supported options.
- Returns:
fig (matplotlib.figure.Figure) – The generated figure.
ani (matplotlib.animation.FuncAnimation or None) – The animation object if
animate=True; otherwiseNone.
See also
default_configDefault rendering options and their documentation.