In [1]:
data = """Comp Formation,Depth
A,100
B,200
C,250
D,400
E,600"""
If you have a CSV file, you can do:
s = Striplog.from_csv(filename=filename)
But we have text, so we do something slightly different, passing the text argument instead. We also pass a stop argument to tell Striplog to make the last unit (E) 50 m thick. (If you don't do this, it will be 1 m thick).
In [2]:
from striplog import Striplog
s = Striplog.from_csv(text=data, stop=650)
Each element of the striplog is an Interval object, which has a top, base and one or more Components, which represent whatever is in the interval (maybe a rock type, or in this case a formation). There is also a data field, which we will use later.
In [3]:
s[0]
Out[3]:
We can plot the striplog. By default, it will use a random legend for the colours:
In [4]:
s.plot(aspect=3)
Or we can plot in the 'tops' style:
In [5]:
s.plot(style='tops', field='formation', aspect=1)
Make some fake data:
In [6]:
from welly import Curve
import numpy as np
basis = np.linspace(0, 699, 700)
data = np.sin(basis/10)
curve = Curve(data=data, basis=basis)
Plot it:
In [7]:
%matplotlib inline
import matplotlib.pyplot as plt
fig, axs = plt.subplots(ncols=2, sharey=True)
axs[0] = s.plot(ax=axs[0])
axs[1] = curve.plot(ax=axs[1])
In [8]:
s.extract(curve, basis=basis, name='GR')
Now we have some the GR data from each unit stored in that unit:
In [9]:
s[1]
Out[9]:
So we could plot a segment of curve, say:
In [10]:
plt.plot(s[1].data['GR'])
Out[10]:
In [11]:
s.extract(curve, basis=basis, name='GRmean', function=np.nanmean)
s[1]
Out[11]:
Other helpful reducing functions:
np.nanmedian — median average (ignoring nans)np.product — productnp.nansum — sum (ignoring nans)np.nanmin — minimum (ignoring nans)np.nanmax — maximum (ignoring nans)scipy.stats.mstats.mode — mode averagescipy.stats.mstats.hmean — harmonic meanscipy.stats.mstats.gmean — geometric meanOr you can write your own, for example:
def trim_mean(a):
"""Compute trimmed mean, trimming min and max"""
return (np.nansum(a) - np.nanmin(a) - np.nanmax(a)) / a.size
Then do:
s.extract(curve, basis=basis, name='GRtrim', function=trim_mean)
The function doesn't have to return a single number like this, it could return anything you like, including a dictionary:
In [12]:
curve.get_stats()
Out[12]:
In [67]:
s.extract(curve, basis=basis, name='GRstats', function=Curve.get_stats)
Now we have a bunch of things in the data dictionary in each Interval:
In [71]:
s[1]
Out[71]:
We can also add bits to the data dictionary manually:
In [70]:
s[1].data['foo'] = 'bar'
s[1]
Out[70]:
In [ ]: