kromatography.plotting package

Subpackages

Submodules

kromatography.plotting.animation_data module

class kromatography.plotting.animation_data.AnimationData[source]

Bases: traits.has_traits.HasStrictTraits

Data storage for building animation plots of the particle data evolution over time during a simulation.

simulation_name = Str

Name of the simulation the data was extracted from

column = Instance(Column)

Column the animation data is about

product = Instance(Product)

Product the animation is about

component_idx = Int

Index of the component the data is about

component_name = Property(depends_on='product, component_idx')

Component the animation is about

bedheight_cm = Property(depends_on='column')

Column bed height

beaddiam_um = Property(depends_on='column')

Bead diameter in packed column

step_start_times = Array

Method step start times during animation

step_names = Array

Method step names

levelsliq = Array

levels for liquid contour plots

levelsbound = Array

levels for bound contour plot

beadX = Array

Axis arrays

columnliqX = Property(Array, depends_on='column')

Boundaries of X values for the column liquid phase data

times = Array

Array of timestamps

beadliqZ = Array

Data in the liquid phase in the bead

beadboundZ = Array

Data in the bound phase in the bead

columnliqZ = Array

Data in the liquid phase in the bead

kromatography.plotting.animation_plot module

Build the chaco version of the animation plot, that is 3 contour plots displaying the concentration of one of the product components in the column liquid phase, in the bead liquid phase and in the bead-bound phase.

class kromatography.plotting.animation_plot.AnimationPlot(**traits)[source]

Bases: traits.has_traits.HasStrictTraits

The plot model for the particle data for each product component in a given simulation

plot = Instance(HPlotContainer)

Container for the plots

product_component = Str

the product component whose particle simulation data is currently viewed

time_slice = Int(0)

the index of the time dimension currently being plotted

all_data = Dict(Str, AnimationData)

The particle simulation data for each product component

active_anim_data = Property(Instance(AnimationData), depends_on='product_component')

The current particle simulation data active

plot_data = Instance(ArrayPlotData)

the data currently being plotted in plot

simulation_name = Str

Name of the simulation from which the data is displayed

name = Str('Column Animation')

name of the plot

contour_plot_from_data(anim_data, array_names, style_dict=None)[source]

Returns the Container of contour plot corresponding to the array data in anim_data w.r.t. arraynames

Parameters:
  • anim_data (AnimationData) – Animation data to plot as a contour plot.
  • array_names (4-tuple of strings) – Attr names in anim_data which will be (x,y,z, levels) arrays for the contour plot.
  • style_dict (dict) – Dictionary of extra stylings to set, currently allowing up to one level of nesting of attributes (with ‘’ key meaning no nesting).
regenerate_plots(including_colorbar=False)[source]

Function to regenerate entire plot (because many parts of each renderer must be updated when product_component or time slice changes)

get_current_step_time()[source]

Returns the step name and the time (in min) of the currently selected time slice.

kromatography.plotting.animation_plot.build_animation_plot_model(study)[source]

Returns instance of AnimationPlot and UUID of source simulation.

kromatography.plotting.api module

kromatography.plotting.chromatogram_plot module

class kromatography.plotting.chromatogram_plot.ChromatogramPlot[source]

Bases: traits.has_traits.HasStrictTraits

The Chaco plot that provides an API to plot ChromeLog instances.

plot_contexts = Dict(Str, Instance(Plot))

The collection of Plots in the container. Each Plot corresponds to a chrome-log family. The key corresponds to the name of the chrome-log family.

remove_empty_plot = Bool(True)

Remove a Plot from the container if there are no curves being rendered. Set to False to avoid the resizing of the Plots in the container when the empty Plot is removed.

container = Instance(ConstraintsPlotContainer)

The instance of PlotContainer that contains all the Plots.

all_plots_index_range = Instance(DataRange1D)

all_plots_index_range will store a common index_range

init()[source]

