Exemplo n.º 1
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

    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.º 2
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.º 3
0
def test_legend():

    legend = Legend.from_csv(csv_text)
    assert legend[0].colour == '#f7e9a6'
    assert legend.max_width == 5
    assert legend.__str__() != ''
    assert legend.__repr__() != ''

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

    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'

    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.º 4
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.º 5
0
    def plot(self,
             legend=None,
             fig_width=1.5,
             aspect=10,
             width_field=None,
             depth_field=None,
             wentworth='fine',
             exxon_style=False,
             yticks_right=False,
             set_ylim=True,
             xlim=None,
             ax=None,
             **kwargs):
        """
        Plot as a ``Striplog`` of ``Bed``s.

        Parameters
        ----------
        legend: striplog.Legend, optional
            If beds have primary component with 'lithology' field, will use ``defaults.litholegend``, otherwise random.
        fig_width: int, optional
            Width of figure, if creating one.
        aspect: int, optional
            Aspect ratio of figure, if creating one.
        width_field: str or int
            The ``Bed.data``` field or ``Bed.values`` column used to define polyon widths.
        depth_field :
            The ``Bed.data`` field or ``Bed.values`` column defining depths of ``width_field`` samples
        wentworth: one of {'fine', 'coarse'}
            Which Wentworth scale to use for xlabels/ticks.
        exxon_style: bool, optional
            Set to true to invert the x-axis (so GS increases to the left).
        yticks_right: bool, optional
            If True, will move yticks/labels to right side. Defualt=False.
        set_ylim: bool, optional
            Whether to set the y-limits of the ax to [self.start, self.stop]. Default=True.
        **kwargs : optional
            ylabelsize, yticksize, xlabelsize, xlabelrotation
        """
        if legend is None:
            # If beds have lithology, use litholegend
            if hasattr(self[0].primary, 'lithology'):
                legend = defaults.litholegend
            # Fall back to random legend if not
            else:
                legend = Legend.random(self.components)

        # Set up an ax if necessary
        if ax is None:
            return_ax = False
            fig = plt.figure(figsize=(fig_width, aspect * fig_width))
            ax = fig.add_axes([0.35, 0.05, 0.6, 0.95])
        else:
            return_ax = True

        if set_ylim:
            ax.set_ylim([self.start.z, self.stop.z])
            #print('Set_ylim: ', [self.start.z, self.stop.z])

        # Determine xlimits
        if xlim is not None:
            min_width, max_width = xlim
            assert min_width < max_width, f'Is {xlim} a valid `xlim`?'
        elif width_field:
            # Set from the data if possible
            min_width = floor(self.min_field(width_field) - 1)
            max_width = ceil(self.max_field(width_field) + 1)
        else:
            # Fall back to component decors if not
            min_width = min(d.width for d in legend) - 1
            max_width = legend.max_width + 1

        ax.set_xlim([min_width, max_width])
        set_wentworth_ticks(ax, min_width, max_width, wentworth=wentworth)

        # Plot the individual Beds as patches
        for bed in self:
            ax.add_patch(
                bed.as_patch(legend, width_field, depth_field, min_width,
                             max_width, **kwargs))

        # Finalize axis settings
        ybase, ytop = ax.get_ylim()
        if self.order is 'depth' and ytop > ybase:
            ax.invert_yaxis()

        if yticks_right:
            ax.yaxis.set_label_position('right')
            ax.yaxis.tick_right()

        if exxon_style:
            ax.invert_xaxis()

        # Tick params settable with kwargs
        ax.tick_params('y',
                       which='major',
                       labelsize=kwargs.get('ylabelsize', 16),
                       size=kwargs.get('yticksize', 16))
        ax.tick_params('x',
                       which='minor',
                       labelsize=kwargs.get('xlabelsize', 12),
                       labelrotation=kwargs.get('xlabelrotation', 60))

        if return_ax:
            return ax