striplog package#

Submodules#

Module contents#

striplog#

class striplog.Component(properties=None)#

Bases: object

Initialize with a dictionary of properties. You can use any properties you want e.g.:

  • lithology: a simple one-word rock type

  • colour, e.g. ‘grey’

  • grainsize or range, e.g. ‘vf-f’

  • modifier, e.g. ‘rippled’

  • quantity, e.g. ‘35%’, or ‘stringers’

  • description, e.g. from cuttings

classmethod from_macrostrat(feature, columns=None)#

Make a Component from a Macrostrat feature dictionary.

classmethod from_text(text, lexicon=None, required=None, first_only=True)#

Generate a Component from a text string, using a Lexicon.

Parameters
  • text (str) – The text string to parse.

  • lexicon (Lexicon) – The dictionary to use for the categories and lexemes.

  • required (str) – An attribute that we must have. If a required attribute is missing from the component, then None is returned.

  • first_only (bool) – Whether to only take the first match of a lexeme against the text string.

Returns

A Component object, or None if there was no

must-have field.

Return type

Component

json()#

Returns a JSON dump of the dictionary representation of the instance.

keys()#

Needed for double-star behaviour, along with __getitem__().

summary(fmt=None, initial=True, default='')#

Given a format string, return a summary description of a component.

Parameters
  • component (dict) – A component dictionary.

  • fmt (str) – Describes the format with a string. If no format is given, you will just get a list of attributes. If you give the empty string (‘’), you’ll get default back. By default this gives you the empty string, effectively suppressing the summary.

  • initial (bool) – Whether to capitialize the first letter. Default is True.

  • default (str) – What to give if there’s no component defined.

Returns

A summary string.

Return type

str

Example

r = Component({‘colour’: ‘Red’,

‘grainsize’: ‘VF-F’, ‘lithology’: ‘Sandstone’})

r.summary() –> ‘Red, vf-f, sandstone’

class striplog.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.Interval(top, base=None, description='', lexicon=None, data=None, components=None, max_component=1, abbreviations=False)#

Bases: object

Used to represent a lithologic or stratigraphic interval, or single point, such as a sample location.

Initialize with a top (and optional base) and a description and/or an ordered list of components.

Parameters
  • top (float) – Required top depth. Required.

  • base (float) – Base depth. Optional.

  • description (str) – Textual description.

  • lexicon (dict) – A lexicon. See documentation. Optional unless you only provide descriptions, because it’s needed to extract components.

  • max_component (int) – The number of components to extract. Default 1.

  • abbreviations (bool) – Whether to parse for abbreviations.

copy()#

Returns a shallow copy of the interval.

difference(other)#

Perform the difference binary operation.

Parameters

other (Interval) – The other Interval.

Returns

Interval. One or two Intervals.

intersect(other, blend=True)#

Perform the intersection binary operation. self must at least partially overlap with other or an IntervalError is raised.

If blend is False, you are essentially replacing self with other.

Parameters
  • other (Interval) – The other Interval.

  • blend (bool) – Whether to blend or not.

Returns

Interval. The intersection of the Interval with the one provided.

invert(copy=False)#

Inverts the interval. If it was depth-ordered (positive numbers increasing downwards.), it will now be elevation-ordered, and vice versa.

Parameters

copy (bool) – Whether to make a copy or not. Default: False.

property kind#

a ‘point’ (where base = top), or an ‘interval’, where thickness > 0.

Returns

Either ‘point’ or ‘interval’.

Return type

str

Type

The type of Interval

property max_thickness#

Returns the maximum possible thickness of the interval, given the uncertainty in its top and base Positions.

Returns

The maximum thickness.

Return type

Float

merge(other, blend=True)#

Perform the merge binary operation. self must at least partially overlap with other or an IntervalError is raised.

If blend is False, you are essentially replacing self with other.

Parameters
  • other (Interval) – The other Interval.

  • blend (bool) – Whether to blend or not.

Returns

Striplog. The merge of the Interval with the one provided.

property middle#

Returns the middle of the interval.

Returns

The middle.

Return type

Float

property min_thickness#

Returns the minimum possible thickness of the interval, given the uncertainty in its top and base Positions.

Returns

The minimum thickness.

Return type

Float

property order#

Gives the order of this interval, based on relative values of top & base.

property primary#

Convenience function returning the first component.

Returns

Component. The first one in the list of components.

relationship(other)#

