示例#1
0
def continuous_stagewise_separate():
    arrsum = ArraySummary("Continuous vs Stage-wise vs Separate")
    with arrsum.create(tex.Section("Overview")):
        arrsum.add_tabular(get_tab_data(data, parameters, by_exp_type, by_reward, get_std, name="STD"))
    for reward_type in ["minimize", "maximize", "target", "range"]:
        grouped_by_reward_params = group_parameters_by(parameters_by_reward_type[reward_type], lambda x: tuple(x[reward_type + "_pred_err"]) if type(x[reward_type + "_pred_err"]) == list else x[reward_type + "_pred_err"])
        for k in grouped_by_reward_params:
            with arrsum.create(tex.Section(reward_type + str(k))):
                groups = group_parameters_by(grouped_by_reward_params[k], lambda x: "stages" if x["continuous"] is None else "continuous")
                with arrsum.create(tex.Subsection("Stages")):
                    sub_groups = group_parameters_by(groups["stages"], lambda x: "separate" if x["separate"] else "joint")
                    with arrsum.create(tex.Subsubsection("Separate")):
                        for p in sub_groups["separate"]:
                            arrsum.add_experiment(p)
                    with arrsum.create(tex.Subsubsection("Joint")):
                        for p in sub_groups["joint"]:
                            arrsum.add_experiment(p)
                arrsum.clearpage()
                with arrsum.create(tex.Subsection("Continuous")):
                    sub_groups = group_parameters_by(groups["continuous"], lambda x: "separate" if x["separate"] else "joint")
                    with arrsum.create(tex.Subsubsection("Separate")):
                        for p in sub_groups["separate"]:
                            arrsum.add_experiment(p)
                    with arrsum.create(tex.Subsubsection("Joint")):
                        for p in sub_groups["joint"]:
                            arrsum.add_experiment(p)
                arrsum.clearpage()
    arrsum.generate_pdf(filepath=path_to_array + "new_impl", clean_tex=False)
示例#2
0
    def sum_sample(self):
        """Summarize the analysis data and plots in a report
        """
        for i in range(len(self.infiles)):
            self.logger.info('\nCreating pdf for sample {} results.\n'.format(
                self.sample[i]))
            geometry_options = {
                'tmargin': '3cm',
                'bmargin': '3cm',
                'rmargin': '3cm',
                'lmargin': '3cm'
            }
            doc = px.Document(documentclass='article',
                              geometry_options=geometry_options)
            doc.preamble.append(
                px.Command('title',
                           'Sequencing results for sample ' + self.sample[i]))
            doc.preamble.append(px.Command('date', px.NoEscape(r'\today')))
            doc.append(px.NoEscape(r'\maketitle'))

            with doc.create(px.Section('Genome coverage')):
                #include table of results with statistics of coverage
                with doc.create(px.Subsection('Coverage results')):
                    with doc.create(px.Tabular(table_spec='l  l')) as table:
                        with open(self.stats_file, 'r') as stats:
                            table.add_hline()
                            stats_data = pd.read_csv(stats, sep='\t')
                            for num in range(len(stats_data.iloc[0])):
                                table.add_row([
                                    stats_data.columns[num],
                                    stats_data.iloc[0][num]
                                ])
                            table.add_hline()
                #include coverage plot
                with doc.create(px.Figure(position='htb!')) as plot:
                    plot.add_image(self.cov_plot[i],
                                   width=px.NoEscape(r'\linewidth'))
                    plot.add_caption(
                        'Genome coverage for sample ' + self.sample[i] +
                        '. Calculated using samtools depth with zero-coverage positions included.'
                    )
            #include mismatch plot comparing the sample to the reference
            with doc.create(px.Section('Comparison to reference genome')):
                with doc.create(px.Figure(position='htb!')) as plot:
                    plot.add_image(self.basefreq_plot + '_' + self.sample[i] +
                                   '.png',
                                   width=px.NoEscape(r'\linewidth'))
                    plot.add_caption(
                        'Mismatch fraction per position for sample ' +
                        self.sample[i] +
                        '. Calculated compared to reference {}.'.format(
                            self.config['folder_locations']['ref_fasta']))

            doc.generate_pdf(
                filepath=os.path.join(self.outputdir, self.sample_info[i] +
                                      '.Report'))
            self.logger.info(
                '\nDone creating pdf for sample {} results.\n'.format(
                    self.sample[i]))
示例#3
0
文件: box.py 项目: cunni/pyspherepack
    def tex_best(cls,
                 filenames=None,
                 texname=None,
                 scaled_rad=None,
                 clamp_edge=None):
        filenames = filenames if filenames is not None else [
            'data/mb_50_2x1.pkl', 'data/mb_50_3x1.pkl'
        ]
        texname = texname if texname is not None else 'data/aggregated_results'
        # set up pylatex doc
        geometry_options = {"margin": "1in"}
        doc = pylatex.Document(texname, geometry_options=geometry_options)
        dapne = lambda s: doc.append(pylatex.NoEscape(s))
        with doc.create(pylatex.Section('Introduction')):
            doc.append(
                'Each section that follows shows an optimized layout for a given number of circles and an approximate aspect ratio of the sheet. Throughout, the following parameters are assumed: clamp edge of 10.0mm, circle diameter of 20mm, spacing between circles of 0.50mm.'
            )
        for fn in filenames:
            mb = cls.load(filename=fn)
            b = mb.best_box['box']
            b.plot(clamp_edge=clamp_edge, scaled_rad=scaled_rad)
            # pylatex to put this in tex
            #matplotlib.use('Agg')
            with doc.create(
                    pylatex.Section(pylatex.NoEscape(
                        r'{} circles, box aspect ratio of roughly ${}\times{}$'
                        .format(b.n_balls, b.box[0], b.box[1])),
                                    label=fn)):
                with doc.create(pylatex.Figure(position='htbp')) as plot:
                    plot.add_plot(width=pylatex.NoEscape(r'0.8\textwidth'))
                    #plot.add_caption('Optimized circle packing for this sheet size.')

            x = b.box_warp(b.logits)
            rad = b.ball_radius(x)
            clamp_edge = clamp_edge if clamp_edge is not None else 0.0
            scaled_rad = scaled_rad if scaled_rad is not None else rad
            scaled_box = scaled_rad / rad * (b.box + 2 * rad)
            scaled_x = scaled_rad / rad * (x + rad)
            #doc.append(pylatex.NoEscape('\noindent Density %:'))
            dapne(r'\noindent Density \%: {:04.2f}\% \\'.format(b.density()))
            dapne(r'Waste \%: {:04.2f}\% \\'.format(100 - b.density()))
            dapne(r'Density with clamp edge \%: {:04.2f}\% \\'.format(
                (b.density() * np.prod(scaled_box) /
                 (scaled_box[1] * (scaled_box[0] + 2 * clamp_edge)))))
            dapne(r'Waste with clamp edge \%: {:04.2f}\% \\'.format(
                100 - (b.density() * np.prod(scaled_box) /
                       (scaled_box[1] * (scaled_box[0] + 2 * clamp_edge)))))

            dapne(r'Circle center coordinates: \\')
            for i in range(b.n_balls):
                #dapne(r'$c_{{{}}}$: {}\\'.format(i+1,scaled_x[i,:]))
                dapne(r'$[{}~~{}]$ \\'.format(scaled_x[i, 0], scaled_x[i, 1]))
            dapne(r'\clearpage')

        doc.generate_tex()
示例#4
0
def model_target():
    arrsum = ArraySummary("Find best learning rate")
    with arrsum.create(tex.Section("Overview")):
        arrsum.add_tabular(get_tab_data(data, parameters, by_nothing, by_reward_type_and_param, get_mean_critic_q, name="critic quality"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_nothing, by_reward_type_and_param, get_mean_end_reward, name="mean reward"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_nothing, by_reward_type_and_param, get_std_end_reward, name="std reward"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_nothing, by_reward_type_and_param, get_mean_end_loss_at_rl, name="mean loss"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_nothing, by_reward_type_and_param, get_std_end_loss, name="std loss"))
    grouped_by_target = group_parameters_by(parameters, by_reward_type_and_param)
    for target in sorted(grouped_by_target):
        with arrsum.create(tex.Section("{}".format(target))):
            for p in grouped_by_target[target]:
                arrsum.add_experiment(p)
            arrsum.clearpage()
    arrsum.generate_pdf(filepath=path_to_array + "new_impl", clean_tex=False)
示例#5
0
def standards_experiments():
    arrsum = ArraySummary("Standard experiments")
    with arrsum.create(tex.Section("Overview")):
        arrsum.add_tabular(get_tab_data(data, parameters, by_reward_type_and_param, by_discount_factor, get_mean_critic_q, name="critic quality"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_reward_type_and_param, by_discount_factor, get_mean_end_reward, name="mean reward"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_reward_type_and_param, by_discount_factor, get_std_end_reward, name="std reward"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_reward_type_and_param, by_discount_factor, get_mean_end_loss_at_rl, name="mean loss"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_reward_type_and_param, by_discount_factor, get_std_end_loss, name="std loss"))
    grouped_by_type = group_parameters_by(parameters, by_reward_type_and_param)
    for exp_type in sorted(grouped_by_type):
        with arrsum.create(tex.Section("{}".format(exp_type))):
            for p in sorted(grouped_by_type[exp_type]):
                arrsum.add_experiment(p)
            arrsum.clearpage()
    arrsum.generate_pdf(filepath=path_to_array + "new_impl", clean_tex=False)
