Exemplo n.º 1
0
def test_error():
    """Test errors are raised.
    """
    rock = Component(r)

    # No component
    with pytest.raises(LegendError):
        Decor({'colour': 'red'})

    # No decoration
    with pytest.raises(LegendError):
        Decor({'component': rock})

    # Bad colour
    with pytest.raises(LegendError):
        Decor({'colour': 'blurple', 'component': rock})

    # Adding incompatible things
    legend = Legend.from_csv(csv_text)
    with pytest.raises(LegendError):
        legend + rock

    # Tolerance not allowed.
    with pytest.raises(LegendError):
        legend.get_component('#f7e9a7', tolerance=-1)
Exemplo n.º 2
0
def test_decor():
    rock = Component(r)
    rock3 = Component(r3)

    d = Decor({'colour': 'red', 'component': rock})
    d3 = Decor({'colour': 'green', 'component': rock3})

    l = d + d3
    assert isinstance(l, Legend)
    assert len(l) == 2
Exemplo n.º 3
0
def test_decor():
    rock = Component(r)
    rock3 = Component(r3)

    d = Decor({'colour': '#FF0000', 'component': rock})
    d3 = Decor({'colour': 'green', 'component': rock3})

    l = d + d3
    assert isinstance(l, Legend)
    assert len(l) == 2
    assert d.rgb == (255, 0, 0)
Exemplo n.º 4
0
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)
    print(decor.component.summary())
    fig = decor.plot(fmt="{lithology} {colour} {grainsize}")
    return fig
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
def test_decor_errors():
    """Test decor errors.
    """
    rock = Component(r)

    # No component
    with pytest.raises(LegendError):
        Decor({'colour': 'red'})

    # No decoration
    with pytest.raises(LegendError):
        Decor({'component': rock})

    # Bad colour
    with pytest.raises(LegendError):
        Decor({'colour': 'blurple', 'component': rock})
Exemplo n.º 8
0
def test_decor_html():
    """For jupyter notebook
    """
    r = {'lithology': 'sand'}
    rock = Component(r)
    d = {'color': '#267022', 'component': rock, 'width': 3}
    decor = Decor(d)
    component_row = """<tr><td><strong>component</strong></td><td style="color:black; background-color:white"><table><tr><td><strong>lithology</strong></td><td>sand</td></tr></table></td></tr>"""
    hatch_row = """<tr><td><strong>hatch</strong></td><td style="color:black; background-color:white">None</td></tr>"""
    colour_row = """<tr><td><strong>colour</strong></td><td style="color:#ffffff; background-color:#267022">#267022</td></tr>"""
    width_row = """<tr><td><strong>width</strong></td><td style="color:black; background-color:white">3.0</td></tr>"""
    html = decor._repr_html_()
    assert component_row in html
    assert hatch_row in html
    assert colour_row in html
    assert width_row in html
Exemplo n.º 9
0
def test_decor_html():
    """For jupyter notebook
    """
    r = {'lithology': 'sand'}
    rock = Component(r)
    d = {'color': '#267022', 'component': rock, 'width': 3}
    decor = Decor(d)
    component_row = """<tr><td><strong>component</strong></td><td style="color:black; background-color:white"><table><tr><td><strong>lithology</strong></td><td>sand</td></tr></table></td></tr>"""
    hatch_row = """<tr><td><strong>hatch</strong></td><td style="color:black; background-color:white">None</td></tr>"""
    colour_row = """<tr><td><strong>colour</strong></td><td style="color:#FFFFFF; background-color:#267022">#267022</td></tr>"""
    width_row = """<tr><td><strong>width</strong></td><td style="color:black; background-color:white">3.0</td></tr>"""
    html = decor._repr_html_()
    assert component_row in html
    assert hatch_row in html
    assert colour_row in html
    assert width_row in html
Exemplo n.º 10
0
def test_legend():
    """Test all the basics.
    """
    legend = Legend.from_csv(text=csv_text)
    assert legend[0].colour == '#f7e9a6'
    assert legend.max_width == 5
    assert legend.__str__() != ''
    assert legend.__repr__() != ''

    assert len(legend[[3, 4]]) == 2
    assert len(legend[3:5]) == 2

    rock = Component(r)
    assert legend.get_colour(rock) == '#eeeeee'
    assert rock not in legend

    d = Decor({'colour': 'red', 'component': rock})
    length = len(legend)
    legend[3] = d
    assert len(legend) == length
    assert legend[3].component == rock
    assert d in legend

    rock3 = Component(r3)
    assert legend.get_colour(rock3) == '#ffdbba'
    assert legend.get_width(rock3) == 3.0

    c = legend.get_component('#f7e9a6')
    assert c.lithology == 'sandstone'
    c2 = legend.get_component('#f7e9a7', tolerance=30)
    assert c2.lithology == 'sandstone'

    colours = [d.colour for d in legend]
    assert len(colours) == 8

    assert Legend.random(rock3)[0].colour != ''

    l = Legend.random([rock, rock3])
    assert len(l) == 2
    assert getattr(l[-1], 'colour') != ''
    assert l.to_csv() != ''
    assert l.max_width == 0

    l = Legend.random([rock, rock3], width=True, colour='#abcdef')
    assert getattr(l[0], 'colour') == '#abcdef'

    # Test sums.
    summed = legend + l
    assert len(summed) == 10

    summed_again = legend + d
    assert len(summed_again) == 9

    summed_again_again = d + legend
    assert len(summed_again_again) == 9

    # Test equality.
    assert not d == legend
