pyspinw.serialisation#

Serialisation mixin

See notes document 004 for details.

Functions

deserialise_fraction(json)

Deserialise a Fraction

deserialise_fraction_or_builtin(json)

Deserialise the pre-json representation of a fraction or builtin

expects_keys(keystring[, parameter_index])

Decorator for functions that take json dicts with given keys as the parameter_index place parameter

header(description)

Header for files

load(filename)

Load a pySpinW object from a file

numpy_deserialise(json)

Deserialisation method numpy data in SPW json

numpy_serialise(data)

Serialisation for numpy data in the SPW json

rgb_deserialise(json)

Deserialise an RGB color

rgb_serialise(rgb)

Serialise an RGB color

save(object, filename[, description, ...])

Save a pySpinW object

serialise_fraction(fraction)

Serialise a Fraction

serialise_fraction_or_builtin(value)

Serialise a union type of fraction or builtin number to pre-json

vec3_deserialise(json)

Deserialise a 3D vector

vec3_serialise(x, y, z)

Serialise a 3D vector

Classes

SPWDeserialisationContexGroup(name, context_data)

Group of objects for deserialisation

SPWDeserialisationContext(context_data)

Context object (see notes document 004) for deserialisation

SPWDeserialisationRequestResponse(value, id, ...)

Return type for deserialisation requests from deserialisation context

SPWSerialisable()

Classes that are serialisable to SPW files should use implement this interface

SPWSerialisationContext()

Context object (see notes document 004) for serialisation

SPWSerialisationContextGroup(name)

A group of objects held for serialisation

Exceptions

SPWSerialisationError

Exceptions thrown by the [de]serialisation process

class pyspinw.serialisation.SPWDeserialisationContexGroup(name: str, context_data: dict)#

Bases: object

Group of objects for deserialisation

put(id, instance)#

Add a resolved instance to the context

request_by_id(id) → SPWDeserialisationRequestResponse#

Ask for an object from this context-group using its serialisation id

It will return an object that contains either the deserialised object, or json that needs to be deserialised (along with appropriate metadata)

request_by_json(json) → SPWDeserialisationRequestResponse#

Ask for an object from this context-group using a json object

It will return an object that contains either the deserialised object, or json that needs to be deserialised (along with appropriate metadata)

class pyspinw.serialisation.SPWDeserialisationContext(context_data: dict)#

Bases: object

Context object (see notes document 004) for deserialisation

class pyspinw.serialisation.SPWDeserialisationRequestResponse(value, id: int, deserialised: bool)#

Bases: object

Return type for deserialisation requests from deserialisation context

Contains a value which can be a deserialised object or json. Has a flag for is whether or not it is the deserialised object

class pyspinw.serialisation.SPWSerialisable#

Bases: object

Classes that are serialisable to SPW files should use implement this interface

classmethod deserialise(json_string: str)#

Deserialise an object of this type from a JSON string

save(filename: str | Path, description: str = '', add_extension: bool = True)#

Save this object to a file

serialisation_name = '<not-implemented>'#
serialise(description: str = '') → str#

Serialise an object of this type to a JSON string

class pyspinw.serialisation.SPWSerialisationContext#

Bases: object

Context object (see notes document 004) for serialisation

serialise()#

Serialise the data in this context to JSON

class pyspinw.serialisation.SPWSerialisationContextGroup(name: str)#

Bases: object

A group of objects held for serialisation

has(key)#

Does this serialisation context have the object specified by ‘key’

put(key, serialisation_data)#

Put a new serialised object into this context

reference(key)#

Return a reference to an object in this group

serialise()#

Get the serialisation data for this group

exception pyspinw.serialisation.SPWSerialisationError#

Bases: Exception

Exceptions thrown by the [de]serialisation process

pyspinw.serialisation.deserialise_fraction(json: dict) → Fraction#

Deserialise a Fraction

pyspinw.serialisation.deserialise_fraction_or_builtin(json: dict) → int | float | Fraction#

Deserialise the pre-json representation of a fraction or builtin

pyspinw.serialisation.expects_keys(keystring: str, parameter_index=0)#

Decorator for functions that take json dicts with given keys as the parameter_index place parameter

pyspinw.serialisation.header(description: str)#

Header for files

pyspinw.serialisation.load(filename: str | Path)#

Load a pySpinW object from a file

pyspinw.serialisation.numpy_deserialise(json: dict) → ndarray#

Deserialisation method numpy data in SPW json

pyspinw.serialisation.numpy_serialise(data: ndarray) → dict#

Serialisation for numpy data in the SPW json

pyspinw.serialisation.rgb_deserialise(json)#

Deserialise an RGB color

pyspinw.serialisation.rgb_serialise(rgb: tuple[float, float, float])#

Serialise an RGB color

pyspinw.serialisation.save(object: SPWSerialisable, filename: str | Path, description: str = '', add_extension: bool = True)#

Save a pySpinW object

pyspinw.serialisation.serialise_fraction(fraction: Fraction) → dict#

Serialise a Fraction

pyspinw.serialisation.serialise_fraction_or_builtin(value: int | float | Fraction)#

Serialise a union type of fraction or builtin number to pre-json

pyspinw.serialisation.vec3_deserialise(json)#

Deserialise a 3D vector

pyspinw.serialisation.vec3_serialise(x, y, z)#

Serialise a 3D vector