def get_input_factory(args): """Parse input factory arguments. Parameters ---------- args : argparse.Namespace arguments Returns ------- TimeseriesFactory input timeseries factory """ input_factory = None input_factory_args = None input_stream = None # standard arguments input_factory_args = {} input_factory_args['interval'] = args.interval input_factory_args['observatory'] = args.observatory input_factory_args['type'] = args.type # stream/url arguments if args.input_file is not None: input_stream = open(args.input_file, 'r') elif args.input_stdin: input_stream = sys.stdin elif args.input_url is not None: input_factory_args['urlInterval'] = args.input_url_interval input_factory_args['urlTemplate'] = args.input_url input_type = args.input if input_type == 'edge': input_factory = edge.EdgeFactory(host=args.input_host, port=args.input_port, locationCode=args.locationcode, **input_factory_args) elif input_type == 'goes': # TODO: deal with other goes arguments input_factory = imfv283.GOESIMFV283Factory( directory=args.input_goes_directory, getdcpmessages=args.input_goes_getdcpmessages, server=args.input_goes_server, user=args.input_goes_user, **input_factory_args) else: # stream compatible factories if input_type == 'iaga2002': input_factory = iaga2002.IAGA2002Factory(**input_factory_args) elif input_type == 'imfv122': input_factory = imfv122.IMFV122Factory(**input_factory_args) elif input_type == 'imfv283': input_factory = imfv283.IMFV283Factory(**input_factory_args) elif input_type == 'pcdcp': input_factory = pcdcp.PCDCPFactory(**input_factory_args) # wrap stream if input_stream is not None: input_factory = StreamTimeseriesFactory(factory=input_factory, stream=input_stream) return input_factory
def get_output_factory(args): """Parse output factory arguments. Parameters ---------- args : argparse.Namespace arguments Returns ------- TimeseriesFactory output timeseries factory """ output_factory = None output_factory_args = None output_stream = None output_url = None # standard arguments output_factory_args = {} output_factory_args['interval'] = args.interval output_factory_args['observatory'] = args.observatory output_factory_args['type'] = args.type # stream/url arguments if args.output_file is not None: output_stream = open(args.output_file, 'wb') elif args.output_stdout: output_stream = sys.stdout elif args.output_url is not None: output_url = args.output_url output_factory_args['urlInterval'] = args.output_url_interval output_factory_args['urlTemplate'] = output_url output_type = args.output if output_type == 'edge': # TODO: deal with other edge arguments locationcode = args.outlocationcode or args.locationcode or None output_factory = edge.EdgeFactory(host=args.output_host, port=args.output_edge_read_port, write_port=args.output_port, locationCode=locationcode, tag=args.output_edge_tag, forceout=args.output_edge_forceout, **output_factory_args) elif output_type == 'plot': output_factory = PlotTimeseriesFactory() else: # stream compatible factories if output_type == 'binlog': output_factory = binlog.BinLogFactory(**output_factory_args) elif output_type == 'iaga2002': output_factory = iaga2002.IAGA2002Factory(**output_factory_args) elif output_type == 'pcdcp': output_factory = pcdcp.PCDCPFactory(**output_factory_args) elif output_type == 'temperature': output_factory = temperature.TEMPFactory(**output_factory_args) elif output_type == 'vbf': output_factory = vbf.VBFFactory(**output_factory_args) # wrap stream if output_stream is not None: output_factory = StreamTimeseriesFactory(factory=output_factory, stream=output_stream) return output_factory
def main(args): """command line factory for geomag algorithms Inputs ------ use geomag.py --help to see inputs, or see parse_args. Notes ----- parses command line options using argparse, then calls the controller with instantiated I/O factories, and algorithm(s) """ # Input Factory if args.input_edge is not None: inputfactory = edge.EdgeFactory( host=args.input_edge, port=args.input_edge_port, observatory=args.observatory, type=args.type, interval=args.interval, locationCode=args.locationcode) elif args.input_iaga_file is not None: inputfactory = iaga2002.StreamIAGA2002Factory( stream=open(args.input_iaga_file, 'r'), observatory=args.observatory, type=args.type, interval=args.interval) elif args.input_iaga_magweb: inputfactory = iaga2002.MagWebFactory( observatory=args.observatory, type=args.type, interval=args.interval) elif args.input_iaga_stdin: inputfactory = iaga2002.StreamIAGA2002Factory( stream=sys.stdin, observatory=args.observatory, type=args.type, interval=args.interval) elif args.input_iaga_url is not None: inputfactory = iaga2002.IAGA2002Factory( urlTemplate=args.input_iaga_url, observatory=args.observatory, type=args.type, interval=args.interval) elif args.input_imfv283_file is not None: inputfactory = imfv283.StreamIMFV283Factory( stream=open(args.input_imfv283_file, 'r'), observatory=args.observatory) elif args.input_imfv283_stdin is not None: inputfactory = imfv283.StreamIMFV283Factory( stream=sys.stdin, observatory=args.observatory) elif args.input_imfv283_url is not None: inputfactory = imfv283.IMFV283Factory( urlTemplate=args.input_imfv283_url, observatory=args.observatory) elif args.input_pcdcp_file is not None: inputfactory = pcdcp.StreamPCDCPFactory( stream=open(args.input_pcdcp_file, 'r'), observatory=args.observatory, type=args.type, interval=args.interval) elif args.input_pcdcp_stdin: inputfactory = pcdcp.StreamPCDCPFactory( stream=sys.stdin, observatory=args.observatory, type=args.type, interval=args.interval) elif args.input_pcdcp_url is not None: inputfactory = pcdcp.PCDCPFactory( urlTemplate=args.input_pcdcp_url, observatory=args.observatory, type=args.type, interval=args.interval) else: print >> sys.stderr, 'Missing required input directive.' # Output Factory if args.output_iaga_file is not None: outputfactory = iaga2002.StreamIAGA2002Factory( stream=open(args.output_iaga_file, 'wb'), observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_iaga_stdout: outputfactory = iaga2002.StreamIAGA2002Factory( stream=sys.stdout, observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_iaga_url is not None: outputfactory = iaga2002.IAGA2002Factory( urlTemplate=args.output_iaga_url, observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_pcdcp_file is not None: outputfactory = pcdcp.StreamPCDCPFactory( stream=open(args.output_pcdcp_file, 'wb'), observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_pcdcp_stdout: outputfactory = pcdcp.StreamPCDCPFactory( stream=sys.stdout, observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_pcdcp_url is not None: outputfactory = pcdcp.PCDCPFactory( urlTemplate=args.output_pcdcp_url, observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_edge is not None: locationcode = args.outlocationcode or args.locationcode or None outputfactory = edge.EdgeFactory( host=args.output_edge, port=args.output_edge_read_port, write_port=args.edge_write_port, observatory=args.observatory, type=args.type, interval=args.interval, locationCode=locationcode, tag=args.output_edge_tag, forceout=args.output_edge_forceout) else: print >> sys.stderr, "Missing required output directive" if args.xyz is not None: algorithm = XYZAlgorithm(informat=args.xyz[0], outformat=args.xyz[1]) elif args.deltaf is not None: algorithm = DeltaFAlgorithm(informat=args.deltaf) else: # TODO get smarter on inchannels/outchannels since input doesn't always # need to use the --inchannels argument, but might (as in iaga2002), # get it from the file. algorithm = Algorithm(inchannels=args.inchannels, outchannels=args.outchannels or args.inchannels) # TODO check for unused arguments. if (args.realtime): now = UTCDateTime() args.endtime = UTCDateTime(now.year, now.month, now.day, now.hour, now.minute) if args.interval == 'minute': args.starttime = args.endtime - 3600 else: args.starttime = args.endtime - 600 print args.starttime, args.endtime controller = Controller(inputfactory, outputfactory, algorithm) if args.update: controller.run_as_update(args) else: controller.run(args)
def main(args): """command line factory for geomag algorithms Inputs ------ use geomag.py --help to see inputs, or see parse_args. Notes ----- parses command line options using argparse, then calls the controller with instantiated I/O factories, and algorithm(s) """ # Input Factory if args.input_edge is not None: inputfactory = edge.EdgeFactory(host=args.input_edge, port=args.input_edge_port, observatory=args.observatory, type=args.type, interval=args.interval, locationCode=args.locationcode) elif args.input_iaga_file is not None: inputfactory = iaga2002.StreamIAGA2002Factory( stream=open(args.input_iaga_file, 'r'), observatory=args.observatory, type=args.type, interval=args.interval) # TODO remove magweb option elif args.input_iaga_magweb: inputfactory = iaga2002.MagWebFactory(observatory=args.observatory, type=args.type, interval=args.interval) elif args.input_iaga_stdin: inputfactory = iaga2002.StreamIAGA2002Factory( stream=sys.stdin, observatory=args.observatory, type=args.type, interval=args.interval) elif args.input_iaga_url is not None: inputfactory = iaga2002.IAGA2002Factory( urlTemplate=args.input_iaga_url, observatory=args.observatory, type=args.type, interval=args.interval) elif args.input_imfv283_file is not None: inputfactory = imfv283.StreamIMFV283Factory( stream=open(args.input_imfv283_file, 'r'), observatory=args.observatory) elif args.input_imfv283_goes: inputfactory = imfv283.GOESIMFV283Factory( directory=args.input_goes_directory, getdcpmessages=args.input_goes_getdcpmessages, observatory=args.observatory, server=args.input_goes_server, user=args.input_goes_user) elif args.input_imfv283_stdin: inputfactory = imfv283.StreamIMFV283Factory( stream=sys.stdin, observatory=args.observatory) elif args.input_imfv283_url is not None: inputfactory = imfv283.IMFV283Factory( urlTemplate=args.input_imfv283_url, observatory=args.observatory) elif args.input_pcdcp_file is not None: inputfactory = pcdcp.StreamPCDCPFactory(stream=open( args.input_pcdcp_file, 'r'), observatory=args.observatory, type=args.type, interval=args.interval) elif args.input_pcdcp_stdin: inputfactory = pcdcp.StreamPCDCPFactory(stream=sys.stdin, observatory=args.observatory, type=args.type, interval=args.interval) elif args.input_pcdcp_url is not None: inputfactory = pcdcp.PCDCPFactory(urlTemplate=args.input_pcdcp_url, observatory=args.observatory, type=args.type, interval=args.interval) else: print >> sys.stderr, 'Missing required input directive.' # Output Factory if args.output_iaga_file is not None: outputfactory = iaga2002.StreamIAGA2002Factory( stream=open(args.output_iaga_file, 'wb'), observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_iaga_stdout: outputfactory = iaga2002.StreamIAGA2002Factory( stream=sys.stdout, observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_iaga_url is not None: outputfactory = iaga2002.IAGA2002Factory( urlTemplate=args.output_iaga_url, observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_pcdcp_file is not None: outputfactory = pcdcp.StreamPCDCPFactory(stream=open( args.output_pcdcp_file, 'wb'), observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_pcdcp_stdout: outputfactory = pcdcp.StreamPCDCPFactory(stream=sys.stdout, observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_pcdcp_url is not None: outputfactory = pcdcp.PCDCPFactory(urlTemplate=args.output_pcdcp_url, observatory=args.observatory, type=args.type, interval=args.interval) elif args.output_edge is not None: locationcode = args.outlocationcode or args.locationcode or None outputfactory = edge.EdgeFactory(host=args.output_edge, port=args.output_edge_read_port, write_port=args.edge_write_port, observatory=args.observatory, type=args.type, interval=args.interval, locationCode=locationcode, tag=args.output_edge_tag, forceout=args.output_edge_forceout) elif args.output_plot: outputfactory = PlotTimeseriesFactory() else: print >> sys.stderr, "Missing required output directive" algorithm = algorithms[args.algorithm]() algorithm.configure(args) # TODO check for unused arguments. if (args.realtime): now = UTCDateTime() args.endtime = UTCDateTime(now.year, now.month, now.day, now.hour, now.minute) if args.interval == 'minute': args.starttime = args.endtime - 3600 else: args.starttime = args.endtime - 600 print args.starttime, args.endtime controller = Controller(inputfactory, outputfactory, algorithm) if args.update: controller.run_as_update(args) else: controller.run(args)