Esempio n. 1
0
def test_fill():
    gappy = Striplog([
        Interval(
            **{
                'top': 0,
                'base': 60,
                'components': [
                    Component({'lithology': 'dolomite'}),
                ]
            }),
        Interval(
            **{
                'top': 65,
                'base': 75,
                'components': [
                    Component({'lithology': 'limestone'}),
                ]
            }),
    ])

    f = gappy.fill(Component({'lithology': 'marl'}))
    assert len(f) == 3
    assert f[1].primary == Component({'lithology': 'marl'})

    f = gappy.fill()
    assert not f[1]
Esempio n. 2
0
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
    assert interval_2 > interval
    answer = '25.00 m of red sandstone'
    assert max(interval, interval_2).summary(fmt=fmt) == answer

    iv = interval_2 + interval
    assert len(iv.components) == 2
    assert iv.base - iv.top == 45.0

    iv = interval + 5
    assert iv.thickness == 25.0

    rock = Component(r)
    iv = interval + rock
    assert len(iv.components) == 2
Esempio n. 3
0
def test_striplog_intersect():
    """Test intersection. This example is from the tutorial.
    """
    chrono = Striplog([
        Interval(**{
            'top': 0,
            'base': 60,
            'components': [Component({'age': 'Holocene'})]
        }),
        Interval(
            **{
                'top': 60,
                'base': 75,
                'components': [Component({'age': 'Palaeogene'})]
            }),
        Interval(
            **{
                'top': 75,
                'base': 100,
                'components': [Component({'age': 'Cretaceous'})]
            }),
    ])
    legend = Legend.builtin('NSDOE')
    imgfile = "tutorial/M-MG-70_14.3_135.9.png"
    strip = Striplog.from_image(imgfile, 14.3, 135.9, legend=legend)
    sands = strip.find('sandstone')
    cretaceous = chrono.find('Palaeogene')
    cret_sand = sands.intersect(cretaceous)
    assert len(cret_sand) == 3
    assert cret_sand.stop.z == 75
Esempio n. 4
0
def test_striplog_union():
    """Test union.
    """
    lappy = Striplog([
        Interval(
            **{
                'top': 0,
                'base': 60,
                'components': [
                    Component({'lithology': 'dolomite'}),
                ]
            }),
        Interval(
            **{
                'top': 55,
                'base': 75,
                'components': [
                    Component({'lithology': 'limestone'}),
                ]
            }),
    ])
    lippy = Striplog([
        Interval(
            **{
                'top': 0,
                'base': 30,
                'components': [
                    Component({'lithology': 'marl'}),
                ]
            }),
    ])
    u = lappy.union(lippy)
    assert len(u) == 2
    assert len(u[0].components) == 2
Esempio n. 5
0
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
    assert interval_2 > interval
    answer = '25.00 m of red sandstone'
    assert max(interval, interval_2).summary(fmt=fmt) == answer

    iv = interval_2 + interval
    assert len(iv.components) == 2
    assert iv.base - iv.top == 45.0

    iv = interval + 5
    assert iv.thickness == 25.0

    rock = Component(r)
    iv = interval + rock
    assert len(iv.components) == 2
Esempio n. 6
0
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
Esempio n. 7
0
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
Esempio n. 8
0
def test_striplog():
    """Test most of the things.
    """
    r1 = Component({'lithology': 'sand'})
    r2 = Component({'lithology': 'shale'})
    r3 = Component({'lithology': 'limestone'})

    # Bottom up: elevation order
    iv1 = Interval(120, 100, components=[r1])
    iv2 = Interval(150, 120, components=[r2])
    iv3 = Interval(180, 160, components=[r1, r2])
    iv4 = Interval(200, 180, components=[r3, r2])

    s1 = Striplog([iv1, iv2])
    s2 = Striplog([iv3, iv4])
    s = s1 + s2
    assert s.order == 'elevation'
    assert len(s) == 4
    assert s.start.z == 100
    assert s.stop.z == 200
    assert s.__repr__() is not ''
    assert s.__str__() is not ''

    s_rev = s.invert(copy=True)
    assert s_rev.order == 'depth'
    x = s.invert()
    assert x is None
    assert s.order == 'depth'
    assert s[0] == iv1
    assert s[0].top.z == 100

    # Top down: depth order
    iv1 = Interval(80, 120, components=[r1])
    iv2 = Interval(120, 150, components=[r2])
    iv3 = Interval(180, 200, components=[r1, r2])
    iv4 = Interval(200, 250, components=[r3, r2])

    s = Striplog([iv1, iv2, iv3, iv4])
    assert s.order == 'depth'
    assert len(s) == 4
    assert s.start.z == 80
    assert s.stop.z == 250
    assert s._Striplog__strict()

    l = [iv.thickness for iv in s]
    assert len(l) == 4

    s[2] = Interval(180, 190, components=[r1, r2])
    assert len(s.find_gaps()) == 2

    # Crop.
    x = s.crop((110, 210), copy=True)
    assert x.start.z == 110

    # To csv
    csv = x.to_csv(header=True)
    assert csv[:3] == 'Top'

    # Add.
    assert len(s + iv4) == 5
