Exemple #1
14
def test_document():
    geometry_options = {
        "includeheadfoot": True,
        "headheight": "12pt",
        "headsep": "10pt",
        "landscape": True
    }

    doc = Document(
        default_filepath='default_filepath',
        documentclass='article',
        fontenc='T1',
        inputenc='utf8',
        lmodern=True,
        data=None,
        page_numbers=True,
        indent=False,
        document_options=["a4paper", "12pt"],
        geometry_options=geometry_options
    )

    repr(doc)

    doc.append('Some text.')
    doc.change_page_style(style="empty")
    doc.change_document_style(style="plain")
    doc.add_color(name="lightgray", model="gray", description="0.6")
    doc.add_color(name="abitless", model="gray", description="0.8")
    doc.set_variable(name="myVar", value="1234")
    doc.set_variable(name="myVar", value="1234")
    doc.change_length(parameter=r"\headheight", value="0.5in")

    doc.generate_tex(filepath='')
    doc.generate_pdf(filepath='', clean=True)
Exemple #2
0
def arxiv_search(search_query):

    url = 'http://export.arxiv.org/api/query?search_query=all:' + \
        search_query + '&start=0&max_results=5'
    data = urllib.request.urlopen(url).read()

    soup = bs(data, features='xml')
    title_array = []
    summary_array = []

    for i in soup.findAll('title'):
        title_array.append(i)

    for i in soup.findAll('summary'):
        summary_array.append(i)

    doc = Document()
    doc.packages.append(
        Package(
            'geometry',
            options=[
                'tmargin=1cm',
                'lmargin=1cm',
                'rmargin=1cm']))

    with doc.create(Section('Search results for \"' + search_query + '\"')):

        for i in range(1, 5):
            doc.append(Subsection(italic(title_array[i].string)))
            doc.append(summary_array[i].string)

    doc.generate_pdf()
Exemple #3
0
def circuit_to_pdf_using_qcircuit_via_tex(circuit: circuits.Circuit,
                                          filepath: str,
                                          pdf_kwargs=None,
                                          qcircuit_kwargs=None,
                                          clean_ext=('dvi', 'ps'),
                                          documentclass='article'):
    """Compiles the QCircuit-based latex diagram of the given circuit.

    Args:
        circuit: The circuit to produce a pdf of.
        filepath: Where to output the pdf.
        pdf_kwargs: The arguments to pass to generate_pdf.
        qcircuit_kwargs: The arguments to pass to
            circuit_to_latex_using_qcircuit.
        clean_ext: The file extensions to clean up after compilation. By
            default, latexmk is used with the '-pdfps' flag, which produces
            intermediary dvi and ps files.
        documentclass: The documentclass of the latex file.
    """
    pdf_kwargs = {'compiler': 'latexmk', 'compiler_args': ['-pdfps'],
                  **({} if pdf_kwargs is None else pdf_kwargs)}
    qcircuit_kwargs = {} if qcircuit_kwargs is None else qcircuit_kwargs
    tex = circuit_to_latex_using_qcircuit(circuit, **qcircuit_kwargs)
    doc = Document(documentclass=documentclass, document_options='dvips')
    doc.packages.append(Package('amsmath'))
    doc.packages.append(Package('qcircuit'))
    doc.append(NoEscape(tex))
    doc.generate_pdf(filepath, **pdf_kwargs)
    for ext in clean_ext:
        try:
            os.remove(filepath + '.' + ext)
        except (OSError, IOError) as e:
            if e.errno != errno.ENOENT:
                raise
Exemple #4
0
def generate_info_report():
			"""
			Generate a report with cover, status und last 2 lines in log for every test
			"""

			## Define the geometry for LaTeX files
			geometry_options = {
					"head": "40pt",
					"margin": "0.5in",
					"bottom": "0.6in",
					"includeheadfoot": True
				}


			## Create the LaTeX object, a instance of Document Class
			doc = Document(documentclass='article', geometry_options=geometry_options)

			## Add cover
			generate_cover2(doc)
			doc.append(NewPage())

			## Add status table
			generate_status_tabel(doc)
			doc.append(NewPage())

			## Add last 2 lines in log.txt
			for i in range(1, 4):
					generate_info_list(doc, i)


			doc.generate_pdf("RiMEA-Projekt Analyse", clean_tex=False)
def test():
    doc = Document("utils_escape_latex")
    section = Section('Escape LaTeX characters test')

    text = escape_latex('''\
    & (ampersand)
    % (percent)
    $ (dollar)
    # (number)
    _ (underscore)
    { (left curly brace)
    } (right curly brace)
    ~ (tilde)
    ^ (caret)
    \\ (backslash)
    --- (three minuses)
    a\xA0a (non breaking space)
    [ (left bracket)
    ] (right bracket)
    ''')

    section.append(text)
    doc.append(section)

    doc.generate_pdf()
def build_document(transcript):
    """
    Processes a Transcript object to build a LaTeX document.
    """
    # Open temporary file
    doc = Document(documentclass='scrartcl', title=transcript.title,
                   subtitle=transcript.school,
                   author=transcript.student,
                   date=transcript.date.strftime('%d %B %Y'), temporary=True)

    doc.packages.append(Package('geometry', option='margin=1.0in'))
    doc.preamble.append(Command('renewcommand', argument=['\\familydefault', '\\sfdefault']))

    doc.append(Command('maketitle'))

    # Iterate through each transcript section
    for t_section in transcript.sections:
        # Create new section
        s = Section(escape_latex(t_section.title))
        # Add content to section
        for s_line in t_section.content:
            s_line = '\t'.join(s_line)
            s.append(escape_latex(s_line) + ' \\\n')

        # Add subsections to section
        for t_subsection in t_section.subsections:
            ss = Subsection(escape_latex(t_subsection.title))
            num_cols = max(len(l) for l in t_subsection.content)
            ss_table = Table(' l ' * num_cols)
            # Add content to subsection
            for ss_line in t_subsection.content:

                ss_line = '\t'.join(ss_line)
                if ss_line.startswith('Course Topic'):
                    ss_table.append('&')
                    ss_table.add_multicolumn(num_cols-1, 'l',
                                             escape_latex(ss_line))
                    ss_table.append(r'\\')
                elif not ss_line[:3].isupper() and not ss_line.startswith('Test'):
                    ss_table.add_multicolumn(num_cols, 'l', escape_latex(ss_line))
                    ss_table.append(r'\\')
                else:
                    if ss_line.startswith('TERM'):
                        ss_table.add_hline()
                    filled = escape_latex(ss_line).split('\t')
                    filled += (num_cols - len(filled)) * ['']
                    ss_table.add_row(filled)

            ss.append(ss_table)
            s.append(ss)

        doc.append(s)
    doc.generate_pdf(clean=True)

    return doc
Exemple #7
0
def get_cv_doc(filename):
    """Returns a pylatex.Document instance pre-loaded with everything needed for my cv style."""
    doc = Document(filename,
                   documentclass='article')

    # Set Packages
    doc.packages.append(Package('marginnote'))
    doc.packages.append(UnsafeCommand('reversemarginpar'))
    doc.packages.append(Package('graphicx'))
    doc.packages.append(Package('classicthesis', options='nochapters'))
    doc.packages.append(Package('currvita', options='LabelsAligned'))
    doc.packages.append(Package('hyperref'))
    doc.packages.append(UnsafeCommand('hypersetup', extra_arguments=r'colorlinks, breaklinks, urlcolor=Maroon, linkcolor=Maroon'))

    doc.packages.append(UnsafeCommand('newlength', r'\datebox', ))
    doc.packages.append(UnsafeCommand('settowidth', r'\datebox', extra_arguments='Tuebingen, Germany'))

    doc.packages.append(UnsafeCommand('renewcommand', r'\cvheadingfont', extra_arguments=r'\LARGE\color{Maroon}'))

    # Unchanged-ish (Extra line break at the end)
    doc.packages.append(UnsafeCommand('newcommand', r'\SubHeading', options=1,
                             extra_arguments=r'\vspace{1em}\noindent\spacedlowsmallcaps{#1}\vspace{0.7em}\\'))

    doc.packages.append(UnsafeCommand('newcommand', r'\Email', options=1,
                             extra_arguments=r'\href{mailto:#1}{#1}'))

    # Unchanged
    doc.packages.append(UnsafeCommand('newcommand', r'\MarginText', options=1, extra_arguments=r'\marginpar{\raggedleft\small#1}'))

    # Unchanged
    doc.packages.append(UnsafeCommand('newcommand', r'\Description', options=1,
                             extra_arguments=r'\hangindent=2em\hangafter=0\footnotesize{#1}\par\normalsize\vspace{1em}'))

    doc.packages.append(UnsafeCommand('newcommand', r'\DescMarg', options=2,
                             extra_arguments=r'\noindent\hangindent=2em\hangafter=0 \parbox{\datebox}{\small} \MarginText{#1} #2 \vspace{0.3em}\\'))

    ##################
    doc.packages.append(UnsafeCommand('newcommand', r'\HeaderOnly', options=2,
                                      extra_arguments= r'\noindent\hangindent=2em\hangafter=0 \parbox{\datebox}{\small \textit{#1}}\hspace{1.5em} #2 \vspace{0.5em}\\'))

    doc.packages.append(UnsafeCommand('newcommand', r'\EntryHeader', options=3,
                             extra_arguments=r'\noindent\hangindent=2em\hangafter=0 \parbox{\datebox}{\small \textit{#2}}\hspace{1.5em} \MarginText{#1} #3 \vspace{0.5em}'))

    doc.packages.append(UnsafeCommand('newcommand', r'\NewEntry', options=4,
            extra_arguments=r'\EntryHeader{#1}{#2}{#3}\\\Description{#4}'))




    # Fill Document
    doc.append(UnsafeCommand('thispagestyle', 'empty'))
    doc.append(NoEscape(r'\raggedright'))

    return doc
Exemple #8
0
def test():
    doc = Document()
    section = Section('Multirow Test')
    figure = Figure()
    image_filename = os.path.join(os.path.dirname(__file__),
                                  '../examples/kitten.jpg')
    figure.add_image(image_filename)
    figure.add_caption('Whoooo an imagage of a pdf')
    section.append(figure)
    doc.append(section)

    doc.generate_pdf()
Exemple #9
0
    def _upload_problem(self, problem):
        """Uploads a specified problem to imgur.

        Returns:
            A tuple (str, (int, int)), where str is the url, on imgur and
            the tuples are the dimensions of the image (width, height).
        Raises:
           LatexParsingException : there was an issue parsing the document
        """
        default_doc = []
        # populate doc with the appropriate problem
        for line in problem[0]:
            # these first two statements are for wrapping the title around in a minipage which allows
            # the problem to be generated on one page and doesn't invoke \newpage
            if line == '\\begin{document}':
                default_doc.append(NoEscape(line))
                default_doc.append(NoEscape('\\begin{minipage}{\\textwidth}'))
            elif line == '\\maketitle':
                default_doc.append(NoEscape(line))
                default_doc.append(NoEscape('\\end{minipage}'))
            elif line == '\\end{itemize}':
                for line2 in problem[1]:
                    default_doc.append(NoEscape(line2))
                default_doc.append(NoEscape(line))
            else:
                default_doc.append(NoEscape(line))

        doc_class_line = NoEscape(default_doc[0])
        use_pkg_line = NoEscape(default_doc[1])
        # skip twocolumn since it makes the problem look spread awfully
        opts = filter(lambda pkg: pkg != 'twocolumn', doc_class_line[doc_class_line.find('[') + 1: doc_class_line.find(']')].split(','))
        args = NoEscape(doc_class_line[doc_class_line.find('{') + 1: doc_class_line.find('}')])
        doc = Document(documentclass=Command('documentclass', options=opts, arguments=args))
        # load packages
        doc.packages = [Package(i) for i in use_pkg_line[use_pkg_line.find('{') + 1: use_pkg_line.find('}')].split(',')]
        # position right after \begin{document}
        it = 4
        while default_doc[it].strip() != '\end{document}':
            doc.append(NoEscape(default_doc[it]))
            it += 1
        # fail safe for future problems which may not parse correctly
        try:
            doc.generate_pdf('default', compiler="pdflatex")
        except:
            raise LatexParsingException

        # These are normal Linux commands that are used to convert the pdf
        # file created by pylatex into a snippet
        os.system("pdfcrop default.pdf")
        os.system("pdftoppm default-crop.pdf|pnmtopng > default.png")
        path = os.path.abspath('default.png')
        uploaded_image = self._client.upload_image(path, title="LaTeX")
        return uploaded_image.link, OnlineImage.get_local_image_info(path)
def test():
    doc = Document()
    Subsection('Only a single string', data='Some words')

    sec1 = Section('Only contains one subsection', data='Subsection')

    sec2 = Section('Only a single italic command', data=Command('textit',
                                                                'Hey'))
    sec2.append('something else that is not italic')
    doc.append(sec1)
    doc.append(sec2)

    doc.generate_pdf()
Exemple #11
0
def test_document():
    doc = Document(
        default_filepath="default_filepath",
        documentclass="article",
        fontenc="T1",
        inputenc="utf8",
        lmodern=True,
        data=None,
    )

    doc.append("Some text.")

    doc.generate_tex(filepath="")
    doc.generate_pdf(filepath="", clean=True)
Exemple #12
0
def test_document():
    doc = Document(
        default_filepath='default_filepath',
        documentclass='article',
        fontenc='T1',
        inputenc='utf8',
        lmodern=True,
        data=None,
    )

    repr(doc)

    doc.append('Some text.')

    doc.generate_tex(filepath='')
    doc.generate_pdf(filepath='', clean=True)
Exemple #13
0
def test_document():
    doc = Document(
        default_filepath='default_filepath',
        documentclass='article',
        fontenc='T1',
        inputenc='utf8',
        author='',
        title='',
        date='',
        data=None,
        maketitle=False
    )

    doc.append('Some text.')

    doc.generate_tex(filepath='')
    doc.generate_pdf(filepath='', clean=True)
class TrainingDocumentWriter:

    def __init__(self, title):
        self.title = title
        self.doc = Document(title)
        self.doc.packages.append(Package('geometry', options=['a4paper', 'top=2cm', 'bottom=2.5cm', 'left=2cm', 'right=2cm']))
        self.doc.packages.append(Package('titlesec', options=['sf']))
        self.doc.packages.append(Package('lmodern'))
        self.doc.append(Command('sffamily'))

        return


    def append_plot(self, pyplot, caption=''):
        with self.doc.create(Plt(position='htbp')) as plot:
            plot.add_plot(pyplot, width=ur'\textwidth')
            if caption!='':
                plot.add_caption(caption)

        return

    def append_section(self, section_title='', content=''):
        with self.doc.create(Section(section_title)):
            if content!='':
                self.doc.append(content)
        return

    def generate_pdf(self,filename=u'', clean=True, compiler='pdflatex'):

        #This is a workaround to save the generated pdf in a different directory (not in working dir)
        cur_path = os.getcwd()
        dirlist = filename.split('/')
        os.chdir(os.path.dirname(filename)) #cd to specified directory

        #Remove possible existing file extension (.pdf)
        if '.' in filename:
            self.doc.generate_pdf(dirlist[len(dirlist)-1].split('.')[0])
        else:
            self.doc.generate_pdf(dirlist[len(dirlist)-1])

        os.chdir(cur_path) #cd to original working directory

        return
Exemple #15
0
def generate_eva_report():
		"""
    Generate a report which contains the evacution time for every test
    """
		geometry_options = {
		"head": "40pt",
		"margin": "0.5in",
		"bottom": "0.6in",
		"includeheadfoot": True
		}
		doc = Document(geometry_options=geometry_options)

		## Define style of report
		reportStyle = PageStyle("reportStyle")

		with reportStyle.create(Head("R")) as left_header:
				with left_header.create(MiniPage(width=NoEscape(r"0.49\textwidth"),
				                                  pos='c', align='l')) as title_wrapper:
					title_wrapper.append(LargeText(bold("RiMEA-Projekt")))
					title_wrapper.append(LineBreak())
					title_wrapper.append(MediumText(bold("Anlyse")))

		doc.preamble.append(reportStyle)

		## Apply Pagestyle
		doc.change_document_style("reportStyle")

		## Create table
		with doc.create(LongTabu("X[c] X[c]",
		                       row_height=1.5)) as report_table:
				report_table.add_row(["Test",
				                    "evacuation time(s)"],
				                   mapper=bold)
				report_table.add_hline()

		## Write the results of 3 tests in table
		for i in range(1,4):
			report_table.add_row(i, get_evac_time(i)[0])

		doc.append(NewPage())

		doc.generate_pdf("RiMEA-Projekt Evacution Analyse", clean_tex=False)
Exemple #16
0
    def handle_request(self, latex_expr):
        """Uploads LaTeX formated equations to imgur and returns a URL.

        Args:
            latex_expr: string that is to converte to LaTeX, requires that string is enclosed by $.
            >>> handle_request("$\int \sqrt{1+\cos x + \sin x} dx$")
        Returns:
            A tuple (str, (int, int)), where str is the url, on imgur and
            the tuples are the dimensions of the image (width, height).
        """
        # create a bare bones latex document with only the one line specified from the user in the document.
        doc = Document(documentclass='minimal')
        doc.packages = [Package(NoEscape(i)) for i in self.packages.split(',')]
        doc.append(NoEscape(latex_expr))
        doc.generate_pdf('default', compiler_args=['-no-shell-escape', ], compiler="pdflatex", clean=True, clean_tex=True)
        # These are normal Linux commands that are used to convert the pdf
        # file created by pylatex into a snippet
        os.system("pdfcrop default.pdf")
        os.system("pdftoppm default-crop.pdf|pnmtopng > default.png")
        path = os.path.abspath('default.png')
        uploaded_image = self._client.upload_image(path, title="LaTeX")
        return uploaded_image.link, OnlineImage.get_local_image_info(path)