示例#6
0
    def describeAdditiveComponents(self):
        """
        Generate a section describing all additive components present.
        """
        n_terms = len(self.kers)
        error = self.cums[-1].error()
        doc = self.doc
        with doc.create(pl.Section("Additive Component Analysis")):
            terms_str = "only one additive component" if n_terms == 1 else "{0} additive components".format(
                n_terms)
            s = r"The pattern underlying the dataset can be decomposed into " \
              + terms_str + ", " \
              + r"which contribute jointly to the final classifier which we have trained. " \
              + r"With all components in action, the classifier can achieve " \
              + r"a cross-validated classification error rate of {0:.2f}\%. ".format(error * 100) \
              + r"The performance cannot be further improved by adding more components. "
            doc.append(ut.NoEscape(s))

            s = "\n\nIn Table 2 we list the full additive model, " \
              + "all input variables, as well as " \
              + "more complex additive components (if any) considered above, " \
              + "ranked by their cross-validated error. "
            doc.append(ut.NoEscape(s))
            self.tabulateAll()

            for i in range(1, n_terms + 1):
                self.describeOneAdditiveComponent(i)
示例#7
0
    def describeVariables(self):
        """
        Generate a section describing all input dimensions / variables.
        """
        n_terms = len(self.best1d)
        doc = self.doc
        with doc.create(pl.Section("Individual Variable Analysis")):
            s = "First, we try to classify the training samples using only one " \
              + "of the {0:d} input dimensions. ".format(n_terms) \
              + "By considering the best classification performance that is " \
              + "achievable in each dimension, we are able to infer which " \
              + "dimensions are the most relevant to the class label assignment. "
            doc.append(ut.NoEscape(s))
            doc.append(ut.NoEscape("\n\n"))

            s = "Note that in Table 1 the baseline performance is also included, which is achieved " \
              + "with a constant GP kernel. The effect of the baseline classifier " \
              + "is to indiscriminately classify all samples as either positive " \
              + "or negative, whichever is more frequent in the training data. " \
              + "The classifier performance in each input dimension will be " \
              + "compared against this baseline to tell if the input variable " \
              + "is discriminative in terms of class determination. "
            doc.append(ut.NoEscape(s))

            for i in range(n_terms):
                self.describeOneVariable(self.best1d[i])
示例#8
0
def main():

    if not os.path.exists("report"):
        os.mkdir("report")

    global tumor
    global max_distance
    global e_method

    for t in tumors:
        print(t)
        doc = pylatex.Document('report/results' + t)
        doc.append(pylatex.NewPage())
        with doc.create(pylatex.Section(t)):
            for m in e_methods:
                for d in max_distances:
                    tumor = t
                    max_distance = d
                    e_method = m
                    with doc.create(
                            pylatex.Subsection("Score = " + m.tag +
                                               ", Max dist. = " + str(d))):
                        do_analysis(doc)

        doc.generate_pdf(clean_tex=False)
示例#9
0
def generate_tex_revision_sheet(filepath, result_path, lines, starting_item):

    geometry_options = {"tmargin": "2.54cm", "lmargin": "2.54cm"}
    doc = pylatex.Document(geometry_options=geometry_options)

    with doc.create(pylatex.Section('Revision sheet')):

        with doc.create(pylatex.LongTable('|r|p{8cm}|p{8cm}|')) as table:
            table.add_hline()
            table.add_row(('Nr.', 'Comment', 'How the comment is addressed'))
            table.add_hline()
            for line in lines:
                if not line.strip():
                    continue
                table.add_row(
                    (starting_item, line.replace('\\newline',
                                                 '').replace(' ', ''), ''))
                table.add_hline()
                starting_item += 1

    if result_path:
        doc.generate_pdf(result_path, clean_tex=False)
    else:
        doc.generate_pdf(filepath[:-4] + '_revision_sheet.tex',
                         clean_tex=False)

    return
示例#10
0
def array_wrt_buffer_size():
    arrsum = ArraySummary("WRT buffer size")
    with arrsum.create(tex.Section("Overview")):
        arrsum.add_tabular(get_tab_data(data, parameters, by_nothing, by_buffer_size, get_mean_critic_q, name="critic quality"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_nothing, by_buffer_size, get_mean_end_reward, name="mean reward"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_nothing, by_buffer_size, get_std_end_reward, name="std reward"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_nothing, by_buffer_size, get_mean_end_loss_at_rl, name="mean loss at rl"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_nothing, by_buffer_size, get_mean_end_loss_at_model, name="mean loss at model"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_nothing, by_buffer_size, get_std_end_loss, name="std loss"))
    grouped_by_buffer_size = group_parameters_by(parameters, by_buffer_size)
    for buf_size in sorted(grouped_by_buffer_size):
        with arrsum.create(tex.Section("{}".format(buf_size))):
            for p in grouped_by_buffer_size[buf_size]:
                arrsum.add_experiment(p)
            arrsum.clearpage()
    arrsum.generate_pdf(filepath=path_to_array + "new_impl", clean_tex=False)
