示例#1
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
示例#2
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'
示例#3
0
def test_histogram():
    """Test histogram. This example is from the tutorial.
    """
    lexicon = Lexicon.default()
    striplog = Striplog.from_las3(las3, lexicon=lexicon)
    _, counts = striplog.histogram()
    assert counts == (124, 6, 6, 5, 3)
示例#4
0
def test_histogram():
    """Test histogram. This example is from the tutorial.
    """
    lexicon = Lexicon.default()
    striplog = Striplog.from_las3(las3, lexicon=lexicon)
    _, counts = striplog.histogram()
    assert counts == (124, 6, 6, 5, 3)
示例#5
0
def test_from_csv():
    lexicon = Lexicon.default()
    csv_string = """  200.000,  230.329,  Anhydrite
                      230.329,  233.269,  Grey vf-f sandstone
                      233.269,  234.700,  Anhydrite
                      234.700,  236.596,  Dolomite
                      236.596,  237.911,  Red siltstone
                      237.911,  238.723,  Anhydrite
                      238.723,  239.807,  Grey vf-f sandstone
                      239.807,  240.774,  Red siltstone
                      240.774,  241.122,  Dolomite
                      241.122,  241.702,  Grey siltstone
                      241.702,  243.095,  Dolomite
                      243.095,  246.654,  Grey vf-f sandstone
                      246.654,  247.234,  Dolomite
                      247.234,  255.435,  Grey vf-f sandstone
                      255.435,  258.723,  Grey siltstone
                      258.723,  259.729,  Dolomite
                      259.729,  260.967,  Grey siltstone
                      260.967,  261.354,  Dolomite
                      261.354,  267.041,  Grey siltstone
                      267.041,  267.350,  Dolomite
                      267.350,  274.004,  Grey siltstone
                      274.004,  274.313,  Dolomite
                      274.313,  294.816,  Grey siltstone
                      294.816,  295.397,  Dolomite
                      295.397,  296.286,  Limestone
                      296.286,  300.000,  Volcanic
                    """
    strip2 = Striplog.from_csv(csv_string, lexicon=lexicon)
    assert len(strip2.top) == 7
示例#6
0
def test_lexicon():
    lexicon = Lexicon.default()
    assert lexicon.find_synonym('Halite') == 'salt'

    s = "lt gn ss w/ sp gy sh"
    answer = 'lighter green sandstone with spotty gray shale'
    assert lexicon.expand_abbreviations(s) == answer
示例#7
0
def test_from_csv():
    lexicon = Lexicon.default()
    csv_string = """  200.000,  230.329,  Anhydrite
                      230.329,  233.269,  Grey vf-f sandstone
                      233.269,  234.700,  Anhydrite
                      234.700,  236.596,  Dolomite
                      236.596,  237.911,  Red siltstone
                      237.911,  238.723,  Anhydrite
                      238.723,  239.807,  Grey vf-f sandstone
                      239.807,  240.774,  Red siltstone
                      240.774,  241.122,  Dolomite
                      241.122,  241.702,  Grey siltstone
                      241.702,  243.095,  Dolomite
                      243.095,  246.654,  Grey vf-f sandstone
                      246.654,  247.234,  Dolomite
                      247.234,  255.435,  Grey vf-f sandstone
                      255.435,  258.723,  Grey siltstone
                      258.723,  259.729,  Dolomite
                      259.729,  260.967,  Grey siltstone
                      260.967,  261.354,  Dolomite
                      261.354,  267.041,  Grey siltstone
                      267.041,  267.350,  Dolomite
                      267.350,  274.004,  Grey siltstone
                      274.004,  274.313,  Dolomite
                      274.313,  294.816,  Grey siltstone
                      294.816,  295.397,  Dolomite
                      295.397,  296.286,  Limestone
                      296.286,  300.000,  Volcanic
                    """
    strip2 = Striplog.from_csv(csv_string, lexicon=lexicon)
    assert len(strip2.top) == 7
示例#8
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'
示例#9
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
示例#10
0
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
示例#11
0
def test_histogram():
    """Test histogram. This example is from the tutorial.
    """
    lexicon = Lexicon.default()
    striplog = Striplog.from_las3(las3, lexicon=lexicon)
    thicks, *_ = striplog.histogram(plot=False)  # See test_plots for plots.
    t = [123.005, 7.919, 5.504, 4.022, 2.964]
    assert np.allclose(t, thicks)
