Reading the output from surfdynamics2d.cu

We go from a flattened std::vector (C++, representing 2-dimensional data) to a .csv file.


In [1]:
%matplotlib inline

In [2]:
import matplotlib.pyplot as plt
import csv
import numpy as np

In [3]:
WIDTH  = 128
HEIGHT = 64
print WIDTH*HEIGHT


8192

In [91]:
# list the csv files we can import
import os
[filename for filename in os.listdir('./') if filename.find('.csv') >= 0 ]


Out[91]:
['simplecpy.csv',
 'addrxyf2_u_x.csv',
 'addrxyf2_u_y.csv',
 'addr_p.csv',
 'addlrout.csv',
 'addrxyf2_u_out_y.csv',
 'addlrin.csv',
 'addrxyf2_u_out_x.csv',
 'addr01.csv']

In [93]:
with open('simplecpy.csv','r') as csvfile_simplecpy:
    plot_simplecpy = csv.reader(csvfile_simplecpy, delimiter=',')
    simplecpy_list = list(  list(rec) for rec in plot_simplecpy ) 
    
with open('addr01.csv','r') as csvfile_addr01:
    plot_addr01 = csv.reader(csvfile_addr01, delimiter=',')
    addr01_list = list(  list(rec) for rec in plot_addr01 )  
    
with open('addlrin.csv','r') as csvfile_addlrin:
    plot_addlrin = csv.reader(csvfile_addlrin, delimiter=',')
    addlrin_list = list(  list(rec) for rec in plot_addlrin )  
    
with open('addlrout.csv','r') as csvfile_addlrout:
    plot_addlrout = csv.reader(csvfile_addlrout, delimiter=',')
    addlrout_list = list(  list(rec) for rec in plot_addlrout )      
    
with open('addr_p.csv','r') as csvfile_addr_p:
    plot_addr_p = csv.reader(csvfile_addr_p, delimiter=',')
    addr_p_list = list(  list(rec) for rec in plot_addr_p )          
    
with open('addrxyf2_u_x.csv','r') as csvfile_addrxyf2_u_x:
    plot_addrxyf2_u_x = csv.reader(csvfile_addrxyf2_u_x, delimiter=',')
    addrxyf2_u_x_list = list(  list(rec) for rec in plot_addrxyf2_u_x )              
    
with open('addrxyf2_u_y.csv','r') as csvfile_addrxyf2_u_y:
    plot_addrxyf2_u_y = csv.reader(csvfile_addrxyf2_u_y, delimiter=',')
    addrxyf2_u_y_list = list(  list(rec) for rec in plot_addrxyf2_u_y )              

with open('addrxyf2_u_out_x.csv','r') as csvfile_addrxyf2_u_out_x:
    plot_addrxyf2_u_out_x = csv.reader(csvfile_addrxyf2_u_out_x, delimiter=',')
    addrxyf2_u_out_x_list = list(  list(rec) for rec in plot_addrxyf2_u_out_x )              
    
with open('addrxyf2_u_out_y.csv','r') as csvfile_addrxyf2_u_out_y:
    plot_addrxyf2_u_out_y = csv.reader(csvfile_addrxyf2_u_out_y, delimiter=',')
    addrxyf2_u_out_y_list = list(  list(rec) for rec in plot_addrxyf2_u_out_y )

In [94]:
csvfile_simplecpy.close()
csvfile_addr01.close()
csvfile_addlrin.close()
csvfile_addlrout.close()
csvfile_addr_p.close()
csvfile_addrxyf2_u_x.close()
csvfile_addrxyf2_u_y.close()
csvfile_addrxyf2_u_out_x.close()
csvfile_addrxyf2_u_out_y.close()

In [95]:
# convert the strings in the list of lists into floats
simplecpy_list = [[float(ele) for ele in row] for row in simplecpy_list]
addr01_list    = [[float(ele) for ele in row] for row in addr01_list]
addlrin_list   = [[float(ele) for ele in row] for row in addlrin_list]
addlrout_list  = [[float(ele) for ele in row] for row in addlrout_list]
addr_p_list  = [[float(ele) for ele in row] for row in addr_p_list]
addrxyf2_u_x_list  = [[float(ele) for ele in row] for row in addrxyf2_u_x_list]
addrxyf2_u_y_list  = [[float(ele) for ele in row] for row in addrxyf2_u_y_list]
addrxyf2_u_out_x_list  = [[float(ele) for ele in row] for row in addrxyf2_u_out_x_list]
addrxyf2_u_out_y_list  = [[float(ele) for ele in row] for row in addrxyf2_u_out_y_list]

