In [1]:
from striplog import Decor
A Decor attaches a display style to a Rock.
In [2]:
print(Decor.__doc__)
We are going to need a Component to make a Decor.
In [3]:
from striplog import Component
r = {'colour': 'grey',
'grainsize': 'vf-f',
'lithology': 'sand',
'porosity': 0.123
}
rock = Component(r)
rock
Out[3]:
In [4]:
d = {'color': '#267022',
'component': rock,
'width': 3}
decor = Decor(d)
decor
Out[4]:
In [5]:
from striplog import Component
r = {'colour': 'grey',
'grainsize': 'vf-f',
'lithology': 'sand',
'porosity': 0.123
}
rock = Component(r)
rock
Out[5]:
Like Rocks, we instantiate Decors with a dict of properties:
In [6]:
d = {'color': '#267022',
'component': rock,
'width': 3}
decor = Decor(d)
decor
Out[6]:
Or instantiate with keyword parameters:
In [7]:
Decor(colour='#86f0b6', component=Component({'colour': 'grey', 'grainsize': 'vf-f', 'porosity': 0.123, 'lithology': 'sand'}), width=3.0)
Out[7]:
You can access its attributes. It has two ways to understand colour:
In [8]:
print("Hex: {}... and RGB: {}".format(decor.colour, decor.rgb))
In [9]:
print(decor)
In [10]:
%matplotlib inline
decor.plot()
In [11]:
decor.hatch = '+'
decor.plot()
There are the standard matplotlib hatch patterns:
In [12]:
hatches = "\/|+x-.o*"
for h in hatches:
Decor({'component': Component({'hatch':h}), 'hatch': h, 'colour': '#eeeeee'}).plot()
And there are some custom ones. These really need to be reconciled and implemented in a more flexible way, perhaps even going as far as a redesign of the mpl implementation.
In [13]:
hatches = "pctLbs!=v^"
for h in hatches:
Decor({'component': Component({'hatch':h}), 'hatch': h, 'colour': '#eeeeee'}).plot(fmt="{hatch}")
We can disaply hatches in a single plot for quick reference:
In [14]:
import matplotlib.pyplot as plt
hatches = ['.', '..', 'o', 'p', 'c', '*', '-', '--', '=', '==', '|',
'||', '!', '!!', '+', '++', '/', '\\', '//', '\\\\', '///',
'\\\\\\', 'x', 'xx', '^', 'v', 't', 'l', 'b', 's']
fig, axs = plt.subplots(figsize=(16,5.25), ncols=10, nrows=3)
fig.subplots_adjust(hspace=0.5)
for ax, h in zip(axs.flatten(), hatches):
ax.set_title(h)
Decor(colour='#eeeeee',
component=Component({'hatch': h}),
hatch=h).plot(fmt='', ax=ax)
In [15]:
from striplog import Legend
print(Legend.__doc__)
We'll define a legend in a CSV file. I can't think of a better way for now. It would be easy to make a web form to facilitate this with, for example, a colour picker. It may not be worth it, though; I imagine one would create one and then leave it alone most of the time.
In [16]:
l = u"""colour, width, component lithology, component colour, component grainsize
#F7E9A6, 3, Sandstone, Grey, VF-F
#FF99CC, 2, Anhydrite, ,
#DBD6BC, 3, Heterolithic, Grey,
#FF4C4A, 2, Volcanic, ,
#86F0B6, 5, Conglomerate, ,
#FF96F6, 2, Halite, ,
#F2FF42, 4, Sandstone, Grey, F-M
#DBC9BC, 3, Heterolithic, Red,
#A68374, 2, Siltstone, Grey,
#A657FA, 3, Dolomite, ,
#FFD073, 4, Sandstone, Red, C-M
#A6D1FF, 3, Limestone, ,
#FFDBBA, 3, Sandstone, Red, VF-F
#FFE040, 4, Sandstone, Grey, C-M
#A1655A, 2, Siltstone, Red,
#363434, 1, Coal, ,
#664A4A, 1, Mudstone, Red,
#666666, 1, Mudstone, Grey, """
In [17]:
legend = Legend.from_csv(text=l)
legend[:5]
Out[17]:
Duplicate lithologies will result in a warning. To avoid strange results, you should fix the problem by removing duplicates.
In [18]:
l = u"""colour, component lithology
#F7E9A6, Sandstone
#F2FF42, Sandstone
#FF99CC, Anhydrite
#DBD6BC, Heterolithic
#FF4C4A, Volcanic
#86F0B6, Conglomerate
#FFD073, Sandstone
"""
In [19]:
Legend.from_csv(text=l)
Out[19]:
We can also export a legend as CSV text:
In [20]:
print(legend.to_csv())
In [21]:
legend = Legend.builtin('nsdoe')
legend
Out[21]:
There is also a default legend, which you can call with Legend.default() (no arguments).
In [22]:
Legend.default()
Out[22]:
There are also default timescales:
In [23]:
time = Legend.default_timescale()
time[:10]
Out[23]:
In [24]:
from IPython.display import Image
Image('z_Lithology_legend_gapless2.png', width=15)
Out[24]:
In [25]:
liths = [
'Conglomerate',
'Sandstone',
'Sandstone',
'Sandstone',
'Sandstone',
'Sandstone',
'Siltstone',
'Siltstone',
'Heterolithic',
'Heterolithic',
'Mudstone',
'Mudstone',
'Limestone',
'Dolomite',
'Anhydrite',
'Halite',
'Coal',
'Volcanic',
'NULL',
]
colours = [
None,
'Grey',
'Red',
'Grey',
'Grey',
'Red',
'Grey',
'Red',
'Grey',
'Red',
'Grey',
'Red',
None,
None,
None,
None,
None,
None,
None,
]
In [26]:
components = [Component({'lithology': l, 'colour': c}) for l, c in zip(liths, colours)]
In [27]:
Legend.from_image('z_Lithology_legend_gapless2.png', components).plot()
The legend is basically a query table. We can ask the Legend what colour to use for a given Rock object:
In [28]:
legend.get_colour(rock)
Out[28]:
In [29]:
rock3 = Component({'colour': 'red',
'grainsize': 'vf-f',
'lithology': 'sandstone'})
legend.get_colour(rock3)
Out[29]:
In [30]:
Legend.random(rock3)
Out[30]:
Sometimes we also want to use a width for a given lithology:
In [31]:
legend.get_width(rock3)
Out[31]:
We can also ask the legend which Rock is represented by a particular colour. (I doubt you'd ever really need to do this, but I had to implement this to allow you to make a Striplog from an image: it looks up the rocks to use by colour.)
In [32]:
legend.get_component('#f7e9a6')
Out[32]:
The Legend behaves more or less like a list, so we can index into it:
In [33]:
legend[3:5]
Out[33]:
Legends can plot themselves.
In [34]:
legend.plot()
Sometimes you don't want to have to make a legend, so you can use a random one. Just pass a list of Components...
In [35]:
# We'll scrape a quick list of 7 components from the default legend:
c = [d.component for d in legend[:7]]
l = Legend.random(c)
l.plot()
There is a default colour table for geological timescales too... it's based on the Wikipedia's colour scheme for the geological timetable.
In [36]:
time[74:79].plot(fmt="{age!t}") # Pass a format for proper case
In [37]:
hatchy = """colour,width,hatch,component colour,component grainsize,component lithology
#dddddd,1,+,,,siltstone,
#dddddd,1,+++,,,greywacke,
#dddddd,2,x,,,anhydrite,
#dddddd,2,xxx,,,gypsum,
#dddddd,3,/,,,missing,
#dddddd,4,..,,,sandstone,
#dddddd,5,o,,,conglomerate,
#dddddd,5,0,,,till,
#dddddd,6,---,,,mudstone,
#dddddd,7,,,,limestone,
"""
Legend.from_csv(text=hatchy).plot()
In [38]:
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(3, 10))
for i, d in enumerate(l):
ax = fig.add_subplot(len(l), 1, i+1)
ax = d.plot(ax=ax)
©2015 Agile Geoscience. Licensed CC-BY. striplog.py