Exemplo n.º 11
0
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)
    print(decor.component.summary())
    fig = decor.plot(fmt="{lithology} {colour} {grainsize}")
    return fig
Exemplo n.º 12
0
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
Exemplo n.º 13
0
def test_decor():
    """Test decor basics.
    """
    rock = Component(r)
    rock3 = Component(r3)

    d = Decor({'colour': '#FF0000', 'component': rock})
    d1 = Decor({'colour': '#F80', 'component': rock3})
    d2 = Decor({'colour': '(255, 128, 0)', 'component': rock3})
    d3 = Decor({'colour': 'orange', 'component': rock3})

    l = d + d3
    assert isinstance(l, Legend)
    assert len(l) == 2
    assert d.rgb == (255, 0, 0)
    assert Decor.random(rock3).colour != ''
    assert d1.colour == '#ff8800'
    assert d2.colour == '#ff8000'
    assert d3.colour == '#ffa500'
Exemplo n.º 14
0
def test_decor():

    r = {'colour': 'grey', 'grainsize': 'vf-f', 'lithology': 'sand'}
    rock = Component(r)

    d = {'color': '#86F0B6', 'component': rock, 'width': 3}
    decor = Decor(d)

    assert decor.component.colour == 'grey'
    assert decor.colour == '#86f0b6'
    assert decor.rgb == (134, 240, 182)
Exemplo n.º 15
0
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
Exemplo n.º 16
0
def test_legend():
    """Test all the basics.
    """
    legend = Legend.from_csv(csv_text)
    assert legend[0].colour == '#f7e9a6'
    assert legend.max_width == 5
    assert legend.__str__() != ''
    assert legend.__repr__() != ''

    assert len(legend[[3, 4]]) == 2
    assert len(legend[3:5]) == 2

    rock = Component(r)
    assert legend.get_colour(rock) == '#eeeeee'
    assert rock not in legend

    d = Decor({'colour': 'red', 'component': rock})
    length = len(legend)
    legend[3] = d
    assert len(legend) == length
    assert legend[3].component == rock
    assert d in legend

    rock3 = Component(r3)
    assert legend.get_colour(rock3) == '#ffdbba'
    assert legend.get_width(rock3) == 3.0

    c = legend.get_component('#f7e9a6')
    assert c.lithology == 'sandstone'
    c2 = legend.get_component('#f7e9a7', tolerance=30)
    assert c2.lithology == 'sandstone'

    colours = [d.colour for d in legend]
    assert len(colours) == 8

    l = Legend.random([rock, rock3])
    assert l != legend
    assert getattr(l[-1], 'colour') != ''
    assert l.to_csv() != ''

    summed = legend + l
    assert len(summed) == 10
Exemplo n.º 17
0
def test_decor():
    """Test decor basics.
    """
    rock = Component(r)
    rock3 = Component(r3)

    d = Decor({'colour': '#FF0000',
               'component': rock})
    d1 = Decor({'colour': '#F80',
               'component': rock3})
    d2 = Decor({'colour': '(255, 128, 0)',
               'component': rock3})
    d3 = Decor({'colour': 'orange',
               'component': rock3})

    l = d + d3
    assert isinstance(l, Legend)
    assert len(l) == 2
    assert d.rgb == (255, 0, 0)
    assert Decor.random(rock3).colour != ''
    assert d1.colour == '#ff8800'
    assert d2.colour == '#ff8000'
    assert d3.colour == '#ffa500'
Exemplo n.º 18
0
# Initializting model using the striplog df
gp.init_data(geo_model, extent, res, surface_points_df=df)

# %%
geo_model.surface_points.df.head()

# %%
geo_model.surfaces

# %%
dec_list = []
for e, i in enumerate(striplog_dict['alpha']):
    dec_list.append(
        Decor({
            '_colour': geo_model.surfaces.df.loc[e, 'color'],
            'width': None,
            'component': i.primary,
            'hatch': None
        }))

# %%
# welly plot with gempy colors
# Create Decor list
dec_list = []
for e, i in enumerate(striplog_dict['alpha']):
    dec_list.append(
        Decor({
            '_colour': geo_model.surfaces.df.loc[e, 'color'],
            'width': None,
            'component': i.primary,
            'hatch': None
        }))
Exemplo n.º 19
0
"""
# 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'
    'hatch': 'o',
    'width': 4