Example #1
0
                        '--port',
                        required=True,
                        help="GNURadio port",
                        default=52001,
                        type=int)

    args = parser.parse_args()
    imp.load_source('config', args.config)

    class MyPrompt(Prompts):
        def in_prompt_tokens(self, cli=None):
            return [(Token.Prompt, 'COMM'), (Token.Prompt, '> ')]

    cfg = Config()
    frame_decoder = FallbackResponseDecorator(
        response_frames.FrameDecoder(response_frames.frame_factories))

    def receive():
        rcv = Receiver(args.target, args.port)
        rcv.connect()
        data = rcv.decode_kiss(rcv.receive())
        rcv.disconnect()
        return frame_decoder.decode(data)

    shell = InteractiveShellEmbed(config=cfg,
                                  user_ns={'receive': receive},
                                  banner2='COMM Terminal')
    shell.prompts = MyPrompt(shell)
    shell.run_code('from telecommand import *')
    shell()
Example #2
0
                                      parse_and_save_raw_and_photo,
                                      'save_beacons': save_beacons,
                                      'parse_and_save_photo':
                                      parse_and_save_photo,
                                      'parse_and_save': parse_and_save,
                                      'run': run,
                                      'receive_raw': receive_raw,
                                      'receive': receive,
                                      'set_timeout': set_timeout,
                                      'send': send,
                                      'send_receive': send_receive,
                                      'parse_file_list':
                                      RemoteFileTools.parse_file_list,
                                      'get_file': get_file,
                                      'RemoteFileTools': RemoteFileTools,
                                      'RemoteFile': RemoteFile,
                                      'sender': sender,
                                      'receiver': rcv,
                                      'get_beacon': get_beacon
                                  },
                                  banner2='COMM Terminal')
    shell.prompts = MyPrompt(shell)
    shell.run_code('from tools.parse_beacon import ParseBeacon')
    shell.run_code('import telecommand as tc')
    shell.run_code('import time')
    shell.run_code('import pprint')
    shell.run_code('import datetime')
    shell.run_code('from devices import camera')
    shell.run_code('from tools.remote_files import *')
    shell()
