striplog.legend module#

Defines a legend for displaying components.

copyright

2015 Agile Geoscience

license

Apache 2.0

class striplog.legend.Decor(*params, **kwargs)#

Bases: object

A single display style. A Decor describes how to display a given set of Component properties.

In general, you will not usually use a Decor on its own. Instead, you will want to use a Legend, which is just a list of Decors, and leave the Decors to the Legend.

Parameters

params (dict) –

The parameters you want in the Decor. There must be a Component to attach the decoration to, and at least 1 other attribute. It’s completely up to you, but you probably want at least a colour (hex names like #AAA or #d3d3d3, or matplotlib’s English-language names listed at http://ageo.co/modelrcolour are acceptable.

The only other parameter the class recognizes for now is ‘width’, which is the width of the striplog element.

Example

my_rock = Component({ … }) d = {‘component’: my_rock, ‘colour’: ‘red’} my_decor = Decor(d)

property colour#
property keys#

Returns the keys of the Decor’s dict.

plot(fmt=None, fig=None, ax=None)#

Make a simple plot of the Decor.

Parameters
  • fmt (str) – A Python format string for the component summaries.

  • fig (Pyplot figure) – A figure, optional. Use either fig or ax, not both.

  • ax (Pyplot axis) – An axis, optional. Use either fig or ax, not both.

Returns

fig or ax or None. If you pass in an ax, you get it back. If you pass

in a fig, you get it. If you pass nothing, the function creates a plot object as a side-effect.

classmethod random(component, match_only=None)#

Returns a minimal Decor with a random colour.

property rgb#

Returns an RGB triple equivalent to the hex colour.

class striplog.legend.Legend(list_of_Decors)#

Bases: object

A look-up table to assist in the conversion of Components to a plot colour.

Parameters

list_of_Decors (list) – The decors to collect into a legend. In general, you will want to leave legend building to the constructor class methods, Legend.default(), and Legend.from_csv(text=string). We can add others over time, such as from_xls and so on.

classmethod builtin(name)#

Generate a default legend.

Parameters
  • name (str) – The name of the legend you want. Not case sensitive. ‘nsdoe’: Nova Scotia Dept. of Energy ‘canstrat’: Canstrat ‘nagmdm__6_2’: USGS N. Am. Geol. Map Data Model 6.2 ‘nagmdm__6_1’: USGS N. Am. Geol. Map Data Model 6.1 ‘nagmdm__4_3’: USGS N. Am. Geol. Map Data Model 4.3 ‘sgmc’: USGS State Geologic Map Compilation

  • 'nagmdm__6_2'. (Default) –

Returns

The legend stored in defaults.py.

Return type

Legend

classmethod builtin_timescale(name)#

Generate a default timescale legend. No arguments.

Returns

The timescale stored in defaults.py.

Return type

Legend

default()#

Generate a default legend.

Parameters
  • name (str) – The name of the legend you want. Not case sensitive. ‘nsdoe’: Nova Scotia Dept. of Energy ‘canstrat’: Canstrat ‘nagmdm__6_2’: USGS N. Am. Geol. Map Data Model 6.2 ‘nagmdm__6_1’: USGS N. Am. Geol. Map Data Model 6.1 ‘nagmdm__4_3’: USGS N. Am. Geol. Map Data Model 4.3 ‘sgmc’: USGS State Geologic Map Compilation

  • 'nagmdm__6_2'. (Default) –

Returns

The legend stored in defaults.py.

Return type

Legend

default_timescale()#

Generate a default timescale legend. No arguments.

Returns

The timescale stored in defaults.py.

Return type

Legend

classmethod from_csv(filename=None, text=None)#

Read CSV text and generate a Legend.

Parameters

string (str) – The CSV string.

In the first row, list the properties. Precede the properties of the component with ‘comp ‘ or ‘component ‘. For example:

colour, width, comp lithology, comp colour #FFFFFF, 0, , #F7E9A6, 3, Sandstone, Grey #FF99CC, 2, Anhydrite, … etc

Note

To edit a legend, the easiest thing to do is probably this:

  • legend.to_csv()

  • Edit the legend, call it new_legend.

  • legend = Legend.from_csv(text=new_legend)

classmethod from_image(filename, components, ignore=None, col_offset=0.1, row_offset=2)#

A slightly easier way to make legends from images.

Parameters
  • filename (str) –

  • components (list) –

  • ignore (list) – Colours to ignore, e.g. “#FFFFFF” to ignore white.

  • col_offset (Number) – If < 1, interpreted as proportion of way across the image. If > 1, interpreted as pixels from left.

  • row_offset (int) – Number of pixels to skip at the top of each interval.

classmethod from_striplog(strip, colour='colour', width='width', hatch='hatch', fields=None)#

Creates a legend for a striplog whose components already contain.

Parameters

components (list) – list of components that need to be in the legend

Returns

legend (striplog.Legend)

get_colour(c, default='#eeeeee', match_only=None)#

Get the display colour of a component. Wraps getattr().

Development note:

Cannot define this as a partial() because I want to maintain the order of arguments in getattr().

Parameters
  • c (component) – The component to look up.

  • default (str) – The colour to return in the event of no match.

  • match_only (list of str) – The component attributes to include in the comparison. Default: All of them.

Returns

str. The hex string of the matching Decor in the Legend.

get_component(colour, tolerance=0, default=None)#

Get the component corresponding to a display colour. This is for generating a Striplog object from a colour image of a striplog.

Parameters
  • colour (str) – The hex colour string to look up.

  • tolerance (float) – The colourspace distance within which to match.

  • default (component or None) – The component to return in the event

  • match. (of no) –

Returns

component. The component best matching the provided colour.

get_decor(c, match_only=None)#

Get the decor for a component.

Parameters
  • c (component) – The component to look up.

  • match_only (list of str) – The component attributes to include in the comparison. Default: All of them.

Returns

Decor. The matching Decor from the Legend, or None if not found.

get_width(c, default=0, match_only=None)#

Get the display width of a component. Wraps getattr().

Development note: Cannot define this as a partial() because I want to maintain the order of arguments in getattr().

Parameters
  • c (component) – The component to look up.

  • default (float) – The width to return in the event of no match.

  • match_only (list of str) – The component attributes to include in the comparison. Default: All of them.

Returns

float. The width of the matching Decor in the Legend.

getattr(c, attr, default=None, match_only=None)#

Get the attribute of a component.

Parameters
  • c (component) – The component to look up.

  • attr (str) – The attribute to get.

  • default (str) – What to return in the event of no match.

  • match_only (list of str) – The component attributes to include in the comparison. Default: All of them.

Returns

obj. The specified attribute of the matching Decor in the Legend.

property max_width#

The maximum width of all the Decors in the Legend. This is needed to scale a Legend or Striplog when plotting with widths turned on.

next()#

Retains Python 2 compatibility.

plot(fmt=None, ax=None)#

Make a simple plot of the legend.

Calls Decor.plot() on all of its members.

TODO: Build a more attractive plot.

classmethod random(components, width=False, colour=None, match_only=None)#

Generate a random legend for a given list of components.

Parameters
  • components (list or Striplog) – A list of components. If you pass a Striplog, it will use the primary components. If you pass a component on its own, you will get a random Decor.

  • width (bool) – Also generate widths for the components, based on the order in which they are encountered.

  • colour (str) – If you want to give the Decors all the same colour, provide a hex string.

  • match_only (list) – A list of Component properties to use.

Returns

A legend (or Decor) with random colours.

Return type

Legend or Decor

to_csv()#

Renders a legend as a CSV string.

No arguments.

Returns

The legend as a CSV.

Return type

str

exception striplog.legend.LegendError#

Bases: Exception

Generic error class.