def test_get_time_array(self): """ Should return an array of time values for a single trace. """ fig = plt.figure() ax = fig.add_subplot(111) splt = SEGYPlotManager(ax, self.segy) tr = self.segy.traces[0] # should have npts values npts = splt.get_header_value(tr.header, 'npts') t = splt.get_time_array(tr.header) self.assertEqual(npts, len(t))
def test_get_header_value(self): """ Should be able to use aliases to get unit-converted values from headers. """ fig = plt.figure() ax = fig.add_subplot(111) splt = SEGYPlotManager(ax, self.segy) # should return exact header values when convert_units=False tr = self.segy.traces[0] for alias in splt.SEGY_HEADER_ALIASES: key = splt.SEGY_HEADER_ALIASES[alias] value = splt.get_header_value(tr.header, alias, convert_units=False) _value = tr.header.__getattribute__(key) self.assertEqual(value, _value) # default should return header values in the plot units splt.DISTANCE_UNIT = 'km' alias = 'offset' key = splt.SEGY_HEADER_ALIASES[alias] scaled_value = splt.get_header_value(tr.header, alias) header_value = tr.header.__getattribute__(key) self.assertEqual(np.round(scaled_value, decimals=3), header_value/1000.)
def test_build_header_database(self): """ Should connect to a database for looking up header attributes. """ fig = plt.figure() ax = fig.add_subplot(111) # connecting to a database in memory should not create a file splt = SEGYPlotManager(ax, self.segy, trace_header_database=':memory:') self.assertFalse(os.path.isfile(':memory:')) # connecting to a filename should create a file if it does not exist filename = 'temp.test_build_header_database.sqlite' if os.path.isfile(filename): os.remove(filename) # should not create database if no pickdb is given splt = SEGYPlotManager(ax, self.segy, trace_header_database=filename) self.assertFalse(os.path.isfile(filename)) # should create database if pickdb is given splt = SEGYPlotManager(ax, self.segy, pickdb=self.pickdb, trace_header_database=filename) self.assertTrue(os.path.isfile(filename)) # clean up os.remove(filename) # create plot manager in memory with pickdb splt = SEGYPlotManager(ax, self.segy, pickdb=self.pickdb) # should be able to get primary fields from the picks trace table pick_keys = splt.pickdb._get_primary_fields(splt.pickdb.TRACE_TABLE) self.assertTrue(len(pick_keys) > 0) # pick primary keys should be in the alias dictionary # or be a header attribute header = self.segy.traces[0].header for k in pick_keys: self.assertTrue(k in splt.SEGY_HEADER_ALIASES \ or hasattr(header, k)) # should add header fields for primary keys in the pick database sql = 'SELECT * FROM %s' %splt.sdb.TRACE_TABLE data = splt.sdb.execute(sql) for key in pick_keys: _key = splt._get_header_alias(key) for i,row in enumerate(data): segy_value = splt.get_header_value( self.segy.traces[i].header, key, convert_units=False) db_value = row[_key] self.assertEqual(segy_value, db_value)