-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcontents.py
executable file
·72 lines (66 loc) · 1.98 KB
/
contents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
from __future__ import with_statement
import glob
import os.path
import sys
header = """\
% Matlab Scattered Data Interpolation Toolbox
%
% Author: Matt Foster <[email protected]>, CSAOS, University of Bath
% License: BSD (Except: natural neighbour -- see readme for license)
%
% Interpolation Functions:"""
footer = """\
%
% Demos:
%
% To generate correlated test data, run:
%
% [yy, xx] = meshgrid(1:100, 1:100);
% % Make some correlated data.
% input = corr_data(100, 15);
% cm = rand(100) > 0.95;
% sampled = input.*cm;
% [xi, yi, zi] = find(sampled);
%
% figure
% imagesc(sampled)
%
% This will generate some sparse test data suitable for both adaptiveNC and
% griddata style methods. To interpolate this using ANC, run:
%
% anc_out = adaptiveNC(sampled, cm)
% figure
% imagesc(anc_out)
%
% To interpolate the data using griddata style functions (RBF, kriging,
% natural neighbour, etc.), run:
%
% nat_out = natural_neighbour(xx, yy, zz, xx, yy);
% rbf_out = rbf(xx, yy, zz, xx, yy);
% kriging_out = kriging(xx, yy, zz, xx, yy);
% figure
% imagesc(nat_out) % etc.
%
% Finally, calculate RMSE values, using:
% anc_rmse = sqrt(mean((input(:) - anc_out(:)).^2))
% nat_rmse = sqrt(mean((input(:) - nat_out(:)).^2))
% % etc.
%
% Please note: Kriging and RBF will probably not work on large data sets due to
% large matrix inversions. You mileage may vary.
% """
with open('toolkit/Contents.m', 'w') as output:
sys.stdout = output # redirect stdout to output file
print header
for fname in glob.glob('toolkit/*.m'):
# Skip this iteration if we're reading the output file
if fname.endswith('Contents.m'):
continue
with open(fname,'r') as f:
f.readline() # read past the first line
line = f.readline() # read the second
base = os.path.basename(fname)
name = os.path.splitext(base)[0]
print "%% %-20s\t- %s" % (name, line.strip('%').rstrip())
print footer