| 1 |
#!/usr/bin/env python |
| 2 |
# |
| 3 |
# Script to plot the contents of a .pix file output |
| 4 |
# with splash -o ascii |
| 5 |
# |
| 6 |
import numpy as np |
| 7 |
import matplotlib.pyplot as plt |
| 8 |
import sys |
| 9 |
import re |
| 10 |
|
| 11 |
def read_header( file ): |
| 12 |
""" |
| 13 |
read the x, y and v plot limits from the .pix header lines |
| 14 |
""" |
| 15 |
pat = re.compile(r'.*min\s*=\s+(\S+)\s+max\s*=\s+(\S+)') |
| 16 |
fh = open(file, 'r') |
| 17 |
count = 0 |
| 18 |
got = 0 |
| 19 |
xmin = np.full((3),0.) |
| 20 |
xmax = np.full((3),1.) |
| 21 |
while (count < 10): |
| 22 |
count += 1 |
| 23 |
|
| 24 |
# Get next line from file |
| 25 |
line = fh.readline() |
| 26 |
|
| 27 |
# if line is empty |
| 28 |
# end of file is reached |
| 29 |
if not line: |
| 30 |
break |
| 31 |
|
| 32 |
# otherwise match lines like "min = 0.000 max = 1.000" |
| 33 |
if (pat.match(line)): |
| 34 |
[m] = pat.findall(line) |
| 35 |
xmin[got] = m[0] |
| 36 |
xmax[got] = m[1] |
| 37 |
got += 1 |
| 38 |
|
| 39 |
return xmin[2],xmax[2],xmin[1],xmax[1],xmin[0],xmax[0] |
| 40 |
|
| 41 |
def read_pix( file ): |
| 42 |
""" |
| 43 |
read the floating point pixel values |
| 44 |
""" |
| 45 |
array = np.loadtxt(file) |
| 46 |
return array |
| 47 |
|
| 48 |
def plot_pix( file ): |
| 49 |
""" |
| 50 |
plot the pixel map with appropriate limits |
| 51 |
""" |
| 52 |
xmin,xmax,ymin,ymax,vmin,vmax = read_header(file) |
| 53 |
img = read_pix(file) |
| 54 |
print(file,img.shape) |
| 55 |
plt.imshow(img,cmap='RdBu',origin='lower',vmin=vmin,vmax=vmax,extent=[xmin,xmax,ymin,ymax]) |
| 56 |
plt.show() |
| 57 |
|
| 58 |
if (len(sys.argv) > 1): |
| 59 |
for file in sys.argv[1:]: |
| 60 |
plot_pix( file ) |
| 61 |
else: |
| 62 |
print('Usage:',strsys.argv[0],'file.pix') |
| 63 |
sys.exit(2) |