示例#11
0
def section() -> pylatex.Section:
    result = pylatex.Section('Conclusions and Outlook')
    result.escape = False
    result.append(r"""
\ESIS\ is a next generation slitless spectrograph, designed to obtain co-temporal spectral and spatial images of the solar 
transition region and corona.
In this report, we present details of the scientific objectives, instrument, image and spectral resolution, data 
acquisition, and flight profile.

\ESIS\ follows on the proven \MOSES\ design, incorporating several design changes to improve the utility of the instrument.
The symmetrical arrangement of \CCDs\ and diffraction gratings results in a compact instrument while increasing the number 
of dispersed images and dispersion planes.
This aids the inversion process, while also allowing access to higher order spectral line profile moments.
Individual gratings improve resolution by controlling aberration in each channel.
The addition of a field stop eliminates spectral contamination and provides an easily recognizable edge for data 
inversion.
The \ESIS\ design also demonstrates that all this can be accomplished in a volume small enough to serve as a prototype for 
a future orbital instrument.

For the first flight, four of the six available \ESIS\ channels will be populated with optics optimized around the 
O\,\textsc{v} emission line.
The large (\SI{11.3}{\arcminute} \roy{\fov}), high resolution \FOV\ (\SI{1.52}{\arcsecond} \roy{\spatialResolutionMax}, \SI{74}{\milli\angstrom} \roy{\spectralResolution}) can 
simultaneously observe the evolution of small scale \EUV\ flows and large scale \MHD\ waves in high temporal cadence. 
\ESIS\ also enables the study of transport of mass and energy in the transition region and corona during the $\sim 5$ 
minute data collection portion of rocket flight.

\ESIS\ was recovered after a successful first launch on September 30, 2019, with analysis of collected data currently 
in-process.
Subsequent flights will be proposed and the instrument refined with an eye toward orbital opportunities.
Suborbital flights will allow us to expand the instrument to its full complement of six channels and refine our data 
analysis methods, but do not provide access to major flares and eruptive events that drive space weather.
The long term prospect is that an \ESIS-like instrument on an orbital platform could provide high cadence maps of 
spectral line profiles in solar flares, allowing unique and comprehensive observations of the dynamics in solar eruptive 
events, flare ribbons, and the flare reconnection region.""")
    return result
示例#12
0
def section(doc: kgpy.latex.Document) -> pylatex.Section:
    result = pylatex.Section(pylatex.NoEscape(r'The \ESIS\ Instrument'))
    result.escape = False
    result.append(
        pylatex.NoEscape(
            r"""\ESIS\ is a multi-projection slitless spectrograph that obtains line intensities, Doppler shifts, and 
widths in a single snapshot over a 2D \FOV.
Starting from the notional instrument described in Sec.~\ref{sec:TheESISConcept}, \ESIS\ has been designed to ensure all 
of the science requirements set forth in Table~\ref{table:scireq} are met.
The final design parameters are summarized in Table~\ref{table:prescription}.

A schematic diagram of a single \ESIS\ channel is presented in Fig.~\ref{fig:schematic}a, while the mechanical features 
of the primary mirror and gratings are detailed in Figs.~\ref{fig:schematic}b and \ref{fig:schematic}c, respectively."""
        ))
    result.append(tables.prescription.table())
    result.append(optics.subsection())
    result.append(optimization_and_tolerancing.subsection(doc))
    result.append(vignetting.subsection())
    result.append(distortion.subsection())
    result.append(coatings_and_filters.subsection())
    result.append(sensitivity_and_cadence.subsection(doc))
    result.append(alignment_and_focus.subsection())
    result.append(apertures_and_baffles.subsection())
    result.append(cameras.subsection())
    result.append(avionics.subsection())
    result.append(pointing_system.subsection())
    result.append(mechanical.subsection())
    return result