示例#12
0
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
示例#13
0
def test_lexicon():
    """All the tests...
    """
    lexicon = Lexicon.default()
    s = lexicon.__str__()
    assert s is not ''
    assert lexicon.__repr__() is not ''
    assert lexicon.find_synonym('Halite') == 'salt'
    assert len(lexicon.categories) == 4

    s = "lt gn ss w/ sp gy sh"
    answer = 'lighter green sandstone with spotty gray shale'
    assert lexicon.expand_abbreviations(s) == answer

    fname = "tutorial/lexicon.json"
    l = Lexicon.from_json_file(fname)
    assert l.__repr__() is not ''
示例#14
0
def test_histogram():
    """Test histogram plot.
    """
    fig, ax = plt.subplots()
    lexicon = Lexicon.default()
    striplog = Striplog.from_las3(las3, lexicon=lexicon)
    *_, ax = striplog.histogram(ax=ax)
    return fig
示例#15
0
    def __init__(self,
                 intervals=None,
                 components=None,
                 name='',
                 legend=None,
                 x_collar=0.,
                 y_collar=0.):
        """
        build a Borehole3D object from Striplog.Intervals list
        
        Parameters
        -----------
        intervals : list
            list of Striplog.Interval object (default = None)
            
        components : 
            (default = None)
        
        name : str 
        
        legend : Striplog Legend object (default = None)
        
        x_collar : float
            X coordinate of the borehole (default = 0)
            
        y_collar : float
            Y coordinate of the borehole (default = 0)
        """

        self.name = name

        if legend is None or not isinstance(legend, Legend):
            self.legend = Legend.default()
        else:
            self.legend = legend

        self.x_collar = x_collar
        self.y_collar = y_collar
        self.omf_legend, self.omf_cmap = striplog_legend_to_omf_legend(
            self.legend)

        if intervals is None:
            lexicon = Lexicon.default()
            with open(ROOT_DIR + '/data/test.las', 'r') as las3:
                default_intv = Striplog.from_las3(las3.read(), lexicon)
                intervals = list(default_intv)
            print("Pay attention that default intervals are actually used !\n")

        self.intervals = intervals
        self.geometry = []

        # instantiation with supers properties
        Striplog.__init__(self, list_of_Intervals=self.intervals)

        # self.uid=uuid #get a unique for identification of borehole in the project

        self.build_geometry()
示例#16
0
def test_from_array():
    lexicon = Lexicon.default()

    a = [(100, 200, 'red sandstone'),
         (200, 250, 'grey shale'),
         (200, 250, 'red sandstone with shale stringers'),
         ]
    s = Striplog.from_array(a, lexicon=lexicon)
    assert s.__str__() != ''
示例#17
0
def test_bar():
    """Test bar plot.
    """
    fig, ax = plt.subplots()
    lexicon = Lexicon.default()
    striplog = Striplog.from_las3(las3, lexicon=lexicon)
    legend = Legend.builtin('nagmdm__6_2')
    ax = striplog.bar(sort=True, legend=legend, ax=ax, align='center')
    return fig
示例#18
0
def test_from_array():
    lexicon = Lexicon.default()

    a = [(100, 200, 'red sandstone'),
         (200, 250, 'grey shale'),
         (200, 250, 'red sandstone with shale stringers'),
         ]
    s = Striplog._from_array(a, lexicon=lexicon)
    assert s.__str__() != ''
示例#19
0
def test_clean_lithology_descriptions():
    lex = Lexicon.default()
    descriptions = [
        'Sand with qtz', 'Sand calc grey fg mg',
        'Clay very sandy, grey greenish, pyritic', 'sandwithclay'
    ]
    x = clean_lithology_descriptions(descriptions, lex)
    assert x[0] == 'sand with quartz'
    assert x[1] == 'sand calcitareous grey fg mg'
    assert x[2] == 'clay very sandy, grey greenish, pyritic'
    assert x[3] == 'sand with clay'