Esempio n. 9
0
def test_error():
    """ Test the IntervalError.
    """
    lexicon = Lexicon.default()
    interval = Interval(20, 40, "Grey sandstone.", lexicon=lexicon)
    with pytest.raises(IntervalError):
        interval + 'this will raise'
Esempio n. 10
0
def get_interval_list(bh):
    """create a list of interval from a list of boreholeORM ojects
    
    Parameters
    ----------
    bh: list
        list of boreholeORM object
         
    
    Returns
    -------
    interval_list: list
                   list of Interval objects
                   
    """
    interval_list = []
    for i in bh.intervals.values():
        top = Position(upper=i.top.upper,
                       middle=i.top.middle,
                       lower=i.top.lower,
                       x=i.top.x,
                       y=i.top.y)
        base = Position(upper=i.base.upper,
                        middle=i.base.middle,
                        lower=i.base.lower,
                        x=i.top.x,
                        y=i.top.y)
        comp = Component.from_text(i.description)
        interval_list.append(
            Interval(top=top,
                     base=base,
                     description=i.description,
                     components=[comp]))
    return interval_list
Esempio n. 11
0
    def __init__(self, top, base, data, keys=None, **kwargs):
        """
        Parameters
        ----------
        top : float
            Top depth or elevation of bed.
        base : float
            Base depth or elevation of bed.
        data : array or dict-like
            Object from which to populate ``Bed`` data. If an array, must be 1-D or 2-D.
            Supported dict-like types include ``dict`` subclasses, ``pd.Series`` and ``namedtuple`` instances.
        keys : list(str), optional
            If ``data`` is an array, ``keys`` can be a list of string keys corresponding to array columns.
            Columns with a single unique value are collapsed to that value, while multi-value columns are kept as arrays.
            If ``data`` is an array and ``keys`` is ``None``, whole array is added under ``'_values'`` key.
        **kwargs
            Any additional keyword args for ``striplog.Interval`` constructor. (``components``, etc.)
        """

        if hasattr(data, 'to_dict'):        # handle `pd.Series` (e.g., from `df.iterrows()`)
            data = data.to_dict()
        elif hasattr(data, '_asdict'):      # handle `namedtuple` (e.g., from `df.itertuples()`)
            data = data._asdict()

        # `data` must either be dict subclass or np.ndarray now
        if isinstance(data, dict):
            assert all(type(k) is str for k in data.keys()), 'Only string keys allowed for dict-like Bed `data`'
            self.data = data
            _ = self.values     # just to catch bad data

        elif isinstance(data, (np.ndarray, np.generic)):
            data = np.expand_dims(data, 0) if data.ndim == 1 else data
            assert data.ndim == 2, 'Array Bed `data` cannot have more than 2 dimensions'

            if keys:
                assert len(keys) == data.shape[-1], 'Number of `keys` must match columns in array `data`'
            else:
                keys = ['_values']

            self.data = {k : None for k in keys}
            self.values = data

        else:
            raise TypeError(f'Bed `data` type must be array or dict-like, not {type(data)}')

        Interval.__init__(self, top, base=base, data=self.data, **kwargs)
Esempio n. 12
0
def test_striplog_merge():
    """Test merging. This example is from the tutorial.
    """
    lappy = Striplog([Interval(**{'top': 0, 
                                  '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': 100,
                                  'components':[Component({'lithology': 'anhydrite'}),]})
                      ])
    assert lappy.find_overlaps(index=True) == [0, 2]
    assert lappy.merge_overlaps() is None
    assert lappy.find_overlaps() is None
    assert lappy.merge_overlaps() is None
Esempio n. 13
0
def test_striplog():

    r1 = Component({'lithology': 'sand'})
    r2 = Component({'lithology': 'shale'})
    r3 = Component({'lithology': 'limestone'})

    # Bottom up: elevation order
    iv1 = Interval(120, 100, components=[r1])
    iv2 = Interval(150, 120, components=[r2])
    iv3 = Interval(180, 160, components=[r1, r2])
    iv4 = Interval(200, 180, components=[r3, r2])

    s1 = Striplog([iv1, iv2])
    s2 = Striplog([iv3, iv4])
    s = s1 + s2
    assert s.order == 'elevation'
    assert len(s) == 4
    assert s.start == 100
    assert s.stop == 200
    assert s.__repr__() is not ''
    assert s.__str__() is not ''

    # Top down: depth order
    iv1 = Interval(80, 120, components=[r1])
    iv2 = Interval(120, 150, components=[r2])
    iv3 = Interval(180, 200, components=[r1, r2])
    iv4 = Interval(200, 250, components=[r3, r2])

    s = Striplog([iv1, iv2, iv3, iv4])
    assert s.order == 'depth'
    assert len(s) == 4
    assert s.start == 80
    assert s.stop == 250

    l = [iv.thickness for iv in s]
    assert len(l) == 4

    s[2] = Interval(180, 190, components=[r1, r2])
    assert len(s.find_gaps()) == 2

    assert s._Striplog__sort()  # Not used, should probably delete
Esempio n. 14
0
    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,
Esempio n. 15
0
                      274.313,  294.816,  Grey siltstone
                      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.