Returns the relationship style. Completely deterministic.

spans(d)#

Determines if depth d is within this interval.

Parameters

d (float) – Level or ‘depth’ to evaluate.

Returns

bool. Whether the depth is in the interval.

split_at(d)#

Splits an interval.

Parameters

d (float) – Level or ‘depth’ to split at.

Returns

tuple. The two intervals that result from the split.

summary(fmt=None, initial=False)#

Returns a summary of the interval.

Parameters
  • fmt (str) – A format string. Optional.

  • initial (bool) – Whether to capitalize the first letter.

Returns

An English-language summary.

Return type

str

property thickness#

Returns the thickness of the interval.

Returns

The thickness.

Return type

Float

union(other, blend=True)#

Perform the union binary operation. self must at least touch other or an IntervalError is raised.

If blend is False, you are essentially replacing self with other.

Parameters
  • other (Interval) – The other Interval.

  • blend (bool) – Whether to blend or not.

Returns

Interval. The union of the Interval with the one provided.

class striplog.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

class striplog.Lexicon(params)#

Bases: object

A Lexicon is a dictionary of ‘types’ and regex patterns.

Most commonly you will just load the default one.

Parameters

params (dict) – The dictionary to use. For an example, refer to the default lexicon in defaults.py.

property categories#

Lists the categories in the lexicon, except the optional categories.

Returns

A list of strings of category names.

Return type

list

classmethod default()#

Makes the default lexicon, as provided in defaults.py.

Returns

The default lexicon.

Return type

Lexicon

expand_abbreviations(text)#

Parse a piece of text and replace any abbreviations with their full word equivalents. Uses the lexicon.abbreviations dictionary to find abbreviations.

Parameters

text (str) – The text to parse.

Returns

The text with abbreviations replaced.

Return type

str

find_synonym(word)#

Given a string and a dict of synonyms, returns the ‘preferred’ word. Case insensitive.

Parameters

word (str) – A word.

Returns

The preferred word, or the input word if not found.

Return type

str

Example

>>> syn = {'snake': ['python', 'adder']}
>>> find_synonym('adder', syn)
'snake'
>>> find_synonym('rattler', syn)
'rattler'
find_word_groups(text, category, proximity=2)#

Given a string and a category, finds and combines words into groups based on their proximity.

Parameters
  • text (str) – Some text.

  • tokens (list) – A list of regex strings.

Returns

list. The combined strings it found.

Example

COLOURS = [r”red(?:dish)?”, r”grey(?:ish)?”, r”green(?:ish)?”] s = ‘GREYISH-GREEN limestone with RED or GREY sandstone.’ find_word_groups(s, COLOURS) –> [‘greyish green’, ‘red’, ‘grey’]

classmethod from_json_file(filename)#

Load a lexicon from a JSON file.

Parameters

filename (str) – The path to a JSON dump.

get_component(text, required=False, first_only=True)#

Takes a piece of text representing a lithologic description for one component, e.g. “Red vf-f sandstone” and turns it into a dictionary of attributes.

parse_description(text)#

Parse a single description into component-like dictionaries.

split_description(text)#

Split a description into parts, each of which can be turned into a single component.

class striplog.Markov_chain(observed_counts, states=None, step=1, include_self=None)#

Bases: object

Markov_chain object.

as_graph(directed=True)#
chi_squared(q=0.95)#

The chi-squared statistic for the given transition frequencies.

Also returns the critical statistic at the given confidence level q (default 95%).

If the first number is bigger than the second number, then you can reject the hypothesis that the sequence is randomly ordered.

Parameters

q (float) – The confidence level, as a float in the range 0 to 1. Default: 0.95.

Returns

The chi-squared statistic.

Return type

float

property degrees_of_freedom: int#
property expected_freqs#
classmethod from_sequence(sequence, states=None, strings_are_states=False, include_self=False, step=1)#

Parse a sequence and make the transition matrix of the specified order.

Provide sequence(s) ordered in upwards direction.

Parameters
  • sequence (list-like) – A list-like, or list-like of list-likes. The inner list-likes represent sequences of states. For example, can be a string or list of strings, or a list or list of lists.

  • states (list-like) – A list or array of the names of the states. If not provided, it will be inferred from the data.

  • strings_are_states (bool) –

    rue if the strings are themselves states (i.e. words or tokens) and not sequences of one-character states. For example, set to True if you provide something like:

    [‘sst’, ‘mud’, ‘mud’, ‘sst’, ‘lst’, ‘lst’]

  • include_self (bool) – Whether to include self-to-self transitions (default is False: do not include them).

  • step (integer) – The distance to step. Default is 1: use the previous state only. If 2, then the previous-but- one state is used as well as the previous state (and the matrix has one more dimension).

  • return_states (bool) – Whether to return the states.

generate_states(n=10, current_state=None)#

Generates the next states of the system.

Parameters
  • n (int) – The number of future states to generate.

  • current_state (str) – The state of the current random variable.

Returns

list. The next n states.

property normalized_difference#
property observed_freqs#
plot_graph(ax=None, figsize=None, max_size=1000, directed=True, edge_labels=False, draw_neg=False, seed=None)#
plot_norm_diff(ax=None, cmap='RdBu', vminmax=None, rotation=0, annotate=False)#

A visualization of the normalized difference matrix.

Parameters
  • ax (Axes) – The axes to plot on. If None, a new figure will be created.

  • cmap (str) – The name of a matplotlib colormap.

  • vminmax (tuple) – The minimum and maximum values to use for the colormap. If None, the min and max of the matrix will be used.

  • rotation (float) – The angle to rotate the labels.

  • annotate (bool) – Whether to annotate the matrix with the values.

Returns

The axes on which the plot was drawn.

Return type

Axes

class striplog.Position(middle=None, upper=None, lower=None, x=None, y=None, units='m', meta=None)#

Bases: object

Used to represent a position: a top or base.

Not sure whether to go with upper-middle-lower or z_max, z_mid, z_min. Sticking to upper and lower, because ordering in Intervals is already based on ‘above’ and ‘below’.

invert()#

Inverts upper and lower in place.

property span#

Property. A tuple of lower, upper. Provided for convenience.

property uncertainty#

Property. The range of the upper and lower bounds.

property z#

Property. Guaranteed to give the ‘middle’ depth, either as defined, or the average of the upper and lower bounds.

class striplog.Striplog(list_of_Intervals, source=None, order='auto')#

Bases: object

A Striplog is a sequence of intervals.

We will build them from LAS files or CSVs.

Parameters
  • list_of_Intervals (list) – A list of Interval objects.

  • source (str) – A source for the data. Default None.

  • order (str) – ‘auto’, ‘depth’, ‘elevation’, or ‘none’. Please refer to the documentation for details. Best idea is to let the default work. Default: ‘auto’.

anneal(mode='middle')#

Fill in empty intervals by growing from top and base.

Note that this operation happens in-place and destroys any information about the Position (e.g. metadata associated with the top or base). See GitHub issue #54.

If there are overlaps in your striplog, then this method may have unexpected results.

Args
mode (str): One of [‘down’, ‘middle’, ‘up’]. Which way to ‘flood’

into the gaps.

Returns

Striplog. A new instance of the Striplog class.

append(item)#

Implements list-like append() method.

bar(height='thickness', sort=False, reverse=False, legend=None, ax=None, figsize=None, **kwargs)#

Make a bar plot of thickness per interval.

Parameters
  • height (str) – The property of the primary component to plot.

  • sort (bool or function) – Either pass a boolean indicating whether to reverse sort by thickness, or pass a function to be used as the sort key.

  • reverse (bool) – Reverses the sort order.

  • legend (Legend) – The legend to plot with.

  • ax (axis) – Optional axis to plot to.

  • figsize (tuple) – A figure size, (width, height), optional.

  • **kwargs – passed to the matplotlib bar plot command, ax.bar().

Returns

If you sent an axis in, you get it back.

Return type

axis

binary_morphology(attr, operation, step=1.0, p=3)#

Perform a discrete binary morphology operation on the striplog.

Args
attr (str): The attribute to use for the filtering. Must have

boolean values.

operation (str): One of erosion, dilation, opening or

closing.

step (float): The step size to use in discretization. Default is

1 but you might want to use something smaller, e.g. 0.1.

p (int): The length of the structuring element, in samples (not

natual units). Odd numbers are symmetrical and more intuitive. Default is 3.

Returns

Striplog. A new striplog instance.

property components#

Property. Returns the list of compenents in the striplog.

Returns

List. A list of the unique components.

copy()#

Returns a shallow copy.

crop(extent, copy=False)#

Crop to a new depth range.

Parameters
  • extent (tuple) – The new start and stop depth. Must be ‘inside’ existing striplog.

  • copy (bool) – Whether to operate in place or make a copy.

Returns

Operates in place by deault; if copy is True, returns a striplog.

property cum#

Property. Gives the cumulative thickness of all filled intervals.

It would be nice to use sum() for this (by defining __radd__), but I quite like the ability to add striplogs and get a striplog and I don’t think we can have both, it’s too confusing.

Not calling it sum, because that’s a keyword.

Returns

Float. The cumulative thickness.

depth(d)#

For backwards compatibility.

extend(item)#

Implements list-like extend() method.

extract(log, basis, name, function=None)#

‘Extract’ a log into the components of a striplog.

Parameters
  • log (array_like) –

  • basis (array_like) –

  • name (str) –

  • function (function) – input, and returns whatever you want to store in the ‘name’ attribute of the primary component.

Returns

A copy of the striplog.

fill(component=None)#

Fill gaps with the component provided.

Example

t = s.fill(Component({‘lithology’: ‘cheese’}))

find(search_term, index=False)#

Look for a regex expression in the descriptions of the striplog. If there’s no description, it looks in the summaries.

If you pass a Component, then it will search the components, not the descriptions or summaries.

Case insensitive.

Parameters
  • search_term (string or Component) – The thing you want to search for. Strings are treated as regular expressions.

  • index (bool) – Whether to return the index instead of the interval.

Returns

A striplog that contains only the ‘hit’ Intervals.

However, if index was True, then that’s what you get.

Return type

Striplog

find_gaps(index=False)#

Finds gaps in a striplog.

Parameters
  • index (bool) – If True, returns indices of intervals with

  • them. (gaps after) –

Returns

A striplog of all the gaps. A sort of anti-striplog.

Return type

Striplog

find_overlaps(index=False)#

Find overlaps in a striplog.

Parameters
  • index (bool) – If True, returns indices of intervals with

  • them. (gaps after) –

Returns

A striplog of all the overlaps as intervals.

Return type

Striplog

classmethod from_canstrat(filename, source='canstrat')#

Eat a Canstrat DAT file and make a striplog.

classmethod from_csv(filename=None, text=None, dlm=',', lexicon=None, points=False, include=None, exclude=None, remap=None, function=None, null=None, ignore=None, source=None, stop=None, fieldnames=None)#

Load from a CSV file or text.

Args

filename (str): The filename, or use text. text (str): CSV data as a string, or use filename. dlm (str): The delimiter, default ‘,’. lexicon (Lexicon): The lexicon to use, optional. Only needed if parsing descriptions (e.g. cuttings). points (bool): Whether to make a point dataset (as opposed to ordinary intervals with top and base. Default is False. include: Default is None. exclude: Default is None. remap: Default is None. function: Default is None. null: Default is None. ignore: Default is None. source: Default is None. stop: Default is None. fieldnames: Default is None.

Returns

Striplog. A new instance.

classmethod from_descriptions(text, lexicon=None, source='CSV', dlm=',', points=False, abbreviations=False, complete=False, order='depth', columns=None)#
Convert a CSV string into a striplog. Expects 2 or 3 fields:

top, description OR top, base, description

Parameters
  • text (str) – The input text, given by well.other.

  • lexicon (Lexicon) – A lexicon, required to extract components.

  • source (str) – A source. Default: ‘CSV’.

  • dlm (str) – The delimiter, given by well.dlm. Default: ‘,’

  • points (bool) – Whether to treat as points or as intervals.

  • abbreviations (bool) – Whether to expand abbreviations in the description. Default: False.

  • complete (bool) – Whether to make ‘blank’ intervals, or just leave gaps. Default: False.

  • order (str) – The order, ‘depth’ or ‘elevation’. Default: ‘depth’.

  • columns (tuple or list) – The names of the columns.

Returns

A striplog object.

Return type

Striplog

Example

# TOP BOT LITH 312.34, 459.61, Sandstone 459.71, 589.61, Limestone 589.71, 827.50, Green shale 827.60, 1010.84, Fine sandstone

classmethod from_dict(dictionary)#

Take a dictionary of the form name:depth and return a striplog of complete intervals.

classmethod from_image(filename, start, stop, legend, source='Image', col_offset=0.1, row_offset=2, tolerance=0, background=None)#

Read an image and generate Striplog.

Parameters
  • filename (str) – An image file, preferably high-res PNG.

  • start (float or int) – The depth at the top of the image.

  • stop (float or int) – The depth at the bottom of the image.

  • legend (Legend) – A legend to look up the components in.

  • source (str) – A source for the data. Default: ‘Image’.

  • col_offset (Number) – The proportion of the way across the image from which to extract the pixel column. Default: 0.1 (ie 10%).

  • row_offset (int) – The number of pixels to skip at the top of each change in colour. Default: 2.

  • tolerance (float) – The Euclidean distance between hex colours, which has a maximum (black to white) of 441.67 in base 10. Default: 0.

  • background (array) – A background colour (as hex) to ignore.

Returns

The striplog object.

Return type

Striplog

classmethod from_img(*args, **kwargs)#

For backwards compatibility.

classmethod from_las3(string, lexicon=None, source='LAS', dlm=',', abbreviations=False)#

Turn LAS3 ‘lithology’ section into a Striplog.

Parameters
  • string (str) – A section from an LAS3 file.

  • lexicon (Lexicon) – The language for conversion to components.

  • source (str) – A source for the data.

  • dlm (str) – The delimiter.

  • abbreviations (bool) – Whether to expand abbreviations.

Returns

The striplog object.

Return type

Striplog

Note

Handles multiple ‘Data’ sections. It would be smarter for it to handle one at a time, and to deal with parsing the multiple sections in the Well object.

Does not read an actual LAS file. Use the Well object for that.

classmethod from_log(log, cutoff=None, components=None, legend=None, legend_field=None, field=None, right=False, basis=None, source='Log')#

Turn a 1D array into a striplog, given a cutoff.

Parameters
  • log (array-like) – A 1D array or a list of integers.

  • cutoff (number or array-like) – The log value(s) at which to bin the log. Optional.

  • components (array-like) – A list of components. Use this or legend.

  • legend (Legend) – A legend object. Use this or components.

  • legend_field ('str') – If you’re not trying to match against components, then you can match the log values to this field in the Decors.

  • field (str) – The field in the Interval’s data to store the log values as.

  • right (bool) – Which side of the cutoff to send things that are equal to, i.e. right on, the cutoff.

  • basis (array-like) – A depth basis for the log, so striplog knows where to put the boundaries.

  • source (str) – The source of the data. Default ‘Log’.

Returns

The striplog object.

Return type

Striplog

classmethod from_macrostrat(lng, lat, buffer_size=0.2)#
Create a striplog from components derived using the MacroStrat API.

This is simply a helper function to make things easier, but it works because we know what our data looks like in advance.

Note: In order to plot this, you will need to add space for text and

other decoration. This simply gives a Striplog back which _can_ be plotted.

Parameters
  • lng (float) – The longitude of the site.

  • lat (float) – The latitude of the site.

  • buffer_size (float) – The size of the buffer to use, in degrees.

Returns

Striplog. A new striplog instance.

Example

>>> lng = -64.3573186
>>> lat = 44.4454632
>>> buffer_size = 0.3
>>> striplog.striplog.from_macrostrat(lng, lat, buffer_size)
{'top': Position({'middle': 358.9, 'units': 'm'}),
    'base': Position({'middle': 419.2, 'units': 'm'}),
    'description': '', 'data': {}, 'components': [Component({
        'map_id': 948660.0, 'scale': 'small', 'source_id': 7.0,
        'name': 'Devonian plutonic: undivided granitic rocks',
        'age': 'devonian', 'lith': 'plutonic: undivided granitic rocks',
        'best_age_top': 358.9, 'best_age_bottom': 419.2, 't_int': 94.0,
        'b_int': 94.0, 'color': '#cb8c37', 'source': 'MacroStrat.org (CC-BY)})]}
{'top': Position({'middle': 358.9, 'units': 'm'}),
    'base': Position({'middle': 541.0, 'units': 'm'}),
    'description': '', 'data': {}, 'components': [Component({
        'map_id': 948228.0, 'scale': 'small', 'source_id': 7.0,
        'name': 'Cambrian-Devonian sedimentary', 'age': 'cambrian-devonian',
        'lith': 'sedimentary', 'best_age_top': 358.9, 'best_age_bottom': 541.0,
        't_int': 94.0, 'b_int': 122.0, 'color': '#99c08d',
        'source': 'MacroStrat.org (CC-BY)})]}
{'top': Position({'middle': 443.8, 'units': 'm'}),
    'base': Position({'middle': 541.0, 'units': 'm'}),
    'description': '', 'data': {}, 'components': [Component({
        'map_id': 973359.0, 'scale': 'small', 'source_id': 7.0,
        'name': 'Cambrian-Ordovician sedimentary', 'age': 'cambrian-ordovician',
        'lith': 'sedimentary', 'best_age_top': 443.8, 'best_age_bottom': 541.0,
        't_int': 112.0, 'b_int': 122.0, 'color': '#409963',
        'source': 'MacroStrat.org (CC-BY)})]}
classmethod from_petrel(filename, stop=None, points=False, null=None, function=None, include=None, exclude=None, remap=None, ignore=None)#

Makes a striplog from a Petrel text file.

Returns

striplog.

get_data(field, function=None, default=None)#

Get data from the striplog.

hist(lumping=None, summary=False, sort=True, plot=True, legend=None, ax=None, rotation=0, ha='center')#

Plots a histogram and returns the data for it.

Parameters
  • lumping (str) – If given, the bins will be lumped based on this attribute of the primary components of the intervals encountered.

  • summary (bool) – If True, the summaries of the components are returned as the bins. Otherwise, the default behaviour is to return the Components themselves.

  • sort (bool) – If True (default), the histogram is sorted by value, starting with the largest.

  • plot (bool) – If True (default), produce a bar plot.

  • legend (Legend) – The legend with which to colour the bars.

  • ax (axis) – An axis object, which will be returned if provided. If you don’t provide one, it will be created but not returned.

  • rotation (int) – The rotation angle of the x-axis tick labels. Default is 0 but -45 is useful.

  • ha (str) – The horizontal alignment of the x-axis tick labels. Default is ‘center’ but ‘left’ is good for -ve rotation.

Returns

A tuple of tuples of entities and counts.

Return type

Tuple

histogram(lumping=None, summary=False, sort=True, plot=True, legend=None, ax=None, rotation=0, ha='center')#

Plots a histogram and returns the data for it.

Parameters
  • lumping (str) – If given, the bins will be lumped based on this attribute of the primary components of the intervals encountered.

  • summary (bool) – If True, the summaries of the components are returned as the bins. Otherwise, the default behaviour is to return the Components themselves.

  • sort (bool) – If True (default), the histogram is sorted by value, starting with the largest.

  • plot (bool) – If True (default), produce a bar plot.

  • legend (Legend) – The legend with which to colour the bars.

  • ax (axis) – An axis object, which will be returned if provided. If you don’t provide one, it will be created but not returned.

  • rotation (int) – The rotation angle of the x-axis tick labels. Default is 0 but -45 is useful.

  • ha (str) – The horizontal alignment of the x-axis tick labels. Default is ‘center’ but ‘left’ is good for -ve rotation.

Returns

A tuple of tuples of entities and counts.

Return type

Tuple

insert(index, item)#
intersect(other)#

Makes a striplog of all intersections.

Parameters

with. (Striplog. The striplog instance to intersect) –

Returns

Striplog. The result of the intersection.

invert(copy=False)#

Inverts the striplog, changing its order and the order of its contents.

Operates in place by default.

Parameters

copy (bool) – Whether to operate in place or make a copy.

Returns

None if operating in-place, or an inverted copy of the striplog

if not.

is_binary(attr=None)#

Determine if attr, which must be an attribute of every primary component, allows this striplog to be interpreted as a binary striplog. If no attr is provided, the first attribute of the primary comp- onent is used.

max_field(field)#
property mean#

Property. Returns the mean thickness of all filled intervals.

Returns

Float. The mean average of interval thickness.

merge(attr, reverse=False)#

Merge the intervals in a striplog, using an attribute of the primary component for priority ordering.

Args

attr (str): The attribute of the component you want to use. You must provide an attribute. reverse (bool): Whether to reverse the condition.

Returns

Striplog: The merged striplog.

merge_neighbours(strict=True)#

Makes a new striplog in which matching neighbours (for which the components are the same) are unioned. That is, they are replaced by a new Interval with the same top as the uppermost and the same bottom as the lowermost.

Args
strict (bool): If True, then all of the components must match.

If False, then only the primary must match.

Returns

Striplog. A new striplog.

merge_overlaps()#

Merges overlaps by merging overlapping Intervals.

The function takes no arguments and returns None. It operates on the striplog ‘in place’

TODO: This function will not work if any interval overlaps more than

one other intervals at either its base or top.

net_to_gross(attr)#

Compute the ratio of intervals having that attribute as True to the total thickness.

TODO

Allow user to give a cut-off value to apply to the attribute, if it’s a continuous scalar and not boolean.

Args

attr (str): Which attribute to use. Must have boolean values.

Returns

float. The net:gross ratio.

next()#

For Python 2 compatibility.

plot(legend=None, width=1.5, ladder=True, aspect=10, ticks=(1, 10), match_only=None, ax=None, return_fig=False, colour=None, cmap='viridis', default=None, style='intervals', field=None, label=None, **kwargs)#

Hands-free plotting.

Parameters
  • legend (Legend) – The Legend to use for colours, etc.

  • width (int) – The width of the plot, in inches. Default 1.

  • ladder (bool) – Whether to use widths or not. Default True.

  • aspect (int) – The aspect ratio of the plot. Default 10.

  • ticks (int or tuple) – The (minor,major) tick interval for depth. Only the major interval is labeled. Default (1,10).

  • match_only (list) – A list of strings matching the attributes you want to compare when plotting.

  • ax (ax) – A maplotlib axis to plot onto. If you pass this, it will be returned. Optional.

  • return_fig (bool) – Whether or not to return the maplotlib fig object. Default False.

  • colour (str) – Which data field to use for colours.

  • cmap (cmap) – Matplotlib colourmap. Default viridis.

  • default (float) – The default (null) value.

  • style (str) – Can be ‘tops’, ‘points’ or ‘field’ for different types of plot. If you use ‘field’, give the name of the field as the field argument.

  • field (str) – The name of the field to use for the width parameter.

  • label (str) – Can be the name of a single Component attribute, or a format string with multiple attributes, like “{colour} {lithology}”.

  • patches.Rectangle. (**kwargs are passed through to matplotlib's) –

Returns

None. Unless you specify return_fig=True or pass in an ax.

plot_axis(ax, legend, ladder=False, default_width=1, match_only=None, colour=None, colour_function=None, cmap=None, default=None, width_field=None, **kwargs)#

Plotting, but only the Rectangles. You have to set up the figure. Returns a matplotlib axis object.

Parameters
  • ax (axis) – The matplotlib axis to plot into.

  • legend (Legend) – The Legend to use for colours, etc.

  • ladder (bool) – Whether to use widths or not. Default False.

  • default_width (int) – A width for the plot if not using widths. Default 1.

  • match_only (list) – A list of strings matching the attributes you want to compare when plotting.

  • colour (str) – Which data field to use for colours.

  • cmap (cmap) – Matplotlib colourmap. Default viridis.

  • default (float) – The default (null) value.

  • width_field (str) – The field to use for the width of the patches.

  • patches.Rectangle. (**kwargs are passed through to matplotlib's) –

Returns

The matplotlib.pyplot axis.

Return type

axis

plot_field(ax, legend=None, field=None, **kwargs)#

Plotting, but only for tops (as opposed to intervals).

plot_points(ax, legend=None, field=None, field_function=None, undefined=0, **kwargs)#

Plotting, but only for points (as opposed to intervals).

plot_tops(ax, legend=None, field=None, **kwargs)#

Plotting, but only for tops (as opposed to intervals).

pop(index)#

Implements list-like pop() method.

prune(limit=None, n=None, percentile=None, keep_ends=False)#

Remove intervals below a certain limit thickness. In place.

Parameters
  • limit (float) – Anything thinner than this will be pruned.

  • n (int) – The n thinnest beds will be pruned.

  • percentile (float) – The thinnest specified percentile will be pruned.

  • keep_ends (bool) – Whether to keep the first and last, regardless of whether they meet the pruning criteria.

quality(tests, alias=None)#

Run a series of tests and return the corresponding results.

Based on curve testing for welly.

Parameters

tests (list) – a list of functions.

Returns

list. The results. Stick to booleans (True = pass) or ints.

read_at(d, index=False)#
Get the index of the interval at a particular ‘depth’ (though this

might be an elevation or age or anything).

Parameters
  • d (Number) – The ‘depth’ to query.

  • index (bool) – Whether to return the index instead of the interval.

Returns

The interval, or if index==True the index of the

interval, at the specified ‘depth’, or None if the depth is outside the striplog’s range.

Return type

Interval

shift(delta=None, start=None)#

Shift all the intervals by delta (negative numbers are ‘up’) or by setting a new start depth.

Returns a copy of the striplog.

property start#

Property. The closest Position to the datum.

Returns

Position.

property stop#

Property. The furthest Position from the datum.

Returns

Position.

thickest(n=1, index=False)#

Returns the thickest interval(s) as a striplog.

Parameters
  • n (int) – The number of thickest intervals to return. Default: 1.

  • index (bool) – If True, only the indices of the intervals are returned. You can use this to index into the striplog.

Returns

Interval. The thickest interval. Or, if index was True, the index of the thickest interval.

thinnest(n=1, index=False)#

Returns the thinnest interval(s) as a striplog.

Parameters
  • n (int) – The number of thickest intervals to return. Default: 1.

  • index (bool) – If True, only the indices of the intervals are returned. You can use this to index into the striplog.

Returns

Interval. The thickest interval. Or, if index was True, the index of the thickest interval.

to_binary_log(attr, step)#

Adaptation of to_log but deals with binary attributes of striplogs.

Args

attr (str): Which attribute to make into a log.

to_canstrat(filename, params)#

Write a Canstrat ASCII file.

Parameters
  • filename (str) –

  • params (dict) – The well details. You can use a welly header object.

Returns:

to_csv(filename=None, as_text=True, use_descriptions=False, dlm=',', header=True)#

Returns a CSV string built from the summaries of the Intervals.

Parameters
  • use_descriptions (bool) – Whether to use descriptions instead of summaries, if available.

  • dlm (str) – The delimiter.

  • header (bool) – Whether to form a header row.

Returns

A string of comma-separated values.

Return type

str

to_flag(**kwargs)#

A wrapper for to_log() that returns a boolean array. Useful for masking. Has the same interface as to_log().

to_las3(use_descriptions=False, dlm=',', source='Striplog')#

Returns an LAS 3.0 section string.

Parameters
  • use_descriptions (bool) – Whether to use descriptions instead of summaries, if available.

  • dlm (str) – The delimiter.

  • source (str) – The sourse of the data.

Returns

A string forming Lithology section of an LAS3 file.

Return type

str

to_log(step=1.0, start=None, stop=None, basis=None, field=None, field_function=None, bins=True, dtype='float', table=None, sort_table=False, legend=None, legend_field=None, match_only=None, undefined=0, return_meta=False)#

Return a fully sampled log from a striplog. Useful for crossplotting with log data, for example.

Parameters
  • step (float) – The step size. Default: 1.0.

  • start (float) – The start depth of the new log. You will want to match the logs, so use the start depth from the LAS file. Default: The basis if provided, else the start of the striplog.

  • stop (float) – The stop depth of the new log. Use the stop depth of the LAS file. Default: The basis if provided, else the stop depth of the striplog.

  • field (str) – If you want the data to come from one of the attributes of the components in the striplog, provide it.

  • field_function (function) – Provide a function to apply to the field you are asking for. It’s up to you to make sure the function does what you want.

  • bins (bool) – Whether to return the index of the items from the lookup table. If False, then the item itself will be returned.

  • dtype (str) – The NumPy dtype string for the output log.

  • table (list) – Provide a look-up table of values if you want. If you don’t, then it will be constructed from the data.

  • sort_table (bool) – Whether to sort the table or not. Default: False.

  • legend (Legend) – If you want the codes to come from a legend, provide one. Otherwise the codes come from the log, using integers in the order of prevalence. If you use a legend, they are assigned in the order of the legend.

  • legend_field (str) – If you want to get a log representing one of the fields in the legend, such as ‘width’ or ‘grainsize’.

  • match_only (list) – If you only want to match some attributes of the Components (e.g. lithology), provide a list of those you want to match.

  • undefined (number) – What to fill in where no value can be determined, e.g. -999.25 or np.nan. Default 0.

  • return_meta (bool) – If True, also return the depth basis (np.linspace), and the component table.

Returns

If return_meta was True, you get:

  • The log data as an array of ints.

  • The depth basis as an array of floats.

  • A list of the components in the order matching the ints.

If return_meta was False (the default), you only get the log data.

Return type

ndarray

property top#

Property.

union(other)#

Makes a striplog of all unions.

Parameters

with. (Striplog. The striplog instance to union) –

Returns

Striplog. The result of the union.

property unique#

Property. Summarize a Striplog with some statistics.

Returns

List. A list of (Component, total thickness thickness) tuples.