Commit aa892862 authored by nuntius35's avatar nuntius35

Sort in Octave, add newlines at end of file

parent fca1a56b
Pipeline #28801736 passed with stage
in 53 seconds
......@@ -23,6 +23,7 @@ fflush(stdout);
tic;
P = dlmread('peak_coords.mat', ',');
P(:,1:2) = deg2rad(P(:,1:2));
[P,I] = sortrows(P,-3);
t = toc;
fprintf('[%f s]\n', t);
fflush(stdout);
......@@ -69,7 +70,7 @@ fflush(stdout);
fprintf('[Octave] Writing results.............');
fflush(stdout);
tic;
dlmwrite('extremals.mat', find(dom));
dlmwrite('extremals.mat', I(find(dom)));
t = toc;
fprintf('[%f s]\n', t);
fflush(stdout);
......@@ -48,6 +48,7 @@ def main():
data['elements'].pop(i)
with open(file, 'w') as data_file:
json.dump(data, data_file, indent=4, ensure_ascii=False)
data_file.write('\n')
end = timer()
print('Finished cleaning data..................', end='')
print('[{:7.3f}s]'.format(end-start))
......@@ -65,18 +66,11 @@ def main():
end = timer()
print('[{:7.3f}s]'.format(end-start))
print('Sorting peaks by height.................', end='')
start = timer()
peak_list.sort(key=lambda x: -x[2])
end = timer()
print('[{:7.3f}s]'.format(end-start))
print('Writing coordinates to file.............', end='')
start = timer()
peak_file = open('peak_coords.mat', 'w')
for peak in peak_list:
print(peak[0], ',', peak[1], ',', peak[2], file=peak_file)
peak_file.close()
with open('peak_coords.mat', 'w') as peak_file:
for peak in peak_list:
print(peak[0], ',', peak[1], ',', peak[2], file=peak_file)
end = timer()
print('[{:7.3f}s]'.format(end-start))
......
......@@ -5,26 +5,19 @@ from timeit import default_timer as timer
def main():
print('Printing the results.')
print('Reading and sorting data................', end='')
print('Reading data............................', end='', flush=True)
start = timer()
with open('peak_data.json', 'r') as data_file:
data = json.load(data_file)
ele_list = []
for i, peak in enumerate(data['elements']):
ele = peak['tags']['ele']
ele_list.append(ele)
index = [i for i, ele in sorted(enumerate(ele_list), key=lambda x: -x[1])]
end = timer()
print('[{:7.3f}s]'.format(end-start))
print('Reading extremals.......................', end='')
start = timer()
ex = []
extremals = open('extremals.mat', 'r')
for i in extremals:
ex.append(index[int(i)-1])
extremals.close()
with open('extremals.mat', 'r') as extremals:
for i in extremals:
ex.append(int(i)-1)
end = timer()
print('[{:7.3f}s]'.format(end-start))
......@@ -43,6 +36,7 @@ def main():
}
with open('extremals.geojson', 'w') as data_file:
json.dump(geojson, data_file, indent=4, ensure_ascii=False)
data_file.write('\n')
end = timer()
print('[{:7.3f}s]'.format(end-start))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment