Esempio n. 1
0
def test_from_image():
    legend = Legend.default()
    imgfile = "tutorial/M-MG-70_14.3_135.9.png"
    striplog = Striplog.from_img(imgfile, 200, 300, legend=legend)
    assert len(striplog) == 26
    assert striplog[-1].primary.summary() == 'Volcanic'
    assert np.floor(striplog.find('sandstone').cum) == 15
    assert striplog.depth(260).primary.lithology == 'siltstone'
    assert striplog.to_las3() is not ''
    assert striplog.to_log()[1][5] == 2.0
    assert striplog.cum == 100.0
    assert striplog.thickest().primary.lithology == 'anhydrite'
    assert striplog.thickest(n=7)[1].primary.lithology == 'sandstone'
    assert striplog.thinnest().primary.lithology == 'dolomite'
    assert striplog.thinnest(n=7)[1].primary.lithology == 'siltstone'

    indices = [2, 7, 20]
    del striplog[indices]
    assert len(striplog.find_gaps()) == len(indices)

    striplog.prune(limit=1.0)
    assert len(striplog) == 14

    striplog.anneal()
    assert not striplog.find_gaps()  # Should be None

    rock = striplog.find('sandstone')[1].components[0]
    assert rock in striplog
Esempio n. 2
0
def test_from_image():
    legend = Legend.default()
    imgfile = "tutorial/M-MG-70_14.3_135.9.png"
    striplog = Striplog.from_img(imgfile, 200, 300, legend=legend)
    assert len(striplog) == 26
    assert striplog[-1].primary.summary() == 'Volcanic'
    assert np.floor(striplog.find('sandstone').cum) == 15
    assert striplog.depth(260).primary.lithology == 'siltstone'
    assert striplog.to_las3() is not ''
    assert striplog.to_log()[1][5] == 2.0
    assert striplog.cum == 100.0
    assert striplog.thickest().primary.lithology == 'anhydrite'
    assert striplog.thickest(n=7)[1].primary.lithology == 'sandstone'
    assert striplog.thinnest().primary.lithology == 'dolomite'
    assert striplog.thinnest(n=7)[1].primary.lithology == 'siltstone'

    indices = [2, 7, 20]
    del striplog[indices]
    assert len(striplog.find_gaps()) == len(indices)

    striplog.prune(limit=1.0)
    assert len(striplog) == 14

    striplog.anneal()
    assert not striplog.find_gaps()  # Should be None

    rock = striplog.find('sandstone')[1].components[0]
    assert rock in striplog
Esempio n. 3
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()
Esempio n. 4
0
def test_striplog_plot():
    """
    Tests mpl image of striplog
    """
    legend = Legend.default()

    imgfile = "tutorial/M-MG-70_14.3_135.9.png"

    striplog = Striplog.from_img(imgfile, 14.3, 135.9, legend=legend)

    fig = striplog.thickest(n=5).plot(legend=legend)
    return fig
Esempio n. 5
0
def test_striplog_plot():
    """
    Tests mpl image of striplog
    """
    legend = Legend.default()

    imgfile = "tutorial/M-MG-70_14.3_135.9.png"

    striplog = Striplog.from_img(imgfile, 14.3, 135.9, legend=legend)

    fig = striplog.thickest(n=5).plot(legend=legend)
    return fig
Esempio n. 6
0
def test_well():

    fname = 'tutorial/P-129_out.LAS'
    well = Well(fname)
    assert well.well.DATE.data == '10-Oct-2007'
    assert well.data['GR'][0] == 46.69865036

    legend = Legend.default()
    f = 'tutorial/P-129_280_1935.png'
    name, start, stop = f.strip('.png').split('_')
    striplog = Striplog.from_img(f, float(start), float(stop), legend=legend, tolerance=35)
    well.add_striplog(striplog, "striplog")
    assert well.striplog.striplog.source == 'Image'
    assert well.striplog.striplog.start == 280.0
    assert len(well.striplogs_to_las3()) == 14841