示例#13
0
    def createPDF(self):
        # Loop through each pacakage
        for ind in range(len(self.mBank["dateEnd"])):
            # Generate type of text to be used for report
            text = self.genText(ind)
            # Create section
            with self.mDoc.create(
                    pyl.Section(self.mBank["dateBegin"][ind] + " - " +
                                self.mBank["dateEnd"][ind])) as sec:
                # Add description of table
                sec.append(text["description"])
                # Add long table of statistics to section
                self.addTable(
                    sec,
                    self.mBank["statistics"][ind],
                    subxlabel={
                        "#": ["count"],
                        "Hours":
                        ["mean", "lower quartile", "median", "upper quartile"]
                    })
                self.addGraph(sec,
                              self.mBank["graphs"][ind],
                              title=text["plotTitle"])
            # Append new page after table/graph
            self.mDoc.append(pyl.NewPage())

        # Generate the pdf, and clean the latex files afterwards
        self.mDoc.generate_pdf(clean=True)
        return
示例#14
0
    def finalize(self):
        doc = util.create_doc(
            f"Correlator Fits: {self.ensemble_name} - {self.task_name}")

        for operator_set, operator_fits in self.operator_fits.items():
            with doc.create(pylatex.Section(str(operator_set))):
                for operator, fits in operator_fits.items():
                    with doc.create(pylatex.Subsection(str(operator))):
                        for fit, fit_infos in fits.items():

                            # normal fits
                            logfile = self.logfile(operator_set, operator,
                                                   fit.name)
                            fit_log = sigmond_info.sigmond_log.FitLog(logfile)
                            if self.fit_plots:
                                plotdir = self.fit_plotdir(
                                    operator_set, operator, fit.name)
                                util.dirGrace2pdf(plotdir)

                            section_title = f"{fit.name} - Model: {fit.model.short_name}"
                            with doc.create(
                                    pylatex.Subsubsection(section_title)):
                                self._add_fits(doc, fit_log, fit.name,
                                               operator_set, fit.ratio,
                                               fit.model.has_gap,
                                               fit.model.has_const)

                            # tmin fits
                            if self.tmin_plots:
                                plotdir = self.tmin_fit_plotdir(
                                    operator_set, operator, fit.name)
                                util.dirGrace2pdf(plotdir)
                                tmin_fit_infos = list()
                                for fit_info in fit_infos['tmin']:
                                    plotfile = self.tmin_fit_plotfile(
                                        operator_set,
                                        fit.name,
                                        fit_info,
                                        extension=util.PlotExtension.pdf)
                                    if os.path.isfile(plotfile):
                                        tmin_fit_infos.append(fit_info)

                                if len(tmin_fit_infos) == 0:
                                    continue

                                tmin_fit_infos.sort(
                                    key=lambda fit_info: fit_info.tmax)
                                section_title = f"$t_{{\\rm min}}$ plots - {fit.name} - Model: {fit.model.short_name}"
                                with doc.create(
                                        pylatex.Subsubsection(
                                            pylatex.NoEscape(section_title))):
                                    self._add_tmins(doc, tmin_fit_infos,
                                                    fit.name, operator_set,
                                                    fit.ratio)

        results_dir = self.results_dir
        os.makedirs(results_dir, exist_ok=True)
        filename = os.path.join(results_dir, self.task_name)
        util.compile_pdf(doc, filename, self.latex_compiler)
示例#15
0
def learning_rates():
    arrsum = ArraySummary("Find best learning rate")
    with arrsum.create(tex.Section("Overview")):
        arrsum.add_tabular(get_tab_data(data, parameters, by_clr, by_alr, get_mean_critic_q, name="critic quality"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_clr, by_alr, get_mean_end_reward, name="mean reward"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_clr, by_alr, get_std_end_reward, name="std reward"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_clr, by_alr, get_mean_end_loss_at_rl, name="mean loss"))
        arrsum.add_tabular(get_tab_data(data, parameters, by_clr, by_alr, get_std_end_loss, name="std loss"))
    grouped_by_clr = group_parameters_by(parameters, by_clr)
    for clr in sorted(grouped_by_clr):
        grouped_by_alr = group_parameters_by(grouped_by_clr[clr], by_alr)
        for alr in sorted(grouped_by_alr):
            with arrsum.create(tex.Section("Critic {}    Actor {}".format(clr, alr))):
                for p in grouped_by_alr[alr]:
                    arrsum.add_experiment(p)
                arrsum.clearpage()
    arrsum.generate_pdf(filepath=path_to_array + "new_impl", clean_tex=False)
示例#16
0
    def add_page2(self):
        doc = self.m_doc
        with doc.create(pl.Section('A section 2')):
            doc.append('Some regular text and some ')
            doc.append(italic('italic text. '))

            with doc.create(pl.Figure(position='h!')) as kitten_pic:
                kitten_pic.add_image("meso.png",
                                     width=NoEscape(r'0.75\textwidth'))

        doc.append(pl.NewPage())
