Exemple #1
0
#!/usr/bin/python

from brainart.utils import get_avg_rgb, get_color_lookup, generate_matching_df, get_packagedir
from brainart.template import get_template, sub_template, save_template
from glob import glob
import numpy as np
import webbrowser
import tempfile
import pandas
import json
import sys
import os

base = get_packagedir()


def generate(template,
             output_folder=None,
             color_lookup="white",
             image_base_path=None,
             bgcolor="black",
             top=20,
             sample=10):
    '''generate
    create a brainart image using a particular color lookup table
    :param template: the template image to generate brainart for! Only jpg has been tested.
    :param output_folder: output folder for the final file. If not specified, will use TMP
    :param color_lookup: one of "white" "black" "greywhite" or "greyblack" will default to using brainart database, and you do not need to worry about setting image_base_path. If you set this to a custom lookup table (should be a pandas dataframe) then you also need to set image_base_path to be the directory with images defined in your lookup table index. Default color lookup is white.
    :param image_base_path: Only specify if you provide a custom color lookup pandas. Default is None, as the base path is the github repo images. 
    :param top: The number of top matches to sample from. Smaller values mean less variation in brains and color. Higher values means possibly more variation in color, and more brains.
    :param bgcolor: background color (string or hex) for the output html page. Default is black, and will be matched to color lookup if one is provided.
Exemple #2
0
#!/usr/bin/python

from brainart.utils import get_packagedir
base = get_packagedir()

def get_template(template_name,ext="html"):
    '''get_template
    :param template_name: name of template (without suffix) to get in the template package folder
    :param ext: extension of template (default is html)
    '''
    template_file = "%s/templates/%s.%s" %(base,template_name,ext)
    filey = open(template_file,"r")
    template = "\n".join(filey.readlines())
    filey.close()
    return template


def sub_template(template,template_tag,substitution):
    '''sub_template
    make a substitution for a template_tag in a template
    :param template: the template, read in as a str
    :param template_tag: the tag in the template, surrounded with {{}}
    :param substitution: the text (str) to substitute with
    '''
    template = template.replace("{{%s}}" %template_tag,substitution)
    return template

def save_template(output_file,html_snippet):
    '''save_template
    :param output_file: the output file to save the template to
    :param html_snippet: the template text to save