blimpy/filterbank.py
def cmd_tool(args=None):
    """ Command line tool for plotting and viewing info on filterbank files """

    from argparse import ArgumentParser

    parser = ArgumentParser(description="Command line utility for reading and plotting filterbank files.")

    parser.add_argument('-p', action='store',  default='ank', dest='what_to_plot', type=str,
                        help='Show: "w" waterfall (freq vs. time) plot; "s" integrated spectrum plot; \
                        "t" for time series; "mm" for spectrum including min max; "k" for kurtosis; \
                        "a" for all available plots and information; and "ank" for all but kurtosis.')
    parser.add_argument('filename', type=str,
                        help='Name of file to read')
    parser.add_argument('-b', action='store', default=None, dest='f_start', type=float,
                        help='Start frequency (begin), in MHz')
    parser.add_argument('-e', action='store', default=None, dest='f_stop', type=float,
                        help='Stop frequency (end), in MHz')
    parser.add_argument('-B', action='store', default=None, dest='t_start', type=int,
                        help='Start integration (begin) ID')
    parser.add_argument('-E', action='store', default=None, dest='t_stop', type=int,
                        help='Stop integration (end) ID')
    parser.add_argument('-i', action='store_true', default=False, dest='info_only',
                        help='Show info only')
    parser.add_argument('-a', action='store_true', default=False, dest='average',
                       help='average along time axis (plot spectrum only)')
    parser.add_argument('-s', action='store', default='', dest='plt_filename', type=str,
                       help='save plot graphic to file (give filename as argument)')
    parser.add_argument('-S', action='store_true', default=False, dest='save_only',
                       help='Turn off plotting of data and only save to file.')
    parser.add_argument('-D', action='store_false', default=True, dest='blank_dc',
                       help='Use to not blank DC bin.')
    parser.add_argument('-c', action='store_true', default=False, dest='calibrate_band_pass',
                        help='Calibrate band pass.')
    args = parser.parse_args()

    # Open blimpy data
    filename = args.filename
    load_data = not args.info_only

    # only load one integration if looking at spectrum
    wtp = args.what_to_plot
    if not wtp or 's' in wtp:
        if args.t_start == None:
            t_start = 0
        else:
            t_start = args.t_start
        t_stop  = t_start + 1

        if args.average:
            t_start = None
            t_stop  = None
    else:
        t_start = args.t_start
        t_stop  = args.t_stop

    if args.info_only:
        args.blank_dc = False
        args.calibrate_band_pass = False

    fil = Filterbank(filename, f_start=args.f_start, f_stop=args.f_stop,
                     t_start=t_start, t_stop=t_stop,
                     load_data=load_data,blank_dc=args.blank_dc,
                     cal_band_pass=args.calibrate_band_pass)
    fil.info()

    # And if we want to plot data, then plot data.
    if not args.info_only:
        # check start & stop frequencies make sense
        #try:
        #    if args.f_start:
        #        print "Start freq: %2.2f" % args.f_start
        #        assert args.f_start >= fil.freqs[0] or np.isclose(args.f_start, fil.freqs[0])
        #
        #    if args.f_stop:
        #        print "Stop freq: %2.2f" % args.f_stop
        #        assert args.f_stop <= fil.freqs[-1] or np.isclose(args.f_stop, fil.freqs[-1])
        #except AssertionError:
        #    print "Error: Start and stop frequencies must lie inside file's frequency range."
        #    print "i.e. between %2.2f-%2.2f MHz." % (fil.freqs[0], fil.freqs[-1])
        #    exit()

        if args.what_to_plot == "w":
            plt.figure("waterfall", figsize=(8, 6))
            fil.plot_waterfall(f_start=args.f_start, f_stop=args.f_stop)
        elif args.what_to_plot == "s":
            plt.figure("Spectrum", figsize=(8, 6))
            fil.plot_spectrum(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='all')
        elif args.what_to_plot == "mm":
            plt.figure("min max", figsize=(8, 6))
            fil.plot_spectrum_min_max(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='all')
        elif args.what_to_plot == "k":
            plt.figure("kurtosis", figsize=(8, 6))
            fil.plot_kurtosis(f_start=args.f_start, f_stop=args.f_stop)
        elif args.what_to_plot == "t":
            plt.figure("Time Series", figsize=(8, 6))
            fil.plot_time_series(f_start=args.f_start, f_stop=args.f_stop,orientation='h')
        elif args.what_to_plot == "a":
            plt.figure("Multiple diagnostic plots", figsize=(12, 9),facecolor='white')
            fil.plot_all(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='all')
        elif args.what_to_plot == "ank":
            plt.figure("Multiple diagnostic plots", figsize=(12, 9),facecolor='white')
            fil.plot_all(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='all',kurtosis=False)

        if args.plt_filename != '':
            plt.savefig(args.plt_filename)

        if not args.save_only:
            if 'DISPLAY' in os.environ.keys():
                plt.show()
            else:
                print("No $DISPLAY available.")
def cmd_tool(args=None):
    """ Command line tool for plotting and viewing info on filterbank files """

    from argparse import ArgumentParser

    parser = ArgumentParser(description="Command line utility for reading and plotting filterbank files.")

    parser.add_argument('-p', action='store',  default='ank', dest='what_to_plot', type=str,
                        help='Show: "w" waterfall (freq vs. time) plot; "s" integrated spectrum plot; \
                        "t" for time series; "mm" for spectrum including min max; "k" for kurtosis; \
                        "a" for all available plots and information; and "ank" for all but kurtosis.')
    parser.add_argument('filename', type=str,
                        help='Name of file to read')
    parser.add_argument('-b', action='store', default=None, dest='f_start', type=float,
                        help='Start frequency (begin), in MHz')
    parser.add_argument('-e', action='store', default=None, dest='f_stop', type=float,
                        help='Stop frequency (end), in MHz')
    parser.add_argument('-B', action='store', default=None, dest='t_start', type=int,
                        help='Start integration (begin) ID')
    parser.add_argument('-E', action='store', default=None, dest='t_stop', type=int,
                        help='Stop integration (end) ID')
    parser.add_argument('-i', action='store_true', default=False, dest='info_only',
                        help='Show info only')
    parser.add_argument('-a', action='store_true', default=False, dest='average',
                       help='average along time axis (plot spectrum only)')
    parser.add_argument('-s', action='store', default='', dest='plt_filename', type=str,
                       help='save plot graphic to file (give filename as argument)')
    parser.add_argument('-S', action='store_true', default=False, dest='save_only',
                       help='Turn off plotting of data and only save to file.')
    parser.add_argument('-D', action='store_false', default=True, dest='blank_dc',
                       help='Use to not blank DC bin.')
    parser.add_argument('-c', action='store_true', default=False, dest='calibrate_band_pass',
                        help='Calibrate band pass.')
    args = parser.parse_args()

    # Open blimpy data
    filename = args.filename
    load_data = not args.info_only

    # only load one integration if looking at spectrum
    wtp = args.what_to_plot
    if not wtp or 's' in wtp:
        if args.t_start == None:
            t_start = 0
        else:
            t_start = args.t_start
        t_stop  = t_start + 1

        if args.average:
            t_start = None
            t_stop  = None
    else:
        t_start = args.t_start
        t_stop  = args.t_stop

    if args.info_only:
        args.blank_dc = False
        args.calibrate_band_pass = False

    fil = Filterbank(filename, f_start=args.f_start, f_stop=args.f_stop,
                     t_start=t_start, t_stop=t_stop,
                     load_data=load_data,blank_dc=args.blank_dc,
                     cal_band_pass=args.calibrate_band_pass)
    fil.info()

    # And if we want to plot data, then plot data.
    if not args.info_only:
        # check start & stop frequencies make sense
        #try:
        #    if args.f_start:
        #        print "Start freq: %2.2f" % args.f_start
        #        assert args.f_start >= fil.freqs[0] or np.isclose(args.f_start, fil.freqs[0])
        #
        #    if args.f_stop:
        #        print "Stop freq: %2.2f" % args.f_stop
        #        assert args.f_stop <= fil.freqs[-1] or np.isclose(args.f_stop, fil.freqs[-1])
        #except AssertionError:
        #    print "Error: Start and stop frequencies must lie inside file's frequency range."
        #    print "i.e. between %2.2f-%2.2f MHz." % (fil.freqs[0], fil.freqs[-1])
        #    exit()

        if args.what_to_plot == "w":
            plt.figure("waterfall", figsize=(8, 6))
            fil.plot_waterfall(f_start=args.f_start, f_stop=args.f_stop)
        elif args.what_to_plot == "s":
            plt.figure("Spectrum", figsize=(8, 6))
            fil.plot_spectrum(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='all')
        elif args.what_to_plot == "mm":
            plt.figure("min max", figsize=(8, 6))
            fil.plot_spectrum_min_max(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='all')
        elif args.what_to_plot == "k":
            plt.figure("kurtosis", figsize=(8, 6))
            fil.plot_kurtosis(f_start=args.f_start, f_stop=args.f_stop)
        elif args.what_to_plot == "t":
            plt.figure("Time Series", figsize=(8, 6))
            fil.plot_time_series(f_start=args.f_start, f_stop=args.f_stop,orientation='h')
        elif args.what_to_plot == "a":
            plt.figure("Multiple diagnostic plots", figsize=(12, 9),facecolor='white')
            fil.plot_all(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='all')
        elif args.what_to_plot == "ank":
            plt.figure("Multiple diagnostic plots", figsize=(12, 9),facecolor='white')
            fil.plot_all(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='all',kurtosis=False)

        if args.plt_filename != '':
            plt.savefig(args.plt_filename)

        if not args.save_only:
            if 'DISPLAY' in os.environ.keys():
                plt.show()
            else:
                print("No $DISPLAY available.")
