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
|
An object to digitize a stratigraphic diagram |
Functions
|
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 theimage
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 thefrom_dataset()
method.The reader for the diagram part can be accessed through the
data_reader
attribute, the reader for the column names through thecolnames_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_after_resize
([event])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
from_dataset
(ds[, ax, plot])Create a new
Straditizer
from a datasetget_attr
(key)get_labels
([categorize])guess_data_lims
([fraction])Guess the limits of the diagram part
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, …])Create marks for editing the occurences
marks_for_samples_sep
([nrows])Create marks for vertical alignment of the columns
marks_for_x_values
([at_col_start])Create two marks for selecting the x-values
Create two marks for selecting the x-values
plot_image
([ax])px2data_y
(coord)Transform the pixel coordinates into data coordinates
Remove the data_box
Remove any drawn marks
reset_image
(image[, reader])Reset the straditizer image
save
(fname)Dump the
Straditizer
instance to a fileset_attr
(key, value)Update an attribute in the
attrs
to_dataset
([ds])All the necessary data as a
xarray.Dataset
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])Attributes
True if xlim and ylim are adjusted
pandas.DataFrame
. The attributes of this straditizerThe matplotlib axes
Block the emitting of signals of this instance
The
straditize.colnames.ColNamesReader
for reading the columnThe horizontal indexes for each column
The
straditize.binary.DataReader
instance to digitize theBuilt-in mutable sequence.
The
straditize.magnifier.Magnifier
for the diagram imageA signal that is emitted if a mark has been added.
set() -> new empty set object
A signal that is emitted, if a mark has been removed.
dict() -> new empty dictionary
-
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
-
property
colnames_reader
¶ The
straditize.colnames.ColNamesReader
for reading the column names
-
property
column_indexes
¶ The horizontal indexes for each column
-
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
¶
-
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 datasetThis method uses a dataset that has been exported with the
to_dataset()
method to intialize a new reader
-
property
full_df
¶
-
property
indexes
¶
-
label_arrs
= ['image_array']¶
-
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_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
-
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'}}¶
-
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
-
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
-
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
-
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
-
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
ax (matplotlib.axes.Axes) – The axes instance
ref (weakref.weakref) – The reference to the
Straditizer
instance
- Returns
The function that can be used to replace ax.format_coord
- Return type
function