Began versioning
authorW. Trevor King <wking@drexel.edu>
Tue, 14 Sep 2010 05:48:29 +0000 (01:48 -0400)
committerW. Trevor King <wking@tremily.us>
Fri, 22 Feb 2013 17:10:00 +0000 (09:10 -0800)
content/monte_carlo/src/plot_image.py [new file with mode: 0755]
content/programming_strategies/Python_Codes/plot_image.py [new file with mode: 0755]
content/programming_strategies/src/gen_data.c [new file with mode: 0644]
content/programming_strategies/src/gen_data_rectangle.c [new file with mode: 0644]
content/programming_strategies/src/gen_data_sharp.c [new file with mode: 0644]
content/programming_strategies/src/plot_image.py [new file with mode: 0644]

diff --git a/content/monte_carlo/src/plot_image.py b/content/monte_carlo/src/plot_image.py
new file mode 100755 (executable)
index 0000000..641e285
--- /dev/null
@@ -0,0 +1,119 @@
+#! /usr/bin/env python
+
+from __future__ import division
+from pylab import *
+import sys
+import Numeric
+
+
+#
+#   plot_image.py
+#
+#   Step 1: make this file executable
+#
+#           chmod +x plot_image.py
+#
+#   Step 2: pipe data in python script
+#
+#           ./gen_data | ./plot_image -s nx ny -c nc -t 'image title'
+#
+#   with optional arguments
+#          -s nx ,ny    image size [16x16]
+#          -c nc        number of contour levels [none]
+#          -t ' '       image title ['some like it hot']
+#
+#   additional:  -g  gray map  [jet map]
+#                -h  hot map
+#
+#   ref: matplotlib web site
+#                                             Michel Vallieres, 2007
+#
+
+                        # dummy function to initialize Z
+def func3(x,y):
+    return 0.005*x*y
+
+                        # defaults
+mycontours = 0
+nx = 16
+ny = 16
+mytitle = 'Some like it hot'
+mymap = cm.jet
+
+                        # parse command line arguments
+n = len( sys.argv )
+i = 1
+while i < n:
+    if sys.argv[i].find("s") == 1:
+        nx = int( sys.argv[i+1] )
+        ny = int( sys.argv[i+2] )
+        i = i + 2
+    elif sys.argv[i].find("c") == 1:
+        mycontours = int( sys.argv[i+1] )
+        i = i + 1
+    elif sys.argv[i].find("t") == 1:
+        mytitle = sys.argv[i+1]
+        i = i + 1
+    elif sys.argv[i].find("g") == 1:
+        mymap = cm.gray
+    elif sys.argv[i].find("h") == 1:
+        mymap = cm.hot
+    else:
+        print " Syntax:    script -s nx ny -c "
+    i = i + 1
+
+                       # identification
+print "Plot_image"
+print "Title:            ", mytitle
+print "Image size:       ", nx, ny
+print "# countour lines: ", mycontours
+
+
+                       # set grid
+x = range( nx )
+y = range( ny )
+
+X,Y = meshgrid( x, y )
+
+Z = func3( X, Y )
+
+                       # read in data
+for j in y:
+   for i in x:
+      Z[j,i] = input()
+
+                       # min & max
+min_data = Z[0,0]
+max_data = Z[0,0]
+for i in x:
+   for j in y:
+      if Z[j,i] < min_data:
+          min_data = Z[j,i]
+      if Z[j,i] > max_data:
+          max_data = Z[j,i]
+
+print "Data range:       ", min_data, max_data
+
+
+                       # colored image
+im = imshow( Z, interpolation='bilinear', origin='lower',
+            cmap=mymap, extent=(1,nx-1.0,1,ny-1.0) )
+
+                       # contour lines
+if mycontours > 0:
+    dcont = ( max_data - min_data ) / ( mycontours - 1 )
+    cset = contour( Z, arange(min_data,max_data,dcont),
+               origin='lower',
+               linewidths=2,
+               extent=(0,nx-1,0,ny-1)
+               )
+
+    clabel( cset, inline=1, fmt='%1.1f', fontsize=10 )
+
+
+                       # render picture
+axis('off')
+
+colorbar()
+title( mytitle )
+show()
diff --git a/content/programming_strategies/Python_Codes/plot_image.py b/content/programming_strategies/Python_Codes/plot_image.py
new file mode 100755 (executable)
index 0000000..09fbab1
--- /dev/null
@@ -0,0 +1,120 @@
+#! /usr/bin/env python
+
+from __future__ import division
+from pylab import *
+import sys
+import Numeric
+
+
+#
+#   plot_image.py
+#
+#   Step 1: make this file executable
+#
+#           chmod +x plot_image.py
+#
+#   Step 2: pipe data in python script
+#
+#           ./gen_data | ./plot_image -s nx ny -c nc -t 'image title'
+#
+#   with optional arguments
+#          -s nx ,ny    image size [16x16]
+#          -c nc        number of contour levels [none]
+#          -t ' '       image title ['some like it hot']
+#
+#   additional:  -g  gray map  [jet map]
+#                -h  hot map
+#
+#   ref: matplotlib web site
+#                                             Michel Vallieres, 2007
+#
+
+                        # dummy function to initialize Z
+def func3(x,y):
+    return 0.005*x*y
+
+                        # defaults
+mycontours = 0
+nx = 16
+ny = 16
+mytitle = 'Some like it hot'
+mymap = cm.jet
+
+                        # parse command line arguments
+n = len( sys.argv )
+i = 1
+while i < n:
+    if sys.argv[i].find("s") == 1:
+        nx = int( sys.argv[i+1] )
+        ny = int( sys.argv[i+2] )
+        i = i + 2
+    elif sys.argv[i].find("c") == 1:
+        mycontours = int( sys.argv[i+1] )
+        i = i + 1
+    elif sys.argv[i].find("t") == 1:
+        mytitle = sys.argv[i+1]
+        i = i + 1
+    elif sys.argv[i].find("g") == 1:
+        mymap = cm.gray
+    elif sys.argv[i].find("h") == 1:
+        mymap = cm.hot
+    else:
+        print " Syntax:    script -s nx ny -c "
+    i = i + 1
+
+                       # identification
+print "Plot_image"
+print "Title:            ", mytitle
+print "Image size:       ", nx, ny
+print "# countour lines: ", mycontours
+
+
+                       # set grid
+x = range( nx )
+y = range( ny )
+
+X,Y = meshgrid( x, y )
+
+Z = func3( X, Y )
+
+                       # read in data
+for j in y:
+   for i in x:
+      Z[j,i] = input()
+
+                       # min & max
+min_data = Z[0,0]
+max_data = Z[0,0]
+for i in x:
+   for j in y:
+      if Z[j,i] < min_data:
+          min_data = Z[j,i]
+      if Z[j,i] > max_data:
+          max_data = Z[j,i]
+
+print "Data range:       ", min_data, max_data
+
+
+                       # colored image
+im = imshow( Z, interpolation='bilinear', origin='lower',
+            cmap=mymap, extent=(1,nx-1.0,1,ny-1.0) )
+
+                       # contour lines
+if mycontours > 0:
+    dcont = ( max_data - min_data ) / ( mycontours - 1 )
+    cset = contour( Z, arange(min_data,max_data,dcont),
+               origin='lower',
+               linewidths=2,
+               extent=(0,nx-1,0,ny-1)
+               )
+
+    clabel( cset, inline=1, fmt='%1.1f', fontsize=10 )
+
+
+                       # render picture
+axis('off')
+
+colorbar()
+title( mytitle )
+show()
+
diff --git a/content/programming_strategies/src/gen_data.c b/content/programming_strategies/src/gen_data.c
new file mode 100644 (file)
index 0000000..665cd2e
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <math.h>
+
+#define N_POINTS 200
+
+main()
+{
+    int i, j;
+    double x, y, dx, dy;
+
+    dx = 2*M_PI/N_POINTS;
+    dy = 2*M_PI/N_POINTS;
+    for (j = 0; j < N_POINTS; j++)
+       for (i = 0; i < N_POINTS; i++) {
+           x = i*dx;
+           y = j*dy;
+           printf("%f \n", 5.0*(1 + sin(x)*cos(y)));
+       }
+}
+
diff --git a/content/programming_strategies/src/gen_data_rectangle.c b/content/programming_strategies/src/gen_data_rectangle.c
new file mode 100644 (file)
index 0000000..ca94d9b
--- /dev/null
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <math.h>
+
+#define N_POINTSx 300
+#define N_POINTSy 200
+
+main()
+{
+    int i, j;
+    double x, y, dx, dy;
+
+    dx = 2*M_PI/N_POINTSx;
+    dy = dx;
+    for (j = 0; j < N_POINTSy; j++)
+      for (i = 0; i < N_POINTSx; i++) {
+            x = i*dx;
+            y = j*dy;
+           printf("%f \n", 5.0*(1 + sin(x)*cos(y)));
+       }
+}
+
diff --git a/content/programming_strategies/src/gen_data_sharp.c b/content/programming_strategies/src/gen_data_sharp.c
new file mode 100644 (file)
index 0000000..f62aecf
--- /dev/null
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include <math.h>
+
+#define N_POINTS 200
+
+main()
+{
+    int i, j;
+    double x, y, value;
+
+    for (j = 0; j < N_POINTS; j++)
+       for (i = 0; i < N_POINTS; i++) {
+         value = 0.0;
+          if ( j > N_POINTS/2 )
+               value = 1.5;
+         printf("%f \n", value);
+       }
+}
+
diff --git a/content/programming_strategies/src/plot_image.py b/content/programming_strategies/src/plot_image.py
new file mode 100644 (file)
index 0000000..09fbab1
--- /dev/null
@@ -0,0 +1,120 @@
+#! /usr/bin/env python
+
+from __future__ import division
+from pylab import *
+import sys
+import Numeric
+
+
+#
+#   plot_image.py
+#
+#   Step 1: make this file executable
+#
+#           chmod +x plot_image.py
+#
+#   Step 2: pipe data in python script
+#
+#           ./gen_data | ./plot_image -s nx ny -c nc -t 'image title'
+#
+#   with optional arguments
+#          -s nx ,ny    image size [16x16]
+#          -c nc        number of contour levels [none]
+#          -t ' '       image title ['some like it hot']
+#
+#   additional:  -g  gray map  [jet map]
+#                -h  hot map
+#
+#   ref: matplotlib web site
+#                                             Michel Vallieres, 2007
+#
+
+                        # dummy function to initialize Z
+def func3(x,y):
+    return 0.005*x*y
+
+                        # defaults
+mycontours = 0
+nx = 16
+ny = 16
+mytitle = 'Some like it hot'
+mymap = cm.jet
+
+                        # parse command line arguments
+n = len( sys.argv )
+i = 1
+while i < n:
+    if sys.argv[i].find("s") == 1:
+        nx = int( sys.argv[i+1] )
+        ny = int( sys.argv[i+2] )
+        i = i + 2
+    elif sys.argv[i].find("c") == 1:
+        mycontours = int( sys.argv[i+1] )
+        i = i + 1
+    elif sys.argv[i].find("t") == 1:
+        mytitle = sys.argv[i+1]
+        i = i + 1
+    elif sys.argv[i].find("g") == 1:
+        mymap = cm.gray
+    elif sys.argv[i].find("h") == 1:
+        mymap = cm.hot
+    else:
+        print " Syntax:    script -s nx ny -c "
+    i = i + 1
+
+                       # identification
+print "Plot_image"
+print "Title:            ", mytitle
+print "Image size:       ", nx, ny
+print "# countour lines: ", mycontours
+
+
+                       # set grid
+x = range( nx )
+y = range( ny )
+
+X,Y = meshgrid( x, y )
+
+Z = func3( X, Y )
+
+                       # read in data
+for j in y:
+   for i in x:
+      Z[j,i] = input()
+
+                       # min & max
+min_data = Z[0,0]
+max_data = Z[0,0]
+for i in x:
+   for j in y:
+      if Z[j,i] < min_data:
+          min_data = Z[j,i]
+      if Z[j,i] > max_data:
+          max_data = Z[j,i]
+
+print "Data range:       ", min_data, max_data
+
+
+                       # colored image
+im = imshow( Z, interpolation='bilinear', origin='lower',
+            cmap=mymap, extent=(1,nx-1.0,1,ny-1.0) )
+
+                       # contour lines
+if mycontours > 0:
+    dcont = ( max_data - min_data ) / ( mycontours - 1 )
+    cset = contour( Z, arange(min_data,max_data,dcont),
+               origin='lower',
+               linewidths=2,
+               extent=(0,nx-1,0,ny-1)
+               )
+
+    clabel( cset, inline=1, fmt='%1.1f', fontsize=10 )
+
+
+                       # render picture
+axis('off')
+
+colorbar()
+title( mytitle )
+show()
+