Exemple #17
0
def start_doc(title, date=datetime.today().date()):
	docclass = Command('documentclass', arguments=Arguments('article'), options=Options('titlepage'))
	# Start LaTex Doc
	doc = Document(title=title, date=date, author='Ken Payne [kenpay@]', maketitle=True, documentclass=docclass)
	#doc.packages.append(Command('usepackage', options=Options('a4paper'), arguments=Arguments('geometry')))
	doc.packages.append(Command('renewcommand', arguments=Arguments('\\familydefault','\sfdefault')))
	doc.packages.append(Command('usepackage', arguments=Arguments('caption, setspace')))
	doc.packages.append(Command('captionsetup', arguments=Arguments('font={large, stretch=1.3}')))
	#doc.packages.append(Command('usepackage', arguments=Arguments('showframe')))
	doc.packages.append(Command('usepackage', arguments=Arguments('geometry'), options=Options('top=1in', 'bottom=1in', 'left=1in', 'right=1in')))
	doc.packages.append(Command('usepackage', arguments=Arguments('tocloft')))
	doc.packages.append(Command('renewcommand', arguments=Arguments('\cftsecleader}{\cftdotfill{\cftdotsep}')))
	doc.packages.append(Command('usepackage', arguments=Arguments('booktabs')))
	doc.packages.append(Command('usepackage', arguments=Arguments('graphicx')))
	doc.packages.append(Command('usepackage', arguments=Arguments('subcaption')))
	doc.packages.append(Command('usepackage', arguments=Arguments('subcaption')))
	doc.packages.append(Command('usepackage', arguments=Arguments('xcolor'), options=Options('usenames,dvipsnames')))
	doc.packages.append(Command('usepackage', arguments=Arguments('fancyheadings')))
	doc.packages.append("\\pagestyle{fancy}")
	doc.packages.append("\\chead{\\bfseries \\textcolor{Gray}{CONFIDENTIAL}}")
	doc.packages.append("\\setcounter{totalnumber}{6}")
	doc.packages.append("\\usepackage{pdflscape}")
	doc.packages.append("\\usepackage[colorlinks = true, linkcolor = blue, urlcolor  = blue, citecolor = blue, anchorcolor = blue]{hyperref}")
	#doc.packages.append(Command('extrafloats', arguments=Arguments(100)))
	doc.packages.append("\\hypersetup{linktocpage}")
	doc.packages.append("\\usepackage{longtable}")
	doc.packages.append("\\usepackage[cc]{titlepic}")
	doc.packages.append("\\titlepic{\centering\includegraphics[width=0.3\\textwidth]{aws.png}}")
	doc.packages.append("\\usepackage[none]{hyphenat}")
	doc.packages.append("\\usepackage[flushleft]{threeparttable}")

	# ----- Doc Begins Here -----
	doc.append(Command('begin', arguments=Arguments('abstract')))
	doc.append("Please add campaign code \href{https://na3.salesforce.com/701500000016PTG}{EMEA-UKIR-FY15-SMART-Report Tool-Tracking} to any  opportunities\
				created. This helps me to asses the usefulness of the tool and to justify any time spent on it!\\\\\
				\\\\\
				Report generated from SMART data for given territory/territories, with the following aims:\\\\\
				\\begin{enumerate}\
				\\item To reduce the 'undiferentiated heavy lifting' associated with performance analysis of\
				a territory. It is my experiance that similar analytics are currently run using SMART/excel, but\
				depend heavily on detailed knowledge of these tools. This report aims remove this skill barrier between AM's\
				and valuable territory insight, allowing more time to be spent on direct customer engagements.\
				\\item To provide \\textbf{actionable} insights into customer spend behaviour by identifying lists of customers\
				exhibiting behaviours of interest (e.g. significant increases, customers moving across tier thresholds etc.).\
				\\end{enumerate}")
	doc.append(Command('end', arguments=Arguments('abstract')))
	doc.append(Command('tableofcontents'))
	return doc
def main(fname, width, *args, **kwargs):
    doc = Document(fname)
    doc.packages.append(Package('geometry', options=['left=2cm', 'right=2cm']))

    doc.append('Introduction.')

    with doc.create(Section('I am a section')):
        doc.append('Take a look at this beautiful plot:')

        with doc.create(Figure(position='htbp')) as plot:
            plot.add_plot(width=NoEscape(width), *args, **kwargs)
            plot.add_caption('I am a caption.')

        doc.append('Created using matplotlib.')

    doc.append('Conclusion.')

    doc.generate_pdf()
Exemple #19
0
def george_report(csv, title):
	# get todays date
	today = datetime.today().date()
	#threshold = date(today.year, today.month, 1)
	threshold = date(today.year, today.month-1, 1)

	# Load data
	data_set = load_data(csv)

	# Start LaTex Doc
	doc = Document(title=title, date=today, author='Ken Payne [kenpay@]', maketitle=True)
	#doc.packages.append(Command('usepackage', options=Options('a4paper'), arguments=Arguments('geometry')))
	doc.packages.append(Command('renewcommand', arguments=Arguments('\\familydefault','\sfdefault')))
	doc.packages.append(Command('usepackage', arguments=Arguments('caption, setspace')))
	doc.packages.append(Command('captionsetup', arguments=Arguments('font={large, stretch=1.3}')))
	#doc.packages.append(Command('usepackage', arguments=Arguments('showframe')))
	doc.packages.append(Command('usepackage', arguments=Arguments('geometry'), options=Options('top=1in', 'bottom=1in', 'left=1in', 'right=1in')))
	doc.packages.append(Command('usepackage', arguments=Arguments('tocloft')))
	doc.packages.append(Command('renewcommand', arguments=Arguments('\cftsecleader}{\cftdotfill{\cftdotsep}')))


	# Report Sections
	# Table of Contents
	doc.append(Command('tableofcontents'))
	# Overview
	overview(doc, data_set, threshold)
	# Fast Movers
	doc.append(Command('clearpage'))
	fast_movers(doc, data_set, 100, threshold, 500)
	# Churn
	doc.append(Command('clearpage'))
	churn(doc, data_set, 5, threshold, 500)
	# Thresholds
	doc.append(Command('clearpage'))
	multi_thresholds(doc, data_set, threshold, deep_dive_thresholds)

	#doc.generate_tex()
	doc.generate_pdf()

	# Clean Up
	cleardirs(".")
Exemple #20
0
    def make_doc(self, foirequest):
        doc = Document(
            lmodern=True,
            geometry_options={
                "a4paper": True,
                "margin": "1in",
            },
        )
        # Change font
        doc.packages.append(Package('fontspec,xunicode,array'))
        doc.packages.append(Package('sectsty'))
        doc.preamble.append(NoEscape("\\usepackage{helvet}"))
        doc.preamble.append(NoEscape("\\sectionfont{\\fontsize{12}{15}\\selectfont}"))

        # Adjust description list
        doc.packages.append(Package('enumitem'))
        doc.preamble.append(NoEscape("\\setlist[description]{labelindent=0cm,style=multiline,leftmargin=1.5cm}"))

        # Hyphenation
        doc.append(NoEscape("\\lefthyphenmin=5"))
        doc.append(NoEscape("\\sloppy"))

        # doc.preamble.append(Command('title', foirequest.title))
        # doc.preamble.append(Command('author', foirequest.get_absolute_domain_short_url()))
        # doc.preamble.append(Command('date', NoEscape('\\today')))
        # doc.append(NoEscape('\\maketitle'))

        # Set up header and footer
        header = PageStyle("header")
        with header.create(Foot("L")):
            header.append(italic(settings.SITE_NAME))
        with header.create(Head("C")):
            header.append(foirequest.title)
        with header.create(Foot("R")):
            header.append(str(
                _('Request #{request_no}').format(request_no=foirequest.pk)))
        with header.create(Foot("C")):
            header.append(italic(NoEscape(r'Seite \thepage\ von \pageref{LastPage}')))
        doc.preamble.append(header)
        doc.change_document_style("header")

        for i, message in enumerate(foirequest.messages):
            last = i == len(foirequest.messages) - 1
            add_message_to_doc(doc, message)
            if not last:
                doc.append(NewPage())

        return doc
Exemple #21
0
def generate_header():
    geometry_options = {"margin": "0.7in"}
    doc = Document(geometry_options=geometry_options)
    # Add document header
    header = PageStyle("header")
    # Create left header
    with header.create(Head("L")):
        header.append("Page date: ")
        header.append(LineBreak())
        header.append("R3")
    # Create center header
    with header.create(Head("C")):
        header.append("Company")
    # Create right header
    with header.create(Head("R")):
        header.append(simple_page_number())
    # Create left footer
    with header.create(Foot("L")):
        header.append("Left Footer")
    # Create center footer
    with header.create(Foot("C")):
        header.append("Center Footer")
    # Create right footer
    with header.create(Foot("R")):
        header.append("Right Footer")

    doc.preamble.append(header)
    doc.change_document_style("header")

    # Add Heading
    with doc.create(MiniPage(align='c')):
        doc.append(LargeText(bold("Title")))
        doc.append(LineBreak())
        doc.append(MediumText(bold("As at:")))

    doc.generate_pdf("header", clean_tex=False)
def generate_unique():
    geometry_options = {
        "head": "40pt",
        "margin": "0.5in",
        "bottom": "0.6in",
        "includeheadfoot": True
    }
    doc = Document(geometry_options=geometry_options)

    # Generating first page style
    first_page = PageStyle("firstpage")

    # Header image
    with first_page.create(Head("L")) as header_left:
        with header_left.create(
                MiniPage(width=NoEscape(r"0.49\textwidth"),
                         pos='c')) as logo_wrapper:
            logo_file = os.path.join(os.path.dirname(__file__),
                                     'sample-logo.png')
            logo_wrapper.append(
                StandAloneGraphic(image_options="width=120px",
                                  filename=logo_file))

    # Add document title
    with first_page.create(Head("R")) as right_header:
        with right_header.create(
                MiniPage(width=NoEscape(r"0.49\textwidth"), pos='c',
                         align='r')) as title_wrapper:
            title_wrapper.append(LargeText(bold("Bank Account Statement")))
            title_wrapper.append(LineBreak())
            title_wrapper.append(MediumText(bold("Date")))

    # Add footer
    with first_page.create(Foot("C")) as footer:
        message = "Important message please read"
        with footer.create(
                Tabularx("X X X X",
                         arguments=NoEscape(r"\textwidth"))) as footer_table:

            footer_table.add_row(
                [MultiColumn(4, align='l', data=TextColor("blue", message))])
            footer_table.add_hline(color="blue")
            footer_table.add_empty_row()

            branch_address = MiniPage(width=NoEscape(r"0.25\textwidth"),
                                      pos='t')
            branch_address.append("960 - 22nd street east")
            branch_address.append("\n")
            branch_address.append("Saskatoon, SK")

            document_details = MiniPage(width=NoEscape(r"0.25\textwidth"),
                                        pos='t',
                                        align='r')
            document_details.append("1000")
            document_details.append(LineBreak())
            document_details.append(simple_page_number())

            footer_table.add_row([
                branch_address, branch_address, branch_address,
                document_details
            ])

    doc.preamble.append(first_page)
    # End first page style

    # Add customer information
    with doc.create(Tabu("X[l] X[r]")) as first_page_table:
        customer = MiniPage(width=NoEscape(r"0.49\textwidth"), pos='h')
        customer.append("Verna Volcano")
        customer.append("\n")
        customer.append("For some Person")
        customer.append("\n")
        customer.append("Address1")
        customer.append("\n")
        customer.append("Address2")
        customer.append("\n")
        customer.append("Address3")

        # Add branch information
        branch = MiniPage(width=NoEscape(r"0.49\textwidth"),
                          pos='t!',
                          align='r')
        branch.append("Branch no.")
        branch.append(LineBreak())
        branch.append(bold("1181..."))
        branch.append(LineBreak())
        branch.append(bold("TIB Cheque"))

        first_page_table.add_row([customer, branch])
        first_page_table.add_empty_row()

    doc.change_document_style("firstpage")
    doc.add_color(name="lightgray", model="gray", description="0.80")

    # Add statement table
    with doc.create(LongTabu("X[l] X[2l] X[r] X[r] X[r]",
                             row_height=1.5)) as data_table:
        data_table.add_row(
            ["date", "description", "debits($)", "credits($)", "balance($)"],
            mapper=bold,
            color="lightgray")
        data_table.add_empty_row()
        data_table.add_hline()
        row = ["2016-JUN-01", "Test", "$100", "$1000", "-$900"]
        for i in range(30):
            if (i % 2) == 0:
                data_table.add_row(row, color="lightgray")
            else:
                data_table.add_row(row)

    doc.append(NewPage())

    # Add cheque images
    with doc.create(LongTabu("X[c] X[c]")) as cheque_table:
        cheque_file = os.path.join(os.path.dirname(__file__),
                                   'chequeexample.png')
        cheque = StandAloneGraphic(cheque_file, image_options="width=200px")
        for i in range(0, 20):
            cheque_table.add_row([cheque, cheque])

    doc.generate_pdf("complex_report", clean_tex=False)
import os
from pylatex import Document, PageStyle, Head, Foot, Section, Subsection, Tabular, Math, TikZ, Axis, \
    Plot, Figure, Matrix, Alignat, StandAloneGraphic, MiniPage, LineBreak, Center, Command
from pylatex.utils import italic, bold, NoEscape

image_filename = os.path.join(os.path.dirname(__file__), 'Invoices\sus_header.png')
geometry_options = {"tmargin": "1cm", "lmargin": "1cm"}
doc = Document(geometry_options=geometry_options)

with doc.create(Figure(position='h!')) as sus_pic:
    sus_pic.add_image(image_filename, width='550px')

doc.append(Command('noindent'))
doc.append(Command('textbf', 'asdasdasd'))
doc.append(Command('linebreak'))
doc.append(Command('textbf', 'asdasdasd'))

doc.generate_pdf('test', clean_tex=False, compiler='pdflatex')
                # you can append to existing items
                itemize.append(Command("ldots"))


if __name__ == '__main__':
    # Basic document
    doc = Document('basic')
    fill_document(doc)

    # Document with `\maketitle` command activated
    doc = Document()
    image_filename = os.path.join(os.path.dirname(__file__), 'final.png')

    with doc.create(Figure(position='h!')) as logo:
        logo.add_image(image_filename, width='300px')
    doc.preamble.append(Command('title', 'note-o-matic Summary'))
    doc.preamble.append(Command('author', 'Generated using note-o-matic'))
    doc.preamble.append(Command('date', NoEscape(r'\today')))
    doc.append(NoEscape(r'\maketitle'))

    fill_document(doc)

    # Add stuff to the document
    with doc.create(Section('Your notes - reworked.')):
        doc.append('uwu')

    doc.generate_pdf('note-o-maticSummary',
                     clean_tex=False,
                     compiler='/Library/TeX/texbin/pdflatex')
    tex = doc.dumps()  # The document as string in LaTeX syntax
Exemple #25
0
doc.preamble.append(NoEscape(r'\usepackage{appendix}'))
doc.preamble.append(NoEscape(r'\usepackage{graphicx}'))
doc.preamble.append(NoEscape(r'\usepackage{pdflscape}'))
doc.preamble.append(NoEscape(r'\usepackage[margin=1in]{geometry}'))
doc.preamble.append(NoEscape(r'\usepackage{hyperref}'))
doc.preamble.append(
    NoEscape(
        r'\hypersetup{colorlinks=true, linkcolor=blue, filecolor=magenta, urlcolor=cyan}'
    ))
doc.preamble.append(NoEscape(r'\urlstyle{same}'))
doc.preamble.append(NoEscape(r'\linespread{1.6}'))

doc.preamble.append(Command('title', 'Trounceflow Countries: Colombia'))
doc.preamble.append(Command('author', 'Michael Trounce'))
doc.preamble.append(Command('date', NoEscape(r'\today')))
doc.append(NoEscape(r'\maketitle'))

doc.append(NoEscape(r'\begin{abstract}'))
doc.append(
    "The `Trounceflow Countries' series of `living' documents provide real-time dynamic summaries of macroeconomic data relevant to the flows-and-positions analysis of emerging market debt. These macroeconomic data concentrate on the structure of the government bond market but also include other useful but hard-to-wrangle data such as the structure of the local institutional investor base. The data is obtained from the Trounceflow App (trounceflow.com) and the document data is automatically updated in line with the automatic updates on the App; links to the underlying national sources are also given in the `living' documents."
)
doc.append(
    LargeText(
        "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThe values presented in this report are the face values of the bonds"
    ))
doc.append(NoEscape(r'\end{abstract}'))

doc.append(NewPage())
doc.append(NoEscape(r'\tableofcontents'))
doc.append(NewPage())
Exemple #26
0
        to_decimal = print_to_latex_two_decimal(avgscores)

        for i, score in enumerate(to_decimal):
            rows[i].append(score)
    for table, row in zip(tables, rows):
        max_v = max(row[1:])
        new_row = []
        new_row.append(row[0])
        row_temp = row[1:]
        id = 1
        for item in row_temp[::2]:
            if item > row_temp[id]:
                new_row.append(bold(item))
                new_row.append(row_temp[id])
            elif item < row_temp[id]:
                new_row.append(item)
                new_row.append(bold(row_temp[id]))
            else:
                new_row.append(item)
                new_row.append(row_temp[id])
            id += 2
        table.add_row(new_row)

doc = Document("overundersampling_SMOTETomek")
for i, tab, in enumerate(tables):
    section = Section(sections[i])
    section.append(tab)
    doc.append(section)
doc.generate_tex(os.path.join(path, 'wyniki/pliki_tex/'))
doc.generate_pdf(os.path.join(path, 'wyniki/pliki_pdf/'))
Exemple #27
0
    def write(self):
        opening = self.config['opening'].replace(
            '$organization', self.posting.get('organization'))
        closing = self.config['closing'].replace(
            '$organization', self.posting.get('organization'))
        output = Document(documentclass='letter')
        output.preamble.append(Command('signature', self.config['sender']))
        output.preamble.append(
            Command('address', NoEscape(self.return_address())))
        output.preamble.append(Command('date', NoEscape(r'\today')))
        output.append(Command('begin', ['letter', self.employer_address()]))
        output.append(Command('opening', 'Dear Hiring Manager,'))
        output.append(opening + self.write_body())
        output.append(NewLine())
        output.append(NewLine())
        output.append(closing)
        output.append(Command('closing', 'Sincerely,'))
        output.append(Command('end', 'letter'))

        filename = '{0}_{1}'.format(
            self.posting['organization'],
            ' '.join(process_input(self.posting['job_title']))).replace(
                ' ', '_').lower()
        output.generate_pdf(filename)
        output.generate_tex(filename)
Exemple #28
0
# -*- coding: utf-8 -*-
r"""A test to make sure the document compiles with inputenc set to `None`."""

from pylatex.base_classes import Arguments
from pylatex import Document

doc = Document('no_inputenc', inputenc=None)
doc.append('test text')

# Make sure inputenc isn't used
assert not any([p.arguments == Arguments('inputenc') for p in doc.packages])

doc.generate_pdf(clean=True, clean_tex=False, silent=False)
header = PageStyle("header")
doc.preamble.append(NoEscape(r'\usepackage{appendix}'))
doc.preamble.append(NoEscape(r'\usepackage{graphicx}'))
doc.preamble.append(NoEscape(r'\usepackage{pdflscape}'))
doc.preamble.append(NoEscape(r'\usepackage[margin=1in]{geometry}'))
doc.preamble.append(NoEscape(r'\usepackage{hyperref}'))
doc.preamble.append(NoEscape(r'\hypersetup{colorlinks=true, linkcolor=blue, filecolor=magenta, urlcolor=cyan}'))
doc.preamble.append(NoEscape(r'\urlstyle{same}'))

doc.preamble.append(NoEscape(r'\linespread{1.6}'))

doc.preamble.append(Command('title','Trounceflow Countries: Argentina'))
doc.preamble.append(Command('author', 'Michael Trounce'))
doc.preamble.append(Command('date', NoEscape(r'\today')))
#doc.preamble.append(Command('footnote', 'The values presented in this report are the face values of the bonds'))
doc.append(NoEscape(r'\maketitle'))

doc.append(NoEscape(r'\begin{abstract}'))
doc.append("The `Trounceflow Countries' series of `living' documents provide real-time dynamic summaries of macroeconomic data relevant to the flows-and-positions analysis of emerging market debt. These macroeconomic data concentrate on the structure of the government bond market but also include other useful but hard-to-wrangle data such as the structure of the local institutional investor base. The data is obtained from the Trounceflow App (trounceflow.com) and the document data is automatically updated in line with the automatic updates on the App; links to the underlying national sources are also given in the `living' documents.")
doc.append(LargeText("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThe values presented in this report are the face values of the bonds"))
doc.append(NoEscape(r'\end{abstract}'))
doc.append(NewPage())

doc.append(NoEscape(r'\tableofcontents'))
doc.append(NewPage())