Initialize the plots.

add_chrome_log(prefix, log)[source]

Add the given chrome-log to the appropriate plot container.

Parameters:
  • prefix (str) – Name of the ChromeLogCollection (typically the name of the exp/sim) the log is part of. Used to build the name of the plot renderer.
  • log (ChromeLog) – Chromatography Log object, containing family information and the data to display.
remove_chrome_log(prefix, log)[source]

Remove a single log (curve) from the appropriate plot container.

Parameters:
  • prefix (str) – Name of the ChromeLogCollection (typically the name of the exp/sim) the log is part of. Used to find the name of the plot renderer.
  • log (ChromeLog) – Chromatography Log object, containing family information and the data to display.
remove_log_family(family_name)[source]

Remove the family of logs grouped under family_name.

refresh_container(force=False)[source]
show_legend()[source]
hide_legend()[source]

Hide the legend and disable its highighting tool to avoid mouse interactions.

kromatography.plotting.chromatogram_plot.build_new_plot_context(container_properties)[source]

Build an empty chaco Plot to display data, using provided props.

Note that this builds an empty Plot or Container. See add_chrome_log and remove_chrome_log for adding/removing line plots in it.

Parameters:container_properties (dict) – Properties to display the
kromatography.plotting.chromatogram_plot.add_sharedx_axes(plot, orientation='normal', vtitle='', htitle='', axis_class=<class 'chaco.axis.PlotAxis'>)[source]

Creates left and bottom axes for a plot. Assumes that the index is horizontal and value is vertical by default; set orientation to something other than “normal” if they are flipped.

kromatography.plotting.data_inspector_tool module

Data inspector tool and overlay for any chaco plot.

kromatography.plotting.data_inspector_tool.add_data_inspector(plot, move_callback=None, include_overlay=False, message_for_data=None)[source]

Add data inspector tool and overlay to a plot plot.

The inspector tool and overlay are added to the plot’s tools and overlays lists and both objects are returned for further use.

class kromatography.plotting.data_inspector_tool.DataInspectorTool(component=None, **kwtraits)[source]

Bases: enable.base_tool.BaseTool

Tool that reports the data location of the current cursor.

data_coord = Any

The coordinates of the cursor.

move_callback = Callable

Function to be called on move events

normal_mouse_move(event)[source]
normal_mouse_leave(event)[source]
class kromatography.plotting.data_inspector_tool.DataInspectorOverlay(component=None, *args, **kw)[source]

Bases: chaco.text_box_overlay.TextBoxOverlay

Overlay for displaying information from a DataInspectorTool.

inspector = Instance(DataInspectorTool)

The inspector tool which has an index into the

message_for_data = Callable

Function which takes and index and returns an info string.

visible = False

The default state of the overlay is invisible (overrides PlotComponent).

visibility = Enum('auto', True, False)

Whether the overlay should auto-hide and auto-show based on the tool’s location, or whether it should be forced to be hidden or visible.

kromatography.plotting.data_models module

class kromatography.plotting.data_models.ChromeFamily(**traits)[source]

Bases: app_common.model_tools.data_element.DataElement

Class describing a family of related chrome data curves.

Typically, curves with same units (e.g. UV, temperature, conductivity etc) would be considered a family.

NOTE: It might be worth considering if we need a separate ChromeFamily class or if we should just collapse the traits into ChromLog. One advantage of keeping the data and the family/plot attributes separate would be to allow saving/loading/editing these attributes.

description = NoneOrStr

A short description of the family.

data_label = NoneOrStr

The label for displaying to user

time_label = NoneOrStr

The label for displaying to user

data_unit_label = NoneOrStr

The units for the data curves

time_unit_label = NoneOrStr

The units for the time axis

plot_container_properties = NoneOrDict

The properties to use for the top level container for the logs in this family

class kromatography.plotting.data_models.ChromeLog(**traits)[source]

