本文整理汇总了Python中General.num_equals方法的典型用法代码示例。如果您正苦于以下问题:Python General.num_equals方法的具体用法?Python General.num_equals怎么用?Python General.num_equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类General
的用法示例。
在下文中一共展示了General.num_equals方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import General [as 别名]
# 或者: from General import num_equals [as 别名]
def __init__(self,filename):
# Whether or not to look for the overload pixels
doOverflow = 1
try:
file = open(filename,'rb')
file.close()
except IOError:
raise UserInputException('%s does not exist' % filename)
self.filename = filename
file = open(filename,'rb')
header = {}
for n in range(96):
a=file.read(8)
b=file.read(72)
header[a]=b
try:
npixelb = int(header['NPIXELB:'].split()[0])
except:
raise Exception("Cannot read in the Bruker data file \
%s because the header field NPIXELB can not be parsed." % filename)
if npixelb != 1 and npixelb != 2 and npixelb != 4:
raise Exception("Cannot read in the Bruker data file \
%s because the The header field NPIXELB must equal 1, 2 or \
4." % npixelb)
try:
ncol = int(header['NCOLS :'].split()[0])
except:
raise Exception("Cannot read in the Bruker data file \
%s because the header field NCOLS can not be parsed." % filename)
try:
nrow = int(header['NROWS :'].split()[0])
except:
raise Exception("Cannot read in the Bruker data file \
%s because the header field NROWS can not be parsed." % filename)
try:
self.headerDistance = General.splitAverage(header['DISTANC:'])
except:
print "Cannot read the DISTANC header field from \
%s" % filename
# sometimes, there are multiple wavelengths in this field
# I am not sure what they are for, but we will just average
# them and hope for the best.
try:
self.headerWavelength = General.splitAverage(header['WAVELEN:'])
except:
print "Cannot read the WAVELEN header field from \
%s" % filename
try:
self.headerCenterX = float(header['CENTER :'].split()[0])
self.headerCenterY = float(header['CENTER :'].split()[1])
except:
print "Cannot read the center header fields from \
%s" % filename
self.size = max(ncol,nrow)
try:
noverfl = int(header['NOVERFL:'].split()[0])
except:
raise Exception("Cannot read in the Bruker data file \
%s because the header field NOVERFL can not be parsed." % filename)
datastring = file.read(ncol*nrow*npixelb)
if npixelb == 1:
temp = Numeric.fromstring(datastring, Numeric.UInt8)
temp.shape = nrow,ncol
if (noverfl != General.num_equals(temp,255)):
print "Warning, cannot read in the overflow \
pixels in Bruker file %s because the header field NOVERFL \
(%s) does not match the number of pixels in the data with value \
equal to exactly 255 (%s). All overloaded pixels must be set in \
the data to 255)." % (filename,noverfl,General.num_equals(temp,255))
doOverflow = 0
elif npixelb == 2:
temp = Numeric.fromstring(datastring, Numeric.UInt16)
temp.shape = nrow,ncol
if (noverfl != General.num_equals(temp,65535)):
print "Warning, cannot read in the overflow \
pixels in Bruker file %s because the header field NOVERFL \
(%s) does not match the number of pixels in the data with value \
equal to exactly 65535 (%s). All overloaded pixels must be set in \
the data to 65535)." % (filename,noverfl,General.num_equals(temp,65535))
#.........这里部分代码省略.........