示例#17
0
def slice_info_section(sl, doc):
    import pylatex
    with doc.create(pylatex.Section('Slice info')):
        lines = [
            'Name: %s' % sl.name,
            'hkl0: %s' % (sl.hkl0, ),
            'projection: %s' % (sl.hkl_projection, ),
        ]
        s = '\n'.join(lines)
        doc.append(verbatim(s))
    return
示例#18
0
 def generate_latex(
     self, sort_by="graphs"
 ):  # graphs = []  #todo allow for setting which graphs to output
     if sort_by == "graphs":
         for graph_type, state_dict in self.tex_dict.items():
             # todo map graph type to human readable section name
             with self.doc.create(pyl.Section(graph_type)):
                 for state, tex_list in state_dict.items():
                     with self.doc.create(pyl.Subsection(state)):
                         [tex_func(doc=self.doc) for tex_func in tex_list]
     else:
         raise NotImplementedError("Sorting by protein state not implemented")
示例#19
0
    def production(self):
        """Plot production against days."""

        prods = mongo.prods(self.cow)
        days = list(range(len(prods)))

        plt.plot(days, prods)
        plt.xlabel(self.DAY_LABEL)
        plt.ylabel(self.PROD_LABEL)

        with self.doc.create(pylatex.Section('Production')):
            self.add_plot()
示例#20
0
    def print_latex(self):
        """
            Gerador de arquivos .tex e .pdf
        """

        pdf = pylatex.Document("default")

        with pdf.create(pylatex.Section("Equações Diofantinas")) as section:

            section.append("Equação:")
            ultimo = self.numbers[-1]
            eq = []
            cont = 1
            for i in self.numbers:
                simbolo = "+"
                if i == ultimo:
                    simbolo = "= 1"
                eq.append(
                    pylatex.NoEscape(" {}x_{} {}".format(i, cont, simbolo)))
                cont = cont + 1

            section.append(pylatex.Math(data=eq))

            text = "n = {}".format(self.order)
            section.append(text)

            m = pylatex.Matrix(self.take_vec(), mtype='b')
            matrix = pylatex.Math(data=['b = ', m])
            section.append(matrix)

            m = pylatex.Matrix(self.take_matrix(), mtype='b')
            matrix = pylatex.Math(data=['A = ', m])
            section.append(matrix)

            section.append("Resposta = {}".format(self.cofactor_matrix()))

            section.append(pylatex.LineBreak())
            section.append("Confirmando:")
            section.append(pylatex.LineBreak())
            s = 0
            for i in range(len(self.numbers)):
                r = self.numbers[i] * self.cofactor_matrix()[i]
                s = s + r
                resp = "\t {}\t{} \t* \t{} \t= \t{} \t({})\n".format(
                    i, self.numbers[i],
                    self.cofactor_matrix()[i], r, s)
                section.append(resp)

        if self.create_pdf:
            pdf.generate_pdf()

        pdf.generate_tex()
示例#21
0
def main():
    doc = pylatex.Document("basic")

    for saga in Saga.objects.order_by("name"):
        with doc.create(pylatex.Section(saga.name)):
            with doc.create(pylatex.Enumerate()) as elements:
                for book in saga.books:
                    color = "red"
                    if book.owned:
                        color = "blue"
                    txt = pylatex.TextColor(color, book.title)
                    elements.add_item(txt)

    doc.generate_pdf("saga_completion", clean_tex=True)
示例#22
0
def make_introduction(make_graphics: bool = False):
    import os

    from aml import globals_

    from mutools import mus

    if make_graphics:
        _make_graphics()

    images = {}
    for iname in os.listdir(globals_.INTRODUCTION_PICTURES_PATH):
        splitted_iname = iname.split(".")
        if splitted_iname[1] == "png":
            ipath = r"{}/{}".format(globals_.INTRODUCTION_PICTURES_PATH, iname)
            images.update({splitted_iname[0]: os.path.realpath(ipath)})

    language_options = {"en": "english", "de": "ngerman"}

    # (2) writing document
    for paper_format in (mus.A4, mus.A3):
        for language in ("de", "en"):
            texts_path = "aml/introduction/texts/{}".format(language)
            texts = {}
            for fname in os.listdir(texts_path):
                subtexts = {}
                for subtext in os.listdir("{}/{}".format(texts_path, fname)):
                    with open("{}/{}/{}".format(texts_path, fname, subtext),
                              "r") as f:
                        subtexts.update({subtext: f.read()})

                texts.update({fname: subtexts})

            path = "{}/introduction_{}_{}".format(globals_.INTRODUCTION_PATH,
                                                  paper_format.name, language)
            document = pylatex.Document(default_filepath=path)
            _prepare_document(document, language_options, language,
                              paper_format)

            document.append(
                pylatex.Section(title=texts["title"]["title"],
                                label=False,
                                numbering=False))

            _add_setup_notes(document, texts, images)
            _add_string_notes(document, texts, images)
            _add_keyboard_notes(document, texts, images)

            print("gen doc {}".format(path))
            document.generate_pdf()