In [96]:
# convert the list of lists of floats into numpy arrays
simplecpy_list = np.array( simplecpy_list )
addr01_list    = np.array( addr01_list)
addlrin_list   = np.array( addlrin_list)
addlrout_list  = np.array( addlrout_list)
addr_p_list  = np.array( addr_p_list)
addrxyf2_u_x_list  = np.array( addrxyf2_u_x_list)
addrxyf2_u_y_list  = np.array( addrxyf2_u_y_list)
addrxyf2_u_out_x_list  = np.array( addrxyf2_u_out_x_list)
addrxyf2_u_out_y_list  = np.array( addrxyf2_u_out_y_list)

In [97]:
print simplecpy_list.shape; print addr01_list.shape; print addlrin_list.shape; print addlrout_list.shape;
print addr_p_list.shape; print addrxyf2_u_x_list.shape; print addrxyf2_u_y_list.shape; 
print addrxyf2_u_out_x_list.shape; print addrxyf2_u_out_y_list.shape;


(64, 128)
(64, 128)
(64, 128)
(64, 128)
(64, 128)
(64, 128)
(64, 128)
(64, 128)
(64, 128)

In [90]:
# np.array_str from 
# cf. http://stackoverflow.com/questions/2891790/pretty-printing-of-numpy-array
print np.array_str(simplecpy_list, precision=3, suppress_small=True); 
print np.array_str(addr01_list, precision=3, suppress_small=True); 
print np.array_str(addlrin_list, precision=3, suppress_small=True); 
print np.array_str(addlrout_list, precision=3, suppress_small=True); 
print np.array_str(addr_p_list, precision=3, suppress_small=True);


[[    0.1     1.1     2.1 ...,   125.1   126.1   127.1]
 [  128.1   129.1   130.1 ...,   253.1   254.1   255.1]
 [  256.1   257.1   258.1 ...,   381.1   382.1   383.1]
 ..., 
 [ 7808.1  7809.1  7810.1 ...,  7933.1  7934.1  7935.1]
 [ 7936.1  7937.1  7938.1 ...,  8061.1  8062.1  8063.1]
 [ 8064.1  8065.1  8066.1 ...,  8189.1  8190.1  8191.1]]
[[     1.2      3.2      5.2 ...,    251.2    253.2    254.2]
 [   257.2    259.2    261.2 ...,    507.2    509.2    510.2]
 [   513.2    515.2    517.2 ...,    763.2    765.2    766.2]
 ..., 
 [ 15617.2  15619.2  15621.2 ...,  15867.2  15869.2  15870.2]
 [ 15873.2  15875.2  15877.2 ...,  16123.2  16125.2  16126.2]
 [ 16129.2  16131.2  16133.2 ...,  16379.2  16381.2  16382.2]]
[[     2.4      4.4      8.4 ...,    500.4    504.4    507.4]
 [   514.4    516.4    520.4 ...,   1012.4   1016.4   1019.4]
 [  1026.4   1028.4   1032.4 ...,   1524.4   1528.4   1531.4]
 ..., 
 [ 31234.4  31236.4  31240.4 ...,  31732.4  31736.4  31739.4]
 [ 31746.4  31748.4  31752.4 ...,  32244.4  32248.4  32251.4]
 [ 32258.4  32260.4  32264.4 ...,  32756.4  32760.4  32763.4]]
[[     1.2      3.2      5.2 ...,    251.2    253.2    254.2]
 [   257.2    259.2    261.2 ...,    507.2    509.2    510.2]
 [   513.2    515.2    517.2 ...,    763.2    765.2    766.2]
 ..., 
 [ 15617.2  15619.2  15621.2 ...,  15867.2  15869.2  15870.2]
 [ 15873.2  15875.2  15877.2 ...,  16123.2  16125.2  16126.2]
 [ 16129.2  16131.2  16133.2 ...,  16379.2  16381.2  16382.2]]
[[     6.8     12.8     20.8 ...,   1004.8   1011.8   1014.8]
 [  1030.8   1036.8   1044.8 ...,   2028.8   2035.8   2038.8]
 [  2054.8   2060.8   2068.8 ...,   3052.8   3059.8   3062.8]
 ..., 
 [ 62470.8  62476.8  62484.8 ...,  63468.8  63475.8  63478.8]
 [ 63494.8  63500.8  63508.8 ...,  64492.8  64499.8  64502.8]
 [ 64518.8  64524.8  64532.8 ...,  65516.8  65523.8  65526.8]]

result of NITERS=2 (a single for loop run of addlrKernels_launch)

