def test_from_text(): rock3 = Component(r3) lexicon = Lexicon.default() s = 'Grey coarse sandstone.' rock4 = Component.from_text(s, lexicon) assert rock3 == rock4 rock5 = Component.from_text(s, lexicon, required='not there') assert not rock5 # Should be None
def test_component_html(): """ For jupyter notebook. Hard to test this because attributes are returned in random order. """ r = {'lithology': 'sand'} rock = Component(r) html = """<table><tr><td><strong>lithology</strong></td><td>sand</td></tr></table>""" assert rock._repr_html_() == html
def test_pattern_fills(): """ Tests mpl image of decors with pattern fills. """ hatches = "pctLbs!=v^" decors = [ Decor({ 'component': Component({'hatch': h}), 'hatch': h, 'colour': '#eeeeee' }) for h in hatches ] fig = plt.figure(figsize=(1, 12)) for i, d in enumerate(decors): ax = fig.add_subplot(len(decors), 1, i + 1) ax = d.plot(ax=ax, fmt='') return fig
def test_summary(): rock = Component(r) s = rock.summary(fmt="My rock: {lithology} ({colour}, {grainsize!u})") assert s == 'My rock: sand (grey, VF-F)' rock6 = Component(r6) s = rock6.summary(fmt="My rock: {lithology}") assert s == 'My rock: _' empty = Component({}) d = "String" assert not empty # Should have False value assert empty.summary(default=d) == d
def test_decor_plot(): """ Tests mpl image of decor. """ r = {'colour': 'grey', 'grainsize': 'vf-f', 'lithology': 'sand'} rock = Component(r) d = {'color': '#86F0B6', 'component': rock, 'width': 3} decor = Decor(d) fig = plt.figure(figsize=(4, 1)) fig = decor.plot(fmt="{lithology!t} {colour} {grainsize}", fig=fig) return fig
def test_interval(): """ Test intervals. """ lexicon = Lexicon.default() interval = Interval(20, 40, "Grey sandstone.", lexicon=lexicon) assert interval.primary.lithology == 'sandstone' fmt = "{colour} {lithology}" answer = '20.00 m of grey sandstone' assert interval.summary(fmt=fmt) == answer interval_2 = Interval(40, 65, "Red sandstone.", lexicon=lexicon) assert interval_2 != interval answer = '20.00 m of grey sandstone' # Max gives uppermost assert max(interval, interval_2).summary(fmt=fmt) == answer iv = interval_2 + interval assert len(iv.components) == 2 assert iv.base.z - iv.top.z == 45.0 rock = Component(r) iv = interval + rock assert len(iv.components) == 2
def test_interval_html(): """For jupyter notebook """ interval = Interval(10, 20, components=[Component(r)]) html_start = '<table><tr><td style="width:2em; background-color:#DDDDDD" rowspan="6"></td><td><strong>top</strong></td><td>10.0</td></tr><tr><td><strong>primary</strong></td><td><table><tr><td><strong>' # Can't test all of it because the component attributes are given in # random order. assert interval._repr_html_()[:187] == html_start # Depth ordered i1 = Interval(top=61, base=62.5, components=[Component({'lithology': 'limestone'})]) i2 = Interval(top=62, base=63, components=[Component({'lithology': 'sandstone'})]) i3 = Interval(top=62.5, base=63.5, components=[Component({'lithology': 'siltstone'})]) i4 = Interval(top=63, base=64, components=[Component({'lithology': 'shale'})]) i5 = Interval(top=63.1, base=63.4, components=[Component({'lithology': 'dolomite'})]) # Elevation ordered i8 = Interval(top=200, base=100, components=[Component({'lithology': 'sandstone'})])
294.816, 295.397, Dolomite 295.397, 296.286, Limestone 296.286, 300.000, Volcanic """ csv_points = """top, porosity 1200, 6.4 1205, 7.3 1210, 8.2 1250, 9.2 1275, 4.3 1300, 2.2""" lappy_list = [Interval(**{'top': 50, 'base': 60, 'components': [Component({'lithology': 'dolomite'}),]}), Interval(**{'top': 55, 'base': 75, 'components': [Component({'lithology': 'limestone'}),]}), Interval(**{'top': 75, 'base': 80, 'components': [Component({'lithology': 'volcanic'}),]}), Interval(**{'top': 78, 'base': 90, 'components': [Component({'lithology': 'anhydrite'}),]}) ] def test_error(): """Test the generic error. """
def test_summary(): rock = Component(r) s = rock.summary(fmt="My rock: {lithology} ({colour}, {GRAINSIZE})") assert s == 'My rock: sand (grey, VF-F)' rock6 = Component(r6) s = rock6.summary(fmt="My rock: {lithology}") assert s == 'My rock: ' empty = Component({}) d = "String" assert not empty # Should have False value assert empty.summary(default=d) == d with pytest.raises(ComponentError): rock.summary(fmt="My rock: {not there}")
def test_init(): rock = Component(r) assert rock.colour == 'grey'
csv_points = """top, porosity 1200, 6.4 1205, 7.3 1210, 8.2 1250, 9.2 1275, 4.3 1300, 2.2""" lappy_list = [ Interval( **{ 'top': 50, 'base': 60, 'components': [ Component({'lithology': 'dolomite'}), ] }), Interval( **{ 'top': 55, 'base': 75, 'components': [ Component({'lithology': 'limestone'}), ] }), Interval( **{ 'top': 75, 'base': 80, 'components': [
def test_integer_comparison(): formations = range(1, 3) table = [Component({'lith': l}) for l in formations] assert (table[0] == table[1]) is False
"topo", "etchegoin", "macoma", "chanac", "mclure", "santa_margarita", "fruitvale", "round_mountain", "olcese", "freeman_jewett", "vedder", "eocene", "cretaceous", "basement", "null" ] colors = dict([("topo", "#cecece"), ("etchegoin", "#00c9d1"), ("macoma", "#007c79"), ("chanac", "#78007a"), ("mclure", "#5263c4"), ("santa_margarita", "#005c2a"), ("fruitvale", "#da4f1f"), ("round_mountain", "#3d270e"), ("olcese", "#cc212d"), ("freeman_jewett", "#ff74a8"), ("vedder", "#ffff00"), ("eocene", "#dc7c62"), ("cretaceous", "#736d1c"), ("basement", "#00b930")]) #components = [Component({'lith': l, 'colour': c}) for l, c in zip(formations, # list(colors.values()))] components = [Component({'lith': l}) for l in formations] def read_borehole_file(path, fix_df=True): """Returns the df with the depths for each borehole in one single row instead instead being each chunck a new row""" df = pd.read_table( path, skiprows=41, header=None, sep='\t', ) df.rename(columns={ 1: 'x', 2: 'y',
Also specify default csv/DataFrame fields to map to `Bed` attributes/data. """ # Zane comments: # Added missing interval decor, but we also need to assign these a default grain size so that they plot. I would assign them a grain size of -4 Psi # added a comment in gs2litho - at the beginning of that comment, there is a f' - is that on purpose? # I didnt yet add missing_interval_decor to component part of gs2litho becasue I'm not sure how we should deal with the grain size of a missing interval... import numpy as np from striplog import Component, Decor, Legend from litholog import wentworth ###+++++++++++++++++++++### ### Default viz objects ### ###+++++++++++++++++++++### mud_decor = Decor({ 'component': Component({'lithology': 'mud'}), 'colour': '#ad8150', # 'xkcd:LightBrown' 'hatch': 'none', 'width': -6, }) sand_decor = Decor({ 'component': Component({'lithology': 'sand'}), 'colour': '#fffe7a', # 'xkcd:LightYellow' 'hatch': '.', 'width': -1 }) gravel_decor = Decor({ 'component': Component({'lithology': 'gravel'}), 'colour': '#ff9408', # 'xkcd:tangerine'
rock = Component(r) iv = interval + rock assert len(iv.components) == 2 def test_interval_html(): """For jupyter notebook """ interval = Interval(10, 20, components=[Component(r)]) html_start = '<table><tr><td style="width:2em; background-color:#DDDDDD" rowspan="6"></td><td><strong>top</strong></td><td>10.0</td></tr><tr><td><strong>primary</strong></td><td><table><tr><td><strong>' # Can't test all of it because the component attributes are given in # random order. assert interval._repr_html_()[:187] == html_start # Depth ordered i1 = Interval(top=61, base=62.5, components=[Component({'lithology': 'limestone'})]) i2 = Interval(top=62, base=63, components=[Component({'lithology': 'sandstone'})]) i3 = Interval(top=62.5, base=63.5, components=[Component({'lithology': 'siltstone'})]) i4 = Interval(top=63, base=64, components=[Component({'lithology': 'shale'})]) i5 = Interval(top=63.1, base=63.4, components=[Component({'lithology': 'dolomite'})]) # Elevation ordered i8 = Interval(top=200, base=100, components=[Component({'lithology': 'sandstone'})]) i7 = Interval(top=150, base=50, components=[Component({'lithology': 'limestone'})]) i6 = Interval(top=100, base=0, components=[Component({'lithology': 'siltstone'})]) def test_interval_invert(): """Test inverting works. """ i = i1.invert(copy=True)