示例#23
0
    def plot(self, data, confint, title):
        with self.doc.create(pylatex.Section(title)):
            for end in (len(data), SHORT_MAX_LAGS):
                dta = data[:end]
                tools.plot_correlogram(dta, self.title)

                if len(confint):
                    plt.fill_between(range(len(dta)),
                                     confint[:, 0][:end],
                                     confint[:, 1][:end],
                                     alpha=0.25)

                    self.add_plot()
                    plt.clf()
示例#24
0
def section() -> pylatex.Section:
    result = pylatex.Section('Mission Profile')
    result.escape = False
    result.append(r"""
\ESIS\ will be launched aboard a sub-orbital Terrier Black Brant sounding rocket from White Sands Missile Range.
The experiment is currently scheduled for launch in August, 2019.
Trajectory will follow a roughly parabolic path, with $>$\SI{270}{\second} solar observing time above 
\SI{160}{\kilo\meter}.
\ESIS\ will begin continuously taking exposures at a fixed cadence immediately after launch, terminating just before the 
payload impacts the upper atmosphere.
Exposure length will be determined by the target selected for launch day.
Exposures taken while the payload shutter door is closed ($<$ \SI{160}{\kilo\meter}) will be used for dark calibration.
Data will be stored on board and downloaded after recovery, however a limited amount of data will be transmitted to the 
ground station via high speed telemetry as a safeguard against payload loss or destruction.
A parachute will slow the descent of the payload after it enters the atmosphere, and recovery will be accomplished by 
helicopter after the payload is located on the ground.""")
    with result.create(
            pylatex.Subsection(
                pylatex.NoEscape('\ESIS\ Mission Update'))) as mission_update:
        mission_update.escape = False
        mission_update.append(r"""
Since the time of writing \ESIS\ launched and was recovered successfully from White Sands Missile Range on 
September 30, 2019.
Unfortunately, due to failure of the mechanical shutter, no \MOSES\ data was obtained during this flight.
A  paper is forthcoming that will document the \ESIS\ instrument in its as-flown configuration~\citep{Courrier_inprep}.
A companion paper will describe \ESIS\ first results~\citep{Parker_inprep}.
Two significant changes, one to the \ESIS\ instrument and one to our alignment procedures, were made prior to launch and 
are summarized below.

The transfer from visible to \EUV\ grating alignment was completed by an alternative means.
The apparatus described by~\citet{Johnson18} was not able to maintain sufficient repeatability during test runs on 
diffraction grating surfaces.
To maintain the launch schedule, a phase shifting interferometer was used to transfer the alignment of the visible 
gratings to the \EUV\ flight gratings. 

A trade study was conducted, and it was decided to remove the primary aperture stop. The advantage was an increase in 
sensitivity.
The disadvantage was to sacrifice the unvignetted design described in Section \ref{subsec:AperturesandBaffles}.
The effective aperture is increased by a factor of 1.7 to 2.7 as a function of \FOV\ in the radial dimension.
The corresponding signal gradient is oriented along the dispersion direction of each channel;
vignetting increases (and signal decreases) when moving towards blue wavelengths 
(\ie\,moving to the left in Figure~\ref{fig:projections}).
This gradient is due almost entirely to vignetting by the central obscuration, and is linear across the entire \FOV.
The principal challenge is that the images cannot be corrected directly;
rather, since the gradient is repeated for each of the overlapping spectral line images, the vignetting can only be 
accounted for by forward modeling.
Since forward modeling is required for all of the inversion procedures under consideration for \ESIS\ data analysis, the 
vignetting was deemed low risk to the mission science.""")
    return result
