def test_xyzalgorithm_uneccesary_channel_empty(): """XYZAlgorithm_test.test_xyzalgorithm_uneccesary_channel_gaps() confirms the process will run when an uneccesary channel is input but contains gaps or is completely empty. ie. gaps in 'Z' channel or and empty 'F' channel. This also makes sure the 'Z' and 'F' channels are passed without any modification. """ algorithm = XYZAlgorithm('obs', 'mag') timeseries = Stream() timeseries += __create_trace('H', [1, 1]) timeseries += __create_trace('E', [1, 1]) timeseries += __create_trace('Z', [1, np.NaN]) timeseries += __create_trace('F', [np.NaN, np.NaN]) outstream = algorithm.process(timeseries) assert_equals(outstream.select(channel='Z')[0].data.all(), timeseries.select(channel='Z')[0].data.all()) assert_equals(outstream.select(channel='F')[0].data.all(), timeseries.select(channel='F')[0].data.all()) ds = outstream.select(channel='D') # there is 1 trace assert_equals(len(ds), 1) d = ds[0] # d has 2 values (same as input) assert_equals(len(d.data), 2) # d has no NaN values assert_equals(np.isnan(d).any(), False)
def test_xyzalgorithm_uneccesary_channel_empty(): """XYZAlgorithm_test.test_xyzalgorithm_uneccesary_channel_gaps() confirms the process will run when an uneccesary channel is input but contains gaps or is completely empty. ie. gaps in 'Z' channel or and empty 'F' channel. This also makes sure the 'Z' and 'F' channels are passed without any modification. """ algorithm = XYZAlgorithm("obs", "mag") timeseries = Stream() timeseries += __create_trace("H", [1, 1]) timeseries += __create_trace("E", [1, 1]) timeseries += __create_trace("Z", [1, np.NaN]) timeseries += __create_trace("F", [np.NaN, np.NaN]) outstream = algorithm.process(timeseries) assert_equal( outstream.select(channel="Z")[0].data.all(), timeseries.select(channel="Z")[0].data.all(), ) assert_equal( outstream.select(channel="F")[0].data.all(), timeseries.select(channel="F")[0].data.all(), ) ds = outstream.select(channel="D") # there is 1 trace assert_equal(len(ds), 1) d = ds[0] # d has 2 values (same as input) assert_equal(len(d.data), 2) # d has no NaN values assert_equal(np.isnan(d).any(), False)
def test_xyzalgorithm_channels(): """XYZAlgorithm_test.test_xyzalgorithm_channels() confirms that the input/output channels are correct for the given informat/outformat during instantiation. """ algorithm = XYZAlgorithm("obs", "geo") inchannels = ["H", "E", "Z", "F"] outchannels = ["X", "Y", "Z", "F"] assert_equal(algorithm.get_input_channels(), inchannels) assert_equal(algorithm.get_output_channels(), outchannels)
def test_xyzalgorithm_channels(): """XYZAlgorithm_test.test_xyzalgorithm_channels() confirms that the input/output channels are correct for the given informat/outformat during instantiation. """ algorithm = XYZAlgorithm('obs', 'geo') inchannels = ['H', 'E', 'Z', 'F'] outchannels = ['X', 'Y', 'Z', 'F'] assert_equals(algorithm.get_input_channels(), inchannels) assert_equals(algorithm.get_output_channels(), outchannels)
def test_xyzalgorithm_process(): """XYZAlgorithm_test.test_xyzalgorithm_process() confirms that a converted stream contains the correct outputchannels. """ algorithm = XYZAlgorithm("obs", "geo") timeseries = Stream() timeseries += __create_trace("H", [1, 1]) timeseries += __create_trace("E", [1, 1]) timeseries += __create_trace("Z", [1, 1]) timeseries += __create_trace("F", [1, 1]) outputstream = algorithm.process(timeseries) assert_equal(outputstream[0].stats.channel, "X")
def test_xyzalgorithm_process(): """XYZAlgorithm_test.test_xyzalgorithm_process() confirms that a converted stream contains the correct outputchannels. """ algorithm = XYZAlgorithm('obs', 'geo') timeseries = Stream() timeseries += __create_trace('H', [1, 1]) timeseries += __create_trace('E', [1, 1]) timeseries += __create_trace('Z', [1, 1]) timeseries += __create_trace('F', [1, 1]) outputstream = algorithm.process(timeseries) assert_is(outputstream[0].stats.channel, 'X')
def fetch_usgs(out_path, date, stn, type='variation', interval='second', he=False, out_template='{stn}{date:%Y%m%d}v{suffix}.{suffix}'): """ Fetch USGS magnetometer data for *date* at *stn*. Store the data in IAGA2002 format and return the file name (*out_template* serves as a template). Limit to data *type* and *interval*. If *he*, then include the H and E channels in the output (that is, local magnetic north and east components). """ out_fname = os.path.join( out_path, out_template.format(stn=stn.lower(), date=date, suffix=interval[:3])) input_factory = geomagio.edge.EdgeFactory() timeseries = input_factory.get_timeseries( observatory=stn, channels=('H', 'E', 'Z', 'F'), type=type, interval=interval, starttime=UTCDateTime('{date:%Y-%m-%d}T00:00:00Z'.format(date=date)), endtime=UTCDateTime('{date:%Y-%m-%d}T23:59:59Z'.format(date=date))) if all([NP.isnan(trace).all() for trace in timeseries.traces]): raise ValueError('no data for {} on {:%Y-%m-%d} found'.format( stn, date)) # convert from HEZF channels to XYZF channels algorithm = XYZAlgorithm(informat='obs', outformat='geo') xyzf = algorithm.process(timeseries) with open(out_fname, 'w') as fid: output_factory = geomagio.iaga2002.IAGA2002Factory() output_factory.write_file(channels=('H', 'E', 'X', 'Y', 'Z', 'F') if he else ('X', 'Y', 'Z', 'F'), fh=fid, timeseries=xyzf) return out_fname
def test_xyzalgorithm_limited_channels(): """XYZAlgorithm_test.test_xyzalgorithm_limited_channels() confirms that only the required channels are necessary for processing ie. 'H' and 'E' are only needed to get 'X' and 'Y' without 'Z' or 'F' """ algorithm = XYZAlgorithm("obs", "mag") count = 5 timeseries = Stream() timeseries += __create_trace("H", [2] * count) timeseries += __create_trace("E", [3] * count) outstream = algorithm.process(timeseries) ds = outstream.select(channel="D") # there is 1 trace assert_equal(len(ds), 1) d = ds[0] # d has `count` values (same as input) assert_equal(len(d.data), count) # d has no NaN values assert_equal(np.isnan(d).any(), False)
def test_xyzalgorithm_limited_channels(): """XYZAlgorithm_test.test_xyzalgorithm_limited_channels() confirms that only the required channels are necessary for processing ie. 'H' and 'E' are only needed to get 'X' and 'Y' without 'Z' or 'F' """ algorithm = XYZAlgorithm('obs', 'mag') count = 5 timeseries = Stream() timeseries += __create_trace('H', [2] * count) timeseries += __create_trace('E', [3] * count) outstream = algorithm.process(timeseries) ds = outstream.select(channel='D') # there is 1 trace assert_equals(len(ds), 1) d = ds[0] # d has `count` values (same as input) assert_equals(len(d.data), count) # d has no NaN values assert_equals(np.isnan(d).any(), False)