Esempio n. 7
0
def test_well():

    fname = 'tutorial/P-129_out.LAS'
    well = Well(fname)
    assert well.well.DATE.data == '10-Oct-2007'
    assert well.data['GR'][0] == 46.69865036

    legend = Legend.default()
    f = 'tutorial/P-129_280_1935.png'
    name, start, stop = f.strip('.png').split('_')
    striplog = Striplog.from_img(f,
                                 float(start),
                                 float(stop),
                                 legend=legend,
                                 tolerance=35)
    well.add_striplog(striplog, "striplog")
    assert well.striplog.striplog.source == 'Image'
    assert well.striplog.striplog.start == 280.0
    assert len(well.striplogs_to_las3()) == 14841
Esempio n. 8
0
def plot_feature_well(tc, gs):
    """
    Plotting function for the feature well.

    Args:
        tc (TransectContainer): The container for the main plot.
        log (axis): A matplotlib axis.
        gs (GridSpec): A matplotlib gridspec.
    """
    fname = tc.settings['curve_display']

    logs = tc.log.get(tc.feature_well)

    if not logs:
        # There was no data for this well, so there won't be a feature plot.
        Notice.fail("There's no well data for feature well " + tc.feature_well)
        return gs

    Z = logs.data['DEPT']

    curves = ['GR', 'DT',
              'DPHI_SAN',
              'NPHI_SAN',
              'DTS',
              'RT_HRLT',
              'RHOB',
              'DRHO']

    window = tc.settings.get('curve_smooth_window') or 51
    ntracks = 5
    lw = 1.0
    smooth = True
    naxes = 0
    ncurv_per_track = np.zeros(ntracks)

    if getattr(tc.log, 'striplog', None):
        ncurv_per_track[0] = 1

    for curve in curves:
        naxes += 1
        params = get_curve_params(curve, fname)
        ncurv_per_track[params['track']] += 1

    axss = plt.subplot(gs[2:, -5])
    axs0 = [axss, axss.twiny()]
    axs1 = [plt.subplot(gs[2:, -4])]
    axs2 = [plt.subplot(gs[2:, -3])]
    axs3 = [plt.subplot(gs[2:, -2])]
    axs4 = [plt.subplot(gs[2:, -1])]

    axs = [axs0, axs1, axs2, axs3, axs4]

    if getattr(tc.log, 'striplog', None):
        legend = Legend.default()
        try:
            logs.striplog[tc.log.striplog].plot_axis(axs0[0], legend=legend)
        except KeyError:
            # In fact, this striplog doesn't exist.
            Notice.fail("There is no such striplog" + tc.log.striplog)
            # And move on...

    axs0[0].set_ylim([Z[-1], 0])
    label_shift = np.zeros(len(axs))

    for curve in curves:
        try:
            values = logs.data[curve]
        except ValueError:
            Notice.warning("Curve not present: "+curve)
            values = np.empty_like(Z)
            values[:] = np.nan

        params = get_curve_params(curve, fname)
        i = params['track']

        j = 0

        label_shift[i] += 1

        linOrlog = params['logarithmic']

        sxticks = np.array(params['xticks'])
        xticks = np.array(sxticks, dtype=float)
        whichticks = 'major'

        if linOrlog == 'log':
            midline = np.log(np.mean(xticks))
            xpos = midline
            whichticks = 'minor'
        else:
            midline = np.mean(xticks)
            xpos = midline

        if smooth:
            values = utils.rolling_median(values, window)

        if curve == 'GR':
            j = 1  # second axis in first track
            label_shift[i] = 1
            if params['fill_left_cond']:
                # do the fill for the lithology track
                axs[i][j].fill_betweenx(Z, params['xleft'], values,
                                        facecolor=params['fill_left'],
                                        alpha=1.0, zorder=11)

        if (curve == 'DPHI_SAN') and params['fill_left_cond']:
            # do the fill for the neutron porosity track
            try:
                nphi = utils.rolling_median(logs.data['NPHI_SAN'], window)
            except ValueError:
                Notice.warning("No NPHI in this well")
                nphi = np.empty_like(Z)
                nphi[:] = np.nan
            axs[i][j].fill_betweenx(Z,
                                    nphi,
                                    values,
                                    where=nphi >= values,
                                    facecolor=params['fill_left'],
                                    alpha=1.0,
                                    zorder=11)

            axs[i][j].fill_betweenx(Z,
                                    nphi,
                                    values,
                                    where=nphi <= values,
                                    facecolor='#8C1717',
                                    alpha=0.5,
                                    zorder=12)

        if curve == 'DRHO':
            blk_drho = 3.2
            values += blk_drho   # this is a hack to get DRHO on RHOB scale
            axs[i][j].fill_betweenx(Z,
                                    blk_drho,
                                    values,
                                    where=nphi <= values,
                                    facecolor='#CCCCCC',
                                    alpha=0.5,
                                    zorder=12)

        # fill right
        if params['fill_right_cond']:

            axs[i][j].fill_betweenx(Z, values, params['xright'],
                                    facecolor=params['fill_right'],
                                    alpha=1.0, zorder=12)

        # plot curve
        axs[i][j].plot(values, Z, color=params['hexcolor'],
                       lw=lw, zorder=13)

        # set scale of curve
        axs[i][j].set_xlim([params['xleft'], params['xright']])

        # ------------------------------------------------- #
        # curve labels
        # ------------------------------------------------- #

        trans = transforms.blended_transform_factory(axs[i][j].transData,
                                                     axs[i][j].transData)

        magic = -Z[-1] / 12.
        axs[i][j].text(xpos, magic - (magic/4)*(label_shift[i]-1),
                       curve,
                       horizontalalignment='center',
                       verticalalignment='bottom',
                       fontsize=12, color=params['hexcolor'],
                       transform=trans)
        # curve units
        units = '${}$'.format(params['units'])
        if label_shift[i] <= 1:
            axs[i][j].text(xpos, magic*0.5,
                           units,
                           horizontalalignment='center',
                           verticalalignment='top',
                           fontsize=12, color='k',
                           transform=trans)

        # ------------------------------------------------- #
        # scales and tickmarks
        # ------------------------------------------------- #

        axs[i][j].set_xscale(linOrlog)
        axs[i][j].set_ylim([Z[-1], 0])
        axs[i][j].axes.xaxis.set_ticks(xticks)
        axs[i][j].axes.xaxis.set_ticklabels(sxticks, fontsize=8)
        for label in axs[i][j].axes.xaxis.get_ticklabels():
            label.set_rotation(90)
        axs[i][j].tick_params(axis='x', direction='out')
        axs[i][j].xaxis.tick_top()
        axs[i][j].xaxis.set_label_position('top')
        axs[i][j].xaxis.grid(True, which=whichticks,
                             linewidth=0.25, linestyle='-',
                             color='0.75', zorder=100)

        axs[i][j].yaxis.grid(True, which=whichticks,
                             linewidth=0.25, linestyle='-',
                             color='0.75', zorder=100)
        axs[i][j].yaxis.set_ticks(np.arange(0, max(Z), 100))
        if i != 0:
                axs[i][j].set_yticklabels("")

    # ------------------------------------------------- #
    # End of curve loop
    # ------------------------------------------------- #

    # Add Depth label
    axs[0][0].text(0, 1.05, 'MD\n$m$', fontsize='10',
                   horizontalalignment='center',
                   verticalalignment='center',
                   transform=axs[0][0].transAxes)

    axs[0][0].axes.yaxis.get_ticklabels()
    axs[0][0].axes.xaxis.set_ticklabels('')

    for label in axs[0][0].axes.yaxis.get_ticklabels():
            label.set_rotation(90)
            label.set_fontsize(10)

    for label in axs[1][0].axes.xaxis.get_ticklabels():
        label.set_rotation(90)
        label.set_fontsize(10)

    # Add Tops
    try:
        if os.path.exists(tc.tops_file):
            tops = utils.get_tops(tc.tops_file)
            topx = get_curve_params('DT', fname)
            topmidpt = np.amax((topx)['xright'])

            # plot tops
            for i in range(ntracks):

                for mkr, depth in tops.iteritems():

                    # draw horizontal bars at the top position
                    axs[i][-1].axhline(y=depth,
                                       xmin=0.01, xmax=.99,
                                       color='b', lw=2,
                                       alpha=0.5,
                                       zorder=100)

                    # draw text box at the right edge of the last track
                    axs[-1][-1].text(x=topmidpt, y=depth, s=mkr,
                                     alpha=0.5, color='k',
                                     fontsize='8',
                                     horizontalalignment='center',
                                     verticalalignment='center',
                                     zorder=10000,
                                     bbox=dict(facecolor='white',
                                               edgecolor='k',
                                               alpha=0.25,
                                               lw=0.25),
                                     weight='light')

    except AttributeError:
        Notice.warning("No tops for this well")
    except TypeError:
        # We didn't get a tops file so move along.
        print "No tops for this well"

    return gs