示例#25
0
    def makeSummary(self):
        """
        Generate the summary section.
        """
        best = self.cums[-1]
        data = best.data
        summands = self.summands

        doc = self.doc
        with doc.create(pl.Section("Executive Summary")):

            dims = np.array(best.getActiveDims())
            # TODO: Shall we normalise?
            # xvar = np.square(np.array(data.getDataShape()['x_sd'])[dims])
            # stvt = np.vstack((dims, best.sensitivity() / xvar))
            # stvt = np.vstack((dims, best.sensitivity()))
            # stvt = stvt[:,stvt[1,:].argsort()[::-1]] # Sort in descending order
            # dims = stvt[0,:].astype(int).tolist()
            # stvt = stvt[1,:]

            s = "The best kernel that we have found relates the class label assignment " \
              + "to input " + dims2text(dims, data)
            if len(dims) > 1:
                s += ". In specific, the model involves "
                if len(summands) == 1:
                    s += prod2text(summands[0].getActiveDims(), data)
                else:
                    s += sum2text(summands)
            s += " ($" + best.latex() + "$). "
            doc.append(ut.NoEscape(s))

            s = "This model can achieve " \
              + r"a cross-validated classification error of {0:.2f}\% and ".format(best.error() * 100) \
              + r"a negative log marginal likelihood of {0:.2f}. ".format(best.getNLML())
            doc.append(ut.NoEscape(s))

            s = "\n\nWe have also analysed the relevance of each input variable. " \
              + "They are listed below in Table 1 " \
              + "in descending order of inferred relevance " \
              + "(i.e.~in ascending order of cross-validated error of " \
              + "the best one-dimensional GP classifier). "
            doc.append(ut.NoEscape(s))
            self.tabulateVariables()

            s = "\n\nIn the rest of the report, we will first describe the " \
              + "contribution of each individual input variable (Section 2). " \
              + "This is followed by a detailed analysis of the additive " \
              + "components that jointly make up the best model (Section 3). "
            doc.append(ut.NoEscape(s))
示例#26
0
    def lactations(self):
        """Plot lactations of ``cow`` together."""

        for lact in sorted(mongo.lacts(self.cow)):
            prods = mongo.prods(self.cow, lact)
            days = mongo.days(self.cow, lact)

            plt.plot(days, prods, label="{}".format(lact))

        plt.xlabel(self.DAY_LABEL)
        plt.ylabel(self.PROD_LABEL)
        plt.legend()

        with self.doc.create(pylatex.Section('Lactations')):
            self.add_plot()
示例#27
0
def section() -> pylatex.Section:
    result = pylatex.Section(pylatex.NoEscape('The \ESIS\ Concept'))
    result.escape = False
    result.append(
        r"""
A primary goal of the \ESIS\ instrument is to improve upon the imaging spectroscopy demonstrated by \MOSES.  
Therefore, the design of the new instrument draws heavily from experiences and lessons learned through two flights of the \MOSES\ instrument.
\ESIS\ and \MOSES\ are both \CTIS\ instruments.
As such, both produce \sout{dispersed images} \roy{overlappograms} of a narrow portion of the solar spectrum, with the goal of enabling the reconstruction of a spectral line profile at every point in the field of view.
The similarities end there, however, as the optical layout of \ESIS\ differs significantly from that of \MOSES.
In this section, we detail some difficulties and limitations encountered with \MOSES, then describe how the new design of \ESIS\ addresses these issues."""
    )
    result.append(moses_limitations.subsection())
    result.append(esis_features.subsection())
    return result
示例#28
0
 def add2document(self, doc) -> None:
     with doc.create(pylatex.Section(self.name)):
         for table in self.tables:
             table.add2document(doc)
             doc.append(pylatex.NoEscape(""))
             doc.append(pylatex.Command("newline"))
             doc.append(pylatex.NoEscape(""))
             doc.append(
                 pylatex.Command(
                     "vspace",
                     arguments="{0}mm".format(
                         self.VERTICAL_SPACE_BETWEEN_TABLE),
                 ))
             doc.append(pylatex.NoEscape(""))
             doc.append(pylatex.Command("newline"))
             doc.append(pylatex.NoEscape(""))
示例#29
0
    def addSection(self, title, text="", plotDict={}, plotPaths={}):

        with self.doc.create(tex.Section(title)):

            if text:
                self.doc.append(text)

            with self.doc.create(tex.Figure(position='h!')) as fig:

                for i, (plotName, cap) in enumerate(plotDict.items()):

                    subplot = self.createFig(plotPaths[plotName], cap)
                    fig.append(subplot)

                    if (i + 1) % 2 == 0:
                        self.doc.append(tex.LineBreak())
示例#30
0
文件: chapter.py 项目: lcpt/pyCost
 def ImprLtxPre(self, doc, sect):
     '''Imprime presupuestos parciales.'''
     if (self.hasQuantities()):
         if (sect != 'root'):
             doc.append(pylatex.Section(self.getTitle()))
         self.quantities.ImprLtxPre(doc, self.getTitle())
         self.subcapitulos.ImprLtxPre(doc,
                                      pylatex_utils.getLatexSection(sect))
         if self.subcapitulos:
             doc.append(pylatex.Command('noindent'))
             doc.append(pylatex_utils.largeCommand())
             doc.append(
                 pylatex.utils.bold('Total: ' + self.getTitle() + ' '))
             doc.append(pylatex.Command('dotfill'))
             doc.append(pylatex.utils.bold(self.getLtxPriceString()))
             doc.append(pylatex.NewLine())
             doc.append(pylatex_utils.NormalSizeCommand())