Package solvcon :: Package io :: Module core :: Class Format
[hide private]
[frames] | no frames]

Class Format

source code


Abstract class for SOLVCON intrinsic I/O format Each of the concrete derived classes represents a version of format. Public interface method is read_meta(). read_meta() method uses _parse_meta() private method to report the meta-data of the format, which is defined in META_* class attributes (as tuples). The default _parse_meta() and _save_meta() use SPEC_OF_META to determine the order and converter the each field of the META section.

The supported intrisic formats must consist of two parts: (i) text part and (ii) binary part. Compression is OK for the binary part. The text part starts at the beginneg of the file and ends after BINARY_MARKER, which the binary part starts after BINARY_MARKER and ends with the file.

Nested Classes [hide private]
  __metaclass__
Sum the length of all META_ entries of bases and derived classes; only collect from 1 level of parents.
Instance Methods [hide private]
solvcon.gendata.AttributeDict
read_meta(self, stream)
Read meta-data from stream.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
tuple
_get_textpart(cls, stream)
Retrieve the text part from the stream.
source code
solvcon.gendata.AttributeDict
_parse_meta(cls, lines)
Parse meta information from the file.
source code
Static Methods [hide private]
numpy.ndarray
_read_array(compressor, shape, dtype, stream, seek_only=False)
Read data from the input stream and convert it to ndarray with given shape and dtype.
source code
 
_write_array(compressor, arr, stream)
Returns: nothing.
source code
Class Variables [hide private]
  BINARY_MARKER = '-*- start of binary data -*-'
a string to mark the starting of binary data.
  FILE_HEADER = None
header of the format; must be overridden.
  FORMAT_REV = None
revision of format; must be overridden.
  READ_BLOCK = 1024
length per reading from file.
  SPEC_OF_META = None
the order and converter of each meta-data section occured in the text part; must be overridden.
  meta_length = 0
length of all META_ entries; calculated by FormatMeta.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

_get_textpart(cls, stream)
Class Method

source code 

Retrieve the text part from the stream.

Parameters:
  • stream (file) - input stream.
Returns: tuple
text lines and length of text part (including separator).

_parse_meta(cls, lines)
Class Method

source code 

Parse meta information from the file.

Parameters:
  • lines (list) - text part of the file.
Returns: solvcon.gendata.AttributeDict
meta information dictionary.

_read_array(compressor, shape, dtype, stream, seek_only=False)
Static Method

source code 

Read data from the input stream and convert it to ndarray with given shape and dtype.

Parameters:
  • compressor (str) - how to compress data arrays.
  • shape (tuple) - ndarray shape.
  • dtype (numpy.dtype or str) - ndarray dtype.
  • stream (file) - input stream.
  • seek_only (bool) - do not really read, only seek; default False.
Returns: numpy.ndarray
resulted array.

_write_array(compressor, arr, stream)
Static Method

source code 
Parameters:
  • compressor (str) - how to compress data arrays.
  • arr (numpy.ndarray) - the array to be written.
  • stream (file) - output stream.
Returns:
nothing.

read_meta(self, stream)

source code 

Read meta-data from stream.

Parameters:
  • stream (file or str) - file object or file name to be read.
Returns: solvcon.gendata.AttributeDict
meta-data, raw text lines of meta-data, and the length of meta-data in bytes.