Ejemplo n.º 1
0
import pytest

import os
import shutil
import pkg_resources as pkg

import nltk

from lisc.objects import Counts, Words
from lisc.requester import Requester
from lisc.core.modutils import safe_import
from lisc.utils.db import create_file_structure
from lisc.tests.utils import create_files, load_base, load_arts, load_arts_all
from lisc.tests.utils import TestDB as TDB

plt = safe_import('.pyplot', 'matplotlib')

###################################################################################################
###################################################################################################

def pytest_configure(config):

    # Set backend for matplotlib tests, if mpl is available
    if plt:
        plt.switch_backend('agg')

@pytest.fixture(scope='session', autouse=True)
def download_data():

    # Download required nltk data for tokenizing
    nltk.download('punkt')
Ejemplo n.º 2
0
"""LISC plots - word clouds."""

import random

from lisc.core.modutils import safe_import

wc = safe_import('wordcloud')

###################################################################################################
###################################################################################################

def create_wordcloud(words):
    """Create WordCloud object.

    Parameters
    ----------
    words : dict
        Words to plot, with their corresponding frequencies.

    Returns
    -------
    wc : WordCloud
        Wordcloud definition.
    """

    cloud = wc.WordCloud(background_color=None,
                         mode='RGBA',
                         width=800,
                         height=400,
                         prefer_horizontal=1,
                         relative_scaling=0.5,
Ejemplo n.º 3
0
        def wrapper(*args, **kwargs):

            if safe_import(dependency):
                return func(*args, **kwargs)
Ejemplo n.º 4
0
"""LISC plots - utilities."""

import os
from functools import wraps

from lisc.utils.db import SCDB
from lisc.core.modutils import safe_import

plt = safe_import('.pyplot', 'matplotlib')
sns = safe_import('seaborn')

###################################################################################################
###################################################################################################

def check_args(names, *inputs):
    """Checks a series of inputs, and renames them and packages them, if they are not None.

    Parameters
    ----------
    names : list of str
        List of names to apply to the given inputs.
    *inputs
        Any input variables to check.

    Returns
    -------
    dict
        A dictionary with the new names and values, for all non None inputs.
    """

    return {label : value for label, value in zip(names, inputs) if value}
Ejemplo n.º 5
0
"""LISC plots - plots for counts data.

Notes
-----
The functions here serve as wrappers on external plotting and analysis
libraries, to give access to relevant plots and clustering measures.
"""

from lisc.plts.utils import check_args, check_ax, savefig, get_cmap
from lisc.core.modutils import safe_import

plt = safe_import('.pyplot', 'matplotlib')
sns = safe_import('seaborn')
hier = safe_import('.cluster.hierarchy', 'scipy')

###################################################################################################
###################################################################################################


@savefig
def plot_matrix(data,
                x_labels=None,
                y_labels=None,
                cmap='purple',
                square=False,
                ax=None):
    """Plot a matrix representation of given data.

    Parameters
    ----------
    data : 2d array