Helper Modules

Saving and loading objects

This module contains functions for saving and loading Z2Pack objects.

z2pack.io.save(obj, file_path, serializer='auto')

Saves an object to the file given in file_path. The saving is made atomic (on systems where os.replace() is atomic) by first creating a temporary file and then moving to the file_path.

Parameters
  • obj – Object to be saved.

  • file_path (str) – Path to the file.

  • serializer (module) – The serializer to be used. Valid options are msgpack json and pickle. By default, the serializer is determined from the file extension. If this does not work, json is used to avoid data loss.

z2pack.io.load(file_path, serializer='auto')

Loads the object that was saved to file_path.

Parameters
  • file_path (str) – Path to the file.

  • serializer (module) – The serializer which should be used to load the result. By default, is deduced from the file extension. If no serializer is given and it cannot be deduced from the file ending, a ValueError is raised, to avoid loading corrupted data.

z2pack.io.load(file_path, serializer='auto')

Loads the object that was saved to file_path.

Parameters
  • file_path (str) – Path to the file.

  • serializer (module) – The serializer which should be used to load the result. By default, is deduced from the file extension. If no serializer is given and it cannot be deduced from the file ending, a ValueError is raised, to avoid loading corrupted data.

z2pack.io.save(obj, file_path, serializer='auto')

Saves an object to the file given in file_path. The saving is made atomic (on systems where os.replace() is atomic) by first creating a temporary file and then moving to the file_path.

Parameters
  • obj – Object to be saved.

  • file_path (str) – Path to the file.

  • serializer (module) – The serializer to be used. Valid options are msgpack json and pickle. By default, the serializer is determined from the file extension. If this does not work, json is used to avoid data loss.

Shapes

This module contains pre-defined shapes to use as the surface argument of surface.run() or line argument for line.run(), defining the shape of the surface or line.

class z2pack.shape.Sphere(center, radius)[source]
Parameters
  • center (list) – Center of the sphere

  • radius (float) – Radius of the sphere

Example usage:

z2pack.surface.run(
    system=..., # Refer to the various ways of defining a system.
    surface=z2pack.shape.Sphere(center=[0, 0, 0], radius=0.1)
)