<commit_before>"""Plotting functions
Helps visualizing spherical microphone data.
"""
import numpy as _np
from collections import namedtuple

from plotly.offline import plot as plt_offline
from plotly.offline import iplot
import plotly.graph_objs as go
from plotly import tools

from .process import plane_wave_decomp
from .utils import env_info, progress_bar, current_time


def showTrace(trace, layout=None, title=None):
    """ Wrapper around plotlys offline .plot() function

    Parameters
    ----------
    trace : plotly_trace
       Plotly generated trace to be displayed offline
    colorize : Bool, optional
       Toggles bw / colored plot [Default: True]

    Returns
    -------
    fig : plotly_fig_handle
       JSON representation of generated figure
    """
    if not layout:
        layout = go.Layout(
            scene=dict(
                xaxis=dict(range=[-1, 1]),
                yaxis=dict(range=[-1, 1]),
                zaxis=dict(range=[-1, 1]),
                aspectmode='cube'
            )
        )
    # Wrap trace in array if needed
    if not isinstance(trace, list):
        trace = [trace]

    fig = go.Figure(
        data=trace,
        layout=layout
    )

    # if colorize:
    #    data[0].autocolorscale = False
    #    data[0].surfacecolor = [0, 0.5, 1]
    if env_info() == 'jupyter_notebook':
        iplot(fig)
    else:
        if title is None:
            title = str(current_time())
        plt_offline(fig, filename=title + '.html')

    return fig


def makeMTX(spat_coeffs, radial_filter, kr_IDX, viz_order=None, stepsize_deg=1):
    """Returns a plane wave decomposition over a full sphere

    Parameters
    ----------
    spat_coeffs : array_like
       Spatial fourier coefficients
    radial_filter : array_like
       Modal radial filters
    kr_IDX : int
       Index of kr to be computed
    viz_order : int, optional
       Order of the spatial fourier transform [Default: Highest available]
    stepsize_deg : float, optional
       Integer Factor to increase the resolution. [Default: 1]

    Returns
    -------
    mtxData : array_like
       Plane wave decomposition (frequency domain)

    Note
    ----
    The file generates a Matrix of 181x360 pixels for the
    visualisation with visualize3D() in 1[deg] Steps (65160 plane waves).
    """
<commit_msg>showTrace() - construct filename from title<commit_after>"""Plotting functions
Helps visualizing spherical microphone data.
"""
import numpy as _np
from collections import namedtuple

from plotly.offline import plot as plt_offline
from plotly.offline import iplot
import plotly.graph_objs as go
from plotly import tools

from .process import plane_wave_decomp
from .utils import env_info, progress_bar, current_time


def showTrace(trace, layout=None, title=None):
    """ Wrapper around plotlys offline .plot() function

    Parameters
    ----------
    trace : plotly_trace
       Plotly generated trace to be displayed offline
    colorize : Bool, optional
       Toggles bw / colored plot [Default: True]

    Returns
    -------
    fig : plotly_fig_handle
       JSON representation of generated figure
    """
    if not layout:
        layout = go.Layout(
            scene=dict(
                xaxis=dict(range=[-1, 1]),
                yaxis=dict(range=[-1, 1]),
                zaxis=dict(range=[-1, 1]),
                aspectmode='cube'
            )
        )
    # Wrap trace in array if needed
    if not isinstance(trace, list):
        trace = [trace]

    fig = go.Figure(
        data=trace,
        layout=layout
    )

    if title is not None:
        fig.layout.update(title=title)
        filename = title + '.html'
    else:
        try:
            filename = fig.layout.title + '.html'
        except AttributeError:
            filename = str(current_time()) + '.html'

    # if colorize:
    #    data[0].autocolorscale = False
    #    data[0].surfacecolor = [0, 0.5, 1]
    if env_info() == 'jupyter_notebook':
        iplot(fig)
    else:
        plt_offline(fig, filename=filename)

    return fig


def makeMTX(spat_coeffs, radial_filter, kr_IDX, viz_order=None, stepsize_deg=1):
    """Returns a plane wave decomposition over a full sphere

    Parameters
    ----------
    spat_coeffs : array_like
       Spatial fourier coefficients
    radial_filter : array_like
       Modal radial filters
    kr_IDX : int
       Index of kr to be computed
    viz_order : int, optional
       Order of the spatial fourier transform [Default: Highest available]
    stepsize_deg : float, optional
       Integer Factor to increase the resolution. [Default: 1]

    Returns
    -------
    mtxData : array_like
       Plane wave decomposition (frequency domain)

    Note
    ----
    The file generates a Matrix of 181x360 pixels for the
    visualisation with visualize3D() in 1[deg] Steps (65160 plane waves).
    """

{'fraction_non_alphanumeric': 0.09161713465874155, 'fraction_numerical': 0.011067841770854684, 'mean_word_length': 2.310719131614654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6410901', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1387, 'n_words': 452}