Esempio n. 9
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
Esempio n. 10
0
def plot_feature_well(tc, gs):
    """
    Plotting function for the feature well.

    Args:
        tc (TransectContainer): The container for the main plot.
        log (axis): A matplotlib axis.
        gs (GridSpec): A matplotlib gridspec.
    """
    fname = tc.settings['curve_display']

    logs = tc.log.get(tc.feature_well)

    if not logs:
        # There was no data for this well, so there won't be a feature plot.
        Notice.fail("There's no well data for feature well " + tc.feature_well)
        return gs

    Z = logs.data['DEPT']

    curves = [
        'GR', 'DT', 'DPHI_SAN', 'NPHI_SAN', 'DTS', 'RT_HRLT', 'RHOB', 'DRHO'
    ]

    window = tc.settings.get('curve_smooth_window') or 51
    ntracks = 5
    lw = 1.0
    smooth = True
    naxes = 0
    ncurv_per_track = np.zeros(ntracks)

    if getattr(tc.log, 'striplog', None):
        ncurv_per_track[0] = 1

    for curve in curves:
        naxes += 1
        params = get_curve_params(curve, fname)
        ncurv_per_track[params['track']] += 1

    axss = plt.subplot(gs[2:, -5])
    axs0 = [axss, axss.twiny()]
    axs1 = [plt.subplot(gs[2:, -4])]
    axs2 = [plt.subplot(gs[2:, -3])]
    axs3 = [plt.subplot(gs[2:, -2])]
    axs4 = [plt.subplot(gs[2:, -1])]

    axs = [axs0, axs1, axs2, axs3, axs4]

    if getattr(tc.log, 'striplog', None):
        legend = Legend.default()
        try:
            logs.striplog[tc.log.striplog].plot_axis(axs0[0], legend=legend)
        except KeyError:
            # In fact, this striplog doesn't exist.
            Notice.fail("There is no such striplog" + tc.log.striplog)
            # And move on...

    axs0[0].set_ylim([Z[-1], 0])
    label_shift = np.zeros(len(axs))

    for curve in curves:
        try:
            values = logs.data[curve]
        except ValueError:
            Notice.warning("Curve not present: " + curve)
            values = np.empty_like(Z)
            values[:] = np.nan

        params = get_curve_params(curve, fname)
        i = params['track']

        j = 0

        label_shift[i] += 1

        linOrlog = params['logarithmic']

        sxticks = np.array(params['xticks'])
        xticks = np.array(sxticks, dtype=float)
        whichticks = 'major'

        if linOrlog == 'log':
            midline = np.log(np.mean(xticks))
            xpos = midline
            whichticks = 'minor'
        else:
            midline = np.mean(xticks)
            xpos = midline

        if smooth:
            values = utils.rolling_median(values, window)

        if curve == 'GR':
            j = 1  # second axis in first track
            label_shift[i] = 1
            if params['fill_left_cond']:
                # do the fill for the lithology track
                axs[i][j].fill_betweenx(Z,
                                        params['xleft'],
                                        values,
                                        facecolor=params['fill_left'],
                                        alpha=1.0,
                                        zorder=11)

        if (curve == 'DPHI_SAN') and params['fill_left_cond']:
            # do the fill for the neutron porosity track
            try:
                nphi = utils.rolling_median(logs.data['NPHI_SAN'], window)
            except ValueError:
                Notice.warning("No NPHI in this well")
                nphi = np.empty_like(Z)
                nphi[:] = np.nan
            axs[i][j].fill_betweenx(Z,
                                    nphi,
                                    values,
                                    where=nphi >= values,
                                    facecolor=params['fill_left'],
                                    alpha=1.0,
                                    zorder=11)

            axs[i][j].fill_betweenx(Z,
                                    nphi,
                                    values,
                                    where=nphi <= values,
                                    facecolor='#8C1717',
                                    alpha=0.5,
                                    zorder=12)

        if curve == 'DRHO':
            blk_drho = 3.2
            values += blk_drho  # this is a hack to get DRHO on RHOB scale
            axs[i][j].fill_betweenx(Z,
                                    blk_drho,
                                    values,
                                    where=nphi <= values,
                                    facecolor='#CCCCCC',
                                    alpha=0.5,
                                    zorder=12)

        # fill right
        if params['fill_right_cond']:

            axs[i][j].fill_betweenx(Z,
                                    values,
                                    params['xright'],
                                    facecolor=params['fill_right'],
                                    alpha=1.0,
                                    zorder=12)

        # plot curve
        axs[i][j].plot(values, Z, color=params['hexcolor'], lw=lw, zorder=13)

        # set scale of curve
        axs[i][j].set_xlim([params['xleft'], params['xright']])

        # ------------------------------------------------- #
        # curve labels
        # ------------------------------------------------- #

        trans = transforms.blended_transform_factory(axs[i][j].transData,
                                                     axs[i][j].transData)

        magic = -Z[-1] / 12.
        axs[i][j].text(xpos,
                       magic - (magic / 4) * (label_shift[i] - 1),
                       curve,
                       horizontalalignment='center',
                       verticalalignment='bottom',
                       fontsize=12,
                       color=params['hexcolor'],
                       transform=trans)
        # curve units
        units = '${}$'.format(params['units'])
        if label_shift[i] <= 1:
            axs[i][j].text(xpos,
                           magic * 0.5,
                           units,
                           horizontalalignment='center',
                           verticalalignment='top',
                           fontsize=12,
                           color='k',
                           transform=trans)

        # ------------------------------------------------- #
        # scales and tickmarks
        # ------------------------------------------------- #

        axs[i][j].set_xscale(linOrlog)
        axs[i][j].set_ylim([Z[-1], 0])
        axs[i][j].axes.xaxis.set_ticks(xticks)
        axs[i][j].axes.xaxis.set_ticklabels(sxticks, fontsize=8)
        for label in axs[i][j].axes.xaxis.get_ticklabels():
            label.set_rotation(90)
        axs[i][j].tick_params(axis='x', direction='out')
        axs[i][j].xaxis.tick_top()
        axs[i][j].xaxis.set_label_position('top')
        axs[i][j].xaxis.grid(True,
                             which=whichticks,
                             linewidth=0.25,
                             linestyle='-',
                             color='0.75',
                             zorder=100)

        axs[i][j].yaxis.grid(True,
                             which=whichticks,
                             linewidth=0.25,
                             linestyle='-',
                             color='0.75',
                             zorder=100)
        axs[i][j].yaxis.set_ticks(np.arange(0, max(Z), 100))
        if i != 0:
            axs[i][j].set_yticklabels("")

    # ------------------------------------------------- #
    # End of curve loop
    # ------------------------------------------------- #

    # Add Depth label
    axs[0][0].text(0,
                   1.05,
                   'MD\n$m$',
                   fontsize='10',
                   horizontalalignment='center',
                   verticalalignment='center',
                   transform=axs[0][0].transAxes)

    axs[0][0].axes.yaxis.get_ticklabels()
    axs[0][0].axes.xaxis.set_ticklabels('')

    for label in axs[0][0].axes.yaxis.get_ticklabels():
        label.set_rotation(90)
        label.set_fontsize(10)

    for label in axs[1][0].axes.xaxis.get_ticklabels():
        label.set_rotation(90)
        label.set_fontsize(10)

    # Add Tops
    try:
        if os.path.exists(tc.tops_file):
            tops = utils.get_tops(tc.tops_file)
            topx = get_curve_params('DT', fname)
            topmidpt = np.amax((topx)['xright'])

            # plot tops
            for i in range(ntracks):

                for mkr, depth in tops.iteritems():

                    # draw horizontal bars at the top position
                    axs[i][-1].axhline(y=depth,
                                       xmin=0.01,
                                       xmax=.99,
                                       color='b',
                                       lw=2,
                                       alpha=0.5,
                                       zorder=100)

                    # draw text box at the right edge of the last track
                    axs[-1][-1].text(x=topmidpt,
                                     y=depth,
                                     s=mkr,
                                     alpha=0.5,
                                     color='k',
                                     fontsize='8',
                                     horizontalalignment='center',
                                     verticalalignment='center',
                                     zorder=10000,
                                     bbox=dict(facecolor='white',
                                               edgecolor='k',
                                               alpha=0.25,
                                               lw=0.25),
                                     weight='light')

    except AttributeError:
        Notice.warning("No tops for this well")
    except TypeError:
        # We didn't get a tops file so move along.
        print "No tops for this well"

    return gs
Esempio n. 11
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