Skip to content

Instantly share code, notes, and snippets.

@TimKraemer
Last active August 29, 2015 14:25
Show Gist options
  • Save TimKraemer/cb256d1cbee84a1e7097 to your computer and use it in GitHub Desktop.
Save TimKraemer/cb256d1cbee84a1e7097 to your computer and use it in GitHub Desktop.
data_to_raw_heightmap.py
from collections import defaultdict
import numpy as np
import time
# A CSV File with about 35 million lines looking like this:
# 578559.000 5917080.000 5.608
# 578560.000 5917080.000 5.639
# 578562.000 5917080.000 -2.629
# ...
FILENAME = "../../Sources/HH_bis_28082013_1m_NN_UTM.txt"
# FILENAME = "../../Sources/test.txt"
def benchmark(functions, iterations):
"""
used for benchmarking performance-critical code
"""
counts = defaultdict(list)
for i in range(iterations):
for func in functions:
start_time = time.time()
func()
counts[func].append(time.time() - start_time)
for key, vals in counts.items():
print key.__name__, ":", sum(vals) / float(len(vals))
def convert_file(filename):
arr = np.fromfile(filename, dtype=np.double, sep=' ')
arr.tofile(filename + '.dat')
def get_extrema(filename):
arr = np.fromfile(filename + '.dat', dtype=np.double)
print('File read')
num_rows = len(arr) // 3
arr = arr.reshape((num_rows, 3)).T
ret = {}
for i, name in enumerate(['x', 'y', 'z']):
ret[name] = {
'min': np.min(arr[i]),
'max': np.max(arr[i])
}
return ret
# convert_file(FILENAME)
print(get_extrema(FILENAME))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment