def test_process_reverse_polarity(): """algorithm_test.AdjustedAlgorithm_test.test_process() Check adjusted data processing versus files generated from original script. Tests reverse polarity martix. """ # load adjusted data transform matrix and pier correction a = adj( statefile="etc/adjusted/adjbou_state_HE_.json", inchannels=["H", "E"], outchannels=["H", "E"], ) # load boulder May 20 files from /etc/ directory with open("etc/adjusted/BOU202005vmin.min") as f: raw = i2.IAGA2002Factory().parse_string(f.read()) with open("etc/adjusted/BOU202005adj.min") as f: expected = i2.IAGA2002Factory().parse_string(f.read()) # process he(raw) channels with loaded transform adjusted = a.process(raw) # compare channels from adjusted and expected streams assert_almost_equal( actual=adjusted.select(channel="H")[0].data, desired=expected.select(channel="H")[0].data, decimal=2, ) assert_almost_equal( actual=adjusted.select(channel="E")[0].data, desired=expected.select(channel="E")[0].data, decimal=2, )
def test_process(): """algorithm_test.DbDtAlgorithm.test_process() Check DbDt result versus files generated from original script """ # initialize DbDt object dbdt = DbDtAlgorithm(inchannels=["H"], outchannels=["H_DT"], period=60) # load boulder May 20 files from /etc/ directory hez_iaga2002_file = open("etc/dbdt/BOU202005vmin.min") hez_iaga2002_string = hez_iaga2002_file.read() hez_dbdt_iaga2002_file = open("etc/dbdt/BOU202005dbdt.min") hez_dbdt_iaga2002_string = hez_dbdt_iaga2002_file.read() factory = i2.IAGA2002Factory() hez = factory.parse_string(hez_iaga2002_string) hez_dbdt = factory.parse_string(hez_dbdt_iaga2002_string) # process hez (raw) channels with dbdt algorithm result = dbdt.process(hez) # unpack channels from result rh = result.select(channel="H_DT")[0] # unpack channels from BOU202005dbdt.min h = hez_dbdt.select(channel="H")[0] assert_almost_equal(h.data, rh.data, 2)
def main(): """Example loading IAGA2002 test data from a directory.""" iaga_dir = path.normpath(path.join(script_dir, '../etc/iaga2002')) factory = iaga2002.IAGA2002Factory('file://' + iaga_dir + '/%(OBS)s/%(interval)s%(type)s/%(obs)s%(ymd)s%(t)s%(i)s.%(i)s', observatory='BOU', channels=('H', 'D', 'Z', 'F'), interval='minute', type='variation') timeseries = factory.get_timeseries( UTCDateTime('2014-11-01'), UTCDateTime('2014-11-02')) print(timeseries)
def test_process_XYZF(): """algorithm_test.AdjustedAlgorithm_test.test_process() Check adjusted data processing versus files generated from original script """ # load adjusted data transform matrix and pier correction a = adj(statefile="etc/adjusted/adjbou_state_.json") # load boulder Jan 16 files from /etc/ directory with open("etc/adjusted/BOU201601vmin.min") as f: raw = i2.IAGA2002Factory().parse_string(f.read()) with open("etc/adjusted/BOU201601adj.min") as f: expected = i2.IAGA2002Factory().parse_string(f.read()) # process hezf (raw) channels with loaded transform adjusted = a.process(raw) # compare channels from adjusted and expected streams assert_almost_equal( actual=adjusted.select(channel="X")[0].data, desired=expected.select(channel="X")[0].data, decimal=2, ) assert_almost_equal( actual=adjusted.select(channel="Y")[0].data, desired=expected.select(channel="Y")[0].data, decimal=2, ) assert_almost_equal( actual=adjusted.select(channel="Z")[0].data, desired=expected.select(channel="Z")[0].data, decimal=2, ) assert_almost_equal( actual=adjusted.select(channel="F")[0].data, desired=expected.select(channel="F")[0].data, decimal=2, )
def main(): """Example loading IAGA2002 test data from a directory.""" iaga_dir = path.normpath(path.join(script_dir, "../etc/iaga2002")) factory = iaga2002.IAGA2002Factory( "file://" + iaga_dir + "/%(OBS)s/%(interval)s%(type)s/%(obs)s%(ymd)s%(t)s%(i)s.%(i)s", observatory="BOU", channels=("H", "D", "Z", "F"), interval="minute", type="variation", ) timeseries = factory.get_timeseries( UTCDateTime("2014-11-01"), UTCDateTime("2014-11-02") ) print(timeseries)
def test_process(): """algorithm_test.AdjustedAlgorithm_test.test_process() Check adjusted data processing versus files generated from original script """ matrix = None pier_correction = None # load adjusted data transform matrix and pier correction a = adj(matrix, pier_correction, 'etc/adjusted/adjbou_state_.json') # load boulder Jan 16 files from /etc/ directory hezf_iaga2002_file = open('etc/adjusted/BOU201601vmin.min') hezf_iaga2002_string = hezf_iaga2002_file.read() xyzf_iaga2002_file = open('etc/adjusted/BOU201601adj.min') xyzf_iaga2002_string = xyzf_iaga2002_file.read() factory = i2.IAGA2002Factory() hezf = factory.parse_string(hezf_iaga2002_string) xyzf = factory.parse_string(xyzf_iaga2002_string) # process hezf (raw) channels with loaded transform adj_bou = a.process(hezf) # unpack channels from loaded adjusted data file x = xyzf.select(channel='X')[0] y = xyzf.select(channel='Y')[0] z = xyzf.select(channel='Z')[0] f = xyzf.select(channel='F')[0] # unpack channels from adjusted processing of raw data x_adj = adj_bou.select(channel='X')[0] y_adj = adj_bou.select(channel='Y')[0] z_adj = adj_bou.select(channel='Z')[0] f_adj = adj_bou.select(channel='F')[0] for r in range(hezf[0].data.size): assert_almost_equals(x.data[r], x_adj.data[r], 1) assert_almost_equals(y.data[r], y_adj.data[r], 1) assert_almost_equals(z.data[r], z_adj.data[r], 1) assert_almost_equals(f.data[r], f_adj.data[r], 1)
def test_process(): """ Check one minute filter data processing versus files generated from original script """ # load boulder Jan 16 files from /etc/ directory min_iaga2002_file = open('etc/filter/BOU20180901vmin.min') min_iaga2002_string = min_iaga2002_file.read() min_iaga2002_file.close() sec_iaga2002_file = open('etc/filter/BOU20180901vsec.sec') sec_iaga2002_string = sec_iaga2002_file.read() sec_iaga2002_file.close() factory = i2.IAGA2002Factory() mint = factory.parse_string(min_iaga2002_string) sec = factory.parse_string(sec_iaga2002_string) # process hezf (raw) channels with loaded transform a = filt(inchannels=('H', 'E', 'Z', 'F'), outchannels=('H', 'E', 'Z', 'F')) filt_bou = a.process(sec) # unpack channels from loaded minutes data file u = mint.select(channel='H')[0] v = mint.select(channel='E')[0] w = mint.select(channel='Z')[0] f = mint.select(channel='F')[0] # unpack channels from filtered data u_filt = filt_bou.select(channel='H')[0] v_filt = filt_bou.select(channel='E')[0] w_filt = filt_bou.select(channel='Z')[0] f_filt = filt_bou.select(channel='F')[0] for r in range(mint[0].data.size): assert_almost_equals(u.data[r], u_filt.data[r], 1) assert_almost_equals(v.data[r], v_filt.data[r], 1) assert_almost_equals(w.data[r], w_filt.data[r], 1) assert_almost_equals(f.data[r], f_filt.data[r], 1)