• G. Mias Lab »
  • Visualization functions

    Submodule pyiomica.visualizationFunctions

    Visualization functions

    Functions:

    saveFigure(fig, saveDir, label, extension, dpi)

    Function primarily used internally to save and close figures

    makeDataHistograms(df, saveDir, dataName[, ...])

    Make a histogram for each Series (time point) in a Dataframe.

    makeLombScarglePeriodograms(df, saveDir, ...)

    Make a combined plot of the signal and its Lomb-Scargle periodogram for each pandas Series (time point) in a Dataframe.

    addVisibilityGraph(data, times[, dataName, ...])

    Draw a Visibility graph of data on a provided Matplotlib figure.

    makeVisibilityGraph(intensities, positions, ...)

    Make either horizontal or normal visibility graph of a time series using function addVisibilityGraph.

    makeVisibilityBarGraph(data, times, saveDir, ...)

    Bar-plot style visibility graph.

    makePlotOfPeak(data_all, scores, ...)

    Plot peaks.

    addColorbarToFigure(fig, data[, ...])

    Add colorbar to figure

    makeDendrogramHeatmapOfClusteringObject(...)

    Make Dendrogram-Heatmap plot along with Visibility graphs.

    plotHVGBarGraphDual(A, data, times, fileName)

    Bar-plot style horizontal visibility graph with different link colors for different perspectives

    plotNVGBarGraphDual(A, data, times, fileName)

    Bar-plot style natural visibility graph with different link colors for different perspectives

    saveFigure(fig, saveDir, label, extension, dpi, close=True)[source]

    Function primarily used internally to save and close figures

    Parameters:
    saveDir: str

    Path of directories to save the object to

    extension: str, Default ‘.png’

    Path of directories to save the object to

    dpi: int, Default 300

    Figure resolution if rasterized

    close: boolean: Default True

    Whether to close the figure after saving

    Returns:

    None

    Usage:

    saveFigure(fig, saveDir, label, extension, dpi)

    makeDataHistograms(df, saveDir, dataName, figsize=(8, 8), range_min=<function amin>, range_max=<function amax>, includeTitle=True, title='Data @ timePoint:', fontsize=8, fontcolor='b', N_bins=100, color='b', extension='.png', dpi=300)[source]

    Make a histogram for each Series (time point) in a Dataframe.

    Parameters:
    df: pandas.DataFrame

    Data to visualize

    saveDir: str

    Path of directories to save the object to

    dataName: str

    Label to include in the file name

    figsize: tuple, Default (8,8)

    Size of the figure in inches

    range_min: str, Default

    How to determine data minimum

    range_max: int, float or function, Default

    How to determine data maximum

    includeTitle: boolean, Default True

    Path of directories to save the object to

    title: str, Default ‘Data @ timePoint:’

    Text of the title

    fontsize: str, Default 8

    Fontsize of the labels

    fontcolor: str, Default ‘b’

    Color of the title font

    N_bins: int, Default 100

    Number of bins in the histogram

    color: str, Default ‘b’

    Color of the bars

    extension: str, Default ‘.png’

    Path of directories to save the object to

    dpi: int, Default 300

    Figure resolution if rasterized

    Returns:

    None

    Usage:

    makeDataHistograms(df, ‘/dir1’, ‘myData’)

    makeLombScarglePeriodograms(df, saveDir, dataName, minNumberOfNonzeroPoints=5, oversamplingRate=100, figsize=(5, 5), title1='TimeSeries Data', title2='Lomb-Scargle periodogram', extension='.png', dpi=300)[source]

    Make a combined plot of the signal and its Lomb-Scargle periodogram for each pandas Series (time point) in a Dataframe.

    Parameters:
    df: pandas.DataFrame

    Data to visualize

    saveDir: str

    Path of directories to save the object to

    dataName: str

    Label to include in the file name

    minNumberOfNonzeroPoints: int, Default 5

    Minimum number of non-zero points in signal to use it

    oversamplingRate: int, Default 100

    Periodogram oversampling rate

    figsize: tuple, Default (8,8)

    Size of the figure in inches

    title1: str, Default ‘TimeSeries Data’

    Text of the upper title

    title2: str, Default ‘Lomb-Scargle periodogram’

    Text of the lower title

    extension: str, Default ‘.png’

    Path of directories to save the object to

    dpi: int, Default 300

    Figure resolution if rasterized

    Returns:

    None

    Usage:

    makeLombScarglePeriodograms(df, ‘/dir1’, ‘myData’)

    addVisibilityGraph(data, times, dataName='G1S1', coords=[0.05, 0.95, 0.05, 0.95], numberOfVGs=1, groups_ac_colors=['b'], fig=None, numberOfCommunities=6, printCommunities=False, fontsize=None, nodesize=None, level=0.55, commLineWidth=0.5, lineWidth=1.0, withLabel=True, withTitle=False, layout='circle', radius=0.07, noplot=False, horizontal=False, communities=None, minNumberOfCommunities=2, communitiesMethod='betweenness_centrality', direction='left', weight='distance')[source]

    Draw a Visibility graph of data on a provided Matplotlib figure. We represent each timepoint in a series as a node. Temporal events are detected and indicated with solid blue lines encompassing groups of points, or communities. The shortest path identifies nodes (i.e. timepoints) that display high intensity, and thus dominate the global signal profile, are robust to noise, and are likely drivers of the global temporal behavior.

    Parameters:
    data: 2d numpy.array

    Array of data to visualize

    times: 1d numpy.array

    Times corresponding to each data point, used for labels

    dataName: str, Default ‘G1S1’

    label to include in file name

    coords: list, Default [0.05,0.95,0.05,0.95]

    Coordinates of location of the plot on the figure

    numberOfVGs: int, Default 1

    Number of plots to add to this figure

    groups_ac_colors: list, Default [‘b’]

    Colors corresponding to different groups of graphs

    fig: matplotlib.figure, Default None

    Figure object

    numberOfCommunities: int, Default 6

    Number of communities

    printCommunities: boolean, Default False

    Whether to print communities details to screen

    fontsize: float, Default None

    Size of labels

    nodesize: float, Default None

    Size of nodes

    level: float, Default 0.55

    Distance of the community lines to nodes

    commLineWidth: float, Default 0.5

    Width of the community lines

    lineWidth: float, Default 1.0

    Width of the edges between nodes

    withLabel: boolean, Default True

    Whether to include label on plot

    withTitle: boolean, Default False

    Whether to include title on plot

    layout: str, Default ‘circle’

    Type of the layout. Other option is ‘line’

    radius: float, Default 0.07

    Radius of the circle

    noplot: boolean, Default False

    Whether to make a plot or only calculate communities

    horizontal: boolean, Default False

    Whether to use horizontal or natural visibility graph.

    communities: tuple, Default None
    A tuple containing communities sturcture of network, and networkx Graph:

    List of list, e.g. [[],[],…]

    networkx.Graph

    minNumberOfCommunities: int, Default 2

    Number of communities to find depends on the number of splits. This parameter is ignored in methods that automatically estimate optimal number of communities.

    communitiesMethod: str, Default ‘betweenness_centrality’
    String defining the method to use for communitiy detection:

    ‘Girvan_Newman’: edge betweenness centrality based approach

    ‘betweenness_centrality’: reflected graph node betweenness centrality based approach

    ‘WDPVG’: weighted dual perspective visibility graph method (note to also set weight variable)

    direction:str, default ‘left’
    The direction that nodes aggregate to communities:

    None: no specific direction, e.g. both sides.

    ‘left’: nodes can only aggregate to the left side hubs, e.g. early hubs

    ‘right’: nodes can only aggregate to the right side hubs, e.g. later hubs

    weight: str, Default ‘distance’
    Type of weight for communitiesMethod=’WDPVG’:

    None: no weighted

    ‘time’: weight = abs(times[i] - times[j])

    ‘tan’: weight = abs((data[i] - data[j])/(times[i] - times[j])) + 10**(-8)

    ‘distance’: weight = A[i, j] = A[j, i] = ((data[i] - data[j])**2 + (times[i] - times[j])**2)**0.5

    Returns:
    tuple

    (graph_nx, data, communities)

    Usage:
    addVisibilityGraph(exampleData, exampleTimes, fig=fig, fontsize=16, nodesize=700,

    level=0.85, commLineWidth=3.0, lineWidth=2.0, withLabel=False)

    makeVisibilityGraph(intensities, positions, saveDir, fileName, communities=None, minNumberOfCommunities=2, communitiesMethod='betweenness_centrality', direction='left', weight='distance', printCommunities=False, fontsize=16, nodesize=500, level=0.5, commLineWidth=3.0, lineWidth=2.0, layout='circle', horizontal=False, radius=0.03, figsize=(10, 10), addColorbar=True, colorbarAxisCoordinates=[0.9, 0.7, 0.02, 0.2], colorbarLabelsize=12, colorbarPrecision=2, extension='png', dpi=300)[source]

    Make either horizontal or normal visibility graph of a time series using function addVisibilityGraph. We represent each timepoint in a series as a node. Temporal events are detected and indicated with solid blue lines encompassing groups of points, or communities. The shortest path identifies nodes (i.e. timepoints) that display high intensity, and thus dominate the global signal profile, are robust to noise, and are likely drivers of the global temporal behavior.

    Parameters:
    intensities:

    Data to plot

    positions:

    Time points corresponding to data

    saveDir: str

    Path of directories to save the object to

    fileName: str

    Label to include in the file name

    horizontal: boolean, Default False

    Whether to use horizontal or natural visibility graph. Note that if communitiesMethod ‘WDPVG’ is set, this setting has no effect.

    communities: tuple, Default None
    A tuple containing communities sturcture of network, and networkx Graph:

    List of list, e.g. [[],[],…]

    networkx.Graph

    minNumberOfCommunities: int, Default 2

    Number of communities to find depends on the number of splits. This parameter is ignored in methods that automatically estimate optimal number of communities.

    communitiesMethod: str, Default ‘betweenness_centrality’
    String defining the method to use for communitiy detection:

    ‘Girvan_Newman’: edge betweenness centrality based approach

    ‘betweenness_centrality’: reflected graph node betweenness centrality based approach

    ‘WDPVG’: weighted dual perspective visibility graph method (note to also set weight variable)

    direction:str, default ‘left’
    The direction that nodes aggregate to communities:

    None: no specific direction, e.g. both sides.

    ‘left’: nodes can only aggregate to the left side hubs, e.g. early hubs

    ‘right’: nodes can only aggregate to the right side hubs, e.g. later hubs

    weight: str, Default ‘distance’
    Type of weight for communitiesMethod=’WDPVG’:

    None: no weighted

    ‘time’: weight = abs(times[i] - times[j])

    ‘tan’: weight = abs((data[i] - data[j])/(times[i] - times[j])) + 10**(-8)

    ‘distance’: weight = A[i, j] = A[j, i] = ((data[i] - data[j])**2 + (times[i] - times[j])**2)**0.5

    printCommunities: boolean, Default False

    Whether to print communities details to screen

    fontsize: float, Default 16

    Labels fontsize

    nodesize: int, Default 500

    Node size

    level: float, Default 0.5

    Level

    commLineWidth: float, Default 3.0

    Communities lines width

    lineWidth: float, Default 2.0

    Edge lines width

    layout: str, Default ‘circle’

    Type of layout, ‘circle’ or ‘line’

    horizontal: boolean, Default False

    Whether to make horizontal of normal visibility graph

    radius: float, Default 0.03

    Rounding of the lines

    figsize: tuple, Default (10,10)

    Figure size in inches

    addColorbar: boolean, Default True

    Whether to add colorbar

    colorbarAxisCoordinates: list, Default [0.90,0.7,0.02,0.2]

    colorbar axis coordinates

    colorbarLabelsize: float, Default 12

    Colorbar labels size

    colorbarPrecision: int, Default 2

    colorbar labels rounding

    extension: str, Default ‘.png’

    Figure extension

    dpi: int, Default 300

    Figure resolution

    Returns:

    None

    Usage:

    makeVisibilityGraph(data, times, ‘dir1/’, ‘myData’)

    makeVisibilityBarGraph(data, times, saveDir, fileName, AdjacencyMatrix=None, horizontal=False, barWidth=0.2, dotColor='b', barColor='r', arrowColor='k', id='', extension='.png', figsize=(8, 4), dpi=300)[source]

    Bar-plot style visibility graph. Representing the intensities as bars, this is equivalent to connecting the top of each bar to another top if there is a direct line-of-sight to that top. The resulting visibility graph has characteristics that reflect the equivalent time series temporal structure and can be used to identify trends.

    Parameters:
    data: 2d numpy.array

    Numpy array of floats

    times: 2d numpy.array

    Numpy array of floats

    fileName: str

    Path where to save the figure file

    fileName: str

    Name of the figure file to save

    AdjacencyMatrix: 2d numpy.array, Default None

    Adjacency matrix of network

    horizontal: boolean, default False

    Horizontal or normal visibility graph

    barWidth: float, default 0.2

    Horizontal or normal visibility graph

    dotColor: str, default ‘b’

    Color of the data points

    barColor: str, default ‘r’

    Color of the bars

    arrowColor: str, default ‘k’

    Color of lines

    id: str or int, default ‘’

    Label to add to the figure title

    extension: str, Default ‘.png’

    Figure format

    figsize: tuple of int, Default (8,4)

    Figure size in inches

    dpi: int, Default 300

    Figure resolution

    Returns:

    None

    Usage:

    makeVisibilityBarGraph(A, data, times, ‘my_figure’)

    makePlotOfPeak(data_all, scores, selected_peak, selected_peak_value, plotID)[source]

    Plot peaks. Function used internally during certain data processing steps

    addColorbarToFigure(fig, data, axisCoordinates=[0.9, 0.7, 0.02, 0.2], cmap=None, norm=None, labelsize=12, precision=2)[source]

    Add colorbar to figure

    Parameters:
    fig: matplotlib.figure

    Data to plot

    cmap: matplotlib.colors.LinearSegmentedColormap, Default None

    Colormap to use

    norm: matplotlib.colors.Normalize, Default None

    Colormap normalization

    axisCoordinates: list, Default [0.90,0.7,0.02,0.2]

    colorbar axis coordinates

    labelsize: float, Default 12

    Colorbar labels size

    precision: int, Default 2

    Colorbar labels rounding

    Returns:

    None

    Usage:

    addColorbarToFigure(fig, data)

    makeDendrogramHeatmapOfClusteringObject(ClusteringObject, saveDir, dataName, AutocorrNotPeriodogr=True, textScale=1.0, figsize=(12, 8), extension='.png', dpi=300, xLabel='Time', plotLabel='Transformed Expression', horizontal=False, minNumberOfCommunities=2, communitiesMethod='WDPVG', direction='left', weight='distance')[source]

    Make Dendrogram-Heatmap plot along with Visibility graphs.

    Parameters:
    ClusteringObject:

    Clustering object

    saveDir: str

    Path of directories to save the object to

    dataName: str

    Label to include in the file name

    AutocorrNotPeriodogr: boolean, Default True

    Whether to use autocorrelation method instead of periodograms

    textScale: float, Default 1.0

    scaling of text size

    figsize: tuple, Default (12,8)

    Figure size in inches

    extension: str, Default ‘.png’

    Figure format extension

    dpi: int, Default 300

    Figure resolution

    xLabel: str, Default ‘Time’

    Label for the x axis in the heatmap

    plotLabel: str, Default ‘Transformed Expression’

    Label for the heatmap plot

    horizontal: boolean, Default False

    Whether to use horizontal or natural visibility graph. Note that if communitiesMethod ‘WDPVG’ is set, this setting has no effect.

    minNumberOfCommunities: int, Default 2

    Number of communities to find depends on the number of splits. This parameter is ignored in methods that automatically estimate optimal number of communities.

    communitiesMethod: str, Default ‘WDPVG’
    String defining the method to use for communitiy detection:

    ‘Girvan_Newman’: edge betweenness centrality based approach

    ‘betweenness_centrality’: reflected graph node betweenness centrality based approach

    ‘WDPVG’: weighted dual perspective visibility graph method (note to also set weight variable)

    direction:str, default ‘left’
    The direction that nodes aggregate to communities:

    None: no specific direction, e.g. both sides.

    ‘left’: nodes can only aggregate to the left side hubs, e.g. early hubs

    ‘right’: nodes can only aggregate to the right side hubs, e.g. later hubs

    weight: str, Default ‘distance’
    Type of weight for communitiesMethod=’WDPVG’:

    None: no weighted

    ‘time’: weight = abs(times[i] - times[j])

    ‘tan’: weight = abs((data[i] - data[j])/(times[i] - times[j])) + 10**(-8)

    ‘distance’: weight = A[i, j] = A[j, i] = ((data[i] - data[j])**2 + (times[i] - times[j])**2)**0.5

    Returns:

    None

    Usage:

    makeDendrogramHeatmap(myObj, ‘/dir1’, ‘myData’, AutocorrNotPeriodogr=True)

    plotHVGBarGraphDual(A, data, times, fileName, title='', fontsize=8, barwidth=0.05, figsize=(8, 4), dpi=600)[source]

    Bar-plot style horizontal visibility graph with different link colors for different perspectives

    Parameters:
    A: 2d numpy.array

    Adjacency matrix

    data: 2d numpy.array

    Data used to make the visibility graph

    times: 1d numpy.array

    Times corresponding to data points

    fileName: str

    Name of the figure file to save

    title: str, Default ‘’

    Label to add to the figure title

    figsize: tuple of int, Default (8,4)

    Figure size in inches

    dpi: int, 600

    Resolution of the image

    barwidth: float, Default 0.05

    The bar width

    fontsize:int, Default 8

    The text font size

    Returns:

    None

    Usage:

    PlotHorizontalVisibilityGraph(A, data, times, ‘Figure.png’, ‘Test Data’)

    plotNVGBarGraphDual(A, data, times, fileName, title='', fontsize=8, barwidth=0.05, figsize=(8, 4), dpi=600)[source]

    Bar-plot style natural visibility graph with different link colors for different perspectives

    Parameters:
    A: 2d numpy.array

    Adjacency matrix

    data: 2d numpy.array

    Data used to make the visibility graph

    times: 1d numpy.array

    Times corresponding to data points

    fileName: str

    Name of the figure file to save

    title: str, Default ‘’

    Label to add to the figure title

    figsize: tuple of int, Default (8,4)

    Figure size in inches

    dpi: int, 600

    Resolution of the image

    barwidth: float, Default 0.05

    The bar width

    fontsize:int, Default 8

    The text font size

    Returns:

    None

    Usage:

    PlotVisibilityGraph(A, data, times, ‘FIgure.png’, ‘Test Data’)