示例#20
0
    def update(self, transect):
        """
        Updates the container data to a profile that intersect the
        transect line.

        Returns nothing. Sets attributes as a side effect.

        Args:
            transect (LineString): A transect line.
        """
        Notice.info("Updating " + self.__class__.__name__)

        # Preprocess
        prepared = prep(transect.buffer(self.settings['buffer']))

        # Get the intersecting points
        points = filter(prepared.contains, self.lookup.keys())

        self.reset_data()
        self.names = []

        for point in points:
            name = self.lookup[point]
            self.names.append(name)
            print name,

            pattern = "^" + name + "_out.las"
            for fname in utils.walk(self.well_dir, pattern):
                # This is a loop but there should only be one matching file.
                well = Well(fname, null_subs=np.nan)
                print well.curves.names
                self.data.append(well)
                self.log_lookup[name] = self.data[-1]

            if not self.log_lookup.get(name):
                print
                self.data.append(None)

            sl_name = getattr(self, 'striplog', None)
            sl = None
            if sl_name and (name == self.feature_well):
                lexicon = Lexicon.default()
                pattern = "^" + name + ".*striplog.las"
                for fname in utils.walk(self.well_dir, pattern):
                    # Load the striplog.
                    sl = Well(fname, lexicon=lexicon, null_subs=np.nan)

                    # Add it to the well
                    self.log_lookup[name].add_striplog(sl.striplog[sl_name],
                                                       sl_name)

            self.coords.append(transect.project(point))
示例#21
0
    def update(self, transect):
        """
        Updates the container data to a profile that intersect the
        transect line.

        Returns nothing. Sets attributes as a side effect.

        Args:
            transect (LineString): A transect line.
        """
        Notice.info("Updating " + self.__class__.__name__)

        # Preprocess
        prepared = prep(transect.buffer(self.settings['buffer']))

        # Get the intersecting points
        points = filter(prepared.contains, self.lookup.keys())

        self.reset_data()
        self.names = []

        for point in points:
            name = self.lookup[point]
            self.names.append(name)
            print name,

            pattern = "^" + name + "_out.las"
            for fname in utils.walk(self.well_dir, pattern):
                # This is a loop but there should only be one matching file.
                well = Well(fname, null_subs=np.nan)
                print well.curves.names
                self.data.append(well)
                self.log_lookup[name] = self.data[-1]

            if not self.log_lookup.get(name):
                print
                self.data.append(None)

            sl_name = getattr(self, 'striplog', None)
            sl = None
            if sl_name and (name == self.feature_well):
                lexicon = Lexicon.default()
                pattern = "^" + name + ".*striplog.las"
                for fname in utils.walk(self.well_dir, pattern):
                    # Load the striplog.
                    sl = Well(fname, lexicon=lexicon, null_subs=np.nan)

                    # Add it to the well
                    self.log_lookup[name].add_striplog(sl.striplog[sl_name],
                                                       sl_name)

            self.coords.append(transect.project(point))
示例#22
0
def test_from_array():
    """Test the array route.
    Deprecated.
    """
    lexicon = Lexicon.default()

    a = [(100, 200, 'red sandstone'),
         (200, 250, 'grey shale'),
         (200, 250, 'red sandstone with shale stringers'),
         ]

    with pytest.warns(DeprecationWarning):
        s = Striplog._from_array(a, lexicon=lexicon)

    assert s.__str__() != ''
示例#23
0
def striplog_from_text(filename, lexicon=None):
    """ creates a Striplog object from a las or flat text file
    
    Parameters
    ----------
    Lexicon : dict
              A vocabulary for parsing lithologic or stratigraphic descriptions
              (default set to Lexicon.default() if lexicon is None)
              
    Returns
    -------
    strip: striplog object
    
 
    """

    if lexicon is None:
        lexicon = Lexicon.default()

    if re.compile(r".+\.las").match(filename):
        print(f"File {filename:s} OK! Creation of the striplog ...")
        with open(filename, 'r') as las3:
            strip = Striplog.from_las3(las3.read(), lexicon)

    elif re.compile(r".+\.(csv|txt)").match(filename):
        print(f"File {filename:s} OK! Creation of the striplog ...")
        f = re.DOTALL | re.IGNORECASE
        regex_data = r'start.+?\n(.+?)(?:\n\n+|\n*\#|\n*$)'  # retrieve data of BH

        pattern = re.compile(regex_data, flags=f)
        with open(filename, 'r') as csv:
            text = pattern.search(csv.read()).group(1)
            text = re.sub(r'[\t]+', ';', re.sub(r'(\n+|\r\n|\r)', '\n', text.strip()))
            strip = Striplog.from_descriptions(text, dlm=';', lexicon=lexicon)

    else:
        print("Error! Please check the file extension !")
        raise

    return strip
