atomcloud.plots package

Submodules

Module contents

Created on Mon Mar 14 19:26:59 2022

@author: hofer

class atomcloud.plots.MultiFunction1D(function_names, constraints=None, use_jax=False)[source]

Bases: MultiFunc

1D cloud multi-function class which inherits from the base class. It uses the imported dictionary of 2D function objects as it’s base dictionary of function objects, but also allows the user to add custom function objects to the dictionary of function objects.

See base class for more details.

Parameters:
  • function_names (list[str]) –

  • constraints (list[str] | None) –

  • use_jax (bool) –

class atomcloud.plots.MultiFunction2D(function_names, constraints=None, use_jax=False)[source]

Bases: MultiFunc

2D cloud multi-function class which inherits from the base class. It uses the imported dictionary of 2D function objects as it’s base dictionary of function objects, but also allows the user to add custom function objects to the dictionary of function objects.

Parameters:
  • function_names (list[str]) – The keys for the function objects in the registry which will be used in the multi-function

  • func_registry – The registry of function objects

  • constraints (list[str] | None) – A list of constraints which will be applied to the the functions in the multi-function (see ConstrainedMultiFunction for more details)

  • use_jax (bool) – If True, the functions in the multi-function will be created using JAX. If False, the functions will be created

Returns:

None

class atomcloud.plots.Path(*args, **kwargs)[source]

Bases: PurePath

PurePath 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. This function works even if the path doesn’t point to anything.

No normalization is done, i.e. all ‘.’ and ‘..’ will be kept along. Use resolve() to get the canonical path to a file.

chmod(mode)[source]

Change the permissions of the path, like os.chmod().

classmethod cwd()[source]

Return a new path pointing to the current working directory (as returned by os.getcwd()).

exists()[source]

Whether this path exists.

expanduser()[source]

Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)

glob(pattern)[source]

Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.

group()[source]

Return the group name of the file gid.

classmethod home()[source]

Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).

is_block_device()[source]

Whether this path is a block device.

is_char_device()[source]

Whether this path is a character device.

is_dir()[source]

Whether this path is a directory.

is_fifo()[source]

Whether this path is a FIFO.

is_file()[source]

Whether this path is a regular file (also True for symlinks pointing to regular files).

is_mount()[source]

Check if this path is a POSIX mount point

is_socket()[source]

Whether this path is a socket.

Whether this path is a symbolic link.

iterdir()[source]

Iterate over the files in this directory. Does not yield any result for the special paths ‘.’ and ‘..’.

lchmod(mode)[source]

Like chmod(), except if the path points to a symlink, the symlink’s permissions are changed, rather than its target’s.

Make the target path a hard link pointing to this path.

Note this function does not make this path a hard link to target, despite the implication of the function and argument names. The order of arguments (target, link) is the reverse of Path.symlink_to, but matches that of os.link.

lstat()[source]

Like stat(), except if the path points to a symlink, the symlink’s status information is returned, rather than its target’s.

mkdir(mode=511, parents=False, exist_ok=False)[source]

Create a new directory at this given path.

open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)[source]

Open the file pointed by this path and return a file object, as the built-in open() function does.

owner()[source]

Return the login name of the file owner.

read_bytes()[source]

Open the file in bytes mode, read it, and close the file.

read_text(encoding=None, errors=None)[source]

Open the file in text mode, read it, and close the file.

Return the path to which the symbolic link points.

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 (for example turning slashes into backslashes under Windows).

rglob(pattern)[source]

Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.

rmdir()[source]

Remove this directory. The directory must be empty.

samefile(other_path)[source]

Return whether other_path is the same or not as this file (as returned by os.path.samefile()).

stat()[source]

Return the result of the stat() system call on this path, like os.stat() does.

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.

Remove this file or link. If the path is a directory, use rmdir() instead.

write_bytes(data)[source]

Open the file in bytes mode, write to it, and close the file.

write_text(data, encoding=None, errors=None)[source]

Open the file in text mode, write to it, and close the file.

class atomcloud.plots.Plot1DFit[source]

Bases: PlotBase

Class for plotting 1D fits. Inherits from the base plotting class.

plot_1Dfit(x, data_dict, title_str, savepath=None)[source]

