annotate carpet-src-1/tools/CARPET/Raw_data.py @ 0:cdd489d98766

Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
author matces
date Tue, 07 Jun 2011 16:50:41 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
1 #!/usr/bin/env python
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
2
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
3 # Copyright 2009 Matteo Cesaroni, Lucilla Luzi
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
4 #
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
5 # This program is free software; ; you can redistribute it and/or modify
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
6 # it under the terms of the GNU Lesser General Public License as published by
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
7 # the Free Software Foundation; either version 3 of the License, or (at your
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
8 # option) any later version.
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
9 #
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful,
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
13 # GNU General Public License for more details.
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
14 .
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
15
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
16 import sys
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
17 from rpy import *
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
18
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
19
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
20 def stop_err(msg):
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
21 sys.stderr.write(msg)
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
22 sys.exit()
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
23
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
24 def main():
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
25
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
26 # Handle input params
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
27 in_fname = sys.argv[1]
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
28 out_fname = sys.argv[2]
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
29 #sys.stdout=open('log.txt','a')
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
30 try:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
31 column = int( sys.argv[3] ) - 1
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
32 column_x = int( sys.argv[4] ) - 1
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
33 column_y = int( sys.argv[5] ) - 1
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
34 except:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
35 stop_err( "..Column not specified, your query does not contain a column of numerical data." )
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
36
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
37
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
38 title = sys.argv[6]
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
39
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
40 skipped_lines = 0
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
41 first_invalid_line = 0
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
42 invalid_value = ''
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
43
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
44 riga = []
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
45 for tuo in range(1,1025):
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
46 riga.append(int(0))
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
47 #print riga
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
48
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
49 matrice = []
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
50 for mio in range(1,769):
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
51 #print mio
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
52 matrice.append(riga)
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
53
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
54 #print matrix
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
55 matrix1 = array(matrice)
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
56 #print matrix1
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
57 for i, line in enumerate( file( in_fname ) ):
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
58 valid = True
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
59 line = line.rstrip('\r\n')
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
60 # Skip comments
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
61 if line and not line.startswith( '#' ):
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
62 # Extract values and convert to floats
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
63 row = []
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
64 val = 0
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
65 val_x = 0
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
66 val_y = 0
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
67 try:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
68 fields = line.split( "\t" )
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
69 val = fields[column]
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
70 val_x = (int(fields[column_x])-1)
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
71 val_y = (int(fields[column_y])-1)
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
72 matrix1[val_x][val_y]=float(val)
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
73
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
74
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
75 except:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
76 valid = False
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
77 skipped_lines += 1
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
78 if not first_invalid_line:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
79 first_invalid_line = i+1
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
80 else:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
81 try:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
82 row.append( float( val ) )
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
83 except ValueError:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
84 valid = False
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
85 skipped_lines += 1
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
86 if not first_invalid_line:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
87 first_invalid_line = i+1
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
88 invalid_value = fields[column]
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
89 else:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
90 valid = False
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
91 skipped_lines += 1
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
92 if not first_invalid_line:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
93 first_invalid_line = i+1
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
94
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
95 output_prima=sys.stdout
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
96 fsock=open('log.txt','w')
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
97 sys.stdout=fsock
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
98
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
99
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
100 for i in range(768):
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
101 for j in range(1024):
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
102 if j<1022:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
103 print "%s\t" %matrix1[i][j],
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
104 if j==1023:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
105 print "%s" %matrix1[i][j]
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
106 sys.stdout=output_prima
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
107 fsock.close()
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
108
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
109 set_default_mode(NO_CONVERSION)
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
110 if skipped_lines < i:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
111 #print "..on columnn %s" %sys.argv[3]
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
112 a=r.read_table("log.txt")
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
113 b=r.as_matrix(a)
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
114 #r.print_(b)
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
115 #b=r.cbind(a[1],a[1])
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
116 r.pdf( out_fname, 8, 8 )
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
117 r.image(z=r.log2(b),col=r.terrain_colors(100000),main=title, xlab="X", ylab="Y")
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
118 r.dev_off()
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
119
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
120 else:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
121 print "..all values in column %s are non-numeric." %sys.argv[3]
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
122
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
123 if skipped_lines > 0:
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
124 print "..skipped %d invalid lines starting with line #%d. Value '%s' is not numeric." % ( skipped_lines, first_invalid_line, invalid_value )
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
125
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
126 r.quit( save="no" )
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
127
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
128 if __name__ == "__main__":
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
129 main()
cdd489d98766 Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
matces
parents:
diff changeset
130