#Summary Chapter 1
doc.append(NoEscape(r'\chapter{Executive Summary}'))
doc.append(NewPage())
Exemple #30
0
def generateTex(filepath=None):
    #read all score files for seen and store them in lists
    #scores ordered in list as: BLEU METEOR TER
    mdBaseLine = searchScores('baselineSeen-Score.txt')
    flat = searchScores('flatseen-score.txt')
    str1 = searchScores('str1seen-score.txt')
    str2 = searchScores('str2seen-score.txt')

    geometry_options = {"tmargin": "1cm", "lmargin": "5cm"}
    doc = Document(geometry_options=geometry_options)

    with doc.create(Section('The evaluation scores for Seen set')):
        doc.append(italic('========================================\n'))
        doc.append(
            italic(
                'We mean by system the extended system which contain 3 model: flat,str1,str2\n'
            ))
        doc.append(italic('baseline the basic baseline of webnlg challeng \n'))
        doc.append(
            italic(
                'modify baseline the modified baseline of webnlg challeng \n'))

        with doc.create(Subsection('Table of Evaluation in term of BLEU \n')):
            with doc.create(Tabular('|r|c|')) as table:
                table.add_hline()
                table.add_row((bold("System"), bold("Bleu")))
                table.add_hline()
                #table.add_row(("system",ScoreList[0], bold(ScoreList[1]),ScoreList[2]))
                #table.add_empty_row()
                table.add_row(("baseline", "54.03"))
                table.add_hline()
                table.add_row(("Modify baseline", mdBaseLine[0]))
                table.add_hline()
                table.add_row(("Flat", bold(flat[0])))
                table.add_hline()
                table.add_row(("Structure1", str1[0]))
                table.add_hline()
                table.add_row(("Structure2", str2[0]))
                table.add_hline()
        with doc.create(
                Subsection('Table of Evaluation in term of METEOR \n')):
            with doc.create(Tabular('|r|c|')) as table:
                table.add_hline()
                table.add_row((bold("System"), bold("METEOR")))
                table.add_hline()
                #table.add_row(("system",ScoreList[0], bold(ScoreList[1]),ScoreList[2]))
                #table.add_empty_row()
                table.add_row(("baseline", "0.39"))
                table.add_hline()
                table.add_row(("Modify baseline", mdBaseLine[1]))
                table.add_hline()
                table.add_row(("Flat", bold(flat[1])))
                table.add_hline()
                table.add_row(("Structure1", str1[1]))
                table.add_hline()
                table.add_row(("Structure2", str2[1]))
                table.add_hline()
        with doc.create(Subsection('Table of Evaluation in term of TER \n')):
            with doc.create(Tabular('|r|c|')) as table:
                table.add_hline()
                table.add_row((bold("System"), bold("TER")))
                table.add_hline()
                #table.add_row(("system",ScoreList[0], bold(ScoreList[1]),ScoreList[2]))
                #table.add_empty_row()
                table.add_row(("baseline", "0.40"))
                table.add_hline()
                table.add_row(("Modify baseline", mdBaseLine[2]))
                table.add_hline()
                table.add_row(("Flat", bold(flat[2])))
                table.add_hline()
                table.add_row(("Structure1", str1[2]))
                table.add_hline()
                table.add_row(("Structure2", str2[2]))
                table.add_hline()
            # table.add_row(("baseline","06.13","0.07","0.80"))
    doc.generate_pdf('SeenSetEvaluation ', clean_tex=False)
Exemple #31
0
def PyLaTex_generator(title, section1, section1Title, section2, section2Title,
                      section3, section3Title, path, includeImages):

    now = datetime.datetime.now()

    # Defines the file folder path and the dependences folder path
    filepath = (path + r"/OUTPUT")
    if (os.path.isdir(filepath) == False):
        os.makedirs(filepath)

    dependencesPath = (path + r"/DEPENDENCES")
    if (os.path.isdir(dependencesPath) == False):
        os.makedirs(dependencesPath)

    # Write the LaTex report
    doc = Document(filepath)
    doc.documentclass = Command(
        'documentclass',
        options=['brazilian', '12pt', 'oneside', 'a4paper'],
        arguments=['article'],
    )

    doc.preamble.append(NoEscape(r'\input{DEPENDENCES/preamble.tex}'))
    doc.preamble.append(Command('titulo', {title}))
    doc.preamble.append(NoEscape(r'\data{\today}'))
    doc.append(NoEscape(r'\setFaixa'))
    doc.append(NoEscape(r'\geraTitulo'))
    doc.append(NoEscape(r'\section{' + section1Title + '}'))
    doc.append(section1)
    doc.append(NoEscape(r'\section{' + section2Title + '}'))
    doc.append(section2)
    doc.append(NoEscape(r'\section{' + section3Title + '}'))
    doc.append(section3)

    # Include all images in the report
    if (includeImages == True and os.path.isdir(path + r"/IMAGES") == True):
        doc.append(NoEscape(r'\section{Dados}'))
        c = 1
        imageComand = ""
        imagesPath = path + r"/IMAGES"

        for image in os.listdir(imagesPath):

            if image == "map.png":
                doc.append(
                    NoEscape(r"""
    \begin{figure}[htb]
        \centering
            \includegraphics[scale=0.30]{""" + r"IMAGES/" + image + r"""}
            \caption{Trajetória da sonda sobre o região de São Carlos}    
    \end{figure}
            """))

            elif image == "Map.html":
                pass

            else:
                if os.path.isfile(os.path.join(imagesPath, image)):
                    splittedGraphName = re.split("_", image[:-4])
                    caption = f"Gráfico {splittedGraphName[1]} versus {splittedGraphName[3]}"
                    if c == 4:
                        imageComand = imageComand + r"    \subfloat[" + caption + r"]{\includegraphics[width = 1.5in]{" + r"IMAGES/" + image + r"}}\\" + "\n"
                        c = 1
                    else:
                        imageComand = imageComand + r"    \subfloat[" + caption + r"]{\includegraphics[width = 1.5in]{" + r"IMAGES/" + image + r"}} &" + "\n"
                        c = c + 1

        doc.append(
            NoEscape(r"""
    \begin{figure}[htb]
        \centering
            \begin{tabular}{cccc}
        """ + "\n" + imageComand + r"""
            \end{tabular}
            \caption{Gráficos}    
    \end{figure}
            """))

    filename = (r"zenith_report_{dia}-{mes}-{ano}".format(dia=now.day,
                                                          mes=now.month,
                                                          ano=now.year))
    doc.generate_tex(r"{filepath}/{filename}".format(filepath=filepath,
                                                     filename=filename))

    # Copy dependence files
    shutil.copy(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     "DEPENDENCES/preamble.tex"), dependencesPath)
    shutil.copy(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     "DEPENDENCES/IMAGES/LogoZ.png"), dependencesPath)
    shutil.copy(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     "DEPENDENCES/IMAGES/zenith-faixa.png"), dependencesPath)

    # make_archive(filename, path, path + "/" + filename + ".zip")

    # Creates a zip file
    directoriesList = [
        path + "/DEPENDENCES", path + "/IMAGES", path + "/OUTPUT"
    ]
    zip_files(directoriesList, path + "/" + filename + ".zip")
Exemple #32
0
    string = string.replace('\\)', '$')

    string = string.replace('&amp;', '&')
    string = string.replace('&nbsp;', '')

    return string


doc = Document()

doc.generate_tex()

doc.preamble.append(Command('title', title))
#doc.preamble.append(Command('author', 'Anonymous author'))
doc.preamble.append(Command('date', due_date))
doc.append(NoEscape(r'\maketitle'))

#TODO: deal with tables
#TODO: deal with q's that aren't multiple choice or T/F

#TODO: need amsmath package

with doc.create(Section('Questions')):
    #i=0
    for q in data["questions"]:

        qTitle = q['title']
        with doc.create(Subsection(qTitle)):
            content = q['content']

            content = strip(content)
Exemple #33
0
del cols[cols.index('Id')]

# import pandas as pd
# modified = pd.DataFrame(data=data, columns=cols, index=dataset.index)

# print(dataset.columns)

document = Document(author='Maxim Kurnikov', title='Hazard dataset',
                    maketitle=True)
# document.packages.append(Package('geometry', options=['tmargin=1cm',
#                                                  'lmargin=1cm']))

import time

with document.create(Section('Histograms')):
    document.append('Here will be histograms')
    for i, col in enumerate(cols):
        with document.create(Subsection(escape_latex(col))):
            document.append(escape_latex('Histogram for {feature}'
                                         .format(feature=col)))
            fig = plt.figure()
            sns.distplot(data[:, i], kde=False)
            with document.create(MatplotlibFigure()) as plot:
                plot.add_plot()
                plot.add_caption(escape_latex('{feature} histogram.'
                                              .format(feature=col)))
            plt.close()
            time.sleep(0.01)


with document.create(Section('Correlation matrix')):
    def save_latex(self,
                   uiObj,
                   Design_Check,
                   reportsummary,
                   filename,
                   rel_path,
                   Disp_2d_image,
                   Disp_3d_image,
                   module=''):
        companyname = str(reportsummary["ProfileSummary"]['CompanyName'])
        companylogo = str(reportsummary["ProfileSummary"]['CompanyLogo'])
        groupteamname = str(reportsummary["ProfileSummary"]['Group/TeamName'])
        designer = str(reportsummary["ProfileSummary"]['Designer'])
        projecttitle = str(reportsummary['ProjectTitle'])
        subtitle = str(reportsummary['Subtitle'])
        jobnumber = str(reportsummary['JobNumber'])
        client = str(reportsummary['Client'])

        does_design_exist = reportsummary['does_design_exist']
        osdagheader = '/ResourceFiles/images/Osdag_header_report.png'
        # Add document header
        geometry_options = {
            "top": "5cm",
            "hmargin": "2cm",
            "headheight": "100pt",
            "footskip": "100pt",
            "bottom": "5cm"
        }
        doc = Document(geometry_options=geometry_options, indent=False)
        doc.packages.append(Package('amsmath'))
        doc.packages.append(Package('graphicx'))
        doc.packages.append(Package('needspace'))
        doc.append(pyl.Command('fontsize', arguments=[8, 12]))
        doc.append(pyl.Command('selectfont'))

        doc.add_color('OsdagGreen', 'RGB', '153,169,36')
        doc.add_color('PassColor', 'RGB', '153,169,36')
        doc.add_color('Red', 'RGB', '255,0,0')
        doc.add_color('Green', 'RGB', '0,200,0')
        doc.add_color('FailColor', 'HTML', '933A16')
        header = PageStyle("header")
        # Create center header
        with header.create(Head("C")):
            with header.create(Tabularx('|l|p{4cm}|l|X|')) as table:
                table.add_hline()
                # MultiColumn(4)
                table.add_row((
                    MultiColumn(
                        2,
                        align='|c|',
                        data=('' if companylogo is '' else StandAloneGraphic(
                            image_options="height=0.95cm",
                            filename=companylogo))),
                    MultiColumn(2,
                                align='|c|',
                                data=[
                                    'Created with',
                                    StandAloneGraphic(
                                        image_options="width=4.0cm,height=1cm",
                                        filename=rel_path + osdagheader)
                                ]),
                ))
                table.add_hline()
                table.add_row(('Company Name', companyname, 'Project Title',
                               projecttitle),
                              color='OsdagGreen')
                table.add_hline()
                table.add_row(
                    ('Group/Team Name', groupteamname, 'Subtitle', subtitle),
                    color='OsdagGreen')
                table.add_hline()
                table.add_row(('Designer', designer, 'Job Number', jobnumber),
                              color='OsdagGreen')
                table.add_hline()
                table.add_row(
                    ('Date', time.strftime("%d /%m /%Y"), 'Client', client),
                    color='OsdagGreen')
                table.add_hline()

        # Create right footer
        with header.create(Foot("R")):
            header.append(NoEscape(r'Page \thepage'))
        #
        # doc.preamble.append(header)
        # doc.change_document_style("header")

        # Add Heading
        # with doc.create(MiniPage(align='c')):

        doc.preamble.append(header)
        doc.change_document_style("header")
        with doc.create(Section('Input Parameters')):
            with doc.create(
                    LongTable('|p{5cm}|p{2.5cm}|p{1.5cm}|p{3cm}|p{3.5cm}|',
                              row_height=1.2)) as table:
                table.add_hline()
                for i in uiObj:
                    # row_cells = ('9', MultiColumn(3, align='|c|', data='Multicolumn not on left'))
                    if i == "Selected Section Details" or i == KEY_DISP_ANGLE_LIST or i == KEY_DISP_TOPANGLE_LIST or i == KEY_DISP_CLEAT_ANGLE_LIST:
                        # if type(uiObj[i]) == list:
                        continue
                    if type(uiObj[i]) == dict:
                        table.add_hline()
                        sectiondetails = uiObj[i]
                        image_name = sectiondetails[KEY_DISP_SEC_PROFILE]

                        Img_path = '/ResourceFiles/images/' + image_name + '.png'
                        if (len(sectiondetails)) % 2 == 0:
                            # merge_rows = int(round_up(len(sectiondetails),2)/2 + 2)
                            merge_rows = int((len(sectiondetails) / 2)) + 2
                        else:
                            merge_rows = round_up((len(sectiondetails) / 2), 2)
                        if (len(sectiondetails)) % 2 == 0:
                            sectiondetails[''] = ''

                        a = list(sectiondetails.keys())
                        # index=0
                        for x in range(1, (merge_rows + 1)):
                            # table.add_row("Col.Det.",i,columndetails[i])
                            if x == 1:
                                table.add_row((
                                    MultiRow(
                                        merge_rows,
                                        data=StandAloneGraphic(
                                            image_options=
                                            "width=5cm,height=5cm",
                                            filename=rel_path + Img_path)),
                                    MultiColumn(2, align='|c|', data=a[x]),
                                    MultiColumn(2,
                                                align='|c|',
                                                data=sectiondetails[a[x]]),
                                ))
                            elif x <= 4:
                                table.add_row((
                                    '',
                                    MultiColumn(2,
                                                align='|c|',
                                                data=NoEscape(a[x])),
                                    MultiColumn(2,
                                                align='|c|',
                                                data=NoEscape(
                                                    sectiondetails[a[x]])),
                                ))
                            else:
                                table.add_row((
                                    '',
                                    NoEscape(a[x]),
                                    sectiondetails[a[x]],
                                    NoEscape(a[merge_rows + x - 4]),
                                    sectiondetails[a[merge_rows + x - 4]],
                                ))
                            table.add_hline(2, 5)
                    elif uiObj[i] == "TITLE":
                        table.add_hline()
                        table.add_row((MultiColumn(
                            5,
                            align='|c|',
                            data=bold(i),
                        ), ))
                        table.add_hline()
                    elif i == 'Section Size*':
                        table.add_hline()
                        table.add_row((
                            MultiColumn(
                                3,
                                align='|c|',
                                data=i,
                            ),
                            MultiColumn(2,
                                        align='|c|',
                                        data="Ref List of Input Section"),
                        ))
                        table.add_hline()
                    elif len(str(uiObj[i])) > 55 and type(
                            uiObj[i]) != pyl.math.Math:
                        str_len = len(str(uiObj[i]))
                        loop_len = round_up((str_len / 55), 1, 1)
                        for j in range(1, loop_len + 1):
                            b = 55 * j + 1
                            if j == 1:
                                table.add_row((
                                    MultiColumn(3,
                                                align='|c|',
                                                data=MultiRow(loop_len,
                                                              data=i)),
                                    MultiColumn(2,
                                                align='|c|',
                                                data=uiObj[i][0:b]),
                                ))
                            else:
                                table.add_row((
                                    MultiColumn(3,
                                                align='|c|',
                                                data=MultiRow(loop_len,
                                                              data="")),
                                    MultiColumn(2,
                                                align='|c|',
                                                data=uiObj[i][b - 55:b]),
                                ))
                        table.add_hline()
                    else:
                        table.add_hline()
                        table.add_row((
                            MultiColumn(3, align='|c|', data=NoEscape(i)),
                            MultiColumn(2, align='|c|', data=uiObj[i]),
                        ))
                        table.add_hline()
            for i in uiObj:
                if i == 'Section Size*' or i == KEY_DISP_ANGLE_LIST or i == KEY_DISP_TOPANGLE_LIST or i == KEY_DISP_CLEAT_ANGLE_LIST:
                    with doc.create(Subsection("List of Input Section")):
                        # with doc.create(LongTable('|p{8cm}|p{8cm}|', row_height=1.2)) as table:
                        with doc.create(Tabularx('|p{4cm}|X|',
                                                 row_height=1.2)) as table:
                            table.add_hline()
                            table.add_row((
                                MultiColumn(
                                    1,
                                    align='|c|',
                                    data=i,
                                ),
                                MultiColumn(1,
                                            align='|X|',
                                            data=uiObj[i].strip("[]")),
                            ))
                            # str_len = len(uiObj[i])
                            # loop_len = round_up((str_len/100),1,1)
                            # table.add_hline()
                            # for j in range(1,loop_len+1):
                            #     b= 100*j+1
                            #     if j ==1:
                            #         table.add_row((MultiColumn(1, align='|c|', data=i, ),
                            #                        MultiColumn(1, align='|X|', data=uiObj[i][0:b]),))
                            #     else:
                            #         table.add_row((MultiColumn(1, align='|c|', data=" ", ),
                            #                        MultiColumn(1, align='|X|', data=uiObj[i][b-100:b]),))
                            table.add_hline()

        doc.append(
            pyl.Command('Needspace', arguments=NoEscape(r'10\baselineskip')))
        doc.append(NewPage())
        count = 0
        with doc.create(Section('Design Checks')):
            with doc.create(
                    Tabularx(
                        r'|>{\centering}p{12.5cm}|>{\centering\arraybackslash}X|',
                        row_height=1.2)) as table:
                table.add_hline()
                # Fail = TextColor("FailColor", bold("Fail"))
                # Pass = TextColor("PassColor", bold("Pass"))

                if does_design_exist != True:
                    table.add_row(bold('Design Status'),
                                  color_cell("Red", bold("Fail")))
                else:
                    table.add_row(bold('Design Status'),
                                  color_cell("Green", bold("Pass")))
                table.add_hline()

            for check in Design_Check:

                if check[0] == 'SubSection':
                    if count >= 1:
                        # doc.append(NewPage())
                        doc.append(
                            pyl.Command(
                                'Needspace',
                                arguments=NoEscape(r'10\baselineskip')))
                    with doc.create(Subsection(check[1])):
                        #########################
                        # if uiObj== "WELDImage":
                        #     table.add_hline()
                        #     table.add_row((MultiColumn(5, align='|c|', data=bold(i), ),))
                        #     table.add_hline()
                        # else:
                        #########################
                        with doc.create(LongTable(check[2], row_height=1.2)
                                        ) as table:  # todo anjali remove
                            table.add_hline()
                            table.add_row(
                                ('Check', 'Required', 'Provided', 'Remarks'),
                                color='OsdagGreen')
                            table.add_hline()
                            table.end_table_header()
                            table.add_hline()
                            count = count + 1
                elif check[0] == "Selected":
                    if count >= 1:
                        # doc.append(NewPage())
                        doc.append(
                            pyl.Command(
                                'Needspace',
                                arguments=NoEscape(r'10\baselineskip')))
                    with doc.create(Subsection(check[1])):
                        with doc.create(LongTable(check[2],
                                                  row_height=1.2)) as table:
                            table.add_hline()
                            for i in uiObj:
                                # row_cells = ('9', MultiColumn(3, align='|c|', data='Multicolumn not on left'))

                                print(i)
                                if type(
                                        uiObj[i]
                                ) == dict and i == 'Selected Section Details':
                                    table.add_hline()
                                    sectiondetails = uiObj[i]
                                    image_name = sectiondetails[
                                        KEY_DISP_SEC_PROFILE]
                                    Img_path = '/ResourceFiles/images/' + image_name + '.png'
                                    if (len(sectiondetails)) % 2 == 0:
                                        # merge_rows = int(round_up(len(sectiondetails),2)/2 + 2)
                                        merge_rows = int(
                                            round_up((len(sectiondetails) /
                                                      2), 1, 0) + 2)
                                    else:
                                        merge_rows = int(
                                            round_up((len(sectiondetails) /
                                                      2), 1, 0) + 1)
                                    print('Hi',
                                          len(sectiondetails) / 2,
                                          round_up(len(sectiondetails), 2) / 2,
                                          merge_rows)
                                    if (len(sectiondetails)) % 2 == 0:
                                        sectiondetails[''] = ''
                                    a = list(sectiondetails.keys())
                                    # index=0
                                    for x in range(1, (merge_rows + 1)):
                                        # table.add_row("Col.Det.",i,columndetails[i])
                                        if x == 1:
                                            table.add_row((
                                                MultiRow(
                                                    merge_rows,
                                                    data=StandAloneGraphic(
                                                        image_options=
                                                        "width=5cm,height=5cm",
                                                        filename=rel_path +
                                                        Img_path)),
                                                MultiColumn(2,
                                                            align='|c|',
                                                            data=NoEscape(
                                                                a[x])),
                                                MultiColumn(
                                                    2,
                                                    align='|c|',
                                                    data=NoEscape(
                                                        sectiondetails[a[x]])),
                                            ))
                                        elif x <= 4:
                                            table.add_row((
                                                '',
                                                MultiColumn(2,
                                                            align='|c|',
                                                            data=NoEscape(
                                                                a[x])),
                                                MultiColumn(
                                                    2,
                                                    align='|c|',
                                                    data=sectiondetails[a[x]]),
                                            ))
                                        else:
                                            table.add_row((
                                                '',
                                                NoEscape(a[x]),
                                                sectiondetails[a[x]],
                                                NoEscape(a[merge_rows + x -
                                                           4]),
                                                sectiondetails[a[merge_rows +
                                                                 x - 4]],
                                            ))

                                        table.add_hline(2, 5)
                            table.add_hline()
                        count = count + 1
                else:

                    if check[3] == 'Fail':
                        table.add_row((NoEscape(check[0])), check[1], check[2],
                                      TextColor("Red", bold(check[3])))
                    else:
                        table.add_row((NoEscape(check[0])), check[1], check[2],
                                      TextColor("Green", bold(check[3])))
                    table.add_hline()

        # 2D images
        if len(Disp_2d_image) != 0:

            if module == KEY_DISP_BCENDPLATE or module == KEY_DISP_BB_EP_SPLICE:
                if does_design_exist and sys.platform != 'darwin':
                    doc.append(NewPage())
                    weld_details = rel_path + Disp_2d_image[0]
                    detailing_details = rel_path + Disp_2d_image[1]
                    stiffener_details = rel_path + Disp_2d_image[2]

                    with doc.create(Section('2D Drawings (Typical)')):

                        with doc.create(Figure()) as image:
                            image.add_image(weld_details,
                                            width=NoEscape(r'0.7\textwidth'),
                                            placement=NoEscape(r'\centering'))
                            image.add_caption(
                                'Typical Weld Details - Beam to End Plate Connection'
                            )
                            # doc.append(NewPage())

                        with doc.create(Figure()) as image_2:
                            image_2.add_image(
                                detailing_details,
                                width=NoEscape(r'0.7\textwidth'),
                                placement=NoEscape(r'\centering'))
                            image_2.add_caption('Typical Detailing')
                            # doc.append(NewPage())

                        with doc.create(Figure()) as image_3:
                            image_3.add_image(
                                stiffener_details,
                                width=NoEscape(r'0.9\textwidth'),
                                placement=NoEscape(r'\centering'))
                            image_3.add_caption('Typical Stiffener Details')
                            # doc.append(NewPage())

            elif module == KEY_DISP_BASE_PLATE:
                if does_design_exist and sys.platform != 'darwin':
                    doc.append(NewPage())
                    bp_sketch = rel_path + Disp_2d_image[0]
                    bp_detailing = rel_path + Disp_2d_image[1]
                    bp_weld = rel_path + Disp_2d_image[2]
                    bp_anchor = rel_path + Disp_2d_image[3]
                    bp_key = rel_path + Disp_2d_image[4]

                    with doc.create(Section('2D Drawings (Typical)')):
                        with doc.create(Figure()) as image_1:
                            image_1.add_image(
                                bp_sketch,
                                width=NoEscape(r'1.0\textwidth'),
                                placement=NoEscape(r'\centering'))
                            image_1.add_caption('Typical Base Plate Details')
                            # doc.append(NewPage())

                        with doc.create(Figure()) as image_2:
                            image_2.add_image(
                                bp_detailing,
                                width=NoEscape(r'1.0\textwidth'),
                                placement=NoEscape(r'\centering'))
                            image_2.add_caption('Typical Base Plate Detailing')
                            # doc.append(NewPage())

                        with doc.create(Figure()) as image_3:
                            image_3.add_image(
                                bp_weld,
                                width=NoEscape(r'1.0\textwidth'),
                                placement=NoEscape(r'\centering'))
                            image_3.add_caption('Typical Weld Details')
                            # doc.append(NewPage())

                        with doc.create(Figure()) as image_4:
                            image_4.add_image(
                                bp_anchor,
                                width=NoEscape(r'0.5\textwidth'),
                                placement=NoEscape(r'\centering'))
                            image_4.add_caption('Typical Anchor Bolt Details')
                            # doc.append(NewPage())

                        if len(Disp_2d_image[-1]) > 0:
                            with doc.create(Figure()) as image_5:
                                image_5.add_image(
                                    bp_key,
                                    width=NoEscape(r'0.9\textwidth'),
                                    placement=NoEscape(r'\centering'))
                                image_5.add_caption(
                                    'Typical Shear Key Details')
                                # doc.append(NewPage())

        if does_design_exist and sys.platform != 'darwin':
            doc.append(NewPage())
            Disp_top_image = "/ResourceFiles/images/top.png"
            Disp_side_image = "/ResourceFiles/images/side.png"
            Disp_front_image = "/ResourceFiles/images/front.png"
            view_3dimg_path = rel_path + Disp_3d_image
            view_topimg_path = rel_path + Disp_top_image
            view_sideimg_path = rel_path + Disp_side_image
            view_frontimg_path = rel_path + Disp_front_image
            with doc.create(Section('3D Views')):
                with doc.create(
                        Tabularx(
                            r'|>{\centering}X|>{\centering\arraybackslash}X|',
                            row_height=1.2)) as table:
                    view_3dimg_path = rel_path + Disp_3d_image
                    view_topimg_path = rel_path + Disp_top_image
                    view_sideimg_path = rel_path + Disp_side_image
                    view_frontimg_path = rel_path + Disp_front_image
                    table.add_hline()
                    table.add_row([
                        StandAloneGraphic(image_options="height=4cm",
                                          filename=view_3dimg_path),
                        StandAloneGraphic(image_options="height=4cm",
                                          filename=view_topimg_path)
                    ])
                    table.add_row('(a) 3D View', '(b) Top View')
                    table.add_hline()
                    table.add_row([
                        StandAloneGraphic(image_options="height=4cm",
                                          filename=view_sideimg_path),
                        StandAloneGraphic(image_options="height=4cm",
                                          filename=view_frontimg_path)
                    ])
                    table.add_row('(c) Side View', '(d) Front View')
                    table.add_hline()
                # with doc.create(Figure(position='h!')) as view_3D:
                #     view_3dimg_path = rel_path + Disp_3d_image
                #     # view_3D.add_image(filename=view_3dimg_path, width=NoEscape(r'\linewidth'))
                #
                #     view_3D.add_image(filename=view_3dimg_path,width=NoEscape(r'\linewidth,height=6.5cm'))
                #
                #     view_3D.add_caption('3D View')

        with doc.create(Section('Design Log')):
            doc.append(
                pyl.Command('Needspace',
                            arguments=NoEscape(r'10\baselineskip')))
            logger_msgs = reportsummary['logger_messages'].split('\n')
            for msg in logger_msgs:
                if ('WARNING' in msg):
                    colour = 'blue'
                elif ('INFO' in msg):
                    colour = 'green'
                elif ('ERROR' in msg):
                    colour = 'red'
                else:
                    continue
                doc.append(TextColor(colour, '\n' + msg))
        try:
            doc.generate_pdf(filename, compiler='pdflatex', clean_tex=False)
        except:
            pass
Exemple #35
0
import numpy as np

from pylatex import Document, Section, Subsection, Tabular, Math, TikZ, Axis, \
    Plot, Figure, Package, Matrix
from pylatex.utils import italic
import os

if __name__ == '__main__':
    image_filename = os.path.join(os.path.dirname(__file__), 'kitten.jpg')

    doc = Document()
    doc.packages.append(Package('geometry', options=['tmargin=1cm',
                                                     'lmargin=10cm']))

    with doc.create(Section('The simple stuff')):
        doc.append('Some regular text and some')
        doc.append(italic('italic text. '))
        doc.append('\nAlso some crazy characters: $&#{}')
        with doc.create(Subsection('Math that is incorrect')):
            doc.append(Math(data=['2*3', '=', 9]))

        with doc.create(Subsection('Table of something')):
            with doc.create(Tabular('rc|cl')) as table:
                table.add_hline()
                table.add_row((1, 2, 3, 4))
                table.add_hline(1, 2)
                table.add_empty_row()
                table.add_row((4, 5, 6, 7))

    a = np.array([[100, 10, 20]]).T
    M = np.matrix([[2, 3, 4],
Exemple #36
0
    def generar(self, Carrera, Asignatura, Curso, listaPreguntas, aleatorio):

        today = str(self.__fecha)

        geometry_options = {
            "head": "48pt",
            "margin": "0.5in",
            "bottom": "0.6in",
            "includeheadfoot": True
        }

        doc = Document(geometry_options=geometry_options)

        header = PageStyle("header")  # DEFINIMOS LA VARIABLE CON ESTILO

        #image_filename = os.path.join(os.path.dirname("__file__"), '../static/zigmap.png') # IMAGEN UNAB

        #data_folder = os.path.join("../", "static/zigmap.png")

        #file_to_open = os.path.join(data_folder, "zigmap.png")

        #image_filename = data_folder
        image_filename = "zigmap.png"

        # Generating first page style
        first_page = PageStyle("firstpage")

        # Header image
        with first_page.create(Head("L")) as header_left:

            with header_left.create(
                    SubFigure(
                        position='L',
                        width=NoEscape(r'0.10\linewidth'))) as logo_wrapper:

                print("IMAGEN")
                #logo_wrapper.add_image('zigmap.png', width=NoEscape(r'\linewidth'))

        # Add document title
        with first_page.create(Head("C")) as center_header:
            with center_header.create(
                    MiniPage(width=NoEscape(r"0.49\textwidth"),
                             pos='c',
                             align='c')) as title_wrapper:
                title_wrapper.append(LargeText(bold(self.__nombre)))

        # Add document title
        with first_page.create(Head("R")) as right_header:
            with right_header.create(
                    MiniPage(width=NoEscape(r"0.49\textwidth"),
                             pos='c',
                             align='r')) as title_wrapper:
                #title_wrapper.append(LargeText(bold("Solemne II")))
                #title_wrapper.append(LineBreak())
                title_wrapper.append(MediumText(bold(
                    Asignatura.get_nombreA())))

        # Add footer
        with first_page.create(Foot("C")) as footer:
            message = "Programación II"
            with footer.create(
                    Tabularx("X X X X", width_argument=NoEscape(
                        r"\textwidth"))) as footer_table:

                footer_table.add_row([
                    MultiColumn(4, align='l', data=TextColor("black", message))
                ])
                footer_table.add_hline(color="black")
                footer_table.add_empty_row()

                branch_address = MiniPage(width=NoEscape(r"0.45\textwidth"),
                                          pos='t',
                                          align='l')
                branch_address.append(
                    MediumText("Facultad de " + Carrera.get_facultad()))
                branch_address.append("\n")
                branch_address.append("")

                branch_address2 = MiniPage(width=NoEscape(r"0.10\textwidth"),
                                           pos='t')
                branch_address2.append("")
                branch_address2.append("\n")
                branch_address2.append("")

                document_details = MiniPage(width=NoEscape(r"0.25\textwidth"),
                                            pos='t',
                                            align='r')
                document_details.append(self.__fecha)
                document_details.append(LineBreak())
                document_details.append("")  # simple_page_number()

                footer_table.add_row([
                    branch_address, branch_address2, branch_address2,
                    document_details
                ])

        doc.preamble.append(first_page)
        # End first page style

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

        ####################################################
        # Add customer information
        with doc.create(Tabu("X[l] X[r]")) as first_page_table:
            customer = MiniPage(width=NoEscape(r"0.55\textwidth"), pos='h')
            customer.append("Nombre: ___________________________________")
            customer.append("\n")
            customer.append("    Rut:  _______________")
            customer.append("\n")
            customer.append("Nota: ______________")
            customer.append("\n")
            customer.append("\n")

            # Add branch information
            branch = MiniPage(width=NoEscape(r"0.35\textwidth"),
                              pos='t!',
                              align='r')

            if self.__unidad == "unidad1":
                branch.append(bold("Unidad: 1"))
            elif self.__unidad == "unidad2":
                branch.append(bold("Unidad: 2"))
            else:
                branch.append(bold("Unidades: 1 & 2"))
            branch.append(LineBreak())

            branch.append(bold("Curso: "))
            branch.append(bold(Curso.get_cod()))
            branch.append(LineBreak())

            branch.append(bold("Ponderación: "))
            branch.append(bold(self.__ponderacion + "%"))
            branch.append(LineBreak())

            first_page_table.add_row([customer, branch])

        doc.append(LargeText(bold("Indicaciones:")))

        # INDICACIONES

        with doc.create(Itemize()) as itemize:
            doc.append(LineBreak())
            itemize.add_item(
                " Lea atentamente los enunciados de cada pregunta antes de contestar."
            )
            itemize.add_item(
                " Conteste su evaluación en silencio, está prohibido conversar o gesticulizar en la sala durante la prueba."
            )
            itemize.add_item(
                " Dispone de 90 minutos para realizar esta evaluación.")
            itemize.add_item(
                " Marque la alternativa con lapiz pasta, no se aceptan marcadas con lapiz grafito."
            )
            itemize.add_item(
                " Utilice solamente sus materiales, está prohibido solicitar materiales a sus compañeros."
            )
            # you can append to existing items
            itemize.append(Command("ldots"))

        doc.change_document_style("firstpage")
        doc.add_color(name="lightgray", model="gray", description="0.80")
        customer.append(LineBreak())

        now = str(datetime.today())

        for p in listaPreguntas:
            with doc.create(Section('Pregunta - ' + p.get_tipo())):

                doc.append(p.get_contenido())

        doc.append(NewPage())

        nombreFile = str(
            self.__nombre) + " - " + self.get_fecha() + " - " + str(aleatorio)

        print(
            "--------------------------ANTES DE DIR------------------------------"
        )

        try:
            # GENERANDO PDF
            doc.generate_pdf(filepath="tests/" + nombreFile,
                             clean_tex=True,
                             clean=True)
            #doc.generate_pdf(dirName + "/" + nombreFile, clean_tex=False)

        except FileNotFoundError as e:
            doc.generate_pdf(filepath="../tests/" + nombreFile,
                             clean_tex=True,
                             clean=True)
Exemple #37
0
def genenerate_tabus(r_arr, errr_arr, psi_arr, errpsi_arr, size_arr,
                     errsize_arr, flux_arr, errflux_arr, tb1_arr, errtb1_arr,
                     dlim1_arr, tb2_arr, errtb2_arr, dlim2_arr, tb1_arrPlanck,
                     errtb1_arrPlanck, tb2_arrPlanck, errtb2_arrPlanck, freq):
    geometry_options = {
        "landscape": False,
        "margin": "0.5in",
        "headheight": "20pt",
        "headsep": "10pt",
        "includeheadfoot": True
    }
    doc = Document(page_numbers=True, geometry_options=geometry_options)

    # Generate data table with 'tight' columns
    table1 = Tabular('c|ccccccccccccccccccc')
    table1.add_row([
        "Component", "S_y", "", "", "r", "", "", "psi", "", "", "x", "", "",
        "y", "", "", "theta", "", "", "theta_lim"
    ],
                   mapper=[bold])
    table1.add_hline()
    table1.add_hline()

    x_arr, errx_arr, y_arr, erry_arr = x_y(r_arr, errr_arr, psi_arr,
                                           errpsi_arr, True)

    for i in range(len(r_arr)):
        flux, errflux = roundErrorVariable(flux_arr[i], errflux_arr[i])
        r, errr = roundErrorVariable(r_arr[i], errr_arr[i])
        psi, errpsi = roundErrorVariable(psi_arr[i] * 180. / np.pi,
                                         errpsi_arr[i] * 180. / np.pi)
        size, errsize = roundErrorVariable(size_arr[i], errsize_arr[i])
        x, errx = roundErrorVariable(x_arr[i], errx_arr[i])
        y, erry = roundErrorVariable(y_arr[i], erry_arr[i])

        row = [
            i, flux,
            "%0.0f" % (0), errflux, r,
            "%0.0f" % (0), errr, psi,
            "%0.0f" % (0), errpsi, x,
            "%0.0f" % (0), errx, y,
            "%0.0f" % (0), erry, size,
            "%0.0f" % (0), errsize,
            "%0.3f" % (dlim1_arr[i])
        ]
        table1.add_row(row)

    table2 = Tabular('c|cccccccccccc')
    table2.add_row([
        "Component", "Tb_1", "", "", "Tb_1Planck", "", "", "Tb_2", "", "",
        "Tb_2Planck", "", ""
    ],
                   mapper=[bold])
    table2.add_hline()
    table2.add_hline()

    for i in range(len(r_arr)):
        row = [
            i,
            "%0.3f" % (tb1_arr[i] / 10**(11)),
            "%0.0f" % (0),
            "%0.3f" % (errtb1_arr[i] / 10**(11)),
            "%0.3f" % (tb1_arrPlanck[i] / 10**(11)),
            "%0.0f" % (0),
            "%0.3f" % (errtb1_arrPlanck[i] / 10**(11)),
            "%0.3f" % (tb2_arr[i] / 10**(11)),
            "%0.0f" % (0),
            "%0.3f" % (errtb2_arr[i] / 10**(11)),
            "%0.3f" % (tb2_arrPlanck[i] / 10**(11)),
            "%0.0f" % (0),
            "%0.3f" % (errtb2_arrPlanck[i] / 10**(11))
        ]
        table2.add_row(row)

    doc.append(table1)
    doc.append(NewPage())
    doc.append(table2)
    doc.append(NewPage())

    doc.generate_pdf("Tb" + str(round(freq)), clean_tex=False)
Exemple #38
0
    with doc.create(Section('A section')):
        doc.append('Some regular text and some ' + italic('italic text. '))

        with doc.create(Subsection('A subsection')):
            doc.append(escape_latex('Also some crazy characters: $&#{}'))


if __name__ == '__main__':
    # Basic document
    doc = Document('basic')
    fill_document(doc)

    doc.generate_pdf()
    doc.generate_tex()

    # Document with `\maketitle` command activated
    doc = Document(author='Author',
                   date='01/01/01',
                   title='Title',
                   maketitle=True)
    fill_document(doc)

    doc.generate_pdf('basic_maketitle', clean=False)

    # Add stuff to the document
    doc.append(Section('A second section'))
    doc.append('Some text.')

    doc.generate_pdf('basic_maketitle2')
    tex = doc.dumps()  # The document as string in LaTeX syntax
Exemple #39
0
def prepareDoc(course):
    geometry = settings.geometry
    title = "{} DERSİ DERS DEĞERLENDİRME ANKETİ SONUÇLARI".format(course.course_name)
    
    doc = Document(indent=False, geometry_options=geometry)
    doc.preamble.append(Command("usepackage","babel","turkish"))
    doc.preamble.append(Command("usepackage","float"))
    doc.preamble.append(Command("usepackage","framed"))
    doc.preamble.append(Command("title", title))
    doc.preamble.append(NoEscape(r"\date{\vspace{-1.5cm}\today}"))
    
    doc.append(NoEscape(r"\maketitle"))
    doc.append(Command("shorthandoff","="))
    
    doc.append(Command("begin", "framed"))
    doc.append(bold("Dersin Kodu : "))
    doc.append("{}".format(course.course_code))
    doc.append(NoEscape(r"\quad"))
    doc.append("({}. sınıf)".format(course.course_grade))
    doc.append(NewLine())
    doc.append(bold("Dersin Türü : "))
    doc.append("{}".format(course.course_type))
    doc.append(NewLine())
    doc.append(bold("Dersin Grubu : "))
    doc.append("{}".format(course.course_group))
    doc.append(NewLine())
    doc.append(bold("Dersin Dönemi : "))
    doc.append("{}".format(course.course_term))
    doc.append(NewLine())
    doc.append(bold("Öğretim Üyesi : "))
    lname = course.lecturer_name + ' ' + course.lecturer_middle + ' ' + course.lecturer_surname
    doc.append(lname)
    doc.append(Command("end", "framed"))
    
    return doc
Exemple #40
0
# count the number of files in the specific folder
no_of_file = []
for x in range(0, file_counter):
    no_of_file.append(x)

# Report Generation
if __name__ == '__main__':
    # basic document
    doc = Document()

    doc.preamble.append(Command('title', 'Report'))
    doc.preamble.append(
        Command('author', 'Stream Processor Performance Testing-' + path))

    doc.preamble.append(Command('date', NoEscape(r'\today')))
    doc.append(NoEscape(r'\maketitle'))
    doc.append(NoEscape(r'\newpage'))

# Generating summary results chart for each run
# throughput summary table and chart

with doc.create(
        Section(
            'Average Throughput During 60-180 seconds time period since the start of the benchmarking experiment'
        )):
    doc.append(NoEscape(r'\hfill \break'))
    fmt = "X[r] X[r]"
    with doc.create(Subsection('Summary Table')):
        with doc.create(LongTabu(fmt, spread="0pt")) as data_table:
            header_row = [
                'Experiment runs', 'Average Throughput(million events/second)'
Exemple #41
0
 def create_pdf(self) -> Document:
     questions = functools.reduce(
         lambda a, b: a + b, map(lambda x: x.get_questions(),
                                 self.questions), [])
     doc = Document()
     doc.preamble.append(Package('titling'))
     for i in range(1, self.count + 1):
         random.shuffle(questions)
         with doc.create(Center()):
             doc.append(HugeText(self.header))
         doc.append(bold('Nombre:'))
         doc.append(LineBreak())
         doc.append(bold('ID:'))
         doc.append(LineBreak())
         with doc.create(FlushRight()):
             doc.append(LargeText(f'Examen tipo {i}'))
         enum = Enumerate()
         for question in questions:
             question.append_to_document(doc, enum)
         doc.append(NewPage())
         doc.append('Guía de respuestas')
         doc.append(enum)
         doc.append(NewPage())
         doc.append(Command('setcounter', ['section', '0']))
     return doc
Exemple #42
0
def gerar_pdf_certificado(certificado):

    # Configurações da classe
    geometry_options = {'landscape': True,
                        'left': '2cm',
                        'right': '1cm'}
    doc = Document(geometry_options=geometry_options, lmodern=False, document_options=['a4paper', 'brazil'],
                   inputenc=None, fontenc=None, font_size='footnotesize')

    # Pacotes
    doc.packages.add(Package('microtype'))
    doc.packages.add(Package('indentfirst'))
    doc.packages.add(Package('graphicx'))
    doc.packages.add(Package('calc'))
    doc.packages.add(Package('fontspec'))
    options_background = ['scale=1',
                          'opacity=1',
                          'angle=0']
    doc.packages.add(Package('background', options=options_background))
    doc.packages.add(Package('csquotes'))

    # Configurações (preâmbulo)
    doc.preamble.append(Command('MakeOuterQuote', '\"'))  # coverte aspas automaticamente, sem precisar de `` e ''
    doc.preamble.append(Command('renewcommand', arguments=[Command('baselinestretch'), '1.5']))
    doc.preamble.append(Command('setlength', arguments=[Command('parindent'), NoEscape(r'.35\textwidth')]))
    doc.preamble.append(Command('setlength', arguments=[Command('parskip'), '0.2cm']))
    doc.preamble.append(Command('setlength', arguments=[Command('emergencystretch'), '5pt']))

    # Imagem de fundo
    doc.preamble.append(NoEscape(r'\backgroundsetup{ contents=\includegraphics{modelo-certificado-20.pdf} }'))

    # Diretório das imagens
    img_dir = '{}/base/static/img/'.format(BASE_DIR)  # necessário barra no final
    doc.preamble.append(UnsafeCommand('graphicspath', '{{{}}}'.format(img_dir)))

    # Início do documento
    doc.append(UnsafeCommand('setmainfont', 'Latin Modern Sans', ['SizeFeatures={Size=16}', 'Ligatures=TeX']))

    doc.append(Command('pagestyle', 'empty'))
    doc.append(Command('BgThispage'))

    doc.append(VerticalSpace(size='2cm', star=True))

    with doc.create(FlushRight()) as fr:
        fr.append(StandAloneGraphic('titulo-certificado.pdf', 'width=6.5cm'))
        fr.append(LineBreak())

    doc.append(VerticalSpace(size=NoEscape('-1cm'), star=True))
    doc.append(Command('Large'))

    # Usado para o nome dos meses ('%B')
    locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8')

    inicio = certificado.relatorio.periodo_inicio.strftime('%d de %B de %Y').lower()
    fim = certificado.relatorio.periodo_inicio.strftime('%d de %B de %Y').lower()
    # TODO: tá faltando coisa
    texto_principal = r'''

    Certificamos que \textbf{{{nome}}} atuou como {funcao}, {sob_coordenacao}no período de {inicio} a {fim}, na cidade de Foz do Iguaçu -- Paraná, com a atividade de extensão: "\textbf{{{titulo}}}", com carga horária de {carga_horaria_total} horas.

    '''

    if certificado.funcao.nome == 'Coordenador(a)':
        sob_coordenacao = ''
    else:
        nome_coordenador = certificado.relatorio.projeto_extensao.coordenador.nome_completo
        sob_coordenacao = r'sob a coordenação de \textbf{{{}}}, '.format(escape_latex(nome_coordenador))

    texto_principal = texto_principal.format(nome=escape_latex(certificado.nome),
                                             funcao=certificado.funcao.nome.lower(),
                                             sob_coordenacao=sob_coordenacao,
                                             inicio=inicio,
                                             fim=fim,
                                             titulo=escape_latex(certificado.relatorio.projeto_extensao.titulo),
                                             carga_horaria_total=str(certificado.carga_horaria_total).split('.')[0])

    # texto_principal = NoEscape(r'''

    # Certificamos que \textbf{Adriana de Oliveira Gomes} participou como bolsista do Programa de Apoio a Inclusão Social em Atividades de Extensão -- Convênio No 750/2014 -- Fundação Araucária, Edital 05/2014-PROEX, sob a orientação do (a) professor (a) \textbf{Fernando Amâncio Aragão}, no período de outubro/2014 a setembro/2015, com a atividade de extensão: \textbf{''Atendimento fisioterapêutico para pacientes com sequelas neurológicas baseada em tarefas funcionais.''}, com carga horária de 960 (novecentas e sessenta) horas.

    # ''')

    doc.append(NoEscape(texto_principal))

    doc.append(VerticalSpace(size='1.5cm', star=True))

    doc.append(HorizontalSpace(size='7cm', star=True))
    dia = timezone.now().strftime('%d')
    mes = timezone.now().strftime('%B')
    ano = timezone.now().strftime('%Y')

    data = NoEscape(r'Foz do Iguaçu, {} de {} de {}'.format(dia, mes, ano))
    largura = Command('widthof', data).dumps()
    with doc.create(MiniPage(width=largura)) as mini:
        with mini.create(Center()) as center:
            center.append(data)
            center.append(NewLine())
            center.append(NewLine())
            center.append(NewLine())
            center.append('Coordenador do Projeto de Extensão')
            center.append(NewLine())
            center.append(NewLine())
            center.append(NewLine())
            center.append('Diretor de Centro')

    os.system('mkdir -p ' + PDF_DIR)

    filepath = '{}/certificado_{}'.format(PDF_DIR, str(certificado.id))
    doc.generate_pdf(filepath, clean_tex=False, compiler=pdfutils.COMPILER, compiler_args=pdfutils.COMPILER_ARGS)

    return filepath
Exemple #43
0
def create_report(system, curves, grid, filename):
    lines = system.lines
    trafos = system.trafos
    buses = system.buses

    geometry_options = {
        "tmargin": "1cm",
        "lmargin": "1cm",
        "rmargin": "1cm",
        "bmargin": "1cm",
        "includeheadfoot": True
    }
    doc = Document(page_numbers=True, geometry_options=geometry_options)
    doc.preamble.append(Command('usepackage', 'cmbright'))
    doc.preamble.append(Command('usepackage', 'tikz'))
    doc.preamble.append(Command('usepackage', 'amsmath'))
    doc.preamble.append(Command('usepackage', 'graphicx'))
    now = datetime.datetime.now()
    doc.append('Report auto-generated by ASPy at '
               '{:02d}/{:02d}/{:02d} {:02d}:{:02d}:{:02d}'.format(
                   now.day, now.month, now.year, now.hour, now.minute,
                   now.second))
    wye_comm = UnsafeCommand(
        'newcommand',
        '\\wye',
        extra_arguments=
        r'\mathbin{\text{\begin{tikzpicture}[x=1pt, y=1pt, scale=2]'
        r'\draw '
        r'(-0.9, 0) -- (0.9, 0) '
        r'(-0.6, -0.5) -- (0.6, -0.5) '
        r'(-0.3, -1) -- (0.3, -1) '
        r'(0, 0) -- ++(0, 1.5) -- ++(1.2, 0) coordinate (tmp)'
        r'-- +(0, -2) '
        r'(tmp) +(45:2) -- (tmp) -- +(135:2) ;'
        r'\end{tikzpicture}}}')
    why_comm = UnsafeCommand(
        'newcommand',
        '\\why',
        extra_arguments=
        r'\mathbin{\text{\begin{tikzpicture}[x=1pt, y=1pt, scale=2]'
        r'\draw '
        r'(1.2, 1.5) coordinate (tmp)'
        r'-- +(0, -2) '
        r'(tmp) +(45:2) -- (tmp) -- +(135:2) ;'
        r'\end{tikzpicture}}}')
    doc.append(wye_comm)
    doc.append(why_comm)
    doc.add_color(name="lightgray", model="gray", description="0.80")
    with doc.create(Section('Buses')):
        with doc.create(Subsection('Power-Flow Solution')):
            with doc.create(LongTable('c|ccccccc')) as tbl:
                tbl.add_hline()
                tbl.add_row(
                    ('Bus', NoEscape('$|V|$ (pu)'),
                     NoEscape('$\\delta$ (deg)'), NoEscape('$P_G$ (MW)'),
                     NoEscape('$Q_G$ (Mvar)'), NoEscape('$P_L$ (MW)'),
                     NoEscape('$Q_L$ (Mvar)'), NoEscape('$Z_L$ (pu)')))
                tbl.add_hline()
                tbl.end_table_header()
                tbl.add_hline()
                tbl.add_row((MultiColumn(8,
                                         align='r',
                                         data='Continued on Next Page'), ))
                tbl.add_hline()
                tbl.end_table_footer()
                tbl.add_hline()
                tbl.end_table_last_footer()

                for i, b in enumerate(buses):
                    if i % 2 == 0:
                        color = 'lightgray'
                    else:
                        color = None
                    tbl.add_row(
                        (b.bus_id + 1, NoEscape('{:.04f}'.format(b.v)),
                         NoEscape('${:.02f}$'.format(b.delta * 180 / np.pi)),
                         NoEscape('{:.02f}'.format(b.pg * 100)),
                         NoEscape('{:.02f}'.format(b.qg * 100)),
                         NoEscape('{:.02f}'.format(b.pl * 100)),
                         NoEscape('{:.02f}'.format(b.ql * 100)), check_inf(
                             b.Z)),
                        color=color)
        with doc.create(Subsection('Fault Calculations')):
            with doc.create(LongTable('c|cccccccccc')) as tbl:
                tbl.add_hline()
                tbl.add_row((MultiRow(2, data='Bus'),
                             MultiColumn(2, align='c', data=NoEscape('TPG')),
                             MultiColumn(2, align='c', data=NoEscape('SLG')),
                             MultiColumn(4, align='c', data=NoEscape('DLG')),
                             MultiColumn(2, align='c', data=NoEscape('LL'))))
                tbl.add_hline(2, 11)
                tbl.add_row(
                    ('', NoEscape('$I_A$ (pu)'), NoEscape('$\\delta_A$ (deg)'),
                     NoEscape('$I_A$ (pu)'), NoEscape('$\\delta_A$ (deg)'),
                     NoEscape('$I_B$ (pu)'), NoEscape('$\\delta_B$ (deg)'),
                     NoEscape('$I_C$ (pu)'), NoEscape('$\\delta_C$ (deg)'),
                     NoEscape('$I_B$ (pu)'), NoEscape('$\\delta_B$ (deg)')))
                tbl.add_hline()
                tbl.end_table_header()
                tbl.add_hline()
                tbl.add_row((MultiColumn(11,
                                         align='r',
                                         data='Continued on Next Page'), ))
                tbl.add_hline()
                tbl.end_table_footer()
                tbl.add_hline()
                tbl.end_table_last_footer()

                for i, b in enumerate(buses):
                    if i % 2 == 0:
                        color = 'lightgray'
                    else:
                        color = None
                    tbl.add_row((b.bus_id + 1, check_inf(np.abs(b.iTPG)),
                                 NoEscape('${:.02f}$'.format(
                                     np.angle(b.iTPG) * 180 / np.pi)),
                                 check_inf(np.abs(b.iSLG)),
                                 NoEscape('${:.02f}$'.format(
                                     np.angle(b.iSLG) * 180 / np.pi)),
                                 check_inf(np.abs(b.iDLGb)),
                                 NoEscape('${:.02f}$'.format(
                                     np.angle(b.iDLGb) * 180 / np.pi)),
                                 check_inf(np.abs(b.iDLGc)),
                                 NoEscape('${:.02f}$'.format(
                                     np.angle(b.iDLGc) * 180 / np.pi)),
                                 check_inf(np.abs(b.iLL)),
                                 NoEscape('${:.02f}$'.format(
                                     np.angle(b.iLL) * 180 / np.pi))),
                                color=color)
    with doc.create(Section('Lines')):
        with doc.create(LongTable('c|cccccccc')) as tbl:
            tbl.add_hline()
            tbl.add_row((MultiRow(2, data='Line'),
                         MultiColumn(3, align='c', data='Parametrization'),
                         MultiColumn(2, align='c', data='Loss'),
                         MultiColumn(3, align='c', data='Flow')))
            tbl.add_hline(2, 9)
            tbl.add_row(
                ('', NoEscape('$R$ (\\%pu)'), NoEscape('$X_L$ (\\%pu)'),
                 NoEscape('$B_C$ (\\%pu)'), NoEscape('$P_{loss}$ (MW)'),
                 NoEscape('$Q_{loss}$ (Mvar)'), NoEscape('$P$ (MW)'),
                 NoEscape('$Q$ (Mvar)'), NoEscape('$I/I_{max}$ (\\%)')))
            tbl.add_hline()
            tbl.end_table_header()
            tbl.add_hline()
            tbl.add_row((MultiColumn(9,
                                     align='r',
                                     data='Continued on Next Page'), ))
            tbl.add_hline()
            tbl.end_table_footer()
            tbl.add_hline()
            tbl.end_table_last_footer()

            for i, lt in enumerate(lines):
                if i % 2 == 0:
                    color = 'lightgray'
                else:
                    color = None
                tbl.add_row((NoEscape('{} -- {}'.format(
                    lt.orig.bus_id + 1, lt.dest.bus_id + 1)),
                             NoEscape('{:.04f}'.format(lt.Zpu.real * 100)),
                             NoEscape('{:.04f}'.format(lt.Zpu.imag * 100)),
                             NoEscape('{:.04f}'.format(lt.Ypu.imag * 100)),
                             NoEscape('{:.02f}'.format(lt.Sper.real * 100)),
                             NoEscape('{:.02f}'.format(lt.Sper.imag * 100)),
                             NoEscape('{:.02f}'.format(lt.S2.real * 100)),
                             NoEscape('{:.02f}'.format(lt.S2.imag * 100)),
                             NoEscape('{:.02f}'.format(
                                 np.abs(lt.Ia) / lt.imax * 100))),
                            color=color)
    with doc.create(Section('Trafos')):
        with doc.create(LongTable('c|cccccccc')) as tbl:
            tbl.add_hline()
            tbl.add_row((MultiRow(2, data='Trafo'),
                         MultiColumn(3, align='c', data='Parametrization'),
                         MultiColumn(2, align='c', data='Loss'),
                         MultiColumn(3, align='c', data='Flow')))
            tbl.add_hline(2, 9)
            tbl.add_row(
                ('', NoEscape('$x^+$ (\\%pu)'), NoEscape('$x^0$ (\\%pu)'),
                 'Configuration', NoEscape('$P_{loss}$ (MW)'),
                 NoEscape('$Q_{loss}$ (Mvar)'), NoEscape('$P$ (MW)'),
                 NoEscape('$Q$ (Mvar)'), NoEscape('$S/S_N$ (\\%)')))
            tbl.add_hline()
            tbl.end_table_header()
            tbl.add_hline()
            tbl.add_row((MultiColumn(9,
                                     align='r',
                                     data='Continued on Next Page'), ))
            tbl.add_hline()
            tbl.end_table_footer()
            tbl.add_hline()
            tbl.end_table_last_footer()

            for i, tr in enumerate(trafos):
                if i % 2 == 0:
                    color = 'lightgray'
                else:
                    color = None
                tbl.add_row((NoEscape('{} -- {}'.format(
                    tr.orig.bus_id + 1, tr.dest.bus_id + 1)),
                             NoEscape('{:.02f}'.format(tr.Z1.imag * 100)),
                             NoEscape('{:.02f}'.format(
                                 tr.Z0.imag * 100)), get_scheme(tr),
                             NoEscape('{:.02f}'.format(tr.Sper.real * 100)),
                             NoEscape('{:.02f}'.format(tr.Sper.imag * 100)),
                             NoEscape('{:.02f}'.format(tr.S2.real * 100)),
                             NoEscape('{:.02f}'.format(tr.S2.imag * 100)),
                             NoEscape('{:.02f}'.format(
                                 np.abs(tr.S2) * 1e8 / tr.snom * 100))),
                            color=color)

    filepath = filename.strip('.pdf')
    make_system_schematic(curves, grid, initial_fontsize=9)
    doc.append(NewPage())
    with doc.create(Section('System')):
        with doc.create(Figure(position='h')) as system_pic:
            system_pic.add_plot(bbox_inches='tight',
                                width=NoEscape('\\textwidth'))
    doc.generate_pdf(filepath,
                     clean_tex=True,
                     compiler='latexmk',
                     compiler_args=['-pdf'])
Exemple #44
0
def part_splitter(unparsed_text):
    '''Creates a list of indices of the unparsed text where the '@' sign shows up.'''
    master_list = []
    for i in range(len(unparsed_text)):
        if unparsed_text[i] == "@":
            master_list.append(i)
    return master_list

if x.get_solution_style() == True:
    parts = part_splitter(z)
    solutions = Document()
    solutions.preamble.append(Command('usepackage', 'amsmath'))
    solutions.preamble.append(Command('title', question_type))
    solutions.preamble.append(Command('author', 'Generated Solutions'))
    solutions.preamble.append(Command('date', NoEscape(r'\today')))
    # solutions.append(NoEscape(r'\maketitle')) Use if a title is desired.

    with solutions.create(Section('Solutions Generated for ' + question_type, numbering=False)):
        for i in range(len(parts)-1):
            x = z[parts[i]+1:parts[i+1]]
            solutions.append(NoEscape(x))

    solutions.generate_tex('Solved-TeX') # Generates .tex file
    solutions.generate_pdf('Solved') # Generates .pdf file
    print("PDF sucessfully created! Opening now...")
    os.popen('./pdfopen.sh')     

else:
    print(x.get_answer()[:-1])
Exemple #45
0
# import bio
import pickle
os.chdir(os.path.dirname('whatecer directory the file papers.dat is'))
with open("papers.dat", "rb") as fp:   # Unpickling
   papers = pickle.load(fp)


i = 0
for p in papers:
  doc = Document()
  doc.preamble.append(Command('title',p['TI']))
  doc.preamble.append(Command('author',';  '.join(p['FAU'])))
  doc.preamble.append(Command('date',p['EDAT']))
  #doc.append(NoEscape(r'\maketitle'))
  with doc.create(Section('A second section')):
    doc.append(NoEscape(r'\maketitle'))
    doc.append(LargeText(bold('Abstract\n\n')))
    doc.append('\n')
    doc.append(p['AB'])
    doc.append('\n\n\n\n')
    doc.append('Mesh Terms\n')
    if 'MH' in p:
      doc.append(p['MH'])
      doc.append('\n\n')
    doc.append(p['SO'])
    doc.append('\n\n')
    doc.append('PMID: ' + p['PMID'])
    doc.append('\n\n')
    if 'PMC' in p:
      doc.append('PMC: ' + p['PMC'])
    doc.generate_pdf(str(i+1), clean_tex=True)
Exemple #46
0
section = Section('Numpy tests')
subsection = Subsection('Array')

vec = Matrix(a)
vec_name = format_vec('a')
math = Math(data=[vec_name, '=', vec])

subsection.append(math)
section.append(subsection)

subsection = Subsection('Matrix')
M = np.matrix([[2, 3, 4],
               [0, 0, 1],
               [0, 0, 2]])
matrix = Matrix(M, mtype='b')
math = Math(data=['M=', matrix])

subsection.append(math)
section.append(subsection)


subsection = Subsection('Product')

math = Math(data=['M', vec_name, '=', Matrix(M*a)])
subsection.append(math)

section.append(subsection)

doc.append(section)
doc.generate_pdf()
Exemple #47
0
    def generate_report(self):
        # Basic document
        # Document with `\maketitle` command activated
        doc = Document(default_filepath=(self.folder + r"/figures"))
        doc.documentclass = Command(
            'documentclass',
            options=['10pt', 'a4'],
            arguments=['article'],
        )
        doc.packages.append(NoEscape(r'\setcounter{tocdepth}{4}'))
        doc.packages.append(NoEscape(r'\setcounter{secnumdepth}{1}'))
        # usepackages
        doc.packages.append(Package('helvet'))
        doc.packages.append(Package('graphicx'))
        doc.packages.append(Package('geometry'))
        doc.packages.append(Package('float'))
        doc.packages.append(Package('amsmath'))
        doc.packages.append(Package('multicol'))
        doc.packages.append(Package('ragged2e'))
        doc.packages.append(Package('breakurl'))
        doc.packages.append(Package('booktabs, multirow'))
        doc.packages.append(Package('epstopdf'))
        doc.packages.append(
            NoEscape(r'\usepackage[nolist, nohyperlinks]{acronym}'))
        doc.packages.append(Package('hyperref'))

        # add commands
        doc.preamble.append(
            NoEscape(r"\renewcommand{\familydefault}{\sfdefault}"))
        doc.preamble.append(
            NoEscape(r"\newcommand\Tstrut{\rule{0pt}{3ex}}  % = `top' strut"))
        doc.preamble.append(
            NoEscape(
                r"\newcommand\Bstrut{\rule[1ex]{0pt}{0pt}}   % = `bottom' strut"
            ))

        # make title
        title = "Report for Session: " + self.session
        doc.preamble.append(Command('title', title))
        #doc.preamble.append(Command('author', 'Anonymous author'))
        doc.preamble.append(Command('date', NoEscape(r'\today')))
        doc.append(NoEscape(r'\maketitle'))
        doc.append(NoEscape(r'\tableofcontents'))
        doc.append(NewPage())
        doc.append(
            NoEscape(r'\newgeometry{vmargin={12mm}, hmargin={10mm,10mm}}'))
        doc.append(NoEscape(r'\bigskip'))

        # summary section
        with doc.create(Section('Session summary')):
            # create summary table
            with doc.create(LongTabu("X | X")) as summary_table:
                with doc.create(Tabular("r r")) as small_table:
                    small_table.add_row(["Summary", ""])
                    small_table.add_hline()
                    small_table.add_row(["Gamble side:", self.gamble_side])
                    small_table.add_hline()
                    small_table.add_row(
                        ["All trials",
                         self.all_trials_df.index.max()])
                    small_table.add_row(
                        ["Good trials",
                         self.good_trials_df.index.max()])
                    small_table.add_row([
                        "Selected trials",
                        self.selected_trials_df.index.max()
                    ])
                    small_table.add_hline()
                    small_table.add_row([
                        "Probability bins",
                        str(self.all_trials_df['probability'].unique())
                    ])

                # add overview plots
                doc.append(NoEscape(self.image_box("hist_fit", last=True)))
                doc.append(NoEscape(self.image_box("trial_length")))
                doc.append(NoEscape(self.image_box("cluster_hist", last=True)))
                doc.append(NewPage())

        # Add stuff to the document
        with doc.create(
                Section('Spike Trains and Histogram for Reward Events')):
            # create necessary variables
            for cluster in self.clusters_df.loc[self.clusters_df['group'] ==
                                                'good'].index:
                # create subsection title
                subsection = "Cluster " + str(cluster)
                with doc.create(Subsection(subsection, label=False)):
                    # create details table
                    with doc.create(LongTabu("X | X")) as details_table:

                        doc.append(
                            NoEscape(self.image_box_cluster("isi", cluster)))
                        doc.append(
                            NoEscape(
                                self.image_box_cluster("spk_train",
                                                       cluster,
                                                       last=True)))
                        details_table.add_hline()
                        details_table.add_row(
                            ["All Trials", "Rewarded Trials"])
                        doc.append(
                            NoEscape(
                                self.image_box_cluster(
                                    "spk_train_hist_all-events", cluster)))
                        doc.append(
                            NoEscape(
                                self.image_box_cluster(
                                    "spk_train_hist_all-events_reward-centered",
                                    cluster,
                                    last=True)))
                        details_table.add_hline()
                        details_table.add_row(
                            ["Gambl Side Reward", "Save Side Reward"])
                        #details_table.end_table_header()
                        doc.append(
                            NoEscape(
                                self.image_box_cluster(
                                    "spk_train_hist_gamble_reward", cluster)))
                        doc.append(
                            NoEscape(
                                self.image_box_cluster(
                                    "spk_train_hist_save_reward",
                                    cluster,
                                    last=True)))
                        #details_table.add_hline()
                        details_table.add_row(
                            ["Gambl Side No-Reward", "Save Side No-Reward"])
                        doc.append(
                            NoEscape(
                                self.image_box_cluster(
                                    "spk_train_hist_gamble_no-reward",
                                    cluster)))
                        doc.append(
                            NoEscape(
                                self.image_box_cluster(
                                    "spk_train_hist_save_no-reward",
                                    cluster,
                                    last=True)))
                doc.append(NewPage())

        # create file_name
        filepath = (self.folder + "/" + self.session + "-report")
        # create pdf
        doc.generate_pdf(
            filepath, clean=True, clean_tex=True
        )  #, compiler='latexmk -f -xelatex -interaction=nonstopmode')
Exemple #48
0
class Traceability(Trace):
    """Automatically generate summary reports of the training.

    Args:
        save_path: Where to save the output files. Note that this will generate a new folder with the given name, into
            which the report and corresponding graphics assets will be written.
        extra_objects: Any extra objects which are not part of the Estimator, but which you want to capture in the
            summary report. One example could be an extra pipeline which performs pre-processing.

    Raises:
        OSError: If graphviz is not installed.
    """
    def __init__(self, save_path: str, extra_objects: Any = None):
        # Verify that graphviz is available on this machine
        try:
            pydot.Dot.create(pydot.Dot())
        except OSError:
            raise OSError(
                "Traceability requires that graphviz be installed. See www.graphviz.org/download for more information.")
        # Verify that the system locale is functioning correctly
        try:
            locale.getlocale()
        except ValueError:
            raise OSError("Your system locale is not configured correctly. On mac this can be resolved by adding \
                'export LC_ALL=en_US.UTF-8' and 'export LANG=en_US.UTF-8' to your ~/.bash_profile")
        super().__init__(inputs="*", mode="!infer")  # Claim wildcard inputs to get this trace sorted last
        # Report assets will get saved into a folder for portability
        path = os.path.normpath(save_path)
        path = os.path.abspath(path)
        root_dir = os.path.dirname(path)
        report = os.path.basename(path) or 'report'
        report = report.split('.')[0]
        self.save_dir = os.path.join(root_dir, report)
        self.resource_dir = os.path.join(self.save_dir, 'resources')
        self.report_name = None  # This will be set later by the experiment name
        os.makedirs(self.save_dir, exist_ok=True)
        os.makedirs(self.resource_dir, exist_ok=True)
        # Other member variables
        self.config_tables = []
        # Extra objects will automatically get included in the report since this Trace is @traceable, so we don't need
        # to do anything with them. Referencing here to stop IDEs from flagging the argument as unused and removing it.
        to_list(extra_objects)
        self.doc = Document()
        self.log_splicer = None

    def on_begin(self, data: Data) -> None:
        exp_name = self.system.summary.name
        if not exp_name:
            raise RuntimeError("Traceability reports require an experiment name to be provided in estimator.fit()")
        # Convert the experiment name to a report name (useful for saving multiple experiments into same directory)
        report_name = "".join('_' if c == ' ' else c for c in exp_name
                              if c.isalnum() or c in (' ', '_')).rstrip().lower()
        report_name = re.sub('_{2,}', '_', report_name)
        self.report_name = report_name or 'report'
        # Send experiment logs into a file
        log_path = os.path.join(self.resource_dir, f"{report_name}.txt")
        if self.system.mode != 'test':
            # See if there's a RestoreWizard
            restore = False
            for trace in self.system.traces:
                if isinstance(trace, RestoreWizard):
                    restore = trace.should_restore()
            if not restore:
                # If not running in test mode, we need to remove any old log file since it would get appended to
                with contextlib.suppress(FileNotFoundError):
                    os.remove(log_path)
        self.log_splicer = LogSplicer(log_path)
        self.log_splicer.__enter__()
        # Get the initialization summary information for the experiment
        self.config_tables = self.system.summary.system_config
        models = self.system.network.models
        n_floats = len(self.config_tables) + len(models)

        self.doc = self._init_document_geometry()
        # Keep tables/figures in their sections
        self.doc.packages.append(Package(name='placeins', options=['section']))
        self.doc.preamble.append(NoEscape(r'\usetikzlibrary{positioning}'))

        # Fix an issue with too many tables for LaTeX to render
        self.doc.preamble.append(NoEscape(r'\maxdeadcycles=' + str(2 * n_floats + 10) + ''))
        self.doc.preamble.append(NoEscape(r'\extrafloats{' + str(n_floats + 10) + '}'))

        # Manipulate booktab tables so that their horizontal lines don't break
        self.doc.preamble.append(NoEscape(r'\aboverulesep=0ex'))
        self.doc.preamble.append(NoEscape(r'\belowrulesep=0ex'))
        self.doc.preamble.append(NoEscape(r'\renewcommand{\arraystretch}{1.2}'))

        self._write_title()
        self._write_toc()

    def on_end(self, data: Data) -> None:
        self._write_body_content()

        # Need to move the tikz dependency after the xcolor package
        self.doc.dumps_packages()
        packages = self.doc.packages
        tikz = Package(name='tikz')
        packages.discard(tikz)
        packages.add(tikz)

        if shutil.which("latexmk") is None and shutil.which("pdflatex") is None:
            # No LaTeX Compiler is available
            self.doc.generate_tex(os.path.join(self.save_dir, self.report_name))
            suffix = '.tex'
        else:
            # Force a double-compile since some compilers will struggle with TOC generation
            self.doc.generate_pdf(os.path.join(self.save_dir, self.report_name), clean_tex=False, clean=False)
            self.doc.generate_pdf(os.path.join(self.save_dir, self.report_name), clean_tex=False)
            suffix = '.pdf'
        print("FastEstimator-Traceability: Report written to {}{}".format(os.path.join(self.save_dir, self.report_name),
                                                                          suffix))
        self.log_splicer.__exit__()

    def _write_title(self) -> None:
        """Write the title content of the file. Override if you want to build on top of base traceability report.
        """
        self.doc.preamble.append(Command('title', self.system.summary.name))
        self.doc.preamble.append(Command('author', f"FastEstimator {fe.__version__}"))
        self.doc.preamble.append(Command('date', NoEscape(r'\today')))
        self.doc.append(NoEscape(r'\maketitle'))

    def _write_toc(self) -> None:
        """Write the table of contents. Override if you want to build on top of base traceability report.
        """
        self.doc.append(NoEscape(r'\tableofcontents'))
        self.doc.append(NoEscape(r'\newpage'))

    def _write_body_content(self) -> None:
        """Write the main content of the file. Override if you want to build on top of base traceability report.
        """
        self._document_training_graphs()
        self.doc.append(NoEscape(r'\newpage'))
        self._document_fe_graph()
        self.doc.append(NoEscape(r'\newpage'))
        self._document_init_params()
        self._document_models()
        self._document_sys_config()
        self.doc.append(NoEscape(r'\newpage'))

    def _document_training_graphs(self) -> None:
        """Add training graphs to the traceability document.
        """
        with self.doc.create(Section("Training Graphs")):
            log_path = os.path.join(self.resource_dir, f'{self.report_name}_logs.png')
            visualize_logs(experiments=[self.system.summary],
                           save_path=log_path,
                           verbose=False,
                           ignore_metrics={'num_device', 'logging_interval'})
            with self.doc.create(Figure(position='h!')) as plot:
                plot.add_image(os.path.relpath(log_path, start=self.save_dir),
                               width=NoEscape(r'1.0\textwidth,height=0.95\textheight,keepaspectratio'))
            for idx, graph in enumerate(self.system.custom_graphs.values()):
                graph_path = os.path.join(self.resource_dir, f'{self.report_name}_custom_graph_{idx}.png')
                visualize_logs(experiments=graph, save_path=graph_path, verbose=False)
                with self.doc.create(Figure(position='h!')) as plot:
                    plot.add_image(os.path.relpath(graph_path, start=self.save_dir),
                                   width=NoEscape(r'1.0\textwidth,height=0.95\textheight,keepaspectratio'))

    def _document_fe_graph(self) -> None:
        """Add FE execution graphs into the traceability document.
        """
        with self.doc.create(Section("FastEstimator Architecture")):
            for mode in self.system.pipeline.data.keys():
                scheduled_items = self.system.pipeline.get_scheduled_items(
                    mode) + self.system.network.get_scheduled_items(mode) + self.system.traces
                signature_epochs = get_signature_epochs(scheduled_items, total_epochs=self.system.epoch_idx, mode=mode)
                epochs_with_data = self.system.pipeline.get_epochs_with_data(total_epochs=self.system.epoch_idx,
                                                                             mode=mode)
                if set(signature_epochs) & epochs_with_data:
                    self.doc.append(NoEscape(r'\FloatBarrier'))
                    with self.doc.create(Subsection(mode.capitalize())):
                        for epoch in signature_epochs:
                            if epoch not in epochs_with_data:
                                continue
                            self.doc.append(NoEscape(r'\FloatBarrier'))
                            with self.doc.create(
                                    Subsubsection(f"Epoch {epoch}",
                                                  label=Label(Marker(name=f"{mode}{epoch}", prefix="ssubsec")))):
                                diagram = self._draw_diagram(mode, epoch)
                                ltx = d2t.dot2tex(diagram.to_string(), figonly=True)
                                args = Arguments(**{'max width': r'\textwidth, max height=0.9\textheight'})
                                args.escape = False
                                with self.doc.create(Center()):
                                    with self.doc.create(AdjustBox(arguments=args)) as box:
                                        box.append(NoEscape(ltx))

    def _document_init_params(self) -> None:
        """Add initialization parameters to the traceability document.
        """
        from fastestimator.estimator import Estimator  # Avoid circular import
        with self.doc.create(Section("Parameters")):
            model_ids = {
                FEID(id(model))
                for model in self.system.network.models if isinstance(model, (tf.keras.Model, torch.nn.Module))
            }
            # Locate the datasets in order to provide extra details about them later in the summary
            datasets = {}
            for mode in ['train', 'eval', 'test']:
                objs = to_list(self.system.pipeline.data.get(mode, None))
                idx = 0
                while idx < len(objs):
                    obj = objs[idx]
                    if obj:
                        feid = FEID(id(obj))
                        if feid not in datasets:
                            datasets[feid] = ({mode}, obj)
                        else:
                            datasets[feid][0].add(mode)
                    if isinstance(obj, Scheduler):
                        objs.extend(obj.get_all_values())
                    idx += 1
            # Parse the config tables
            start = 0
            start = self._loop_tables(start,
                                      classes=(Estimator, BaseNetwork, Pipeline),
                                      name="Base Classes",
                                      model_ids=model_ids,
                                      datasets=datasets)
            start = self._loop_tables(start,
                                      classes=Scheduler,
                                      name="Schedulers",
                                      model_ids=model_ids,
                                      datasets=datasets)
            start = self._loop_tables(start, classes=Trace, name="Traces", model_ids=model_ids, datasets=datasets)
            start = self._loop_tables(start, classes=Op, name="Operators", model_ids=model_ids, datasets=datasets)
            start = self._loop_tables(start,
                                      classes=(Dataset, tf.data.Dataset),
                                      name="Datasets",
                                      model_ids=model_ids,
                                      datasets=datasets)
            start = self._loop_tables(start,
                                      classes=(tf.keras.Model, torch.nn.Module),
                                      name="Models",
                                      model_ids=model_ids,
                                      datasets=datasets)
            start = self._loop_tables(start,
                                      classes=types.FunctionType,
                                      name="Functions",
                                      model_ids=model_ids,
                                      datasets=datasets)
            start = self._loop_tables(start,
                                      classes=(np.ndarray, tf.Tensor, tf.Variable, torch.Tensor),
                                      name="Tensors",
                                      model_ids=model_ids,
                                      datasets=datasets)
            self._loop_tables(start, classes=Any, name="Miscellaneous", model_ids=model_ids, datasets=datasets)

    def _loop_tables(self,
                     start: int,
                     classes: Union[type, Tuple[type, ...]],
                     name: str,
                     model_ids: Set[FEID],
                     datasets: Dict[FEID, Tuple[Set[str], Any]]) -> int:
        """Iterate through tables grouping them into subsections.

        Args:
            start: What index to start searching from.
            classes: What classes are acceptable for this subsection.
            name: What to call this subsection.
            model_ids: The ids of any known models.
            datasets: A mapping like {ID: ({modes}, dataset)}. Useful for augmenting the displayed information.

        Returns:
            The new start index after traversing as many spaces as possible along the list of tables.
        """
        stop = start
        while stop < len(self.config_tables):
            if classes == Any or issubclass(self.config_tables[stop].type, classes):
                stop += 1
            else:
                break
        if stop > start:
            self.doc.append(NoEscape(r'\FloatBarrier'))
            with self.doc.create(Subsection(name)):
                self._write_tables(self.config_tables[start:stop], model_ids, datasets)
        return stop

    def _write_tables(self,
                      tables: List[FeSummaryTable],
                      model_ids: Set[FEID],
                      datasets: Dict[FEID, Tuple[Set[str], Any]]) -> None:
        """Insert a LaTeX representation of a list of tables into the current doc.

        Args:
            tables: The tables to write into the doc.
            model_ids: The ids of any known models.
            datasets: A mapping like {ID: ({modes}, dataset)}. Useful for augmenting the displayed information.
        """
        for tbl in tables:
            name_override = None
            toc_ref = None
            extra_rows = None
            if tbl.fe_id in model_ids:
                # Link to a later detailed model description
                name_override = Hyperref(Marker(name=str(tbl.name), prefix="subsec"),
                                         text=NoEscape(r'\textcolor{blue}{') + bold(tbl.name) + NoEscape('}'))
            if tbl.fe_id in datasets:
                modes, dataset = datasets[tbl.fe_id]
                title = ", ".join([s.capitalize() for s in modes])
                name_override = bold(f'{tbl.name} ({title})')
                # Enhance the dataset summary
                if isinstance(dataset, FEDataset):
                    extra_rows = list(dataset.summary().__getstate__().items())
                    for idx, (key, val) in enumerate(extra_rows):
                        key = f"{prettify_metric_name(key)}:"
                        if isinstance(val, dict) and val:
                            if isinstance(list(val.values())[0], (int, float, str, bool, type(None))):
                                val = jsonpickle.dumps(val, unpicklable=False)
                            else:
                                subtable = Tabularx('l|X', width_argument=NoEscape(r'\linewidth'))
                                for k, v in val.items():
                                    if hasattr(v, '__getstate__'):
                                        v = jsonpickle.dumps(v, unpicklable=False)
                                    subtable.add_row((k, v))
                                # To nest TabularX, have to wrap it in brackets
                                subtable = ContainerList(data=[NoEscape("{"), subtable, NoEscape("}")])
                                val = subtable
                        extra_rows[idx] = (key, val)
            tbl.render_table(self.doc, name_override=name_override, toc_ref=toc_ref, extra_rows=extra_rows)

    def _document_models(self) -> None:
        """Add model summaries to the traceability document.
        """
        with self.doc.create(Section("Models")):
            for model in humansorted(self.system.network.models, key=lambda m: m.model_name):
                if not isinstance(model, (tf.keras.Model, torch.nn.Module)):
                    continue
                self.doc.append(NoEscape(r'\FloatBarrier'))
                with self.doc.create(Subsection(f"{model.model_name.capitalize()}")):
                    if isinstance(model, tf.keras.Model):
                        # Text Summary
                        summary = []
                        model.summary(line_length=92, print_fn=lambda x: summary.append(x))
                        summary = "\n".join(summary)
                        self.doc.append(Verbatim(summary))
                        with self.doc.create(Center()):
                            self.doc.append(HrefFEID(FEID(id(model)), model.model_name))

                        # Visual Summary
                        # noinspection PyBroadException
                        try:
                            file_path = os.path.join(self.resource_dir,
                                                     "{}_{}.pdf".format(self.report_name, model.model_name))
                            dot = tf.keras.utils.model_to_dot(model, show_shapes=True, expand_nested=True)
                            # LaTeX \maxdim is around 575cm (226 inches), so the image must have max dimension less than
                            # 226 inches. However, the 'size' parameter doesn't account for the whole node height, so
                            # set the limit lower (100 inches) to leave some wiggle room.
                            dot.set('size', '100')
                            dot.write(file_path, format='pdf')
                        except Exception:
                            file_path = None
                            print(
                                f"FastEstimator-Warn: Model {model.model_name} could not be visualized by Traceability")
                    elif isinstance(model, torch.nn.Module):
                        if hasattr(model, 'fe_input_spec'):
                            # Text Summary
                            # noinspection PyUnresolvedReferences
                            inputs = model.fe_input_spec.get_dummy_input()
                            self.doc.append(
                                Verbatim(
                                    pms.summary(model.module if self.system.num_devices > 1 else model,
                                                inputs,
                                                print_summary=False)))
                            with self.doc.create(Center()):
                                self.doc.append(HrefFEID(FEID(id(model)), model.model_name))
                            # Visual Summary
                            # Import has to be done while matplotlib is using the Agg backend
                            old_backend = matplotlib.get_backend() or 'Agg'
                            matplotlib.use('Agg')
                            # noinspection PyBroadException
                            try:
                                # Fake the IPython import when user isn't running from Jupyter
                                sys.modules.setdefault('IPython', MagicMock())
                                sys.modules.setdefault('IPython.display', MagicMock())
                                import hiddenlayer as hl
                                with Suppressor():
                                    graph = hl.build_graph(model.module if self.system.num_devices > 1 else model,
                                                           inputs)
                                graph = graph.build_dot()
                                graph.attr(rankdir='TB')  # Switch it to Top-to-Bottom instead of Left-to-Right
                                # LaTeX \maxdim is around 575cm (226 inches), so the image must have max dimension less
                                # than 226 inches. However, the 'size' parameter doesn't account for the whole node
                                # height, so set the limit lower (100 inches) to leave some wiggle room.
                                graph.attr(size="100,100")
                                graph.attr(margin='0')
                                file_path = graph.render(filename="{}_{}".format(self.report_name, model.model_name),
                                                         directory=self.resource_dir,
                                                         format='pdf',
                                                         cleanup=True)
                            except Exception:
                                file_path = None
                                print("FastEstimator-Warn: Model {} could not be visualized by Traceability".format(
                                    model.model_name))
                            finally:
                                matplotlib.use(old_backend)
                        else:
                            file_path = None
                            self.doc.append("This model was not used by the Network during training.")
                    if file_path:
                        with self.doc.create(Figure(position='ht!')) as fig:
                            fig.append(Label(Marker(name=str(FEID(id(model))), prefix="model")))
                            fig.add_image(os.path.relpath(file_path, start=self.save_dir),
                                          width=NoEscape(r'1.0\textwidth,height=0.95\textheight,keepaspectratio'))
                            fig.add_caption(NoEscape(HrefFEID(FEID(id(model)), model.model_name).dumps()))

    def _document_sys_config(self) -> None:
        """Add a system config summary to the traceability document.
        """
        with self.doc.create(Section("System Configuration")):
            with self.doc.create(Itemize()) as itemize:
                itemize.add_item(escape_latex(f"FastEstimator {fe.__version__}"))
                itemize.add_item(escape_latex(f"Python {platform.python_version()}"))
                itemize.add_item(escape_latex(f"OS: {sys.platform}"))
                itemize.add_item(f"Number of GPUs: {torch.cuda.device_count()}")
                if fe.fe_deterministic_seed is not None:
                    itemize.add_item(escape_latex(f"Deterministic Seed: {fe.fe_deterministic_seed}"))
            with self.doc.create(LongTable('|lr|', pos=['h!'], booktabs=True)) as tabular:
                tabular.add_row((bold("Module"), bold("Version")))
                tabular.add_hline()
                tabular.end_table_header()
                tabular.add_hline()
                tabular.add_row((MultiColumn(2, align='r', data='Continued on Next Page'), ))
                tabular.add_hline()
                tabular.end_table_footer()
                tabular.end_table_last_footer()
                color = True
                for name, module in humansorted(sys.modules.items(), key=lambda x: x[0]):
                    if "." in name:
                        continue  # Skip sub-packages
                    if name.startswith("_"):
                        continue  # Skip private packages
                    if isinstance(module, Base):
                        continue  # Skip fake packages we mocked
                    if hasattr(module, '__version__'):
                        tabular.add_row((escape_latex(name), escape_latex(str(module.__version__))),
                                        color='black!5' if color else 'white')
                        color = not color
                    elif hasattr(module, 'VERSION'):
                        tabular.add_row((escape_latex(name), escape_latex(str(module.VERSION))),
                                        color='black!5' if color else 'white')
                        color = not color

    def _draw_diagram(self, mode: str, epoch: int) -> pydot.Dot:
        """Draw a summary diagram of the FastEstimator Ops / Traces.

        Args:
            mode: The execution mode to summarize ('train', 'eval', 'test', or 'infer').
            epoch: The epoch to summarize.

        Returns:
            A pydot digraph representing the execution flow.
        """
        ds = self.system.pipeline.data[mode]
        if isinstance(ds, Scheduler):
            ds = ds.get_current_value(epoch)
        pipe_ops = get_current_items(self.system.pipeline.ops, run_modes=mode, epoch=epoch) if isinstance(
            ds, Dataset) else []
        net_ops = get_current_items(self.system.network.ops, run_modes=mode, epoch=epoch)
        net_post = get_current_items(self.system.network.postprocessing, run_modes=mode, epoch=epoch)
        traces = sort_traces(get_current_items(self.system.traces, run_modes=mode, epoch=epoch))
        diagram = pydot.Dot(compound='true')  # Compound lets you draw edges which terminate at sub-graphs
        diagram.set('rankdir', 'TB')
        diagram.set('dpi', 300)
        diagram.set_node_defaults(shape='box')

        # Make the dataset the first of the pipeline ops
        pipe_ops.insert(0, ds)
        label_last_seen = defaultdict(lambda: str(id(ds)))  # Where was this key last generated

        batch_size = ""
        if isinstance(ds, Dataset):
            if hasattr(ds, "fe_batch") and ds.fe_batch:
                batch_size = ds.fe_batch
            else:
                batch_size = self.system.pipeline.batch_size
                if isinstance(batch_size, Scheduler):
                    batch_size = batch_size.get_current_value(epoch)
                if isinstance(batch_size, dict):
                    batch_size = batch_size[mode]
        if batch_size is not None:
            batch_size = f" (Batch Size: {batch_size})"
        self._draw_subgraph(diagram, diagram, label_last_seen, f'Pipeline{batch_size}', pipe_ops)
        self._draw_subgraph(diagram, diagram, label_last_seen, 'Network', net_ops + net_post)
        self._draw_subgraph(diagram, diagram, label_last_seen, 'Traces', traces)
        return diagram

    @staticmethod
    def _draw_subgraph(progenitor: pydot.Dot,
                       diagram: Union[pydot.Dot, pydot.Cluster],
                       label_last_seen: DefaultDict[str, str],
                       subgraph_name: str,
                       subgraph_ops: List[Union[Op, Trace, Any]]) -> None:
        """Draw a subgraph of ops into an existing `diagram`.

        Args:
            progenitor: The very top level diagram onto which Edges should be written.
            diagram: The diagram into which to add new Nodes.
            label_last_seen: A mapping of {data_dict_key: node_id} indicating the last node which generated the key.
            subgraph_name: The name to be associated with this subgraph.
            subgraph_ops: The ops to be wrapped in this subgraph.
        """
        subgraph = pydot.Cluster(style='dashed', graph_name=subgraph_name, color='black')
        subgraph.set('label', subgraph_name)
        subgraph.set('labeljust', 'l')
        for idx, op in enumerate(subgraph_ops):
            node_id = str(id(op))
            Traceability._add_node(progenitor, subgraph, op, label_last_seen)
            if isinstance(op, Trace) and idx > 0:
                # Invisibly connect traces in order so that they aren't all just squashed horizontally into the image
                progenitor.add_edge(pydot.Edge(src=str(id(subgraph_ops[idx - 1])), dst=node_id, style='invis'))
        diagram.add_subgraph(subgraph)

    @staticmethod
    def _add_node(progenitor: pydot.Dot,
                  diagram: Union[pydot.Dot, pydot.Cluster],
                  op: Union[Op, Trace, Any],
                  label_last_seen: DefaultDict[str, str],
                  edges: bool = True) -> None:
        """Draw a node onto a diagram based on a given op.

        Args:
            progenitor: The very top level diagram onto which Edges should be written.
            diagram: The diagram to be appended to.
            op: The op (or trace) to be visualized.
            label_last_seen: A mapping of {data_dict_key: node_id} indicating the last node which generated the key.
            edges: Whether to write Edges to/from this Node.
        """
        node_id = str(id(op))
        if isinstance(op, (Sometimes, SometimesT)) and op.op:
            wrapper = pydot.Cluster(style='dotted', color='red', graph_name=str(id(op)))
            wrapper.set('label', f'Sometimes ({op.prob}):')
            wrapper.set('labeljust', 'l')
            edge_srcs = defaultdict(lambda: [])
            if op.extra_inputs:
                for inp in op.extra_inputs:
                    if inp == '*':
                        continue
                    edge_srcs[label_last_seen[inp]].append(inp)
            Traceability._add_node(progenitor, wrapper, op.op, label_last_seen)
            diagram.add_subgraph(wrapper)
            dst_id = Traceability._get_all_nodes(wrapper)[0].get_name()
            for src, labels in edge_srcs.items():
                progenitor.add_edge(
                    pydot.Edge(src=src, dst=dst_id, lhead=wrapper.get_name(), label=f" {', '.join(labels)} "))
        elif isinstance(op, (OneOf, OneOfT)) and op.ops:
            wrapper = pydot.Cluster(style='dotted', color='darkorchid4', graph_name=str(id(op)))
            wrapper.set('label', 'One Of:')
            wrapper.set('labeljust', 'l')
            Traceability._add_node(progenitor, wrapper, op.ops[0], label_last_seen, edges=True)
            for sub_op in op.ops[1:]:
                Traceability._add_node(progenitor, wrapper, sub_op, label_last_seen, edges=False)
            diagram.add_subgraph(wrapper)
        elif isinstance(op, (Fuse, FuseT)) and op.ops:
            Traceability._draw_subgraph(progenitor, diagram, label_last_seen, f'Fuse:', op.ops)
        elif isinstance(op, (Repeat, RepeatT)) and op.op:
            wrapper = pydot.Cluster(style='dotted', color='darkgreen', graph_name=str(id(op)))
            wrapper.set('label', f'Repeat:')
            wrapper.set('labeljust', 'l')
            wrapper.add_node(
                pydot.Node(node_id,
                           label=f'{op.repeat if isinstance(op.repeat, int) else "?"}',
                           shape='doublecircle',
                           width=0.1))
            # dot2tex doesn't seem to handle edge color conversion correctly, so have to set hex color
            progenitor.add_edge(pydot.Edge(src=node_id + ":ne", dst=node_id + ":w", color='#006300'))
            Traceability._add_node(progenitor, wrapper, op.op, label_last_seen)
            # Add repeat edges
            edge_srcs = defaultdict(lambda: [])
            for out in op.outputs:
                if out in op.inputs and out not in op.repeat_inputs:
                    edge_srcs[label_last_seen[out]].append(out)
            for inp in op.repeat_inputs:
                edge_srcs[label_last_seen[inp]].append(inp)
            for src, labels in edge_srcs.items():
                progenitor.add_edge(pydot.Edge(src=src, dst=node_id, constraint=False, label=f" {', '.join(labels)} "))
            diagram.add_subgraph(wrapper)
        else:
            if isinstance(op, ModelOp):
                label = f"{op.__class__.__name__} ({FEID(id(op))}): {op.model.model_name}"
                model_ref = Hyperref(Marker(name=str(op.model.model_name), prefix='subsec'),
                                     text=NoEscape(r'\textcolor{blue}{') + bold(op.model.model_name) +
                                     NoEscape('}')).dumps()
                texlbl = f"{HrefFEID(FEID(id(op)), name=op.__class__.__name__).dumps()}: {model_ref}"
            else:
                label = f"{op.__class__.__name__} ({FEID(id(op))})"
                texlbl = HrefFEID(FEID(id(op)), name=op.__class__.__name__).dumps()
            diagram.add_node(pydot.Node(node_id, label=label, texlbl=texlbl))
            if isinstance(op, (Op, Trace)) and edges:
                # Need the instance check since subgraph_ops might contain a tf dataset or torch dataloader
                Traceability._add_edge(progenitor, op, label_last_seen)

    @staticmethod
    def _add_edge(progenitor: pydot.Dot, op: Union[Trace, Op], label_last_seen: Dict[str, str]):
        """Draw edges into a given Node.

        Args:
            progenitor: The very top level diagram onto which Edges should be written.
            op: The op (or trace) to be visualized.
            label_last_seen: A mapping of {data_dict_key: node_id} indicating the last node which generated the key.
        """
        node_id = str(id(op))
        edge_srcs = defaultdict(lambda: [])
        for inp in op.inputs:
            if inp == '*':
                continue
            edge_srcs[label_last_seen[inp]].append(inp)
        for src, labels in edge_srcs.items():
            progenitor.add_edge(pydot.Edge(src=src, dst=node_id, label=f" {', '.join(labels)} "))
        for out in op.outputs:
            label_last_seen[out] = node_id

    @staticmethod
    def _get_all_nodes(diagram: Union[pydot.Dot, pydot.Cluster]) -> List[pydot.Node]:
        """Recursively search through a `diagram` looking for Nodes.

        Args:
            diagram: The diagram to be inspected.

        Returns:
            All of the Nodes available within this diagram and its child diagrams.
        """
        nodes = diagram.get_nodes()
        for subgraph in diagram.get_subgraphs():
            nodes.extend(Traceability._get_all_nodes(subgraph))
        return nodes

    @staticmethod
    def _init_document_geometry() -> Document:
        """Init geometry setting of the document.

        Return:
            Initialized Document object.
        """
        return Document(geometry_options=['lmargin=2cm', 'rmargin=2cm', 'bmargin=2cm'])
Exemple #49
0
def Ascenso(objective, varbls, f, punto):
	l      = Symbol("r")
	s      = Symbol("x")
	varbls = [ Symbol(var) for var in varbls if var in f ]
	f      = Lambda(varbls, f)

	Nabla = [ Lambda(varbls, diff(f(*flatten(varbls)),var)) for var in varbls ]

	punto = Matrix(punto)
	count = 1

	nabla_eval = Matrix([ Nab(*flatten(punto)) for Nab in Nabla ])

	out = open("../data/data.out", "w")

	### Para crear el .pdf con latex
	doc = Document()
	doc.packages.append(Package('geometry', options=['margin=1in']))
	doc.packages.append(Package('inputenc', options=['utf8']))
	doc.packages.append(Package('babel', options=['spanish', 'activeacute']))
	doc.packages.append(Package('enumerate'))
	doc.packages.append(Package('amsthm'))
	doc.packages.append(Package('amssymb'))
	doc.packages.append(Package('amsmath'))
	doc.append('\\decimalpoint')

	doc.append('Maximizar:' if objective else 'Minimizar:')
	doc.append(Math(data = ['f('+ parseVarbls(varbls) + ')=' + parseFunction(f, varbls)] ))
	doc.append('Derivando la función:')

	doc.append('\\begin{align*}')
	for i in range(len(Nabla)):
		out.write('D_' + str(varbls[i]) + " = " + str(Nabla[i](*flatten(varbls))).replace('**', '^') + '\n' )
		doc.append('\\nabla f_{' + str(varbls[i]) + "} & = " + parseFunction(Nabla[i], varbls) + '\\\\' )
	doc.append('\\end{align*}')

	doc.append('Tomamos como punto inicial $p_0 =('+parseVarbls(list(punto))+')$.\
		Iterando con el método del \\textit{ascenso/descenso más pronunciado} obtenemos:$$$$')

	condition = conditional(nabla_eval)

	while(condition > 0):

		### latex
		doc.append('\\textbf{Iteración '+str(count)+'.}\\\\')
		doc.append('Evaluamos $\\nabla f$ en el punto $p_{'+str(count-1)+'}=(' + parseVarbls([round(c, 3) for c in punto]) + \
			')$, entonces $\\nabla f =(' + parseVarbls([round(c, 3) for c in nabla_eval]) + ')$. Obteniendo $h(r)$:')


		h = Lambda(l, f(*flatten(punto + l*nabla_eval)))
		l_nopt = findOptimum(h, objective)
		punto = punto + l_nopt*nabla_eval


		### salida
		out.write("\nIteración " + str(count)+'\\\\')
		out.write("\n\nNabla(p_" + str(count - 1) + ") = " +  str(list(nabla_eval)) + "\n")
		out.write(("\nMAX " if objective == 1 else "\nMIN ") + "h(r)=" + str(h(l)).replace('**', '^'))
		out.write("\nlamb = " + str(l_nopt) + "\n")
		out.write('\np_' + str(count) + ' = ' + str(list(punto)) + '\n')

		
		### latex
		doc.append(Math(data=['h(r)='+parseFunction(h, [l])]))
		doc.append(('Maximizando' if objective else 'Minimizando')+' $h$ encontramos $r$='+str(round(l_nopt, 3))+'.\
			Así $p_{'+str(count)+'}$=('+parseVarbls([round(c, 3) for c in punto])+').$$$$')

		doc.append('\\begin{center}')
		with doc.create(TikZ()):
			plot_options = 'height=9cm, width=9cm, xmin=' + str(l_nopt-5)
			with doc.create(Axis(options=plot_options)) as plot:
				plot_options = 'smooth, red'
				functoplot = str(h(s).expand()).replace('**', '^')
				plot.append(Plot(name='h(r)', func=functoplot, options=plot_options))
				plot.append(Plot(name='(h(r),r)', coordinates=[[N(l_nopt), N(h(l_nopt))]]))
		doc.append('\\end{center}')

		doc.append('$$$$')


		nabla_eval = Matrix([ N(Nab(*flatten(punto))) for Nab in Nabla ])
		condition = conditional(nabla_eval)
		count = count + 1

	### latex
	doc.append('Por lo tanto el punto '+('máximo' if objective else 'mínimo')+' es: ('+parseVarbls([round(c, 3) for c in punto])+')')

	doc.generate_pdf('ascenso')
	os.system('mv ascenso.pdf ../pdfs/ascenso.pdf')
	os.system('okular ../pdfs/ascenso.pdf &')
 
	out.close()
        matched_frames[reference_key3] = calib_frame_by_sep
        matched_frames[reference_key4] = star_sep
                
        if calib_frame_by_sep not in colors_dict:
            colors_dict[calib_frame_by_sep] = next(color_cycler)
                        

#-----------Create the table
#Create the doc
doc = Document(dz.reducFolders['reduc_data'] + 'closest_flat')
doc.packages.append(Package('geometry', options=['left=1cm', 'right=1cm', 'top=1cm', 'bottom=1cm']))
doc.packages.append(Package('preview', options=['active', 'tightpage']))
doc.packages.append(Package('color', options=['usenames', 'dvipsnames',]))
 
#Table pre-commands
doc.append(NoEscape(r'\begin{table*}[h]'))
doc.append(NoEscape(r'\begin{preview}')) 
doc.append(NoEscape(r'\centering'))
doc.append(NoEscape(r'\pagenumbering{gobble}'))
 
#Table header
table_format = 'llllllll'  
 
#Elements we want to put in the table
idces_table     = (dz.reducDf.frame_tag.isin(dz.observation_dict['objects'] + dz.observation_dict['Standard_stars'] + ['flat', 'arc'])) & (dz.reducDf.file_location.str.contains('/raw_fits/')) 
file_names      = dz.reducDf[idces_table].sort_values(['RUN']).file_name.values
file_folders    = dz.reducDf[idces_table].sort_values(['RUN']).file_location.values
RA_values       = dz.reducDf[idces_table].sort_values(['RUN']).RA.values
DEC_values      = dz.reducDf[idces_table].sort_values(['RUN']).DEC.values
UT              = dz.reducDf[idces_table].sort_values(['RUN']).UT.values
objects         = dz.reducDf[idces_table].sort_values(['RUN']).frame_tag.values
Exemple #51
0
class PDFRenderer(object):
    def __init__(self, statistics: List, histograms: List, figure_width=8):
        """
        :param statistics: List of tuples (name, value)
        :param histograms: List of tuples (name, list[int])
        """
        self.doc = Document('output')
        self.statistics = statistics
        self.histograms = histograms
        self.figure_size = (figure_width, 3 * len(histograms))
        self.fill_document()

    def set_title(self, title):
        self.doc.preamble.append(Command('title', title))
        self.doc.append(NoEscape(r'\maketitle'))

    def add_author(self, author):
        self.doc.preamble.append(Command('author', author))

    def set_date(self):
        self.doc.preamble.append(Command('date', NoEscape(r'\today')))

    def build_statistics_table(self):
        if not self.statistics:
            return
        self.doc.append(Command('centering'))
        with self.doc.create(Section('DP Statistics')):
            table1 = Tabular('|c|c|')
            table1.add_hline()
            table1.add_row((MultiColumn(2, align='|c|', data='Summary'), ))
            table1.add_hline()
            for stat in self.statistics:
                table1.add_row((stat['statistic'], stat['result']['value']))
                table1.add_hline()
            self.doc.append(table1)

    def build_histograms(self):
        if not self.histograms:
            return
        fig = plt.figure(tight_layout=True, figsize=self.figure_size)
        gs = gridspec.GridSpec(len(self.histograms), 2)
        for i, hist_dict in enumerate(self.histograms):
            ax = fig.add_subplot(gs[i, :])
            ax.bar(x=hist_dict['data'], height=hist_dict['height'])
            ax.set_xlabel(hist_dict['name'])
        with self.doc.create(Section('DP Histograms')):
            with self.doc.create(Figure(position='htbp')) as plot:
                plot.add_plot()
                plot.add_caption('DP Histograms')

    def fill_document(self):
        self.build_statistics_table()
        self.build_histograms()

    def save_pdf(self, filepath):
        self.doc.generate_pdf(filepath=filepath, clean_tex=False)

    def save_latex(self, filepath):
        self.doc.generate_tex(filepath=filepath)

    def get_latex(self):
        return self.doc.dumps()
from pylatex.basic import NewLine
from pylatex.base_classes import Arguments
from pylatex import Document, Section, Itemize, Command, Package, Subsection


sort.main()

geometry_options = {'margin': '1in'}

document = Document('.', geometry_options=geometry_options)
document.packages.append(Package('hyperref'))

document.preamble.append(Command('title', 'Reading List'))
document.preamble.append(Command('author', 'Daniel Saunders'))
document.preamble.append(Command('date', NoEscape(r'\today')))
document.append(NoEscape(r'\maketitle'))

document.append('Note: Work in progress. Some dates before mid-July 2018 are approximate.')


def create_read_section(document, medium):
	with document.create(Subsection('Read')):
		with document.create(Itemize()) as itemize:
			try:
				df = pd.read_csv(os.path.join(medium, 'read.csv'))
			except pd.errors.EmptyDataError:
				return

			for _, row in df.iterrows():
				title = row.Title
				read = row.Read
Exemple #53
0
from pylatex.utils import NoEscape


class AllTT(Environment):
    """A class to wrap LaTeX's alltt environment."""

    packages = [Package('alltt')]
    escape = False
    content_separator = "\n"

# Create a new document
doc = Document()
with doc.create(Section('Wrapping Latex Environments')):
    doc.append(NoEscape(
        r"""
        The following is a demonstration of a custom \LaTeX{}
        command with a couple of parameters.
        """))

    # Put some data inside the AllTT environment
    with doc.create(AllTT()):
        verbatim = ("This is verbatim, alltt, text.\n\n\n"
                    "Setting \\underline{escape} to \\underline{False} "
                    "ensures that text in the environment is not\n"
                    "subject to escaping...\n\n\n"
                    "Setting \\underline{content_separator} "
                    "ensures that line endings are broken in\n"
                    "the latex just as they are in the input text.\n"
                    "alltt supports math: \\(x^2=10\\)")
        doc.append(verbatim)
Exemple #54
0
    A class representing a custom LaTeX command.

    This class represents a custom LaTeX command named
    ``exampleCommand``.
    """

    _latex_name = 'exampleCommand'
    packages = [Package('color')]


# Create a new document
doc = Document()
with doc.create(Section('Custom commands')):
    doc.append(NoEscape(
        r"""
        The following is a demonstration of a custom \LaTeX{}
        command with a couple of parameters.
        """))

    # Define the new command
    new_comm = Command('newcommand', '\exampleCommand', options=3,
                       extra_arguments=r'\color{#1} #2 #3 \color{black}')
    doc.append(new_comm)

    # Use our newly created command with different arguments
    doc.append(ExampleCommand(arguments=Arguments('blue', 'Hello', 'World!')))
    doc.append(ExampleCommand(arguments=Arguments('green', 'Hello', 'World!')))
    doc.append(ExampleCommand(arguments=Arguments('red', 'Hello', 'World!')))

with doc.create(Section('Custom environments')):
    doc.append(NoEscape(
Exemple #55
0
        with doc.create(Subsection("A subsection")):
            doc.append("Also some crazy characters: $&#{}")


if __name__ == "__main__":
    # Basic document
    doc = Document("basic")
    fill_document(doc)

    doc.generate_pdf()
    doc.generate_tex()

    # Document with `\maketitle` command activated
    doc = Document()

    doc.preamble.append(Command("title", "Awesome Title"))
    doc.preamble.append(Command("author", "Anonymous author"))
    doc.preamble.append(Command("date", NoEscape(r"\today")))
    doc.append(NoEscape(r"\maketitle"))

    fill_document(doc)

    doc.generate_pdf("basic_maketitle", clean=False)

    # Add stuff to the document
    with doc.create(Section("A second section")):
        doc.append("Some text.")

    doc.generate_pdf("basic_maketitle2")
    tex = doc.dumps()  # The document as string in LaTeX syntax
Exemple #56
0
import numpy as np

from pylatex import Document, Section, Subsection, Tabular, Math, TikZ, Axis, \
    Plot, Figure, Package, Matrix
from pylatex.utils import italic
import os

if __name__ == '__main__':
    image_filename = os.path.join(os.path.dirname(__file__), 'kitten.jpg')

    doc = Document()
    doc.packages.append(Package('geometry', options=['tmargin=1cm',
                                                     'lmargin=10cm']))

    with doc.create(Section('The simple stuff')):
        doc.append('Some regular text and some')
        doc.append(italic('italic text. '))
        doc.append('\nAlso some crazy characters: $&#{}')
        with doc.create(Subsection('Math that is incorrect')):
            doc.append(Math(data=['2*3', '=', 9]))

        with doc.create(Subsection('Table of something')):
            with doc.create(Tabular('rc|cl')) as table:
                table.add_hline()
                table.add_row((1, 2, 3, 4))
                table.add_hline(1, 2)
                table.add_empty_row()
                table.add_row((4, 5, 6, 7))

    a = np.array([[100, 10, 20]]).T
    M = np.matrix([[2, 3, 4],
Exemple #57
0
    def generateExam(self):

        doc = Document('basic')
        doc.documentclass = Command(
            'documentclass',
            options=['12pt'],
            arguments=['exam'],
        )

        doc.packages.append(Package('amsmath'))
        doc.preamble.append(Command('pagestyle', 'headandfoot'))
        doc.preamble.append(
            Command(
                'firstpageheader',
                NoEscape(
                    r"""%s : %s \\ \today}{}{Name: \underline{\hspace{2.5in}}"""
                    % (self.course, self.subject))))

        doc.append(
            Command(
                'center',
                Command(
                    'fbox',
                    Command('fbox', 'NO CALCULATORS OR EXTERNAL RESOURCES'))))
        doc.append(Command('begin', 'questions'))

        for mcq in self.mcqs:
            doc.append(NoEscape(r'\question ' + mcq.prompt))
            doc.append(Command('begin', 'checkboxes'))
            for ans in mcq.answers:
                doc.append(Command('choice', ans))

        for frq in self.frqs:
            doc.append(NoEscape(r'\question ' + NoEscape(frq.prompt)))
            doc.append(Command('vspace', frq.spacing + 'in'))

        doc.append(Command('end', 'questions'))

        big_code = pyqrcode.create(np.array_str(self.answerKey), mode='binary')
        big_code.png('code.png')

        with doc.create(Figure(position='b!')) as code:
            code.add_image('code.png', width='50px')

        doc.generate_pdf(clean_tex=False, compiler='pdfLaTeX')
        doc.generate_tex()
Exemple #58
0
from pylatex.utils import NoEscape
import os


def dessiner(doc, chemin):
    for photo in os.listdir(chemin):
        with doc.create(Section('Showing subfigures')):
            image_filename = os.path.join(chemin, photo)
            with doc.create(Figure(width=NoEscape(r'\linewidth'))) as frog:
                frog.add_image(image_filename, width=NoEscape(r'\linewidth'))


if __name__ == '__main__':
    # Basic document
    doc = Document("GrenouilleBrune")

    doc.preamble.append(Command('title', 'Awesome Title'))
    doc.preamble.append(Command('author', 'Lucas Boutarfa'))
    doc.preamble.append(Command('date', NoEscape(r'\today')))
    doc.append(NoEscape(r'\maketitle'))

    doc.append(Command("section", NoEscape(r"Une section")))
    doc.append('du Texte')

    dessiner(doc, "test")
    doc.create(Section("une autre section"))
    doc.append("plus de texte")
    doc.generate_pdf(clean_tex=False)
    doc.generate_tex()
    #print(doc.dumps())
def run():
    adjacency_matrix = _get_adjacency_matrix()
    x = _get_x(adjacency_matrix, DATA_FRAMES)
    x_dot = _get_x_dot(x)
    x_cv_list = []
    x_dot_cv_list = []
    for observation in range(M):
        x_cv = _get_x(adjacency_matrix, CV_DATA_FRAMES)
        x_cv_list.append(x_cv)
        x_dot_cv = _get_x_dot(x_cv)
        x_dot_cv_list.append(x_dot_cv)

    # SINDy for individual nodes
    latex_document = Document('basic')
    latex_document.packages.append(Package('breqn'))
    for node_index in range(NUMBER_OF_NODES):
        theta, latex_functions = _get_theta(x, adjacency_matrix, node_index)
        aicc_list = []
        least_aicc = sys.maxsize
        best_xi = None
        ith_derivative = x_dot[:, node_index]
        for candidate_lambda in CANDIDATE_LAMBDAS:
            xi = _sindy(ith_derivative, theta, candidate_lambda)
            k = np.count_nonzero(xi)
            error = 0
            for observation in range(M):
                x_cv = x_cv_list[observation]
                x_dot_cv = x_dot_cv_list[observation]
                theta_cv, _ = _get_theta(x_cv, adjacency_matrix, node_index)
                error += np.sum(
                    np.abs(x_dot_cv[:, node_index] -
                           (np.matmul(theta_cv, xi.T))))
            aicc = M * math.log(error / M) + 2 * k
            if M - k - 2:
                aicc += 2 * (k + 1) * (k + 2) / (M - k - 2)
            else:  # TODO what to do with division by zero
                aicc += 2 * (k + 1) * (k + 2)
            aicc_list.append(aicc)
            if aicc < least_aicc:
                least_aicc = aicc
                best_xi = xi

        plt.figure(figsize=(16, 9), dpi=96)
        plt.plot([
            math.log10(candidate_lambda)
            for candidate_lambda in CANDIDATE_LAMBDAS
        ], aicc_list)
        plt.xlabel('log10(lambda)')
        plt.ylabel('AIC')
        plt.savefig(os.path.join(OUTPUT_DIR,
                                 'node_%d_lambda.png' % node_index))
        plt.close('all')

        latex_document.append(NoEscape(r'\clearpage $'))
        line = r'\frac{dx_{%d}}{dt}=' % node_index
        line_content = []
        for j in range(best_xi.shape[0]):
            if best_xi[j]:
                line_content.append(r'%f' % best_xi[j] + latex_functions[j])

        line += ' + '.join(line_content)
        latex_document.append(NoEscape(line))
        latex_document.append(NoEscape(r'$'))
    latex_document.generate_pdf(
        os.path.join(OUTPUT_DIR, 'individual_equations.pdf'))
def create_pdf(recipes):
    doc = Document()
    doc.packages.append(Package("hyperref", options="hidelinks"))

    doc.append("\\begin{titlepage}\n"
               "\\centering\n"
               "{\\scshape\\Huge\\textbf The Greater Book of Transmutation \\par}\n"
               "\\vspace{1.5cm}\n"
               "{\\scshape\\large How to make almost anything in a few easy steps \\par}\n"
               "\\vspace{5.5cm}\n"
               "{\\large A Procedurally Generated DIY Book \\par}\n"
               "{\\large for the \href{https://github.com/dariusk/NaNoGenMo-2015}{NaNoGenMo 2015} \\par}\n"
               "\\vspace{0.5cm}\n"
               "{\\large by \\href{http://dragonlab.de}{Tobias Wehrum} \\par}\n"
               "\\vfill\n"
               "{\\scriptsize using data by: \\par}\n"
               "\\vspace{0.3cm}\n"
               "{\\scriptsize\\href{http://web.usf.edu/FreeAssociation}{Nelson, D. L., McEvoy, C. L., \\& Schreiber, T. A. (1998). The University of South Florida word association, rhyme, and word fragment norms}\\par}\n"
               "\\vspace{0.3cm}\n"
               "{\\scriptsize\\href{https://www.englishclub.com/vocabulary/nouns-uncountable-list.htm}{English Club: Uncountable Nouns List}\\par}\n"
               "\\vspace{0.3cm}\n"
               "{\\scriptsize\\href{http://archives.nd.edu/whitaker/dictpage.htm}{LATIN-ENGLISH DICTIONARY WORDLIST Version 1.97FC by William Whitaker}\\par}\n"
               "\\vspace{0.5cm}\n"
               "\\end{titlepage}\n"
               "\n"
               "\\setcounter{tocdepth}{1}\n"
               "\\renewcommand*\\contentsname{How to make...}\n"
               "\\tableofcontents\n"
               "\\newpage");

    for r in recipes:
        r.print_to_doc(doc)

    try:
        os.remove("TheGreaterBookOfTransmutation.toc")
    except Exception as err:
        traceback.print_tb(err.__traceback__)

    try:
        doc.generate_pdf("TheGreaterBookOfTransmutation")
    except Exception as err:
        traceback.print_tb(err.__traceback__)

    try:
        doc.generate_tex("TheGreaterBookOfTransmutation")
    except Exception as err:
        traceback.print_tb(err.__traceback__)