Example #3
0
def main():
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    args = parser.parse_args()

    ##########
    # initial arg processing

    if os.path.splitext(os.path.basename(args.IFO))[1] in [".hdf5", ".h5"]:
        Budget = None
        freq, traces, attrs = io.load_hdf5(args.IFO)
        ifo = getattr(attrs, "IFO", None)
        plot_style = attrs

    else:
        Budget, ifo, freq, plot_style = load_ifo(args.IFO)
        # FIXME: this should be done only if specified, to allow for
        # using any FREQ specified in budget module by default
        freq = np.logspace(np.log10(args.flo), np.log10(args.fhi), args.npoints)
        traces = None

    if args.yaml:
        if not ifo:
            parser.exit(2, "no IFO structure available.")
        print(ifo.to_yaml(), end="")
        return
    if args.text:
        if not ifo:
            parser.exit(2, "no IFO structure available.")
        print(ifo.to_txt(), end="")
        return
    if args.diff:
        if not ifo:
            parser.exit(2, "no IFO structure available.")
        fmt = "{:30} {:>20} {:>20}"
        Budget, ifoo, freq, plot_style = load_ifo(args.diff)
        diffs = ifo.diff(ifoo)
        if diffs:
            print(fmt.format("", args.IFO, args.diff))
            for p in diffs:
                k = str(p[0])
                v = repr(p[1])
                ov = repr(p[2])
                print(fmt.format(k, v, ov))
        return

    if args.title:
        plot_style["title"] = args.title
    elif Budget:
        plot_style["title"] = "GWINC Noise Budget: {}".format(Budget.name)
    else:
        plot_style["title"] = "GWINC Noise Budget: {}".format(args.IFO)

    if args.plot:
        if args.save:
            # FIXME: this silliness seems to be the only way to have
            # matplotlib usable on systems without a display.  There must
            # be a better way.  'AGG' is a backend that works without
            # displays.  but it has to be set before any other matplotlib
            # stuff is imported.  and we *don't* want it set if we do want
            # to show an interactive plot.  there doesn't seem a way to
            # set this opportunistically.
            import matplotlib

            matplotlib.use("AGG")
        try:
            from matplotlib import pyplot as plt
        except RuntimeError:
            logging.warning("no display, plotting disabled.")
            args.plot = False

    if args.fom:
        import inspiral_range

        try:
            range_func, fargs = args.fom.split(":")
        except ValueError:
            range_func = args.fom
            fargs = ""
        range_params = {}
        for param in fargs.split(","):
            if not param:
                continue
            p, v = param.split("=")
            if not v:
                raise ValueError('missing parameter value "{}"'.format(p))
            if p != "approximant":
                v = float(v)
            range_params[p] = v

    ##########
    # main calculations

    if not traces:
        if ifo:
            logging.info("precomputing ifo...")
            ifo = precompIFO(freq, ifo)
        logging.info("calculating budget...")
        budget = Budget(freq=freq, ifo=ifo)
        budget.load()
        budget.update()
        traces = budget.calc_trace()

    # logging.info('recycling factor: {: >0.3f}'.format(ifo.gwinc.prfactor))
    # logging.info('BS power:         {: >0.3f} W'.format(ifo.gwinc.pbs))
    # logging.info('arm finesse:      {: >0.3f}'.format(ifo.gwinc.finesse))
    # logging.info('arm power:        {: >0.3f} kW'.format(ifo.gwinc.parm/1000))

    if args.fom:
        logging.info("calculating inspiral {}...".format(range_func))
        H = inspiral_range.CBCWaveform(freq, **range_params)
        logging.debug("params: {}".format(H.params))
        fom = eval("inspiral_range.{}".format(range_func))(freq, noises["Total"], H=H)
        logging.info("{}({}) = {:.2f} Mpc".format(range_func, fargs, fom))
        fom_title = "{func} {m1}/{m2} Msol: {fom:.2f} Mpc".format(
            func=range_func,
            m1=H.params["m1"],
            m2=H.params["m2"],
            fom=fom,
        )
        plot_style["title"] += "\n{}".format(fom_title)

    ##########
    # output

    # save noise traces to HDF5 file
    if args.save and os.path.splitext(args.save)[1] in [".hdf5", ".h5"]:
        logging.info("saving budget traces {}...".format(args.save))
        if ifo:
            plot_style["IFO"] = ifo.to_yaml()
        io.save_hdf5(path=args.save, freq=freq, traces=traces, **plot_style)

    # interactive shell plotting
    elif args.interactive:
        ipshell = InteractiveShellEmbed(
            user_ns={
                "freq": freq,
                "traces": traces,
                "ifo": ifo,
                "plot_style": plot_style,
                "plot_noise": plot_noise,
            },
            banner1="""
GWINC interactive plotter

You may interact with plot using "plt." methods, e.g.:

>>> plt.title("foo")
>>> plt.savefig("foo.pdf")
""",
        )
        ipshell.enable_pylab()
        ipshell.run_code("plot_noise(freq, traces, **plot_style)")
        ipshell.run_code("plt.title('{}')".format(plot_style["title"]))
        ipshell()

    # standard plotting
    elif args.plot:
        logging.info("plotting noises...")
        fig = plt.figure()
        ax = fig.add_subplot(1, 1, 1)
        plot_noise(freq, traces, ax=ax, **plot_style)
        fig.tight_layout()
        if args.save:
            fig.savefig(
                args.save,
            )
        else:
            plt.show()
Example #4
0
lock = threading.Lock()

_setup_log()

stop_event = threading.Event()
time_guard = TimeGuard(obc, lock)
time_guard_thread = threading.Thread(target=time_guard.run, args=())

executor = Executor(obc, lock)
reporter = Reporter()


def generate_report(path, name):
    reporter.generate(executor.results_table, path, name)


cfg = Config()
shell = InteractiveShellEmbed(config=cfg,
                              user_ns={
                                  'describe': reporter.test_description,
                                  'generate_report': generate_report,
                                  'time_guard_thread': time_guard_thread,
                                  'obc': obc,
                                  'end': time_guard.stop,
                                  'executor': executor
                              },
                              banner2='PW-Sat2 Health Check')
shell.prompts = MyPrompt(shell)
shell.run_code('time_guard_thread.start()')
shell()
Example #5
0
        'RemoteFile': RemoteFile,
        'sender': sender,
        'receiver': rcv,
        'jebnij_bekona': jebnij_bekona
    }

    from shell_cmd import build_shell_commands

    shell_cmds = build_shell_commands(sender, rcv, frame_decoder, analyzer,
                                      user_ns, monitor_connector)

    user_ns.update(shell_cmds)

    shell = InteractiveShellEmbed(config=cfg, user_ns=user_ns, banner2=banner)
    shell.prompts = MyPrompt(shell)
    shell.run_code('from tools.parse_beacon import ParseBeacon')
    shell.run_code('import telecommand as tc')
    shell.run_code('import time')
    shell.run_code('from pprint import pprint')
    shell.run_code('import datetime')
    shell.run_code('from devices import camera')
    shell.run_code('from tools.remote_files import *')
    shell.run_code('from radio.task_actions import *')
    shell.run_code('import response_frames')
    shell.run_code('import response_frames as rf')

    if args.session != 0:
        with open(
                os.path.join(os.path.dirname(__file__), '..', '..', 'mission',
                             'sessions', str(args.session), 'data.json'),
                'r') as session_data_file: