source: trunk/test/simple_linefind.py@ 1647

Last change on this file since 1647 was 1647, checked in by Max Voronkov, 15 years ago

slight modification of the output of the simple line finder test

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/usr/bin/env python
2from asap import *
3import time,sys
4
5wait_str = ""
6if len(sys.argv)>=2:
7 if sys.argv[1].lower() == "wait":
8 wait_str = " Press Enter."
9
10# read the spectrum from ascii file
11f = open('data/atca_spectrum.dat')
12spc=[]
13try:
14 for line in f:
15 parts=line.split()
16 if len(parts)!=3:
17 raise RuntimeError, "Expect 3 parts, you have %s"% (parts,)
18 spc.append(float(parts[2]))
19finally:
20 f.close()
21
22
23#run the line finder
24
25lf = simplelinefinder()
26rng=lf.find_lines(spc,threshold=3,splitFeatures=False)
27
28print "Found %i lines.%s" % (len(rng),wait_str)
29b=len(spc)/4
30e=len(spc)*3/4
31plotter._plotter.plot(range(b,e),spc[b:e])
32plotter._plotter.set_line(number=0,label='Input spectrum')
33plotter._plotter.show()
34if wait_str == "":
35 time.sleep(1.5)
36else:
37 raw_input()
38cnt = 1
39for line in rng:
40 if len(line)!=2:
41 raise RuntimeError, "Line is supposed to have two parameters"
42 b = line[0]-1
43 if b<0:
44 b=0
45 e = line[1]+1
46 if e>len(spc):
47 e=len(spc)
48 print "Showing line %i located at %s.%s" % (cnt,line,wait_str)
49 plotter._plotter.set_line(label='Line %i' % cnt)
50 cnt = cnt + 1
51 plotter._plotter.plot(range(b,e),spc[b:e])
52 plotter._plotter.show()
53 if wait_str == "":
54 time.sleep(1.5)
55 else:
56 raw_input()
57
58print "Test of simple line finder is successful"
Note: See TracBrowser for help on using the repository browser.