[[    0.1     1.1     2.1 ...,   125.1   126.1   127.1]
 [  128.1   129.1   130.1 ...,   253.1   254.1   255.1]
 [  256.1   257.1   258.1 ...,   381.1   382.1   383.1]
 ..., 
 [ 7808.1  7809.1  7810.1 ...,  7933.1  7934.1  7935.1]
 [ 7936.1  7937.1  7938.1 ...,  8061.1  8062.1  8063.1]
 [ 8064.1  8065.1  8066.1 ...,  8189.1  8190.1  8191.1]]
[[     1.2      3.2      5.2 ...,    251.2    253.2    254.2]
 [   257.2    259.2    261.2 ...,    507.2    509.2    510.2]
 [   513.2    515.2    517.2 ...,    763.2    765.2    766.2]
 ..., 
 [ 15617.2  15619.2  15621.2 ...,  15867.2  15869.2  15870.2]
 [ 15873.2  15875.2  15877.2 ...,  16123.2  16125.2  16126.2]
 [ 16129.2  16131.2  16133.2 ...,  16379.2  16381.2  16382.2]]
[[     2.4      4.4      8.4 ...,    500.4    504.4    507.4]
 [   514.4    516.4    520.4 ...,   1012.4   1016.4   1019.4]
 [  1026.4   1028.4   1032.4 ...,   1524.4   1528.4   1531.4]
 ..., 
 [ 31234.4  31236.4  31240.4 ...,  31732.4  31736.4  31739.4]
 [ 31746.4  31748.4  31752.4 ...,  32244.4  32248.4  32251.4]
 [ 32258.4  32260.4  32264.4 ...,  32756.4  32760.4  32763.4]]
[[     1.2      3.2      5.2 ...,    251.2    253.2    254.2]
 [   257.2    259.2    261.2 ...,    507.2    509.2    510.2]
 [   513.2    515.2    517.2 ...,    763.2    765.2    766.2]
 ..., 
 [ 15617.2  15619.2  15621.2 ...,  15867.2  15869.2  15870.2]
 [ 15873.2  15875.2  15877.2 ...,  16123.2  16125.2  16126.2]
 [ 16129.2  16131.2  16133.2 ...,  16379.2  16381.2  16382.2]]

In [98]:
# np.array_str from 
# cf. http://stackoverflow.com/questions/2891790/pretty-printing-of-numpy-array
print np.array_str(addrxyf2_u_x_list, precision=3, suppress_small=True); 
print np.array_str(addrxyf2_u_y_list, precision=3, suppress_small=True); 
print np.array_str(addrxyf2_u_out_x_list, precision=3, suppress_small=True); 
print np.array_str(addrxyf2_u_out_y_list, precision=3, suppress_small=True);


[[     0.1     10.1     20.1 ...,   1250.1   1260.1   1270.1]
 [  1280.1   1290.1   1300.1 ...,   2530.1   2540.1   2550.1]
 [  2560.1   2570.1   2580.1 ...,   3810.1   3820.1   3830.1]
 ..., 
 [ 78080.1  78090.1  78100.1 ...,  79330.1  79340.1  79350.1]
 [ 79360.1  79370.1  79380.1 ...,  80610.1  80620.1  80630.1]
 [ 80640.1  80650.1  80660.1 ...,  81890.1  81900.1  81910.1]]
[[ 0.     0.001  0.002 ...,  0.125  0.126  0.127]
 [ 0.128  0.129  0.13  ...,  0.253  0.254  0.255]
 [ 0.256  0.257  0.258 ...,  0.381  0.382  0.383]
 ..., 
 [ 7.808  7.809  7.81  ...,  7.933  7.934  7.935]
 [ 7.936  7.937  7.938 ...,  8.061  8.062  8.063]
 [ 8.064  8.065  8.066 ...,  8.189  8.19   8.191]]
[[     10.2      30.2      50.2 ...,    2510.2    2530.2    2540.2]
 [   2570.2    2590.2    2610.2 ...,    5070.2    5090.2    5100.2]
 [   5130.2    5150.2    5170.2 ...,    7630.2    7650.2    7660.2]
 ..., 
 [ 156170.   156190.   156210.  ...,  158670.   158690.   158700. ]
 [ 158730.   158750.   158770.  ...,  161230.   161250.   161260. ]
 [ 161290.   161310.   161330.  ...,  163790.   163810.   163820. ]]
[[  0.001   0.003   0.005 ...,   0.251   0.253   0.254]
 [  0.257   0.259   0.261 ...,   0.507   0.509   0.51 ]
 [  0.513   0.515   0.517 ...,   0.763   0.765   0.766]
 ..., 
 [ 15.617  15.619  15.621 ...,  15.867  15.869  15.87 ]
 [ 15.873  15.875  15.877 ...,  16.123  16.125  16.126]
 [ 16.129  16.131  16.133 ...,  16.379  16.381  16.382]]

In [ ]: