Workspace

class Workspace(*args, **kwargs)[source]

Bases: dict

The Workspace object provides the highest level of adminstrative control over active OpenPNM sessions.

It is a dictionary that stores a list of all open Projects by name.

This class is a singleton so that whenever and wherever a Workspace is instantiated, the same instance is obtained. This allows it to maintain a definitive record of all open Projects.

See also

Project

Notes

The Workspace object contains a variety of functions that one might expect from the ‘file-menu’ in a typical GUI.

close_project(project)[source]

Removes the specified Project from the Workspace

This does not save the project, so any changes will be lost.

copy()[source]
copy_project(project, name=None)[source]

Make a copy of an existing Project

Parameters
  • project (Project object) – The Project object to be copied

  • name (string, optional) – A name for the new copy of the project. If not supplied, then one will be generated (e.g. ‘proj_02’)

Returns

proj – A handle to the new Project

Return type

list

load_project(filename, overwrite=False)[source]

Loads a Project from the specified ‘pnm’ file

The loaded project is added to the Workspace . This will not delete any existing Projects in the Workspace and will rename any Projects being loaded if necessary.

Parameters

filename (string or path object) – The name of the file to open. See Notes for more information.

See also

load_workspace

Notes

The filename can be a string such as ‘saved_file.pnm’. The string can include absolute path such as ‘C:networkssaved_file.pnm’, or can be a relative path such as ‘....saved_file.pnm’, which will look 2 directories above the current working directory. Can also be a path object object such as that produced by pathlib or os.path in the Python standard library.

load_workspace(filename)[source]

Load project(s) from a saved workspace into current workspace

Parameters

filename (str or path object) – The filename containing the saved workspace

Notes

??

new_project(name=None)[source]

Creates a new empty Project object

Parameters

name (string (optional)) – The unique name to give to the project. If none is given, one will be automatically generated (e.g. ‘proj_01`)

Returns

proj – An empty Project object, suitable for passing into a Network generator

Return type

list

save_project(project, filename=None)[source]

Saves given Project to a pnm file

This will include all of associated objects, including algorithms.

Parameters
  • project (OpenPNM Project) – The project to save.

  • filename (string, optional) – If no filename is given, the given project name is used. See Notes for more information.

See also

save_workspace

Notes

The filename can be a string such as ‘saved_file.pnm’. The string can include absolute path such as ‘C:networkssaved_file.pnm’, or can be a relative path such as ‘....saved_file.pnm’, which will look 2 directories above the current working directory. Can also be a path object object such as that produced by pathlib or os.path in the Python standard library.

save_workspace(filename=None)[source]

Save all projects in the current workspace as a single file

Parameters

filename (str) – The filename to use when saving. If not provided, the present date and time are used.

Notes

The file is actually zip archive containing pnm files, one for each project in the workspace. This archive can be extracted and each pnm file can be loaded manually using load_project or the openpnm.io.PNM class.