Source code for ccpnmodel.ccpncore.lib.spectrum.formats_noLongerUsed.Xeasy

"""Module Documentation here

"""
#=========================================================================================
# Licence, Reference and Credits
#=========================================================================================
__copyright__ = "Copyright (C) CCPN project (http://www.ccpn.ac.uk) 2014 - 2017"
__credits__ = ("Wayne Boucher, Ed Brooksbank, Rasmus H Fogh, Luca Mureddu, Timothy J Ragan & Geerten W Vuister")
__licence__ = ("CCPN licence. See http://www.ccpn.ac.uk/v3-software/downloads/license",
               "or ccpnmodel.ccpncore.memops.Credits.CcpnLicense for licence text")
__reference__ = ("For publications, please use reference from http://www.ccpn.ac.uk/v3-software/downloads/license",
                 "or ccpnmodel.ccpncore.memops.Credits.CcpNmrReference")

#=========================================================================================
# Last code modification
#=========================================================================================
__modifiedBy__ = "$modifiedBy: CCPN $"
__dateModified__ = "$dateModified: 2017-07-07 16:33:16 +0100 (Fri, July 07, 2017) $"
__version__ = "$Revision: 3.0.0 $"
#=========================================================================================
# Created
#=========================================================================================

__author__ = "$Author: CCPN $"
__date__ = "$Date: 2017-04-07 10:28:48 +0000 (Fri, April 07, 2017) $"
#=========================================================================================
# Start of code
#=========================================================================================
import os, sys

# from ccpn.util.Common import checkIsotope
from ccpn.util.Logging import getLogger

# from memops.qtgui.MessageDialog import showError

XEASY_PARAM_DICT = {
    'ndim'  : 'Number of dimensions',
    'nbits' : '16 or 8 bit file type',
    'sf'    : 'Spectrometer frequency in w',
    'sw'    : 'Spectral sweep width in w',
    'maxppm': 'Maximum chemical shift in w',
    'npts'  : 'Size of spectrum in w',
    'block' : 'Submatrix size in w',
    'order' : 'Permutation for w',
    'fold'  : 'Folding in w',  # not used
    'type'  : 'Type of spectrum',  # not used
    'nuc'   : 'Identifier for dimension w',
}

FILE_TYPE = 'Xeasy'


[docs]def readParams(paramFileName): # Format invariant headerSize = 0 blockHeaderSize = 0 isFloatData = True isBigEndian = (sys.byteorder == 'big') sampledValues = [] sampledSigmas = [] pulseProgram = None dataScale = 1.0 # Params fileObj = open(paramFileName, 'rU') firstLine = 'Version ....................... ' line = fileObj.readline().strip() if line[:32] != firstLine: msg = 'The file %s does not look like an XEASY param file because the first line does not start "%s"' # showError('Error', msg % (paramFileName, firstLine)) return if line[-1] != '1': getLogger().warning('this XEASY param file version is not 1 so might not be interpreted correctly') lines = fileObj.readlines() dd = {} for line in lines: key = line[:32].replace('.', '').strip() value = line[32:].strip() dd[key] = value fileObj.close() def getValue(key, dim, func): "Return value from Xeasy parameter dict, using keys defined in XEASY_PARAM_DICT or None on error" if key not in XEASY_PARAM_DICT: getLogger().warning('key "%s" not defined in XEASY_PARAM_DICT') return None if dim is not None: paramKey = XEASY_PARAM_DICT[key] + str(dim) else: paramKey = XEASY_PARAM_DICT[key] if paramKey not in dd: getLogger().warning('parameterKey "%s" not defined in "%s"' % (paramKey, paramFileName)) return None return func(dd[paramKey]) ndim = getValue('ndim', None, int) if ndim is None: raise ValueError('decoding "%s"' % paramFileName) numPoints = [0] * ndim blockSizes = [0] * ndim refPpms = [0] * ndim refPoints = [0] * ndim specWidths = [0] * ndim specFreqs = [0] * ndim isotopes = [None] * ndim nbits = getValue('nbits', None, int) if nbits is None: raise ValueError('decoding "%s"' % paramFileName) wordSize = int(nbits / 8) dataFile = paramFileName[:-5] + str(nbits) for dim in range(1, ndim + 1): # There is a mapping defined in the parameter file idx = getValue('order', dim, int) - 1 numPoints[idx] = getValue('npts', dim, int) blockSizes[idx] = getValue('block', dim, int) specFreqs[idx] = getValue('sf', dim, float) # Spectral widths defined in ppm specWidths[idx] = getValue('sw', dim, float) * specFreqs[idx] refPpms[idx] = getValue('maxppm', dim, float) refPoints[idx] = 1.0 # isotopes[idx] = checkIsotope(getValue('nuc', dim, str)) data = (FILE_TYPE, dataFile, numPoints, blockSizes, wordSize, isBigEndian, isFloatData, headerSize, blockHeaderSize, isotopes, specFreqs, specWidths, refPoints, refPpms, sampledValues, sampledSigmas, pulseProgram, dataScale) return data