def cmd_tool ( args = None ) : from argparse import ArgumentParser parser = ArgumentParser ( description = "Command line utility for reading and plotting filterbank files." ) parser . add_argument ( '-p' , action = 'store' , default = 'ank' , dest = 'what_to_plot' , type = str , help = 'Show: "w" waterfall (freq vs. time) plot; "s" integrated spectrum plot; \
                        "t" for time series; "mm" for spectrum including min max; "k" for kurtosis; \
                        "a" for all available plots and information; and "ank" for all but kurtosis.' ) parser . add_argument ( 'filename' , type = str , help = 'Name of file to read' ) parser . add_argument ( '-b' , action = 'store' , default = None , dest = 'f_start' , type = float , help = 'Start frequency (begin), in MHz' ) parser . add_argument ( '-e' , action = 'store' , default = None , dest = 'f_stop' , type = float , help = 'Stop frequency (end), in MHz' ) parser . add_argument ( '-B' , action = 'store' , default = None , dest = 't_start' , type = int , help = 'Start integration (begin) ID' ) parser . add_argument ( '-E' , action = 'store' , default = None , dest = 't_stop' , type = int , help = 'Stop integration (end) ID' ) parser . add_argument ( '-i' , action = 'store_true' , default = False , dest = 'info_only' , help = 'Show info only' ) parser . add_argument ( '-a' , action = 'store_true' , default = False , dest = 'average' , help = 'average along time axis (plot spectrum only)' ) parser . add_argument ( '-s' , action = 'store' , default = '' , dest = 'plt_filename' , type = str , help = 'save plot graphic to file (give filename as argument)' ) parser . add_argument ( '-S' , action = 'store_true' , default = False , dest = 'save_only' , help = 'Turn off plotting of data and only save to file.' ) parser . add_argument ( '-D' , action = 'store_false' , default = True , dest = 'blank_dc' , help = 'Use to not blank DC bin.' ) parser . add_argument ( '-c' , action = 'store_true' , default = False , dest = 'calibrate_band_pass' , help = 'Calibrate band pass.' ) args = parser . parse_args ( ) # Open blimpy data filename = args . filename load_data = not args . info_only # only load one integration if looking at spectrum wtp = args . what_to_plot if not wtp or 's' in wtp : if args . t_start == None : t_start = 0 else : t_start = args . t_start t_stop = t_start + 1 if args . average : t_start = None t_stop = None else : t_start = args . t_start t_stop = args . t_stop if args . info_only : args . blank_dc = False args . calibrate_band_pass = False fil = Filterbank ( filename , f_start = args . f_start , f_stop = args . f_stop , t_start = t_start , t_stop = t_stop , load_data = load_data , blank_dc = args . blank_dc , cal_band_pass = args . calibrate_band_pass ) fil . info ( ) # And if we want to plot data, then plot data. if not args . info_only : # check start & stop frequencies make sense #try: #    if args.f_start: #        print "Start freq: %2.2f" % args.f_start #        assert args.f_start >= fil.freqs[0] or np.isclose(args.f_start, fil.freqs[0]) # #    if args.f_stop: #        print "Stop freq: %2.2f" % args.f_stop #        assert args.f_stop <= fil.freqs[-1] or np.isclose(args.f_stop, fil.freqs[-1]) #except AssertionError: #    print "Error: Start and stop frequencies must lie inside file's frequency range." #    print "i.e. between %2.2f-%2.2f MHz." % (fil.freqs[0], fil.freqs[-1]) #    exit() if args . what_to_plot == "w" : plt . figure ( "waterfall" , figsize = ( 8 , 6 ) ) fil . plot_waterfall ( f_start = args . f_start , f_stop = args . f_stop ) elif args . what_to_plot == "s" : plt . figure ( "Spectrum" , figsize = ( 8 , 6 ) ) fil . plot_spectrum ( logged = True , f_start = args . f_start , f_stop = args . f_stop , t = 'all' ) elif args . what_to_plot == "mm" : plt . figure ( "min max" , figsize = ( 8 , 6 ) ) fil . plot_spectrum_min_max ( logged = True , f_start = args . f_start , f_stop = args . f_stop , t = 'all' ) elif args . what_to_plot == "k" : plt . figure ( "kurtosis" , figsize = ( 8 , 6 ) ) fil . plot_kurtosis ( f_start = args . f_start , f_stop = args . f_stop ) elif args . what_to_plot == "t" : plt . figure ( "Time Series" , figsize = ( 8 , 6 ) ) fil . plot_time_series ( f_start = args . f_start , f_stop = args . f_stop , orientation = 'h' ) elif args . what_to_plot == "a" : plt . figure ( "Multiple diagnostic plots" , figsize = ( 12 , 9 ) , facecolor = 'white' ) fil . plot_all ( logged = True , f_start = args . f_start , f_stop = args . f_stop , t = 'all' ) elif args . what_to_plot == "ank" : plt . figure ( "Multiple diagnostic plots" , figsize = ( 12 , 9 ) , facecolor = 'white' ) fil . plot_all ( logged = True , f_start = args . f_start , f_stop = args . f_stop , t = 'all' , kurtosis = False ) if args . plt_filename != '' : plt . savefig ( args . plt_filename ) if not args . save_only : if 'DISPLAY' in os . environ . keys ( ) : plt . show ( ) else : print ( "No $DISPLAY available." )
Command line tool for plotting and viewing info on filterbank files
Command line tool for plotting and viewing info on filterbank files