Bases: app_common.model_tools.data_element.DataElement

Contains all relevant data for a curve in the Chromatogram.

NOTE: The main difference from XYData is that this class has attributes specific to creating a plot (e.g. family, unit converted etc) whereas the XYData contains the raw data from the experiment/simulation.

x_data = NoneOr1DArray

The x and y data for the log.

family = Instance(ChromeFamily)

The family (e.g. UV/ Temperature / pH) that this belongs to.

renderer_properties = Dict

The properties to use for rendering the logs corr. to this family.

source_type = Either(None, Enum(['experiment', 'simulation', 'fraction']))

The source for the Chrome data. Again prob. belongs in ChromeLog.

class kromatography.plotting.data_models.ChromeLogCollection[source]

Bases: app_common.model_tools.data_element.DataElement

Holds a collection of ChromeLogs and any context specific information for that collection.

This class should provide access to the logs/data from a single experiment/simulation and any specific context information needed for unit converters etc. (e.g. t0, info for CV to time conversion etc).

Notes

:

  • It might make sense for these classes to have a map of unit converters that can be used by Chromatogram(Model/Plot) to convert the data to appropriate units. (can we use the unit_manager from scimath here ?)
  • Also, it would be nice to make this sit on top of a BaseExperiment and provide lazy access to data. That way, we don’t have to explicitly construct the ChromeLog for all available data
logs = Instance(OrderedDict, ())

The collection of ChromeLog instances managed by this object.

source_type = Enum(['experiment', 'simulation'])

Type of origin: collection built from an experiment or a sim?

source = NoneOrStr

Name of the source experiment this collection will inherit styling from

class kromatography.plotting.data_models.ChromatogramModel[source]

Bases: app_common.model_tools.data_element.DataElement

Class that contains the data required for a chromatogram editor.