Handles the actual plotting of the 1D fit data using matplotlib.pyplot (see plot_fit for variable descriptions).

plot_fit(fit_dicts, x, data, mask=None, title='', savepath=None, verbose=True, *args, **kwargs)[source]

Plot the fit results

Parameters:
  • fit_dicts (dict) – Dictionary containing the fit results for a 1D multi-function fit.

  • x (np.ndarray) – The x coordinates of the data.

  • data (np.ndarray) – The original data which was fit using the multi-function to determine the parameters (params).

  • mask (np.ndarray, optional) – The mask to be applied to the data.

  • title (str, optional) – The title of the plot. Defaults to ‘’.

  • savepath (str, optional) – The path to save the plot. Defaults to None.

  • verbose (bool, optional) – If True, the data for each function will be returned. Defaults to True.

Return type:

None

class atomcloud.plots.Plot2DBase[source]

Bases: PlotBase

fig_axes(func_strs, verbose, ax_size=4.5)[source]

Generates the figure and axes for the 2D fit plot.

Parameters:
  • func_strs (list[str]) – The list of function strings used in the fit.

  • verbose (bool) – If True, the data for each function in the multi-function fit will be plotted.

  • ax_size (float) – The size of the each axis.

Returns:

A tuple containing the figure, a dictionary of the 2D axes, a dictionary of the 1D axes, and the colorbar axis. The keys for the 2D axes are ‘data’, ‘total’, and the function strings. The keys for the 1D axes are ‘x’ and ‘y’.

Return type:

tuple[matplotlib.pyplot.Figure, dict, dict, matplotlib.pyplot.Axes]

plot_1d(x, y, xdata_dict, ydata_dict, ax_dict, ptype)[source]

Plots the 1D sum data for the x and y axes.

Parameters:
  • x (ndarray) – The x coordinates of the data.

  • y (ndarray) – The y coordinates of the data.

  • xdata_dict (dict[str, numpy.ndarray]) – The dictionary containing the x-axis data.

  • ydata_dict (dict[str, numpy.ndarray]) – The dictionary containing the y-axis data.

  • ax_dict (dict[str, matplotlib.pyplot.Axes]) – The dictionary containing the x and y axes.

  • ptype (str) –

plot_2d(coords, data_dict, axes_2d, cax)[source]

Plots the 2D fit data including the original data, the total fit data, and the individual function fit data both for the sum data and the full 2d data.

Parameters:
  • coords (tuple[numpy.ndarray, numpy.ndarray]) – The tuple containing the x and y coordinates of the data.

  • data_dict (dict[str, numpy.ndarray]) – The dictionary containing the 2d data, total 2d fit data and the individual function 2d fit data.

  • axes_2d (dict[str, matplotlib.pyplot.Axes]) – The dictionary containing the 2d axes in the figure.

  • cax (matplotlib.pyplot.Axes) – The colorbar axis.

Return type:

None

set_colorbar_position(axes, cax)[source]

Set the position of the colorbar axis.

Parameters:
  • axes (list[list[matplotlib.pyplot.Axes]]) – The list of data axes in the figure.

  • cax (matplotlib.pyplot.Axes) – The colorbar axis.

class atomcloud.plots.Plot2DFit[source]

Bases: Plot2DBase

make a more general plotting class that can be used in a variety of objects

get_data1d(XY_tuple, data_dict, mask=None)[source]

Get the 1D data for the x and y axes for the sum data, total fit sum data, and the individual function sum data.

Parameters:
  • XY_tuple (tuple[numpy.ndarray, numpy.ndarray]) – The tuple containing the x and y coordinates of the data.

  • data_dict (dict[str, numpy.ndarray]) – The dictionary containing the 2d data, total 2d fit data

  • data. (and the individual function 2d fit) –

  • mask (ndarray | None) – The mask to be applied to the data.

Returns:

A tuple containing the x and y coordinates of the data, and the x and y data dictionaries for the sum data, total fit sum data, and the individual function sum data.

Return type:

tuple[numpy.ndarray, numpy.ndarray, dict[str, numpy.ndarray], dict[str, numpy.ndarray]]

plot_fit(fit_dicts, XY_tuple, data, mask=None, title='', savepath=None, verbose=True, *args, **kwargs)[source]
Parameters:
  • fit_dicts (dict) –

  • XY_tuple (tuple[numpy.ndarray, numpy.ndarray]) –

  • data (ndarray) –

  • mask (ndarray | None) –

  • title (str) –

  • savepath (str | Path | None) –

  • verbose (bool) –

sum_data_mask(XY_tuple, data, mask)[source]

Sum the data in the masked region, but particularly for the case of weird masks this is a hacky way to do this, but it works for now

class atomcloud.plots.Plot2DSumFit[source]

Bases: Plot2DBase

Class for plotting 2D sum fits. Inherits from the base 2D plotting class.

plot_fit(fit_dicts, XY_tuple, data, mask=None, title='', savepath=None, verbose=True, *args, **kwargs)[source]

Plot the fit results from the 2D sum fit.

Parameters:
  • fit_dicts (dict) – Dictionary containing the fit results for a 2D multi-function fit.

  • XY_tuple (tuple[np.ndarray, np.ndarray]) – The x and y coordinates of the data.

  • data (np.ndarray) – The original data which was fit using the multi-function to determine the parameters (params).

  • mask (np.ndarray, optional) – The mask to be applied to the data.

  • title (str, optional) – The title of the plot. Defaults to ‘’.

  • savepath (str, optional) – The path to save the plot. Defaults to None.

  • verbose (bool, optional) – If True, the data for each function will be plotted. Defaults to True.

Return type:

None

unpack_fit_dicts(fit_dicts)[source]

Unpack the sumfit fit dictionaries into the necessary components for plotting as they are nested in the fit_dicts and comprised of the 1d and 2d fit dictionaries.

Parameters:

fit_dicts (dict) – The fit dictionaries for the 2D sum fit.

Returns:

The function strings for the 2D fit. constraints: The constraints for the 2D fit. params2d: The seed parameters for the 2D fit. xparams: The parameters for the x-axis 1D fit. yparams: The parameters for the y-axis 1D fit.

Return type:

func_strs

class atomcloud.plots.PlotBase[source]

Bases: object

get_data(data, mask, fit_dicts, verbose=True)[source]

Get the fit info and processed data for plotting.

Parameters:
  • data – The original data which was fit using the multi-function to determine the parameters (params).

  • mask – The mask to be applied to the data.

  • fit_dicts – Dictionary containing the fit results for a multi-function fit.

  • verbose – If True, the data for each function will be returned.

handle_title(title, base_title, base_save_name)[source]
mask_data(data, mask=None)[source]

Mask the data if a mask is provided.

Parameters:
  • data (ndarray) – The data to be masked.

  • mask (ndarray | None) – The mask to be applied to the data.

Returns:

The masked data

Return type:

ndarray

plot_data(multi_func, coords, data, params, func_strs, verbose=True)[source]

Gets the data for the plot.

Parameters:
  • multi_func (object) – The multi-function used to create the fit data.

  • x – The x coordinates of the data.

  • data (ndarray) – The original data which was fit using the multi-function to determine the parameters (params).

  • params (list[list[float]]) – The fit parameters to create the multi-function fit data.

  • func_strs (list[str]) – The function strings used in the multi-function.

  • verbose (bool) – If True, the data for each function will be returned.

  • coords (ndarray | Iterable[ndarray]) –

Returns:

A dictionary containing the original data, the total fit data, and the fit data for each function which comprises the multi-function fit.

Return type:

dict

save_plot(path, img_name)[source]

Save the current plot to a file.

Parameters:
  • path (str | Path) – The path to the directory where the image will be saved.

  • img_name (str) – The name of the image file.

  • Returns – None

Return type:

None

title_string(constraints=None, init_str='')[source]

Create a title string for a plot.

Parameters:
  • constraints (Iterable[str] | None) – A list of constraints which will be applied to the the functions in the multi-function (see ConstrainedMultiFunction for more details)

  • init_str (str) – The initial string which will be used in the title. This is useful if you want to add a title to a plot which already has a title.

Returns:

The title string

Return type:

str

atomcloud.plots.nominal_list(param_list)[source]