ccpn.core.lib.SpectrumDataSources package

Subpackages

Submodules

ccpn.core.lib.SpectrumDataSources.AzaraSpectrumDataSource module

This file contains the Azara data access class it serves as an interface between the V3 Spectrum class and the actual spectral data

See SpectrumDataSourceABC for a description of the methods

class ccpn.core.lib.SpectrumDataSources.AzaraSpectrumDataSource.AzaraSpectrumDataSource(**kwargs)[source]

Bases: ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC

Azara spectral storage

blockHeaderSize = 0
dataFormat = 'Azara'
defaultOpenReadMode = 'rb'
headerSize = 0
isBlocked = True
isFloatData = True
openMethod(mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

Open file and return a stream. Raise OSError upon failure.

file is either a text or byte string giving the name (and the path if the file isn’t in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.)

mode is an optional string that specifies the mode in which the file is opened. It defaults to ‘r’ which means open for reading in text mode. Other common values are ‘w’ for writing (truncating the file if it already exists), ‘x’ for creating and writing to a new file, and ‘a’ for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are:

Character

Meaning

‘r’

open for reading (default)

‘w’

open for writing, truncating the file first

‘x’

create a new file and open it for writing

‘a’

open for writing, appending to the end of the file if it exists

‘b’

binary mode

‘t’

text mode (default)

‘+’

open a disk file for updating (reading and writing)

‘U’

universal newline mode (deprecated)

The default mode is ‘rt’ (open for reading text). For binary random access, the mode ‘w+b’ opens and truncates the file to 0 bytes, while ‘r+b’ opens the file without truncation. The ‘x’ mode implies ‘w’ and raises an FileExistsError if the file already exists.

Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn’t. Files opened in binary mode (appending ‘b’ to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when ‘t’ is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

‘U’ mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode.

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

  • Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.

  • “Interactive” text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.

encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.

errors is an optional string that specifies how encoding errors are to be handled—this argument should not be used in binary mode. Pass ‘strict’ to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass ‘ignore’ to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register or run ‘help(codecs.Codec)’ for a list of the permitted encoding error strings.

newline controls how universal newlines works (it only applies to text mode). It can be None, ‘’, ‘n’, ‘r’, and ‘rn’. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in ‘n’, ‘r’, or ‘rn’, and these are translated into ‘n’ before being returned to the caller. If it is ‘’, universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any ‘n’ characters written are translated to the system default line separator, os.linesep. If newline is ‘’ or ‘n’, no translation takes place. If newline is any of the other legal values, any ‘n’ characters written are translated to the given string.

If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case.

A custom opener can be used by passing a callable as opener. The underlying file descriptor for the file object is then obtained by calling opener with (file, flags). opener must return an open file descriptor (passing os.open as opener results in functionality similar to passing None).

open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode (‘w’, ‘r’, ‘wt’, ‘rt’, etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom.

It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode.

property parameterPath

- None, immutable - Path of the parameter file

readParameters()[source]

Read the parameters from the azara parameter file Returns self

setPath(path, substituteSuffix=False)[source]

Set the path, optionally change .par in .spc suffix and do some checks by calling the super class

suffixes = ['.spc', '.par']
wordSize = 4

ccpn.core.lib.SpectrumDataSources.BrukerSpectrumDataSource module

This file contains the Bruker data access class it serves as an interface between the V3 Spectrum class and the actual spectral data Some routines rely on code from the Nmrglue package, included in the miniconda distribution

See SpectrumDataSourceABC for a description of the methods

class ccpn.core.lib.SpectrumDataSources.BrukerSpectrumDataSource.BrukerSpectrumDataSource(**kwargs)[source]

Bases: ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC

Bruker spectral data reading Intialization can be with: - a directory with Bruker data - a directory with Bruker processed data (pdata/x) - Bruker processed data [1r, 2rr, etc]

allowDirectory = True
blockHeaderSize = 0
dataFormat = 'Bruker'
defaultOpenReadMode = 'rb'
headerSize = 0
isBlocked = True
isFloatData = False
nameFromPath()[source]

Return a name derived from _brukerRoot and pdataDir

openMethod(mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

Open file and return a stream. Raise OSError upon failure.

file is either a text or byte string giving the name (and the path if the file isn’t in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.)

mode is an optional string that specifies the mode in which the file is opened. It defaults to ‘r’ which means open for reading in text mode. Other common values are ‘w’ for writing (truncating the file if it already exists), ‘x’ for creating and writing to a new file, and ‘a’ for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are:

Character

Meaning

‘r’

open for reading (default)

‘w’

open for writing, truncating the file first

‘x’

create a new file and open it for writing

‘a’

open for writing, appending to the end of the file if it exists

‘b’

binary mode

‘t’

text mode (default)

‘+’

open a disk file for updating (reading and writing)

‘U’

universal newline mode (deprecated)

The default mode is ‘rt’ (open for reading text). For binary random access, the mode ‘w+b’ opens and truncates the file to 0 bytes, while ‘r+b’ opens the file without truncation. The ‘x’ mode implies ‘w’ and raises an FileExistsError if the file already exists.

Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn’t. Files opened in binary mode (appending ‘b’ to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when ‘t’ is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

‘U’ mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode.

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

  • Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.

  • “Interactive” text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.

encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.

errors is an optional string that specifies how encoding errors are to be handled—this argument should not be used in binary mode. Pass ‘strict’ to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass ‘ignore’ to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register or run ‘help(codecs.Codec)’ for a list of the permitted encoding error strings.

newline controls how universal newlines works (it only applies to text mode). It can be None, ‘’, ‘n’, ‘r’, and ‘rn’. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in ‘n’, ‘r’, or ‘rn’, and these are translated into ‘n’ before being returned to the caller. If it is ‘’, universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any ‘n’ characters written are translated to the system default line separator, os.linesep. If newline is ‘’ or ‘n’, no translation takes place. If newline is any of the other legal values, any ‘n’ characters written are translated to the given string.

If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case.

A custom opener can be used by passing a callable as opener. The underlying file descriptor for the file object is then obtained by calling opener with (file, flags). opener must return an open file descriptor (passing os.open as opener results in functionality similar to passing None).

open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode (‘w’, ‘r’, ‘wt’, ‘rt’, etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom.

It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode.

property parentPath: ccpn.util.Path.aPath

- <function aPath at 0x12ff52e50>, immutable - Return an absolute path of parent directory, i.e. _BrukerRoot, as a Path instance or None when dataFile is not defined. Subclassed to accommodate the special Bruker directory structure

readParameters()[source]

Read the parameters from the Bruker directory Returns self

setPath(path, substituteSuffix=False)[source]

Parse and set path, assure there is the directory with acqus and pdata dirs set the _brukerRoot and _pdata attributes to point to the relevant directories

Return self or None on error

suffixes = [None]
termDict = {'AMP': 'amplitude of pulses', 'AQ': 'acquisition time in seconds', 'AQSEQ': '3D acquisition order', 'AQ_mod': 'acquisition mode', 'AUNM': 'name of an acquisition AU program', 'BF(1-8)': 'basic frequency for frequency channel f(1-8)', 'BYTORDP': 'Byte order (endianness)', 'CNST': 'constant used in pulse programs', 'CPDPRG(1-8)': 'names of CPD programs', 'D': 'time delays', 'DDR': 'digital digitizer resolution', 'DE': 'pre-scan delay', 'DECIM': 'decimation factor of the digital filter', 'DIGMOD': 'digitizer mode', 'DIGTYP': 'digitizer type', 'DQDMODE': 'sign of the frequency shift during digital quadrature detection', 'DR': 'digitizer resolution', 'DS': 'number of dummy scans', 'DSLIST': 'dataset list', 'DSPFIRM': 'firmware used for digital filtering', 'DW': 'dwell time', 'DWOV': 'oversampling dwell time', 'EXP': 'experiment performed', 'FCUCHAN': 'routing between logical frequency channels and FCU s', 'FIDRES': 'FID resolution', 'FQ1LIST': 'irradiation frequency lists', 'FW': 'analog filter width', 'FnMODE': 'Acquisition mode of the indirect dimensions (2D and 3D)', 'GP031': 'gradient parameter table', 'GRDPROG': 'gradient program name', 'HDDUTY': 'homodecoupling duty cycle (in percent)', 'HPMOD': 'routing between high power amplifiers and preamplifier modules', 'HPPRGN': 'high power preamplifier gain', 'IN': 'increment for delay D', 'INP': 'increment for pulse P', 'L': 'loop counter', 'LOCNUC': 'lock nucleus', 'MASR': 'MAS spin rate', 'NBL': 'number of blocks (of acquisition memory)', 'ND0': 'number of delays D0', 'ND10': 'number of delays D10', 'NS': 'number of scans', 'NUC(1-8)': 'nucleus for frequency channel f(1-8)', 'O(1-8)': 'irradiation frequency offset for frequency channel f(1-8) in Hz', 'O(1-8)P': 'irradiation frequency offset for frequency channel f(1-8) in ppm', 'OVERFLW': 'data overflow check', 'P': 'pulse length', 'PARMODE': 'dimensionality of the raw data', 'PCPD': 'CPD pulse length', 'PHCOR': 'correction angle for phase programs', 'PH_ref': 'receiver phase correction', 'PL': 'power level', 'POWMOD': 'power mode', 'PRECHAN': 'routing between Switchbox outputs and Preamplifier modules', 'PRGAIN': 'high power preamplifier gain', 'PROSOL': 'copy prosol parameters to corresponding acquisition parameters', 'PULPROG': 'pulse program used for the acquisition', 'QNP': 'QNP nucleus selection', 'RECCHAN': 'receiver channel', 'RG': 'receiver gain', 'RO': 'sample rotation frequency in Hz', 'RSEL': 'routing between FCU s and amplifiers', 'SEOUT': 'SE 451 receiver unit output to be used', 'SFO(1-8)': 'irradiation (carrier) frequencies for channel f(1-8)', 'SOLVENT': 'the sample solvent', 'SP07': 'shaped pulse parameter table', 'SW': 'spectral width in ppm', 'SWIBOX': 'routing between Switchbox inputs and Switchbox outputs', 'SW_h': 'spectral width in Hz', 'TD': 'time domain; number of raw data points', 'TD0': 'loop counter for multidimensional experiments', 'TE': 'demand temperature on the temperature unit', 'V9': 'maximum variation of a delay', 'VALIST': 'variable amplitude (power) list', 'VCLIST': 'variable counter list', 'VDLIST': 'variable delay list', 'VPLIST': 'variable pulse list', 'VTLIST': 'variable temperature list', 'WBST': 'number of wobble steps', 'WBSW': 'wobble sweep width', 'ZGOPTNS': 'acquisition (zg) options'}
wordSize = 4
ccpn.core.lib.SpectrumDataSources.BrukerSpectrumDataSource.read_jcamp(filename: str, encoding: str = 'UTF-8') dict[source]

Read a Bruker JCAMP-DX file into a dictionary.

Creates two special dictionary keys _coreheader and _comments Bruker parameter “$FOO” are extracted into strings, floats or lists and assigned to dic[“FOO”]

filenamestr

Filename of Bruker JCAMP-DX file.

encodingstr

Encoding of Bruker JCAMP-DX file. Defaults to the system default locale

dicdict

Dictionary of parameters in file.

write_jcamp : Write a Bruker JCAMP-DX file.

This is not a fully functional JCAMP-DX reader, it is only intended to read Bruker acqus (and similar) files.

ccpn.core.lib.SpectrumDataSources.EmptySpectrumDataSource module

This file contains the data access stuff for “Empty” spectra, ie. those without actual data as used for simulated peaklists it serves as an interface between the V3 Spectrum class and the non-existent data, yield zero’s in all cases

See SpectrumDataSourceABC for a description of the methods

class ccpn.core.lib.SpectrumDataSources.EmptySpectrumDataSource.EmptySpectrumDataSource(**kwargs)[source]

Bases: ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC

Empty spectral data handling

blockHeaderSize = 0
classmethod checkForValidFormat(path)[source]

check if valid format corresponding to dataFormat by; :return: None

dataFormat = 'Empty'
getPlaneData(position: Optional[Sequence] = None, xDim: int = 1, yDim: int = 2)[source]

Get plane defined by xDim, yDim and position (all 1-based) return NumPy data array with zero’s

getPointData(position: Optional[Sequence] = None) float[source]

Get value defined by points (1-based) returns 0.0

getRegionData(sliceTuples, aliasingFlags=None)[source]
Return an numpy array containing the points defined by

sliceTuples=[(start_1,stop_1), (start_2,stop_2), …],

containing only zero’s

sliceTuples are 1-based; sliceTuple stop values are inclusive (i.e. different from the python slice object)

Optionally allow for aliasing per dimension:

0: No aliasing 1: aliasing with identical sign

-1: aliasing with inverted sign

getSliceData(position: Optional[Sequence] = None, sliceDim: int = 1)[source]

Get slice defined by sliceDim and position (all 1-based) return NumPy data array of zero’s

hasBlockCached = False
hasValidPath()[source]

Always True

headerSize = 0
isBlocked = False
isFloatData = True
nameFromPath()[source]

Return a name derived from path (to be subclassed for specific cases; e.g. Bruker)

openFile(mode=None, **kwds)[source]

Return None, as there is no actual file

openMethod(mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

Open file and return a stream. Raise OSError upon failure.

file is either a text or byte string giving the name (and the path if the file isn’t in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.)

mode is an optional string that specifies the mode in which the file is opened. It defaults to ‘r’ which means open for reading in text mode. Other common values are ‘w’ for writing (truncating the file if it already exists), ‘x’ for creating and writing to a new file, and ‘a’ for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are:

Character

Meaning

‘r’

open for reading (default)

‘w’

open for writing, truncating the file first

‘x’

create a new file and open it for writing

‘a’

open for writing, appending to the end of the file if it exists

‘b’

binary mode

‘t’

text mode (default)

‘+’

open a disk file for updating (reading and writing)

‘U’

universal newline mode (deprecated)

The default mode is ‘rt’ (open for reading text). For binary random access, the mode ‘w+b’ opens and truncates the file to 0 bytes, while ‘r+b’ opens the file without truncation. The ‘x’ mode implies ‘w’ and raises an FileExistsError if the file already exists.

Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn’t. Files opened in binary mode (appending ‘b’ to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when ‘t’ is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

‘U’ mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode.

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

  • Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.

  • “Interactive” text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.

encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.

errors is an optional string that specifies how encoding errors are to be handled—this argument should not be used in binary mode. Pass ‘strict’ to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass ‘ignore’ to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register or run ‘help(codecs.Codec)’ for a list of the permitted encoding error strings.

newline controls how universal newlines works (it only applies to text mode). It can be None, ‘’, ‘n’, ‘r’, and ‘rn’. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in ‘n’, ‘r’, or ‘rn’, and these are translated into ‘n’ before being returned to the caller. If it is ‘’, universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any ‘n’ characters written are translated to the system default line separator, os.linesep. If newline is ‘’ or ‘n’, no translation takes place. If newline is any of the other legal values, any ‘n’ characters written are translated to the given string.

If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case.

A custom opener can be used by passing a callable as opener. The underlying file descriptor for the file object is then obtained by calling opener with (file, flags). opener must return an open file descriptor (passing os.open as opener results in functionality similar to passing None).

open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode (‘w’, ‘r’, ‘wt’, ‘rt’, etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom.

It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode.

property path: ccpn.util.Path.aPath

- <function aPath at 0x12ff52e50>, immutable - :return empty Path string, as a path is not defined

readParameters()[source]

Read the parameters from the Spectrum instance Returns self

setPath(path, substituteSuffix=False)[source]

define valid path: always set to None for EmptySpectrumDataSource

suffixes = [None]
wordSize = 4

ccpn.core.lib.SpectrumDataSources.FelixSpectrumDataSource module

This file contains the Felix data access class it serves as an interface between the V3 Spectrum class and the actual spectral data

See SpectrumDataSourceABC for a description of the methods

class ccpn.core.lib.SpectrumDataSources.FelixSpectrumDataSource.FelixSpectrumDataSource(**kwargs)[source]

Bases: ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC

Felix spectral storage

blockHeaderSize = 0
dataFormat = 'Felix'
defaultOpenReadMode = 'rb'
headerSize = 4096
isBlocked = True
isFloatData = True
openMethod(mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

Open file and return a stream. Raise OSError upon failure.

file is either a text or byte string giving the name (and the path if the file isn’t in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.)

mode is an optional string that specifies the mode in which the file is opened. It defaults to ‘r’ which means open for reading in text mode. Other common values are ‘w’ for writing (truncating the file if it already exists), ‘x’ for creating and writing to a new file, and ‘a’ for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are:

Character

Meaning

‘r’

open for reading (default)

‘w’

open for writing, truncating the file first

‘x’

create a new file and open it for writing

‘a’

open for writing, appending to the end of the file if it exists

‘b’

binary mode

‘t’

text mode (default)

‘+’

open a disk file for updating (reading and writing)

‘U’

universal newline mode (deprecated)

The default mode is ‘rt’ (open for reading text). For binary random access, the mode ‘w+b’ opens and truncates the file to 0 bytes, while ‘r+b’ opens the file without truncation. The ‘x’ mode implies ‘w’ and raises an FileExistsError if the file already exists.

Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn’t. Files opened in binary mode (appending ‘b’ to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when ‘t’ is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

‘U’ mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode.

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

  • Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.

  • “Interactive” text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.

encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.

errors is an optional string that specifies how encoding errors are to be handled—this argument should not be used in binary mode. Pass ‘strict’ to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass ‘ignore’ to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register or run ‘help(codecs.Codec)’ for a list of the permitted encoding error strings.

newline controls how universal newlines works (it only applies to text mode). It can be None, ‘’, ‘n’, ‘r’, and ‘rn’. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in ‘n’, ‘r’, or ‘rn’, and these are translated into ‘n’ before being returned to the caller. If it is ‘’, universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any ‘n’ characters written are translated to the system default line separator, os.linesep. If newline is ‘’ or ‘n’, no translation takes place. If newline is any of the other legal values, any ‘n’ characters written are translated to the given string.

If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case.

A custom opener can be used by passing a callable as opener. The underlying file descriptor for the file object is then obtained by calling opener with (file, flags). opener must return an open file descriptor (passing os.open as opener results in functionality similar to passing None).

open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode (‘w’, ‘r’, ‘wt’, ‘rt’, etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom.

It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode.

readParameters()[source]

Read the parameters from the Felix file header Returns self

suffixes = ['.mat', '.dat']
wordSize = 4

ccpn.core.lib.SpectrumDataSources.Hdf5SpectrumDataSource module

This file contains the HDF5 data access stuff it serves as an interface between the V3 Spectrum class and the actual Hdf5 data formats The Hdf5 format has writing capabilities

Version history: No-version: Luca’s initial implementation 1.0 (float): Version info (float) stored as ‘version’ in parameters;

spectralWidth definition updated (if need be)

1.0.1 (string): hdf5 metadata; stored in attributes top object (i.e. self.fp)

See SpectrumDataSourceABC for a description of the methods

class ccpn.core.lib.SpectrumDataSources.Hdf5SpectrumDataSource.Hdf5Metadata[source]

Bases: dict

A class to store/manage the Hdf5 metadata

initCurrentValues()[source]

Initialise with default values

restoreFromHdf5(fp)[source]

Update self from the Hdf5 file

saveToHdf5(fp)[source]

Update the Hdf5 file with self

class ccpn.core.lib.SpectrumDataSources.Hdf5SpectrumDataSource.Hdf5SpectrumDataSource(**kwargs)[source]

Bases: ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC

HDF5 spectral storage

blockHeaderSize = 0
compressionModes = ('lzf', 'gzip')
dataFormat = 'Hdf5'
defaultAppendMode = 'a'
defaultCompressionMode = None
defaultOpenReadMode = 'r'
defaultOpenReadWriteMode = 'r+'
defaultOpenWriteMode = 'w'
getPlaneData(position: Optional[Sequence] = None, xDim: int = 1, yDim: int = 2) ccpn.core._implementation.SpectrumData.PlaneData[source]

Get plane defined by xDim, yDim and position (all 1-based) :return PlaneData (i.e. numpy.ndarray) object.

getPointData(position: Optional[Sequence] = None) float[source]

Get value defined by position (1-based)

getRegionData(sliceTuples, aliasingFlags=None)[source]
Return an numpy array containing the points defined by

sliceTuples=[(start_1,stop_1), (start_2,stop_2), …],

sliceTuples are 1-based; sliceTuple stop values are inclusive (i.e. different from the python slice object)

Optionally allow for aliasing per dimension:

0: No aliasing 1: aliasing with identical sign

-1: aliasing with inverted sign

getSliceData(position: Optional[Sequence] = None, sliceDim: int = 1) ccpn.core._implementation.SpectrumData.SliceData[source]

Get slice defined by sliceDim and position (all 1-based) :return SliceData object (i.e. a numpy.ndarray) object

hasBlockCached = False
hasWritingAbility = True
headerSize = 0
isBlocked = False
isFloatData = True
openFile(mode, check=True, **kwds)[source]

open self.path, set self.fp, Raise Runtime error on opening errors

Parameters
  • mode

    open file mode; from hdf5 documentation:

    r Readonly, file must exist (default) r+ Read/write, file must exist w Create file, truncate if exists w- or x Create file, fail if exists a Read/write if exists, create otherwise

  • check – check for metadata and old parameter definitions

:return self.fp

openMethod

alias of h5py._hl.files.File

readParameters()[source]

Read the parameter values from the hdf5 data structure :return self

setPlaneData(data, position: Optional[Sequence] = None, xDim: int = 1, yDim: int = 2)[source]

Set data as plane defined by xDim, yDim and position (all 1-based)

setPointData(value, position: Optional[Sequence] = None) float[source]

Set point value defined by position (1-based)

setSliceData(data, position: Optional[Sequence] = None, sliceDim: int = 1)[source]

Set data as slice defined by sliceDim and position (all 1-based)

property spectrumData

- None, immutable -

property spectrumParameters

- None, immutable -

suffixes = ['.ndf5', '.hdf5']
wordSize = 4
writeParameters()[source]

write the parameter values into the hdf5 data structure :return self

class ccpn.core.lib.SpectrumDataSources.Hdf5SpectrumDataSource.String(value)[source]

Bases: bytes

Bytes representation of string

decode()[source]

Decode the bytes using the codec registered for encoding.

encoding

The encoding with which to decode the bytes.

errors

The error handling scheme to use for the handling of decoding errors. The default is ‘strict’ meaning that decoding errors raise a UnicodeDecodeError. Other possible values are ‘ignore’ and ‘replace’ as well as any other name registered with codecs.register_error that can handle UnicodeDecodeErrors.

ccpn.core.lib.SpectrumDataSources.JcampSpectrumDataSource module

This file contains the JCAMP data access class it serves as an interface between the V3 Spectrum class and the actual spectral data Some routines rely on code from the Nmrglue package, included in the miniconda distribution

See SpectrumDataSourceABC for a description of the methods

class ccpn.core.lib.SpectrumDataSources.JcampSpectrumDataSource.JcampSpectrumDataSource(**kwargs)[source]

Bases: ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC

JCAMP spectral data reading; 1D only

allowDirectory = False
blockHeaderSize = 0
dataFormat = 'Jcamp'
defaultOpenReadMode = 'r'
getSliceData(position: Optional[Sequence] = None, sliceDim: int = 1)[source]

Return a 1D slice

headerSize = 0
isBlocked = False
isFloatData = False
openMethod(mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

Open file and return a stream. Raise OSError upon failure.

file is either a text or byte string giving the name (and the path if the file isn’t in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.)

mode is an optional string that specifies the mode in which the file is opened. It defaults to ‘r’ which means open for reading in text mode. Other common values are ‘w’ for writing (truncating the file if it already exists), ‘x’ for creating and writing to a new file, and ‘a’ for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are:

Character

Meaning

‘r’

open for reading (default)

‘w’

open for writing, truncating the file first

‘x’

create a new file and open it for writing

‘a’

open for writing, appending to the end of the file if it exists

‘b’

binary mode

‘t’

text mode (default)

‘+’

open a disk file for updating (reading and writing)

‘U’

universal newline mode (deprecated)

The default mode is ‘rt’ (open for reading text). For binary random access, the mode ‘w+b’ opens and truncates the file to 0 bytes, while ‘r+b’ opens the file without truncation. The ‘x’ mode implies ‘w’ and raises an FileExistsError if the file already exists.

Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn’t. Files opened in binary mode (appending ‘b’ to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when ‘t’ is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

‘U’ mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode.

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

  • Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.

  • “Interactive” text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.

encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.

errors is an optional string that specifies how encoding errors are to be handled—this argument should not be used in binary mode. Pass ‘strict’ to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass ‘ignore’ to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register or run ‘help(codecs.Codec)’ for a list of the permitted encoding error strings.

newline controls how universal newlines works (it only applies to text mode). It can be None, ‘’, ‘n’, ‘r’, and ‘rn’. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in ‘n’, ‘r’, or ‘rn’, and these are translated into ‘n’ before being returned to the caller. If it is ‘’, universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any ‘n’ characters written are translated to the system default line separator, os.linesep. If newline is ‘’ or ‘n’, no translation takes place. If newline is any of the other legal values, any ‘n’ characters written are translated to the given string.

If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case.

A custom opener can be used by passing a callable as opener. The underlying file descriptor for the file object is then obtained by calling opener with (file, flags). opener must return an open file descriptor (passing os.open as opener results in functionality similar to passing None).

open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode (‘w’, ‘r’, ‘wt’, ‘rt’, etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom.

It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode.

readParameters()[source]

Read the parameters from the file this will also read the data into the two arrays, as it is parsed in one go by the nmrglue routine

suffixes = ['.dx', '.DX']
wordSize = 4

ccpn.core.lib.SpectrumDataSources.NmrPipeSpectrumDataSource module

This file contains the NmrPipe data access class it serves as an interface between the V3 Spectrum class and the actual spectral data

See SpectrumDataSourceABC for a description of the methods

The NmrPipe data access completely relies on the Hdf5buffer option: the NmrPipe file is fully read into the temporary buffer at the moment of first data access

class ccpn.core.lib.SpectrumDataSources.NmrPipeSpectrumDataSource.NmrPipeInputStreamDataSource(**kwargs)[source]

Bases: ccpn.core.lib.SpectrumDataSources.NmrPipeSpectrumDataSource.NmrPipeSpectrumDataSource

NmrPipe spectral storage, reading from an stdinp stream

closeFile()[source]

close the file

fillHdf5Buffer(hdf5buffer)[source]

Fill hdf5 buffer reading all slices from input stream

class ccpn.core.lib.SpectrumDataSources.NmrPipeSpectrumDataSource.NmrPipeSpectrumDataSource(**kwargs)[source]

Bases: ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC

NmrPipe spectral storage

MAXDIM = 4
baseDimensionality
blockHeaderSize = 0
dataFormat = 'NMRPipe'
defaultOpenReadMode = 'rb'
fillHdf5Buffer()[source]

Fill hdf5buffer with data from self

headerSize = 512
isBlocked = False
isFloatData = True
nFiles
openMethod(mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

Open file and return a stream. Raise OSError upon failure.

file is either a text or byte string giving the name (and the path if the file isn’t in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.)

mode is an optional string that specifies the mode in which the file is opened. It defaults to ‘r’ which means open for reading in text mode. Other common values are ‘w’ for writing (truncating the file if it already exists), ‘x’ for creating and writing to a new file, and ‘a’ for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are:

Character

Meaning

‘r’

open for reading (default)

‘w’

open for writing, truncating the file first

‘x’

create a new file and open it for writing

‘a’

open for writing, appending to the end of the file if it exists

‘b’

binary mode

‘t’

text mode (default)

‘+’

open a disk file for updating (reading and writing)

‘U’

universal newline mode (deprecated)

The default mode is ‘rt’ (open for reading text). For binary random access, the mode ‘w+b’ opens and truncates the file to 0 bytes, while ‘r+b’ opens the file without truncation. The ‘x’ mode implies ‘w’ and raises an FileExistsError if the file already exists.

Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn’t. Files opened in binary mode (appending ‘b’ to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when ‘t’ is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

‘U’ mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode.

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

  • Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.

  • “Interactive” text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.

encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.

errors is an optional string that specifies how encoding errors are to be handled—this argument should not be used in binary mode. Pass ‘strict’ to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass ‘ignore’ to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register or run ‘help(codecs.Codec)’ for a list of the permitted encoding error strings.

newline controls how universal newlines works (it only applies to text mode). It can be None, ‘’, ‘n’, ‘r’, and ‘rn’. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in ‘n’, ‘r’, or ‘rn’, and these are translated into ‘n’ before being returned to the caller. If it is ‘’, universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any ‘n’ characters written are translated to the system default line separator, os.linesep. If newline is ‘’ or ‘n’, no translation takes place. If newline is any of the other legal values, any ‘n’ characters written are translated to the given string.

If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case.

A custom opener can be used by passing a callable as opener. The underlying file descriptor for the file object is then obtained by calling opener with (file, flags). opener must return an open file descriptor (passing os.open as opener results in functionality similar to passing None).

open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode (‘w’, ‘r’, ‘wt’, ‘rt’, etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom.

It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode.

readParameters()[source]

Read the parameters from the NmrPipe file header Returns self

setPath(path, substituteSuffix=False)[source]

define valid path to a (binary) data file, if needed appends or substitutes the suffix (if defined).

return self or None on error

suffixes = ['.dat', '.fid', '.ft1', '.ft2', '.ft3', '.ft4']
template

A trait that defines a string object, casts from bytes object and is json serialisable

wordSize = 4

ccpn.core.lib.SpectrumDataSources.NmrViewSpectrumDataSource module

This file contains the NmrView data access class it serves as an interface between the V3 Spectrum class and the actual spectral data

See SpectrumDataSourceABC for a description of the methods

class ccpn.core.lib.SpectrumDataSources.NmrViewSpectrumDataSource.NmrViewSpectrumDataSource(**kwargs)[source]

Bases: ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC

NmrView spectral storage

alternateDataFormatNames = ['NmrView']
blockHeaderSize = 0
dataFormat = 'NMRView'
defaultOpenReadMode = 'rb'
headerSize = 512
isBlocked = True
isFloatData = True
openMethod(mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

Open file and return a stream. Raise OSError upon failure.

file is either a text or byte string giving the name (and the path if the file isn’t in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.)

mode is an optional string that specifies the mode in which the file is opened. It defaults to ‘r’ which means open for reading in text mode. Other common values are ‘w’ for writing (truncating the file if it already exists), ‘x’ for creating and writing to a new file, and ‘a’ for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are:

Character

Meaning

‘r’

open for reading (default)

‘w’

open for writing, truncating the file first

‘x’

create a new file and open it for writing

‘a’

open for writing, appending to the end of the file if it exists

‘b’

binary mode

‘t’

text mode (default)

‘+’

open a disk file for updating (reading and writing)

‘U’

universal newline mode (deprecated)

The default mode is ‘rt’ (open for reading text). For binary random access, the mode ‘w+b’ opens and truncates the file to 0 bytes, while ‘r+b’ opens the file without truncation. The ‘x’ mode implies ‘w’ and raises an FileExistsError if the file already exists.

Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn’t. Files opened in binary mode (appending ‘b’ to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when ‘t’ is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

‘U’ mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode.

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

  • Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.

  • “Interactive” text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.

encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.

errors is an optional string that specifies how encoding errors are to be handled—this argument should not be used in binary mode. Pass ‘strict’ to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass ‘ignore’ to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register or run ‘help(codecs.Codec)’ for a list of the permitted encoding error strings.

newline controls how universal newlines works (it only applies to text mode). It can be None, ‘’, ‘n’, ‘r’, and ‘rn’. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in ‘n’, ‘r’, or ‘rn’, and these are translated into ‘n’ before being returned to the caller. If it is ‘’, universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any ‘n’ characters written are translated to the system default line separator, os.linesep. If newline is ‘’ or ‘n’, no translation takes place. If newline is any of the other legal values, any ‘n’ characters written are translated to the given string.

If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case.

A custom opener can be used by passing a callable as opener. The underlying file descriptor for the file object is then obtained by calling opener with (file, flags). opener must return an open file descriptor (passing os.open as opener results in functionality similar to passing None).

open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode (‘w’, ‘r’, ‘wt’, ‘rt’, etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom.

It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode.

readParameters()[source]

Read the parameters from the Felix file header Returns self

suffixes = ['.nv']
wordSize = 4

ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC module

This file contains the ABC wrapper around the model datasource stuff (fail to define a better name)

it serves as an interface between the V3 Spectrum class and the actual spectral data formats of different flavours (e.g. Bruker, NmrPipe, Azara, Felix, Varian/Agilent, Hdf5 (internal), etc)

the core methods are:

checkForValidFormat() classmethod; check if valid format corresponding to dataFormat;

returns True/False

readParameters() read paramters from spectral data format

(to be subclassed; call super().readParameters() before returning)

writeParameters() write parameters to spectral data format (currently hdf5 and NmrPipe only)

(to be subclassed)

copyParametersTo() copy parameters from self to a target SpectrumDataSource instance copyDataTo() copy data from self to target SpectrumDataSource instance

copyParametersFrom() copy parameters from a source to self copyDataFrom() copy data from self a source to self

importFromSpectrum() import parameters (and optionally path) from a Spectrum instance exportToSpectrum() export parameters (and optionally path) to a Spectrum instance

getByDimension() Get specific parameter in dimension order setByDimension() Set specific parameter in dimension order

getSliceData() get 1D slice (to be subclassed) setSliceData() set 1D slice (to be subclassed; specific formats only)

getPlaneData() get 2D plane (to be subclassed) setPlaneData() set 2D plane (to be subclassed; specific formats only)

getPointData() Get value defined by position (1-based, integer values) getPointValue() Get interpolated value defined by position (1-based, float values)

getRegionData() Return an numpy array containing the points defined by

sliceTuples=[(start_1,stop_1), (start_2,stop_2), …], (1, based, optional aliasing)

setPath define valid path to a (binary) data file, if needed appends or substitutes the suffix (if defined);

use path attribute to obtain Path instance to the absolute path of the data file

openExistingFile() opens an existing file; used in “with” statement; yields the instance openNewFile() opens a new file; used in “with” statement; yields the instance closeFile() closes file

allPlanes() yields a (position, planeData) tuple iterator over all planes allSlices() yields a (position, sliceData) tuple iterator over all slices allPoints() yields a (position, point) tuple iterator over all points

Example 1 (No Spectrum instance used):

with AzaraSpectrumDataSource().openExistingFile(inputPath) as input:

output = Hdf5SpectrumDataSource().copyParametersFrom(input)

with output.openNewFile(outputPath):
for position, data in input.allPlanes(xDim=1, yDim=2):

output.setPlaneData(data, position=position, xDim=1, yDim=2)

Example 2 (with Spectrum instance):

sp = get(‘SP:hnca’) axes = (‘H’,’N’) xDim, yDim = sp.getByAxisCode(‘dimensions’, axes)

with Hdf5SpectrumDataSource(spectrum=sp).openNewFile(outputPath) as output:
for position, data in sp.allPlanes(axes, exactMatch=False):

output.setPlaneData(data, position=position, xDim=xDim, yDim=yDim)

Example 3 (using Spectrum instance to make a hdf5 duplicate):

sp = get(‘SP:hnca’) outputPath = ‘myCopiedHNCA.hdf5’

with Hdf5SpectrumDataSource(spectrum=sp).openNewFile(outputPath) as output:

output.copyDataFrom(sp.dataSource)

class ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.DataSourceTrait(**kwds)[source]

Bases: ccpn.util.traits.CcpNmrTraits.Instance

Specific trait for a Datasource instance encoding access to the (binary) spectrum data. None indicates no spectrumDataSource has been defined

class jsonHandler[source]

Bases: ccpn.util.traits.TraitJsonHandlerBase.CcpNmrJsonClassHandlerABC

klass

alias of ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC

class ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC(**kwargs)[source]

Bases: ccpn.util.traits.CcpNmrJson.CcpNmrJson

ABC for NMR spectral data sources reading/writing

MAXDIM = 8
allPlanes(xDim=1, yDim=2)[source]

An iterator over all planes defined by xDim, yDim, yielding (position, data-array) tuples dims and positions are one-based

allPoints()[source]

An iterator over all points, yielding (position, pointValue) tuples positions are one-based

allSlices(sliceDim=1)[source]

An iterator over all slices defined by sliceDim, yielding (position, data-array) tuples dims and positions are one-based

allowDirectory = False
alternateDataFormatNames = []
assignmentTolerances

Casting list, any iterable

axisCodes

Casting list, any iterable

axisLabels

Casting list, any iterable

blockHeaderSize = 0
blockSizes

Casting list, any iterable

property cache

- None, immutable - Returns the Block cache instance

classmethod checkForValidFormat(path)[source]

check if valid format corresponding to dataFormat by: - creating an instance of the class - setting and checking path - reading (and checking dimensionCount) parameters

Returns

None or instance of the class

checkForValidPlane(position, xDim, yDim)[source]

Asserts if position, xDim, yDim are valid Return valid position

checkForValidPosition(position)[source]

Checks if position (1-based) is valid, expand if None and append if necessay Return valid position

checkForValidRegion(sliceTuples, aliasingFlags)[source]

Checks if slicesTuples are valid

aliasingFlags: Optionally allow for aliasing per dimension:

0: No aliasing 1: aliasing with positive sign

-1: aliasing with negative sign

checkForValidSlice(position, sliceDim)[source]

Checks that sliceDim is valid, returns valid (expanded) position if None

classVersion = 1.0
clearCache()[source]

Clear the cache

closeFile()[source]

Close the file and clear the cache

closeHdf5Buffer()[source]

Close the hdf5Buffer

comment

A trait that defines a string object, casts from bytes object and is json serialisable

copyDataFrom(source)[source]

Copy data from source to self; return self

copyDataTo(target)[source]

Copy data from self to target; return self

copyParametersFrom(source)[source]

Copy parameters from source to self

copyParametersTo(target)[source]

Copy parameters from self to target; return self

dataFormat = None
dataScale
dataType

alias of numpy.float32

date

A trait that defines a string object, casts from bytes object and is json serialisable

defaultAppendMode = 'a'
defaultOpenReadMode = 'r+'
defaultOpenReadWriteMode = 'r+'
defaultOpenWriteMode = 'w'
dimensionCount
property dimensionIndices: tuple

- tuple, immutable - A zero-based tuple of dimension indices [0,dimensionCount-1]

dimensionOrder

Casting list, any iterable

dimensionTypes

Casting list, any iterable

property dimensions: tuple

- tuple, immutable - A one-based tuple of dimensions [1,dimensionCount]

disableCache()[source]

Disable the caching of blockdata

property dtype

- None, immutable - return the numpy dtype string based on settings

duplicateDataToHdf5(path=None)[source]

Make a duplicate from self to a Hdf5 file; return an Hdf5SpectrumDataSource instance

estimateNoise()[source]

Estimate and return a noise level Use mean of abs of dataPlane or dataSlice

property expectedFileSizeInBytes: int

- int, immutable - The expected file size in Bytes

exportToSpectrum(spectrum, includePath=True)[source]

copy parameters & path (optionally) to spectrum, set spectrum attribute, and return self

fillHdf5Buffer()[source]

Fill hdf5Buffer with data from self; this routine will be subclassed in the more problematic cases such as NmrPipe

foldingModes

Casting list, any iterable

gaussianBroadenings

Casting list, any iterable

getByDimensions(parameterName: str, dimensions: Sequence[int])[source]

Return values defined by parameterName in order defined by dimensions (1..dimensionCount).

getDimensionalParameters() collections.OrderedDict[source]

Return a OrderedDict of (parameterName, values) for dimensional parameters

getNonDimensionalParameters() collections.OrderedDict[source]

Return a OrderedDict of (parameterName, values) for non-dimensional parameters

getPlaneData(position: Optional[Sequence] = None, xDim: int = 1, yDim: int = 2) ccpn.core._implementation.SpectrumData.PlaneData[source]

Get plane defined by xDim, yDim and position (all 1-based) Check for hdf5buffer first, then blocked format Optionally to be subclassed

:return PlaneData (i.e. numpy.ndarray) object.

getPointData(position: Optional[Sequence] = None) float[source]

Get value defined by position (1-based, integer values) Use getPointValue() for an interpolated value

getPointValue(position, aliasingFlags=None)[source]

Get interpolated value defined by position (1-based, float values), optionally aliased The result is calculated from a weighted average of the two values at the neighbouring grid points for each dimension

aliasingFlags: Optionally allow for aliasing per dimension:

0: No aliasing 1: aliasing with positive sign

-1: aliasing with negative sign

Use getPointData() for a method using an integer-based grid position argument

getRegionData(sliceTuples, aliasingFlags=None) ccpn.core._implementation.SpectrumData.RegionData[source]

Return an numpy array containing the points defined by sliceTuples

:param sliceTuples, list [(start_1,stop_1), (start_2,stop_2), …],

sliceTuples are 1-based; sliceTuple stop values are inclusive ( i.e. different from the python slice object)

Parameters

aliasingFlags

Optionally allow for aliasing per dimension:

0: No aliasing 1: aliasing with positive sign

-1: aliasing with negative sign

:return RegionData (i.e. numpy.ndarray) object.

getSliceData(position: Optional[Sequence] = None, sliceDim: int = 1) ccpn.core._implementation.SpectrumData.SliceData[source]

Get slice defined by sliceDim and position (all 1-based) Check for hdf5buffer first, then blocked format Optionally to be subclassed

:return SliceData object (i.e. a numpy.ndarray) object

getSliceDataFromPlane(position, xDim: int, yDim: int, sliceDim: int) ccpn.core._implementation.SpectrumData.SliceData[source]

Routine to get sliceData using getPlaneData :return SliceData object (i.e. a numpy.ndarray) object

hasBlockCached = True
hasOpenFile()[source]

Return True if dataSoure has active open file pointer

hasValidPath() bool[source]

Return true if the path is valid

hasWritingAbility = False
headerSize = 0
importFromDataSource(dataSource)[source]

copy parameters & path from dataSource, return self

importFromSpectrum(spectrum, includePath=True)[source]

copy parameters & path (optionally) from spectrum, set spectrum attribute and return self

initialiseHdf5Buffer()[source]

Initialise a Hdf5SpectrumBuffer instance. :return: Hdf5SpectrumBuffer instance

isAquisition

Casting list, any iterable

isBigEndian
isBlocked = False
property isBuffered

- None, immutable - ReturnTrue if file is buffered

isComplex

Casting list, any iterable

isDimensionalParameter(parameterName) bool[source]

:return True if parameterName is dimensional

isFloatData = True
isotopeCodes

Casting list, any iterable

isotopeDefaultDataDict = {'13C': {'pointCount': 256, 'spectralRange': (130.0, 5.0)}, '15N': {'pointCount': 128, 'spectralRange': (130.0, 100.0)}, '19F': {'pointCount': 512, 'spectralRange': (250.0, 40.0)}, '1H': {'pointCount': 512, 'spectralRange': (12.0, -1.0)}}
keysInOrder = True
lorentzianBroadenings

Casting list, any iterable

maxCacheSize = 67108864
measurementTypes

Casting list, any iterable

nameFromPath() str[source]

Return a name derived from path (to be subclassed for specific cases; e.g. Bruker)

noiseLevel
openExistingFile(path=None, mode=None)[source]

Open file, read parameters, check isotopes and close if mode is None it defaults to self.defaultOpenReadMode

Yields self; i.e. one can do:
with SpectrumDataSource().openExistingFile(path) as ds:

data = ds.getSliceData()

openFile(mode, **kwds)[source]

open self.path, set self.fp, Raise RunTimeError on opening errors :return self.fp

openMethod = None
openNewFile(path=None, mode=None)[source]

Open new file, write parameters, and close at the end Yields self; i.e. one can do:

with SpectrumDataSource(spectrum=sp).openNewFile(path) as ds:

ds.writeSliceData(data)

property parentPath: ccpn.util.Path.aPath

- <function aPath at 0x12ff52e50>, immutable - Return an absolute path of parent of self.dataFile as a Path instance or None when dataFile is not defined. For subclassing; e.g. in case of Bruker

property path: ccpn.util.Path.aPath

- <function aPath at 0x12ff52e50>, immutable - Return an absolute path of datapath as a Path instance or None when dataFile is not defined.

phases0

Casting list, any iterable

phases1

Casting list, any iterable

pointCounts

Casting list, any iterable

printParameters(path=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Print all to path

pulseProgram

A trait that defines a string object, casts from bytes object and is json serialisable

readParameters()[source]

Read the parameters from the format-specific dataFile into the data structure;

to be subclassed; super needs to be called at the end to clean up

referencePoints

Casting list, any iterable

referenceValues

Casting list, any iterable

sampledSigmas

Fixing default_value problem

sampledValues

Fixing default_value problem

saveAllTraitsToJson = True
setBuffering(isBuffered: bool, bufferIsTemporary: bool = True, bufferPath=None)[source]

Define the SpectrumDataSource buffering status :param isBuffered (True, False): set the buffering status :param bufferIsTemporary (True, False): define buffer as temporary (i.e. disgarded on close) :param bufferPath: optional path to store the buffer file

setByDimensions(parameterName: str, values: Sequence, dimensions: Sequence[int])[source]

Set values defined by parameterName in order defined by dimensions (1..dimensionCount).

setDefaultParameters(nDim=8)[source]

Set default values for all parameters

setDimensionCount(dimensionCount)[source]

Change the dimensionality, assuring proper values of the dimensional parameters

setPath(path, substituteSuffix=False)[source]

define valid path to a (binary) data file, if needed appends or substitutes the suffix (if defined).

return self or None on error

setPlaneData(data, position: Optional[Sequence] = None, xDim: int = 1, yDim: int = 2)[source]

Set the plane data defined by xDim, yDim and position (all 1-based) from NumPy data array

Can be subclassed

setPointData(value, position: Optional[Sequence] = None) float[source]

Set point value defined by position (1-based) Can be sub-classed

setSliceData(data, position: Optional[Sequence] = None, sliceDim: int = 1)[source]

Set data as slice defined by sliceDim and position (all 1-based) Can be subclassed

spectralWidthsHz

Casting list, any iterable

spectrometerFrequencies

Casting list, any iterable

suffixes = []
temperature
property totalNumberOfPoints: int

- int, immutable - Total number of points of the data

transposeParameters(dimension1, dimension2)[source]

Transpose parameters of dimension1 and dimenson2 (1-based)

windowFunctions

Casting list, any iterable

wordSize = 4
writeParameters()[source]

to be subclassed

ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.checkPathForSpectrumFormats(path)[source]

Check path if it corresponds to any spectrum data format :return a SpectrumDataSource instance with parameters read or None if there was no match

ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.getDataFormats() collections.OrderedDict[source]

Get spectrum datasource formats

Returns

a dictonary of (format-identifier-strings, SpectrumDataSource classes) as (key, value) pairs

ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.getSpectrumDataSource(path, dataFormat)[source]

Get a SpectrumDataSource instance of type dataFormat for path :param path: a Path instance :param dataFormat: a valid dataFormat indentifier :return The SpectrumDataSource instance or None if incorrect

ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.testMain()[source]

ccpn.core.lib.SpectrumDataSources.UcsfSpectrumDataSource module

This file contains the Ucsf data access class it serves as an interface between the V3 Spectrum class and the actual spectral data

See SpectrumDataSourceABC for a description of the methods

class ccpn.core.lib.SpectrumDataSources.UcsfSpectrumDataSource.UcsfSpectrumDataSource(**kwargs)[source]

Bases: ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC

Ucsf spectral storage

MAXDIM = 7
blockHeaderSize = 0
dataFormat = 'UCSF'
defaultOpenReadMode = 'rb'
property headerSize

- None, immutable - int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

isBlocked = True
isFloatData = True
openMethod(mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

Open file and return a stream. Raise OSError upon failure.

file is either a text or byte string giving the name (and the path if the file isn’t in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.)

mode is an optional string that specifies the mode in which the file is opened. It defaults to ‘r’ which means open for reading in text mode. Other common values are ‘w’ for writing (truncating the file if it already exists), ‘x’ for creating and writing to a new file, and ‘a’ for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are:

Character

Meaning

‘r’

open for reading (default)

‘w’

open for writing, truncating the file first

‘x’

create a new file and open it for writing

‘a’

open for writing, appending to the end of the file if it exists

‘b’

binary mode

‘t’

text mode (default)

‘+’

open a disk file for updating (reading and writing)

‘U’

universal newline mode (deprecated)

The default mode is ‘rt’ (open for reading text). For binary random access, the mode ‘w+b’ opens and truncates the file to 0 bytes, while ‘r+b’ opens the file without truncation. The ‘x’ mode implies ‘w’ and raises an FileExistsError if the file already exists.

Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn’t. Files opened in binary mode (appending ‘b’ to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when ‘t’ is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

‘U’ mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode.

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

  • Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.

  • “Interactive” text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.

encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.

errors is an optional string that specifies how encoding errors are to be handled—this argument should not be used in binary mode. Pass ‘strict’ to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass ‘ignore’ to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register or run ‘help(codecs.Codec)’ for a list of the permitted encoding error strings.

newline controls how universal newlines works (it only applies to text mode). It can be None, ‘’, ‘n’, ‘r’, and ‘rn’. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in ‘n’, ‘r’, or ‘rn’, and these are translated into ‘n’ before being returned to the caller. If it is ‘’, universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any ‘n’ characters written are translated to the system default line separator, os.linesep. If newline is ‘’ or ‘n’, no translation takes place. If newline is any of the other legal values, any ‘n’ characters written are translated to the given string.

If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case.

A custom opener can be used by passing a callable as opener. The underlying file descriptor for the file object is then obtained by calling opener with (file, flags). opener must return an open file descriptor (passing os.open as opener results in functionality similar to passing None).

open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode (‘w’, ‘r’, ‘wt’, ‘rt’, etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom.

It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode.

readParameters()[source]

Read the parameters from the Felix file header Returns self

suffixes = ['.ucsf']
wordSize = 4

ccpn.core.lib.SpectrumDataSources.XeasySpectrumDataSource module

This file contains the Xeasy data access class it serves as an interface between the V3 Spectrum class and the actual spectral data

See SpectrumDataSourceABC for a description of the methods

class ccpn.core.lib.SpectrumDataSources.XeasySpectrumDataSource.XeasySpectrumDataSource(**kwargs)[source]

Bases: ccpn.core.lib.SpectrumDataSources.SpectrumDataSourceABC.SpectrumDataSourceABC

Xeasy spectral storage

blockHeaderSize = 0
dataFormat = 'Xeasy'
defaultOpenReadMode = 'rb'
property dtype

- None, immutable - return the numpy dtype string; usigned 2 byte words

headerSize = 0
isBlocked = True
isFloatData = False
openMethod(mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

Open file and return a stream. Raise OSError upon failure.

file is either a text or byte string giving the name (and the path if the file isn’t in the current working directory) of the file to be opened or an integer file descriptor of the file to be wrapped. (If a file descriptor is given, it is closed when the returned I/O object is closed, unless closefd is set to False.)

mode is an optional string that specifies the mode in which the file is opened. It defaults to ‘r’ which means open for reading in text mode. Other common values are ‘w’ for writing (truncating the file if it already exists), ‘x’ for creating and writing to a new file, and ‘a’ for appending (which on some Unix systems, means that all writes append to the end of the file regardless of the current seek position). In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) The available modes are:

Character

Meaning

‘r’

open for reading (default)

‘w’

open for writing, truncating the file first

‘x’

create a new file and open it for writing

‘a’

open for writing, appending to the end of the file if it exists

‘b’

binary mode

‘t’

text mode (default)

‘+’

open a disk file for updating (reading and writing)

‘U’

universal newline mode (deprecated)

The default mode is ‘rt’ (open for reading text). For binary random access, the mode ‘w+b’ opens and truncates the file to 0 bytes, while ‘r+b’ opens the file without truncation. The ‘x’ mode implies ‘w’ and raises an FileExistsError if the file already exists.

Python distinguishes between files opened in binary and text modes, even when the underlying operating system doesn’t. Files opened in binary mode (appending ‘b’ to the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when ‘t’ is appended to the mode argument), the contents of the file are returned as strings, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

‘U’ mode is deprecated and will raise an exception in future versions of Python. It has no effect in Python 3. Use newline to control universal newlines mode.

buffering is an optional integer used to set the buffering policy. Pass 0 to switch buffering off (only allowed in binary mode), 1 to select line buffering (only usable in text mode), and an integer > 1 to indicate the size of a fixed-size chunk buffer. When no buffering argument is given, the default buffering policy works as follows:

  • Binary files are buffered in fixed-size chunks; the size of the buffer is chosen using a heuristic trying to determine the underlying device’s “block size” and falling back on io.DEFAULT_BUFFER_SIZE. On many systems, the buffer will typically be 4096 or 8192 bytes long.

  • “Interactive” text files (files for which isatty() returns True) use line buffering. Other text files use the policy described above for binary files.

encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent, but any encoding supported by Python can be passed. See the codecs module for the list of supported encodings.

errors is an optional string that specifies how encoding errors are to be handled—this argument should not be used in binary mode. Pass ‘strict’ to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass ‘ignore’ to ignore errors. (Note that ignoring encoding errors can lead to data loss.) See the documentation for codecs.register or run ‘help(codecs.Codec)’ for a list of the permitted encoding error strings.

newline controls how universal newlines works (it only applies to text mode). It can be None, ‘’, ‘n’, ‘r’, and ‘rn’. It works as follows:

  • On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in ‘n’, ‘r’, or ‘rn’, and these are translated into ‘n’ before being returned to the caller. If it is ‘’, universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated.

  • On output, if newline is None, any ‘n’ characters written are translated to the system default line separator, os.linesep. If newline is ‘’ or ‘n’, no translation takes place. If newline is any of the other legal values, any ‘n’ characters written are translated to the given string.

If closefd is False, the underlying file descriptor will be kept open when the file is closed. This does not work when a file name is given and must be True in that case.

A custom opener can be used by passing a callable as opener. The underlying file descriptor for the file object is then obtained by calling opener with (file, flags). opener must return an open file descriptor (passing os.open as opener results in functionality similar to passing None).

open() returns a file object whose type depends on the mode, and through which the standard file operations such as reading and writing are performed. When open() is used to open a file in a text mode (‘w’, ‘r’, ‘wt’, ‘rt’, etc.), it returns a TextIOWrapper. When used to open a file in a binary mode, the returned class varies: in read binary mode, it returns a BufferedReader; in write binary and append binary modes, it returns a BufferedWriter, and in read/write mode, it returns a BufferedRandom.

It is also possible to use a string or bytearray as a file for both reading and writing. For strings StringIO can be used like a file opened in a text mode, and for bytes a BytesIO can be used like a file opened in a binary mode.

property parameterPath

- None, immutable - Path of the parameter file

readParameters()[source]

Read the parameters from the Xeasy parameter file Returns self

setPath(path, substituteSuffix=False)[source]

Set the path, optionally change .par in .spc suffix and do some checks by calling the super class Return self or None on error

suffixes = ['.param', '.16']
wordSize = 2