from striplog import Decor

"""
Explanation: Display objects
A striplog depends on a hierarchy of objects. This notebook shows the objects related to display:

Decor: One element from a legend — describes how to display a Rock.
Legend: A set of Decors — describes how to display a set of Rocks or a Striplog.

<hr />

Decor
End of explanation
"""


print(Decor.__doc__)

"""
Explanation: A Decor attaches a display style to a Rock.
End of explanation
"""


from striplog import Component
r = {'colour': 'grey',
     'grainsize': 'vf-f',
     'lithology': 'sand'}
rock = Component(r)
rock

"""
Explanation: We are going to need a Component to make a Decor.
End of explanation
"""


d = {'color': '#86F0B6',
     'component': rock,
     'width': 3}
decor = Decor(d)
decor

"""
Explanation: Like Rocks, we instantiate Decors with a dict of properties:
End of explanation
"""


decor.colour

decor.rgb

%matplotlib inline
decor.plot()

"""
Explanation: You can access its attributes. It has two ways to understand colour:
End of explanation
"""


from striplog import Legend
print(Legend.__doc__)

"""
Explanation: <hr />

Legend
End of explanation
"""


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, """

legend = Legend.from_csv(l)
legend[:5]

legend = Legend.default()
print(legend.to_csv())

"""
Explanation: 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.
End of explanation
"""


Legend.default()

"""
Explanation: In fact, this is the default legend.
End of explanation
"""


legend.get_colour(rock)

rock3 = Component({'colour': 'red',
           'grainsize': 'vf-f',
           'lithology': 'sandstone'})
legend.get_colour(rock3)

"""
Explanation: We can ask the Legend what colour to use for a given Rock object:
End of explanation
"""


legend.get_width(rock3)

"""
Explanation: Sometimes we also want to use a width for a given lithology:
End of explanation
"""


legend.get_component('#f7e9a6')

"""
Explanation: 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.)
End of explanation
"""


legend[3:5]

"""
Explanation: The Legend behaves more or less like a list, so we can index into it:
End of explanation
"""


legend.plot()

"""
Explanation: Legends can plot themselves.
End of explanation
"""


# 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()

"""
Explanation: Sometimes you don't want to have to make a legend, so you can use a random one. Just pass a list of Components...
End of explanation
"""


