straditize.straditizer module

Core module of the Straditizer class

This module defines the Straditizer class, the main object to digitize a stratigraphic diagram

Disclaimer

Copyright (C) 2018-2019 Philipp S. Sommer

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Classes

Straditizer(image[, ax, plot, attrs])

An object to digitize a stratigraphic diagram

Functions

format_coord_func(ax, ref)

Create a function that can replace the

class straditize.straditizer.Straditizer(image, ax=None, plot=True, attrs=None)[source]

Bases: straditize.label_selection.LabelSelection

An object to digitize a stratigraphic diagram

One instance of a straditizer manages the digitization of a PIL.Image.Image hold in the image attribute.

To create a new Straditizer instance, you can either provide a PIL.Image.Image to the class constructor (i.e. stradi = Straditizer(image)) or you use the from_dataset() method.

The reader for the diagram part can be accessed through the data_reader attribute, the reader for the column names through the colnames_reader attribute.

Parameters
  • image (PIL.Image.Image or np.ndarray) – The image file to process. A numpy array should be 3D with shape (Y, X, 4), where the last channel […, -1] should represent the alpha channel. A PIL.Image.Image will be converted to a RGBA image (if not already)

  • ax (matplotlib.axes.Axes) – The matplotlib axes. If None, a new one will be created

  • attrs (dict or pandas.DataFrame) – The attributes for this straditizer

Methods

adjust_lims()

adjust_lims_after_resize([event])

adjust_lims_after_zoom(ax)

align_columns()

Shift the columns after the marks have been moved

close()

create_magni_marks(marks)

Copy the created marks to the magnifiers axes

create_variable(ds, vname, data, **kwargs)

Insert the data into a variable in an xr.Dataset

data2px_y(coord)

Transform the data coordinates into pixel coordinates

digitize_diagram()

draw_data_box()

draw_figure()

from_dataset(ds[, ax, plot])

Create a new Straditizer from a dataset

get_attr(key)

get_labels([categorize])

get_reader_for_column(col)

guess_data_lims([fraction])

Guess the limits of the diagram part

image_array()

init_reader([reader_type, ax])

load(fname[, ax, plot])

marks_for_column_ends([threshold])

marks_for_column_starts([threshold])

marks_for_data_selection([nums, fraction, …])

marks_for_occurences()

Create marks for editing the occurences

marks_for_samples()

marks_for_samples_sep([nrows])

marks_for_vertical_alignment()

Create marks for vertical alignment of the columns

marks_for_x_values([at_col_start])

Create two marks for selecting the x-values

marks_for_y_values()

Create two marks for selecting the x-values

plot_image([ax])

px2data_y(coord)

Transform the pixel coordinates into data coordinates

remove_data_box()

Remove the data_box

remove_marks()

Remove any drawn marks

reset_image(image[, reader])

Reset the straditizer image

save(fname)

Dump the Straditizer instance to a file

set_attr(key, value)

Update an attribute in the attrs

show_data_diagram()

show_full_image()

to_dataset([ds])

All the necessary data as a xarray.Dataset

update_column_ends()

update_column_starts()

update_data_part()

update_image(arr, mask)

Update the image from the given 3D-array

update_occurences([remove])

Set the occurences from the given marks

update_samples([remove])

update_samples_sep([remove])

update_xvalues()

update_yvalues()

Attributes

adjusting

True if xlim and ylim are adjusted

attrs

pandas.DataFrame. The attributes of this straditizer

attrs_dict

ax

The matplotlib axes

block_signals

Block the emitting of signals of this instance

colnames_reader

The straditize.colnames.ColNamesReader for reading the column

column_indexes

The horizontal indexes for each column

data_reader

The straditize.binary.DataReader instance to digitize the

data_xlim

data_ylim

fig

final_df

full_df

indexes

label_arrs

Built-in mutable sequence.

magni

The straditize.magnifier.Magnifier for the diagram image

mark_added

A signal that is emitted if a mark has been added.

mark_cids

set() -> new empty set object

mark_removed

A signal that is emitted, if a mark has been removed.

nc_meta

dict() -> new empty dictionary

valid_attrs

yaxis_px

adjust_lims()[source]
adjust_lims_after_resize(event=None)[source]
adjust_lims_after_zoom(ax)[source]
property adjusting

True if xlim and ylim are adjusted

align_columns()[source]

Shift the columns after the marks have been moved

This method should be called after the marks_for_vertical_alignment() method to align the columns

attrs = None

pandas.DataFrame. The attributes of this straditizer

property attrs_dict
ax = None

The matplotlib axes

property block_signals

Block the emitting of signals of this instance

close()[source]
property colnames_reader

The straditize.colnames.ColNamesReader for reading the column names

property column_indexes

The horizontal indexes for each column

create_magni_marks(marks)[source]

Copy the created marks to the magnifiers axes

create_variable(ds, vname, data, **kwargs)[source]

Insert the data into a variable in an xr.Dataset

data2px_y(coord)[source]

Transform the data coordinates into pixel coordinates

Parameters

coord (1D np.ndarray) – The coordinate values

Returns

The numpy array with transformed coordinates

Return type

np.ndarray

data_reader = None

The straditize.binary.DataReader instance to digitize the data

property data_xlim
property data_ylim
digitize_diagram()[source]
draw_data_box()[source]
draw_figure()[source]
property fig
fig_h = None
fig_w = None
property final_df
classmethod from_dataset(ds, ax=None, plot=True)[source]

Create a new Straditizer from a dataset

This method uses a dataset that has been exported with the to_dataset() method to intialize a new reader

property full_df
get_attr(key)[source]
get_labels(categorize=1)[source]
get_reader_for_column(col)[source]
guess_data_lims(fraction=0.7)[source]

Guess the limits of the diagram part

Parameters

fraction (float) – The smallest fraction that has to be covered for a cell to be considered as a corner

Returns

  • np.array – xmin and xmax of the diagram part (see data_xlim)

  • np.array – ymin and ymax of the diagram part (see data_ylim)

image_array()[source]
property indexes
init_reader(reader_type='area', ax=None, **kwargs)[source]
label_arrs = ['image_array']
classmethod load(fname, ax=None, plot=True)[source]
magni = None

The straditize.magnifier.Magnifier for the diagram image

mark_added

A signal that is emitted if a mark has been added. Functions are expected to accept one argument, the newly created straditize.cross_mark.CrossMarks instance

mark_cids = {}
mark_removed

A signal that is emitted, if a mark has been removed. Functions are expected to accept one argument, the removed straditize.cross_mark.CrossMarks instance

marks_for_column_ends(threshold=None)[source]
marks_for_column_starts(threshold=None)[source]
marks_for_data_selection(nums=2, fraction=0.7, guess_lims=True)[source]
marks_for_occurences()[source]

Create marks for editing the occurences

marks_for_samples()[source]
marks_for_samples_sep(nrows=3)[source]
marks_for_vertical_alignment()[source]

Create marks for vertical alignment of the columns

This method creates one mark for each column. These marks should then be moved to positions that should be on the same vertical level. After that, the align_columns() method has to be called

marks_for_x_values(at_col_start=True)[source]

Create two marks for selecting the x-values

Parameters

at_col_start (bool) – If True, and no translation has yet been performed, create a mark at the column start and ask for the corresponding value

marks_for_y_values()[source]

Create two marks for selecting the x-values

nc_meta = {'axis': {'long_name': 'Axis coordinate'}, 'data_lims': {'dims': ('axis', 'limit'), 'long_name': 'Limits of the data diagram', 'units': 'px'}, 'done_tasks': {'long_name': 'Tasks that are marked as done by the user'}, 'image': {'dims': ('y', 'x', 'rgba'), 'long_name': 'Full stratigraphic diagram', 'units': 'color'}, 'limit': {'long_name': 'Minimum and maximum limit'}, 'px_data': {'long_name': 'Coordinate for pixel-to-data translations'}, 'yaxis_translation': {'dims': ('px_data', 'limit'), 'long_name': 'Pixel to data mapping for y-axis'}}
plot_image(ax=None, **kwargs)[source]
px2data_y(coord)[source]

Transform the pixel coordinates into data coordinates

Parameters

coord (1D np.ndarray) – The coordinate values in pixels

Returns

The numpy array with transformed coordinates

Return type

np.ndarray

remove_data_box()[source]

Remove the data_box

remove_marks()[source]

Remove any drawn marks

reset_image(image, reader=False)[source]

Reset the straditizer image

Parameters
  • image (PIL.Image.Image) – The new image to use

  • reader (bool) – If True, the image of the data reader will be replaced, too

save(fname)[source]

Dump the Straditizer instance to a file

Parameters

fname (str) – The file name where to save the instance

set_attr(key, value)[source]

Update an attribute in the attrs

show_data_diagram()[source]
show_full_image()[source]
to_dataset(ds=None)[source]

All the necessary data as a xarray.Dataset

Parameters

ds (xarray.Dataset) – The dataset in which to insert the data. If None, a new one will be created

Returns

Either the given ds or a new xarray.Dataset instance

Return type

xarray.Dataset

update_column_ends()[source]
update_column_starts()[source]
update_data_part()[source]
update_image(arr, mask)[source]

Update the image from the given 3D-array

Parameters
  • arr (3D np.ndarray of dtype float) – The image array

  • mask (boolean mask of the same shape as arr) – The mask of features that shall be set to 0 in arr

update_occurences(remove=True)[source]

Set the occurences from the given marks

update_samples(remove=True)[source]
update_samples_sep(remove=True)[source]
update_xvalues()[source]
update_yvalues()[source]
property valid_attrs
yaxis_data = None
property yaxis_px
straditize.straditizer.format_coord_func(ax, ref)[source]

Create a function that can replace the matplotlib.axes.Axes.format_coord()

Parameters
Returns

The function that can be used to replace ax.format_coord

Return type

function