SurfaceTopography.Container.IO package

Submodules

SurfaceTopography.Container.IO.CE module

class SurfaceTopography.Container.IO.CE.CEFileOpener(zipname, filename)

Bases: object

__init__(zipname, filename)
class SurfaceTopography.Container.IO.CE.CEReader(fn, datafile_keys=['original', 'squeezed-netcdf'], ignore_filters=False)

Bases: ContainerReaderBase

__init__(fn, datafile_keys=['original', 'squeezed-netcdf'], ignore_filters=False)

Read all surfaces in a contact.engineering container file and associated metadata. The container is a ZIP file with raw data files and a YAML file meta.yml that contains all metadata not contained in the raw data files.

Parameters:
  • fn (str or stream) – File or stream that contains the ZIP-container.

  • datafile_keys (list of str, optional) – List of possible keys in ‘meta.yml’ that contains the name of the datafile to open. Code will try these keys in order. If a key starts with ‘squeezed’, the pipeline is not constructed from the metadata. (Default: [‘original’, ‘squeezed-netcdf’])

  • ignore_filters (bool, optional) – If True, the filter pipeline is not (re-)constructed from the metadata. (Default: False)

Returns:

surface_containers – List of all surfaces contained in this container file.

Return type:

list of :obj:`SurfaceContainer`s

container(index=0)

Returns an instance of a subclass of SurfaceContainer that contains a list of topographies.

Parameters:

index (int) – Index of the container to load. (Default: 0, which loads the first container)

Returns:

surface_container – The object containing a list with actual topography data.

Return type:

subclass of SurfaceContainer

SurfaceTopography.Container.IO.CE.write_containers(containers, fn)

Write multiple surface containers into a ZIP file.

Parameters:
  • containers (list of :obj:`SurfaceContainer`s) – Containers to be written to the ZIP file.

  • fn (str or stream) – File or stream to write the ZIP-container to.

SurfaceTopography.Container.IO.Reader module

class SurfaceTopography.Container.IO.Reader.ContainerReaderBase

Bases: object

Base class for container readers. These are object that allow to open a file (from filename or stream object), inspect its metadata and then request to load a surface container from it. Metadata is typically extracted without reading the full file.

Readers should adhere to the following design rules: 1. Opening a file should be fast and therefore not read the whole data.

The data is read only when requesting it via the surface method.

  1. Data corruption must be detected when opening the file. The surface method must not fail because of file corruption issues.

These rules are important to allow smooth operation of the readers in the web application TopoBank.

classmethod format()

Short string identifier for this file format. Identifier must be unique and is typically equal to the file extension of this format.

classmethod mime_types()

MIME types supported by this reader.

classmethod file_extensions()

A list of typical file extensions for this reader. Can be None if there are no typical file extensions.

classmethod name()

Short name of this file format.

classmethod description()

Long description of this file format. Should be formatted as markdown.

close()
property nb_surfaces

Number of surfaces stored in this container file

abstract container(index=0)

Returns an instance of a subclass of SurfaceContainer that contains a list of topographies.

Parameters:

index (int) – Index of the container to load. (Default: 0, which loads the first container)

Returns:

surface_container – The object containing a list with actual topography data.

Return type:

subclass of SurfaceContainer

SurfaceTopography.Container.IO.ZAG module

class SurfaceTopography.Container.IO.ZAG.ZAGReader(fobj)

Bases: ContainerReaderBase

__init__(fobj)

Read all surfaces in a contact.engineering container file and associated metadata. The container is a ZIP file with raw data files and a YAML file meta.yml that contains all metadata not contained in the raw data files.

Parameters:

fn (str or stream) – File or stream that contains the ZIP-container.

Returns:

surface_containers – List of all surfaces contained in this container file.

Return type:

list of :obj:`SurfaceContainer`s

close()
container(index=0)

Returns an instance of a subclass of SurfaceContainer that contains a list of topographies.

Parameters:

index (int) – Index of the container to load. (Default: 0, which loads the first container)

Returns:

surface_container – The object containing a list with actual topography data.

Return type:

subclass of SurfaceContainer

Module contents

SurfaceTopography.Container.IO.detect_format(fobj)

Detect file format based on its content.

Parameters:

fobj (filename or file object)

SurfaceTopography.Container.IO.open_container(fobj, format=None)

Returns a container reader object for the file fobj.

Parameters:
  • fobj (str or filelike object) – Path of the file or file-like object.

  • format (str, optional) – Specify in which format the file should be interpreted. (Default: None, which means autodetect file format)

Returns:

SurfaceTopography.Container.IO.read_container(fn, format=None, **kwargs)

Returns a surface container object representing a list of topographies.

Parameters:

fobj (str or filelike object) – Path of the file or file-like object.

Returns:

container – A list of container objects.

Return type:

list of subclasses of SurfaceContainer

SurfaceTopography.Container.IO.read_published_container(publication_url, **request_args)

Download a container from a URL.

Parameters:
  • publication_url (str) – Full URL of container location.

  • request_args (dict) – Additional dictionary passed to request.get.

Returns:

container – Surface container object read from URL.

Return type:

SurfaceContainer