Skip to content

Instantly share code, notes, and snippets.

@gonuke
Last active August 15, 2018 15:13
Show Gist options
  • Save gonuke/f97d0f966399340a0d0df3484d28e942 to your computer and use it in GitHub Desktop.
Save gonuke/f97d0f966399340a0d0df3484d28e942 to your computer and use it in GitHub Desktop.
import numpy as np
num_blocks = 64
lines_in_block = 300
skip_lines = 1
data_offset = { 'up' : 0, 'down' : 17 }
names = ['block',' energy', 's_up', 'p_up', 'd_up', 'f_up', 's_down', 'p_down', 'd_down', 'f_down']
formats = ['i8', 'f8', 'f8', '3f8', '5f8', '7f8', 'f8', '3f8', '5f8', '7f8']
rec_type = np.dtype({'names':names, 'formats': formats})
data = np.array([], dtype=rec_type)
with open('orig_file') as in_file:
for block in range(num_blocks):
for line_num in range(lines_in_block):
line = in_file.readline()
line_data = [float(d) for d in line.strip().split()] # strips new line, splts based on white space, and converts from string to float
new_record = np.array([block, line_data[0], line_data[1], line_data[2:5], line_data[5:10], line_data[10:17],
line_data[17], line_data[18:21], line_data[21:26], line_data[26:33] ],
dtype=rec_type)
data = np.append(data,new_record)
for skip_line_num in range(skip_lines):
discard = in_file.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment