diff --git a/bin/geomag.py b/bin/geomag.py index 7d055eeee0b6949d7d4736c46eeba9bfec776a54..4586cc2ba7efa877732d7dd88bef39adf1ad76be 100755 --- a/bin/geomag.py +++ b/bin/geomag.py @@ -25,66 +25,12 @@ def main(): Inputs ------ - --input: string - the type of data for input - currently either iaga or edge. - --output: string - the type of data for ouput - currently either iaga or edge. - --starttime: string - formatted as a obspy.core.UTCDateTime object - the starttime for data input/output - --endtime: string - formatted as a obspy.core.UTCDateTime object - the endtime for data input/output - --observatory:string - - --channels: array_like - list of channels - --type: string - data type - --invterval: string - data interval. - --algorithm: string - name of an algorithm to use. - --xyz-informat: string - The input format/coordinate system of the input file. - geo: geographic coordinate system (xyzf) - mag: magnetic north coordinate system (hdzf) - obs: observatory coordinate system (hezf) - obsd: observatory coordinate system (hdzf) - --xyz-outformat: string - The ouput format/coordinate system of the output file. - geo: geographic coordinate system (xyzf) - mag: magnetic north coordinate system (hdzf) - obs: observatory coordinate system (hezf or hdzf) - --input_iaga_magweb: boolean - indicates to use http://magweb.cr.usgs.gov/data/magnetometer/ as the - source of iaga2002 files. - --input_iaga_url: string - url of iaga2002 files to use as the data source. - --input-iaga-urltemplate: string - template for the subdirectories that files are found in. - example: %(OBS)s/%(interval)s%(type)s/ - --input-iaga-filetemplate: string - template for the file name - example: %(obs)s%(ymd)s%(t)s%(i)s.%(i)s - --input-iaga-file: string - the filename of the Iaga2002 file to be read from - --input-iaga-stdin: boolean - indicates the file will be coming from stdin - --output_iaga_file: string - the filename of a new Iaga2002 file to be read to - --output-iaga-url: string - url of directory to write output files in. - --output-iaga-urltemplate: string - template for the subdirectories that files are to be written in. - example: %(OBS)s/%(interval)s%(type)s/ - --output-iaga-filetemplate: string - template for the file name - example: %(obs)s%(ymd)s%(t)s%(i)s.%(i)s - --output-iaga-stdout: boolen - indicates output will go to stdout + see --help from commandline. + + Notes + ----- + parses command line options using argparse, then calls the controller + with instantiated I/O factories, and algorithm(s) """ args = parse_args() @@ -101,16 +47,12 @@ def main(): observatory=args.observatory, type=args.type, interval=args.interval) - elif args.input_iaga_file is not None: - iagaFile = open(args.input_iaga_file, 'r').read() - inputfactory = iaga2002.StreamIAGA2002Factory( - stream=iagaFile, - observatory=args.observatory, - type=args.type, - interval=args.interval) - elif args.input_iaga_stdin: - print >> sys.stderr, "Iaga Input waiting for data from stdin" - iagaFile = sys.stdin.read() + elif args.input_iaga_file is not None or args.input_iaga_stdin: + if args.input_iaga_file is not None: + iagaFile = open(args.input_iaga_file, 'r').read() + else: + print >> sys.stderr, "Iaga Input waiting for data from stdin" + iagaFile = sys.stdin.read() inputfactory = iaga2002.StreamIAGA2002Factory( stream=iagaFile, observatory=args.observatory, diff --git a/geomagio/Algorithm.py b/geomagio/Algorithm.py index 2af8b10343223fafa3a12c34bff6fa39c160b950..b4fbf6e7ae0fa61104ddd080ebde25acce623ed7 100644 --- a/geomagio/Algorithm.py +++ b/geomagio/Algorithm.py @@ -14,8 +14,9 @@ class Algorithm(object): An algorithm processes a stream of timeseries to produce new timeseries. """ - def __init__(self, channels=None): - self._channels = channels + def __init__(self, inchannels=None, outchannels=None): + self._inchannels = inchannels + self._outchannels = outchannels pass def process(self, stream): @@ -41,7 +42,7 @@ class Algorithm(object): array_like list of channels the algorithm needs to operate. """ - return self._channels + return self._inchannels def get_output_channels(self): """Get output channels @@ -51,4 +52,4 @@ class Algorithm(object): array_like list of channels the algorithm will be returning. """ - return self._channels + return self._outchannels diff --git a/geomagio/Controller.py b/geomagio/Controller.py index 93e4ca65ef273b12ca317321d976ed7451f94f87..4a4e846b5bc565bc60ee5cabdc8f1ad45c7bbf05 100644 --- a/geomagio/Controller.py +++ b/geomagio/Controller.py @@ -13,7 +13,7 @@ class Controller(object): algorithm: the algorithm(s) that will take procees the timeseries data """ - def __init__(self, inputFactory, outputFactory, algorithm=None): + def __init__(self, inputFactory, outputFactory, algorithm): self._inputFactory = inputFactory self._algorithm = algorithm self._outputFactory = outputFactory @@ -31,9 +31,6 @@ class Controller(object): input_channels = self._algorithm.get_input_channels() timeseries = self._inputFactory.get_timeseries(starttime, endtime, channels=input_channels) - if self._algorithm is not None: - processed = self._algorithm.process(timeseries) - else: - processed = timeseries + processed = self._algorithm.process(timeseries) output_channels = self._algorithm.get_output_channels() self._outputFactory.put_timeseries(processed, channels=output_channels) diff --git a/geomagio/XYZAlgorithm.py b/geomagio/XYZAlgorithm.py index d71f989e01dee541fc7ba1f81321be595ebf9ea0..0f70c3dd50f444ae608072e3b3e8c9c9f986b5d7 100644 --- a/geomagio/XYZAlgorithm.py +++ b/geomagio/XYZAlgorithm.py @@ -33,7 +33,8 @@ class XYZAlgorithm(Algorithm): """ def __init__(self, informat=None, outformat=None): - Algorithm.__init__(self) + Algorithm.__init__(self, inchannels=CHANNELS[self.informat], + outchannels=CHANNELS[self.outformat]) self.informat = informat self.outformat = outformat @@ -54,26 +55,6 @@ class XYZAlgorithm(Algorithm): return False return True - def get_input_channels(self): - """Get input channels - - Returns - ------- - array_like - list of channels the algorithm needs to operate. - """ - return CHANNELS[self.informat] - - def get_output_channels(self): - """Get output channels - - Returns - ------- - array_like - list of channels the algorithm will be returning. - """ - return CHANNELS[self.outformat] - def process(self, timeseries): """converts a timeseries stream into a different coordinate system