Notes

  • The model contains a collection of ChromeLogCollection.
  • A ChromeLogCollection is a collection of time series data from either an experiment or a simulation.
  • Each model has a reference ‘ChromeLogCollection`.
  • It should be possible add/remove instances of ChromLogCollection.
log_collections = Dict(Str, Instance(ChromeLogCollection))

The collection of all chrome data (multiple ChromeLogCollections). This object should contain all the data, for a study, that should be displayed in the chaco plot.

kromatography.plotting.model_factories module

Factory functions for creating the model objects needed for the plots.

kromatography.plotting.model_factories.create_chrome_family(name)[source]

Create a new ChromeFamily for a (known) family name.

kromatography.plotting.model_factories.create_chrome_log(name, source_name, family_name, source_type, x_data, y_data, data_mask=None)[source]

Build a chromatography log, specifying the name, family and data.

Parameters:
  • name (str) – Name of the log being created.
  • source_name (str) – Name of the collection’s source, that is the experiment name if experimental data is used, or the source experiment’s name if simulated data is used. Used to select the log’s color.
  • family_name (str) – Name of the log type: UV, conductivity, pH, ... Used to control which plot container to display the log in.
  • source_type (str) – Type of collection containing the log: experiment, simulation, fractions? Used to control the curve type (solid, dashed, symbols).
  • x_data (ndarray) – Data points along the x axis.
  • y_data (ndarray) – Data points along the y axis.
  • data_mask (slice [OPTIONAL]) – Slice of the data to display.
kromatography.plotting.model_factories.build_chrome_log_collection_from_experiment(expt)[source]

Build a collection of Chromatography logs (plots) from all expt data.

Note: no filtering based on time is applied: it is therefore assumed that the load phase starts at the beginning of the AKTA recording.

FIXME: Once units can be reliably parsed from AKTA and Excel readers make sure that the units are set for all results. Also, create unit converters that might be specific to experiment/simulation (e.g. cv_to_duration, cv_to_time, AU_to_AU/cm etc.)

kromatography.plotting.model_factories.build_chrome_log_collection_from_simulation(sim)[source]

Build a collection of Chromatography logs (plots) from all data in an experiment.

kromatography.plotting.model_factories.build_chromatogram_model(study, expts=None, sims=None, sim_group=None)[source]

Takes a study, and builds a model to plot data from its experiments and simulations. Defaults to showing all experiment and simulation data. Only one of experiment_name or simulation_name should be specified at a time, or neither.

Parameters:
  • study (Study) – Study containing all simulations to display against 1 or more experiment.
  • expts (list(Experiment) (OPTIONAL)) – List of Experiments to display. Only simulations for which it is set as source_experiment will be displayed against.
  • sims (list(Simulation) (OPTIONAL)) – List of simulations to display. Their source_experiment will be displayed along with it.
  • sim_group (SimulationGroup (OPTIONAL)) – Simulation group to plot all the simulations from.

kromatography.plotting.mpl_column_animation module

kromatography.plotting.mpl_column_animation.column_animation(sim)[source]

Make an animation for each product component contained in the simulation.

kromatography.plotting.mpl_column_animation.column_animation_for_comp(sim, component_idx)[source]

Build a Matplotlib animation displaying the evolution of a product component concentration over time.

Parameters:
  • sim (Simulation) – Simulation object that contains particle data as part of its results.
  • component_idx (int) – Index of the component to display the animated time evolution.
kromatography.plotting.mpl_column_animation.initialize_animation_figs(sim_name, anim_data)[source]

kromatography.plotting.mpl_param_impact_plot module

kromatography.plotting.mpl_param_impact_plot.plot_performance_as_tornado_plot(data, perf_name, cp_perf=None, select_cols=None, filepath='', **plt_style)[source]

Make a tornado/Pareto plot to show how a performance parameter changes with and around a set of input parameters.

Parameters:
  • data (DataFrame) – Table of impacts of parameters (columns) on a set of performances (rows). The impact is described as the difference between the performance for a certain value of a parameter and the value of that performance at a reference parameter value (or reference simulation). These columns are expected to be sorted from the most impactful to the least. See extract_perf_data() to generate this dataframe from a list of simulation grids.
  • perf_name (str) – Name of the performance to plot the impact of parameters on. For display in title only.
  • cp_perf (float [OPTIONAL]) – Value of the reference simulation, used to reset all other data. For display in title only.
  • select_cols (int [OPTIONAL]) – Number of parameters to display the impact of. By default, don’t skip anything.
  • filepath (str [OPTIONAL]) – Path to the file to save the plot into, if any. Leave blank to skip saving to file.
  • plt_style (dict) – General styling keyword for a Matplotlib plot. Supports all attributes of a app_common..mpl_tools..mpl_style_description.PltStyleDescription. # noqa

Examples

>>> print(data)
                          Stop collect               Start collect
low1                          3.411318                    1.003988
high1                        -4.069830                   -0.740883
low2                          6.179353                    3.698790
high2                        -9.043037                   -5.305777
set point                     0.000000                    0.000000
>>> perf_name = 'Step Yield'
>>> cp_perf = 69.80
>>> plot_performance_as_tornado_plot(data, perf_name, cp_perf=cp_perf,
                                     title_fontsize=24)
kromatography.plotting.mpl_param_impact_plot.extract_perf_data(param_grids, perf_name, index_desc, param_labels=None, param_list=None)[source]

Convert a dictionary of grid data, aggregate it and sort it to prepare it for plot_performance_as_tornado_plot().

Parameters:
  • param_grids (dict) – Dictionary mapping scanned parameter names to the grid’s group_data contained in 5-point or 7-point simulation grids, each scanning 1 parameter, to study their impact on performances.
  • perf_name (str) – Name of the performance to extract data for.
  • index_desc (list) – List of descriptions of the index. Depending on how the grid was created, the location of the low, center and high value in the index may differ. Typical values are [“low1”, “high1”, “low2”, “high2”, “set point”] and [“low2”, “low1”, “set point”, “high1”, “high2”].
  • param_labels (dict, [OPTIONAL]) – Mapping between parameters scanned and a shortened/pretty version to display in output DF. Defaults to standards stored in this module.
  • param_list (dict, [OPTIONAL]) – Mapping between parameter scanned and a description of how it was scanned: center value, the difference(s) with the values explored, and a string representation of the unit of the center value. No pretty display of unit/range information in the results if not provided.

kromatography.plotting.mpl_plot_akta module

Utility for easy exploration of content of AKTA files.

kromatography.plotting.mpl_plot_akta.plot_akta_data(akta_content)[source]

Display 1 timeseries read from an AKTA file.

Parameters:akta_content (dict) –

Dictionary containing numpy arrays with a set of x values and y values. These arrays are assumed to be mapped to keys of the form ‘time_NAME’ and NAME where NAME describes the type of data stored.

This expects a dictionary as returned by kromatography.io.akta_reader.read_akta.

kromatography.plotting.mpl_plot_chromatogram module

kromatography.plotting.mpl_plot_chromatogram.plot_chromatogram(expt, sim)[source]

Build maplotlib plot to display experimental chromatogram and simulation chromatogram together following legacy code pattern.

FIXME: This should take a study, experiment name/id and optionally a bunch of simulation id and create complete plot data.

kromatography.plotting.mpl_plot_chromatogram.build_data(expt, sim)[source]

Convert experiment and simulation into plot data.

FIXME: This should ideally adapt ExperimentResult/SimulationResult objects to a ChromatographyPlotData that can then be plotted by the ChromatogramPlot (chaco plot) FIXME: check expt and sim are compatible

kromatography.plotting.mpl_sim_grid module

Scripting functions to plot simulation grid performances using Matplotlib.

kromatography.plotting.mpl_sim_grid.plot_sim_group_performances(group_data, param1, param2, show_plots=True, save_plots=False, file_format='.png', **kwargs)[source]

Plot all performance parameters as a function of 2 parameters scanned.

Parameters:
  • group_data (DataFrame) – SimulationGroup output data.
  • param2 (param1,) – Scanned parameters to plot the performances against. First parameter display along the index, second along the columns.
  • show_plots (bool) – Plot all outputs as an interactive Matplotlib window?
  • save_plots (bool) – Save all plots into a (separate) file?
  • file_format (str) – File format to save the plots into. Supported formats: eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff. Ignored if save_to_file=False.
  • kwargs (dict) – Additional plotting parameters. See plot_as_heatmap() for details.
kromatography.plotting.mpl_sim_grid.filter_dataframe(group_data, filter_data)[source]

Filter DataFrame along the parameters (columns) specified.

Parameters:
  • group_data (DataFrame) – Data to filter.
  • filter_data (dict) – Mapping between a parameter name and a 2-tuple of min and max values beyond which to remove data rows.
kromatography.plotting.mpl_sim_grid.extract_output_data(group_data, parameters, param_filter=None)[source]

Extract output data from grid data, and pivot them to prepare to plot.

Parameters:
  • group_data (DataFrame) – SimulationGroup output data.
  • parameters (list) – List of the 2 parameter names to pivot along (first parameter display along the index, second along the columns). There can be more entries in the list, if filtering other parameters is needed.
  • param_filter (dict [OPTIONAL]) – Additional parameters to filter on. The dict maps the additional parameters to the min/max values they need to be within.
kromatography.plotting.mpl_sim_grid.plot_output_as_heatmaps(output_map, filepath='', **kwargs)[source]

Print the dictionary of outputs as 2D heatmaps.

Returns the mapping between the figure created and the performance plotted on it, so that they can be recovered and saved as image files.

Parameters:
  • output_map (dict) – Dictionary of dataframes containing output parameters as a function of 2 scanned parameters.
  • filepath (str) – Folder path to save all produced plots into. Filename will be generated from each output plotted.
  • kwargs (dict) – Additional plotting parameters. See plot_as_heatmap() for details.
Returns:

Mapping between the performance plotted and the figure number.

Return type:

Dict

kromatography.plotting.mpl_sim_grid.plot_as_heatmap(data, title, add_cross_at=None, param_labels=None, smooth='gauss', filepath='', **plt_style)[source]

Build a Matplotlib heatmap to display pivoted table of an output as a function of 2 scanned parameters.

If smoothing is applied, 5 contours are drawn on top of the heatmaps.

Parameters:
  • data (DataFrame) – DataFrame containing output parameter as a function of 2 scanned parameters.
  • title (str) – Name of the output
  • add_cross_at (tuple [OPTIONAL]) – (x, y) coordinate of a red cross to be added. Leave as None to skip.
  • param_labels (dict [OPTIONAL]) – Dictionary mapping parameter names to pretty names to use in plot labels.
  • filepath (str) – Path to the file to save the plot to, if any.
  • smooth (str [OPTIONAL, default="None"]) – What type of smoothing should be applied to the 2D matrix of data before plotting. Supported values are “None” and “gauss”.
  • plt_style (dict) – General styling keyword for a Matplotlib plot. Supports all attributes of a app_common..mpl_tools..mpl_style_description.PltStyleDescription. # noqa

kromatography.plotting.plot_utils module

Plotting Functionality for Experiment and Simulation Results

kromatography.plotting.plot_utils.plot_data(data)[source]

Creates and returns a matplotlib axes with data plotted.

Parameters:data (dict) – “name” : “dataset” pairs, where dataset is a dictionary of ‘x’ data, ‘y’ data, ‘name’ of the dataset, and ‘kind’ of the dataset (see PLOT_PROPERTIES for valid ‘kind’s)

kromatography.plotting.utilities module

Utility functions related to plotting.

Note

The utility functions returning properties for a family / curve can be moved to a separate module with the hardcoded values being instead loaded # from a CSV/JSON file.

class kromatography.plotting.utilities.ColorCycler[source]

Bases: object

Class used to cycle colors based on the experiment / sim name

known_collections = {}
kromatography.plotting.utilities.get_base_properties_for_family(family_name)[source]

Return properties associated with the given family_name.

kromatography.plotting.utilities.get_plot_container_properties_for_family(family_name)[source]

Return properties for the Plot object containing the renderers for a given family.

kromatography.plotting.utilities.get_renderer_properties(collection_source, family, source_type)[source]

Return properties for plotting a log for the given family and source.

The returned properties are passed when creating a renderer using Plot.plot.

kromatography.plotting.utilities.flatten_nested_mapping(data_dict, root=None)[source]

Flatten a nested dictionary to construct a flat dictionary where the keys are POSIX paths indicating the relative position of the values in the original dictionary. i.e. {‘a’: {‘b’: 10}, ‘c’:20} –> {‘a/b’: 10, ‘c’:20}

kromatography.plotting.utilities.interpolate_properties(properties, namespace=None)[source]

Interpolate any fmt strings in properties.

The basic idea is to allow some keys to be named as <attr_name>_fmt with a value being a format string. The format string would be passed a namspace containing the normal keys. This allows us to store plot properties that depend on others properties.

If namespace is explicitly passed, then it is used when interpolating the strings.

Here is an example (note g_fmt contains the format string in input and gets converted to g in the output):

In [16]: aa = {‘a’:10, ‘b’: {‘c’: ‘sfsdsfdsf’}, ‘g_fmt’: “{a}_{b/c}”} In [17]: chaco_chromatogram.interpolate_properties(aa) Out[17]: {‘a’: 10, ‘b’: {‘c’: ‘sfsdsfdsf’}, ‘g’: ‘10_sfsdsfdsf’}