示例#24
0
def test_from_csv():
    """Test the CSV route.
    """
    lexicon = Lexicon.default()
    strip2 = Striplog.from_csv(csv_intervals, lexicon=lexicon)
    assert len(strip2.top) == 7
示例#25
0
def test_from_csv():
    lexicon = Lexicon.default()
    strip2 = Striplog.from_csv(csv_string, lexicon=lexicon)
    assert len(strip2.top) == 7
示例#26
0
__author__ = 'kiruba'
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import itertools
from striplog import striplog, Legend, Lexicon

legend = Legend.default()
lexicon = Lexicon.default()



csv_string = """  200.000,  230.329,  Anhydrite
  230.329,  233.269,  Grey vf-f sandstone
  233.269,  234.700,  Anhydrite
  234.700,  236.596,  Dolomite
  236.596,  237.911,  Red siltstone
  237.911,  238.723,  Anhydrite
  238.723,  239.807,  Grey vf-f sandstone
  239.807,  240.774,  Red siltstone
  240.774,  241.122,  Dolomite
  241.122,  241.702,  Grey siltstone
  241.702,  243.095,  Dolomite
  243.095,  246.654,  Grey vf-f sandstone
  246.654,  247.234,  Dolomite
  247.234,  255.435,  Grey vf-f sandstone
  255.435,  258.723,  Grey siltstone
  258.723,  259.729,  Dolomite
  259.729,  260.967,  Grey siltstone
  260.967,  261.354,  Dolomite
  261.354,  267.041,  Grey siltstone
示例#27
0
def test_from_descriptions():
    """Test the CSV route.
    """
    lexicon = Lexicon.default()
    strip2 = Striplog.from_descriptions(text=csv_intervals, lexicon=lexicon)
    assert len(strip2.top) == 7
示例#28
0
def test_from_las3():
    """Test the LAS3 route.
    """
    lexicon = Lexicon.default()
    s = Striplog.from_las3(las3, lexicon=lexicon)
    assert len(s) == 14
示例#29
0
def test_from_array():
    lexicon = Lexicon.default()

    a = [(100, 200, "red sandstone"), (200, 250, "grey shale"), (200, 250, "red sandstone with shale stringers")]
    s = Striplog._from_array(a, lexicon=lexicon)
    assert s.__str__() != ""
示例#30
0
def test_from_descriptions():
    """Test the CSV route.
    """
    lexicon = Lexicon.default()
    strip2 = Striplog.from_descriptions(text=csv_intervals, lexicon=lexicon)
    assert len(strip2.unique) == 7
示例#31
0
def test_histogram():
    lexicon = Lexicon.default()
    striplog = Striplog.from_las3(las3, lexicon=lexicon)
    _, counts = striplog.histogram()
    assert counts == (123, 6, 6, 5, 3)
示例#32
0
def test_from_csv():
    lexicon = Lexicon.default()
    strip2 = Striplog.from_csv(csv_string, lexicon=lexicon)
    assert len(strip2.top) == 7
示例#33
0
__author__ = 'kiruba'
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import itertools
from striplog import striplog, Legend, Lexicon

legend = Legend.default()
lexicon = Lexicon.default()

csv_string = """  200.000,  230.329,  Anhydrite
  230.329,  233.269,  Grey vf-f sandstone
  233.269,  234.700,  Anhydrite
  234.700,  236.596,  Dolomite
  236.596,  237.911,  Red siltstone
  237.911,  238.723,  Anhydrite
  238.723,  239.807,  Grey vf-f sandstone
  239.807,  240.774,  Red siltstone
  240.774,  241.122,  Dolomite
  241.122,  241.702,  Grey siltstone
  241.702,  243.095,  Dolomite
  243.095,  246.654,  Grey vf-f sandstone
  246.654,  247.234,  Dolomite
  247.234,  255.435,  Grey vf-f sandstone
  255.435,  258.723,  Grey siltstone
  258.723,  259.729,  Dolomite
  259.729,  260.967,  Grey siltstone
  260.967,  261.354,  Dolomite
  261.354,  267.041,  Grey siltstone
  267.041,  267.350,  Dolomite
  267.350,  274.004,  Grey siltstone
示例#34
0
def test_histogram():
    lexicon = Lexicon.default()
    striplog = Striplog.from_las3(las3, lexicon=lexicon)
    _, counts = striplog.histogram()
    assert counts == (123, 6, 6, 5, 3)