[1648] | 1 | #!/usr/bin/env python |
---|
| 2 | # run this script with a command line parameter "wait" in order it to wait |
---|
| 3 | # pressing enter instead of a time delay |
---|
| 4 | |
---|
| 5 | from asap import * |
---|
| 6 | import time,sys |
---|
| 7 | |
---|
| 8 | input_dataset = "data/mopra_g327.3-0.6.sdfits" |
---|
| 9 | |
---|
| 10 | # read command line parameter |
---|
| 11 | wait_str = "" |
---|
| 12 | if len(sys.argv)>=2: |
---|
| 13 | if sys.argv[1].lower() == "wait": |
---|
| 14 | wait_str = " Press Enter." |
---|
| 15 | |
---|
| 16 | # read scantable |
---|
| 17 | sc=scantable(input_dataset) |
---|
| 18 | # this file is already reduced, so we can just plot it |
---|
| 19 | |
---|
| 20 | plotter.plot(sc) |
---|
| 21 | plotter.set_legend('Input spectrum') |
---|
| 22 | #plotter._plotter.set_line(number=0,label='Input spectrum') |
---|
| 23 | |
---|
| 24 | # now set up and run line finder |
---|
| 25 | fl=linefinder() |
---|
| 26 | fl.set_scan(sc) |
---|
| 27 | fl.set_options(avg_limit=1,threshold=4,box_size=0.1,noise_box=0.1,noise_stat='median') |
---|
| 28 | nlines=fl.find_lines() |
---|
| 29 | print 'Found %i lines.' % nlines |
---|
| 30 | |
---|
| 31 | if nlines!=0: |
---|
| 32 | r=fl.get_ranges() |
---|
| 33 | print "Channel ranges: %s" % (r,) |
---|
| 34 | print wait_str |
---|
| 35 | if wait_str == "": |
---|
| 36 | time.sleep(1) |
---|
| 37 | else: |
---|
| 38 | raw_input() |
---|
| 39 | for l in range(1,len(r),2): |
---|
| 40 | print "Line %i from channel %i to %i.%s" % (l/2+1,r[l-1],r[l],wait_str) |
---|
| 41 | #plotter.set_range(r[l-1]-3,r[l]+3) |
---|
| 42 | b=int(r[l-1])-3 |
---|
| 43 | e=int(r[l])+3 |
---|
| 44 | if b<0: |
---|
| 45 | b=0 |
---|
| 46 | if e>=sc.nchan(): |
---|
| 47 | e=sc.nchan() |
---|
| 48 | add_colours = ['red','blue','pink','brown'] |
---|
| 49 | if l/2 >= 9: |
---|
| 50 | plotter._plotter.set_line(colour=add_colours[(l/2-9)%len(add_colours)]) |
---|
| 51 | plotter._plotter.set_line(label='Line %i'% (l/2+1)) |
---|
| 52 | plotter._plotter.plot(range(b,e),sc.get_spectrum(0)[b:e]) |
---|
| 53 | plotter._plotter.show() |
---|
| 54 | if wait_str == "": |
---|
| 55 | time.sleep(1) |
---|
| 56 | else: |
---|
| 57 | raw_input() |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | plotter.save('output/linefinder.png', dpi=80) |
---|
| 61 | print "Test of line finder is successfull" |
---|