从@marcin 提供的链接中,您可以了解数据格式,我已经提取了标头,但是为了重塑数组,我得到了错误数量的值:
import struct
import numpy as np
file_path = r'5x22_2fofc.dsn6'
with open(file_path,'rb') as f:
brick = f.read(512)
header = brick # the firs brick is our header
n = 2 # number of bytes per entry
entries = [header[i:i + n] for i in range(0, len(header), n)]
header_desc = [
'x start', # 1
'y start', # 2
'z start', # 3
'x extent', # 4
'y extent', # 5
'z extent', # 6
'x sampling rate', # 7
'y sampling rate', # 8
'z sampling rate', # 9
'Header(18) * A Cell Edge', # 10
'Header(18) * B Cell Edge', # 11
'Header(18) * C Cell Edge', # 12
'Header(18) * alfa', # 13
'Header(18) * beta', # 14
'Header(18) * gamma', # 15
'Header(19) (253 -3) /(rmax -rmin)', # 16
'(3rmax - 253rmin)/(rmax -rmin)]', # 17
'Cell Constant Scaling Factor', # 18
'100'] # 19
header_conv = [struct.unpack('>h',i)[0] for i in entries]
# we now extract the data afte the header(using an offset)
data = np.memmap(file_path,dtype='uint8',offset=512,mode='r')
for i in zip(header_desc,header_conv):
print(i)
这是我提取的标题:
('x start', -20)
('y start', -56)
('z start', -135)
('x extent', 126)
('y extent', 118)
('z extent', 272)
('x sampling rate', 170)
('y sampling rate', 96)
('z sampling rate', 266)
('Header(18) * A Cell Edge', 14912)
('Header(18) * B Cell Edge', 8345)
('Header(18) * C Cell Edge', 23783)
('Header(18) * alfa', 7200)
('Header(18) * beta', 7868)
('Header(18) * gamma', 7200)
('Header(19) (253 -3) /(rmax -rmin)', 1375)
('(3rmax - 253rmin)/(rmax -rmin)]', 80)
('Cell Constant Scaling Factor', 80)
('100', 100)