From ee34e97799098df82433ca8ee78540d39b399a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 31 Mar 2021 15:12:42 +0300 Subject: [PATCH] wip report-and-generate --- IV/extract-and-generate | 28 ++++++++++++++ IV/layer2img.py | 85 ----------------------------------------- IV/mj-msc.tex | 32 +++------------- 3 files changed, 34 insertions(+), 111 deletions(-) create mode 100755 IV/extract-and-generate delete mode 100755 IV/layer2img.py diff --git a/IV/extract-and-generate b/IV/extract-and-generate new file mode 100755 index 0000000..2d97d49 --- /dev/null +++ b/IV/extract-and-generate @@ -0,0 +1,28 @@ +#!/bin/bash +set -euo pipefail + +fail() { + >&2 echo "$1" + exit 1 +} + +dir=$(mktemp -d) + +echo "Extracting all files from the report ..." +pdfdetach -saveall -o "$dir" mj-msc-all.pdf + +echo "Re-generating the report..." +fail=0 +make -C "$dir" -j $(nproc) mj-msc-all.pdf 2>&1 > make.log || fail=1 + +if [[ $fail == 1 ]]; then + >&2 echo "Generation failed. Here are the last 10 log lines:" + tail -10 "$dir/make.log" + exit 1 +fi + +open=open +if [[ $(uname) == Linux ]] + open=xdg-open +fi +"$open" "$dir/mj-msc-all.pdf" diff --git a/IV/layer2img.py b/IV/layer2img.py deleted file mode 100755 index 95b6a4c..0000000 --- a/IV/layer2img.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/python3 -import argparse -import geopandas -import psycopg2 -import matplotlib.pyplot as plt - -from matplotlib import rc, patches - -INCH = 25.4 # mm -BOUNDS = ('xmin', 'ymin', 'xmax', 'ymax') -GREEN, ORANGE, PURPLE = '#1b9e77', '#d95f02', '#7570b3' - - -def plt_size(string): - if not string: - return None - try: - w, h = string.split("x") - return float(w) / INCH, float(h) / INCH - except Exception as e: - raise argparse.ArgumentTypeError from e - - -def parse_args(): - parser = argparse.ArgumentParser( - description='Convert geopackage to an image') - group1 = parser.add_mutually_exclusive_group() - group1.add_argument('--group1-infile') - group1.add_argument('--group1-table') - parser.add_argument('-o', '--outfile', metavar='') - parser.add_argument( - '--size', type=plt_size, help='Figure size in mm (WWxHH)') - parser.add_argument( '--clip', type=float, nargs=4, metavar=BOUNDS) - - group2 = parser.add_mutually_exclusive_group() - group2.add_argument('--group2-infile', type=str) - group2.add_argument('--group2-table', type=str) - - group3 = parser.add_mutually_exclusive_group() - group3.add_argument('--group3-infile', type=str) - group3.add_argument('--group3-table', type=str) - return parser.parse_args() - - -def read_layer(maybe_table, maybe_file): - if maybe_table: - conn = psycopg2.connect("host=127.0.0.1 dbname=osm user=osm") - sql = "SELECT geom FROM %s" % maybe_table - return geopandas.read_postgis(sql, con=conn, geom_col='geom') - elif maybe_file: - return geopandas.read_file(maybe_file) - - -def main(): - args = parse_args() - group1 = read_layer(args.group1_table, args.group1_infile) - group2 = read_layer(args.group2_table, args.group2_infile) - group3 = read_layer(args.group3_table, args.group3_infile) - - rc('text', usetex=True) - fig, ax = plt.subplots() - if args.size: - fig.set_size_inches(args.size) - if c := args.clip: - ax.set_xlim(left=c[0], right=c[2]) - ax.set_ylim(bottom=c[1], top=c[3]) - - if group1 is not None: - group1.plot(ax=ax, color=PURPLE) - if group2 is not None: - group2.plot(ax=ax, color=ORANGE) - if group3 is not None: - group3.plot(ax=ax, color=GREEN) - - ax.axis('off') - ax.margins(0, 0) - fig.tight_layout(0) - if args.outfile: - fig.savefig(args.outfile, bbox_inches=0, dpi=600) - else: - plt.show() - - -if __name__ == '__main__': - main() diff --git a/IV/mj-msc.tex b/IV/mj-msc.tex index b85b0ba..ad3f6e5 100644 --- a/IV/mj-msc.tex +++ b/IV/mj-msc.tex @@ -128,36 +128,16 @@ ChaikinSmoothing}. \begin{appendices} -\section{Žeimena and Lakaja in context} - \section{Code listings} -For the curious users it may be useful to see how the analysis was executed. -Also, given the source listings, it should be relatively straightforward to -re-run the same analysis on a different area. +We strongly believe that ability to reproduce the graphs here is critical for + the longevity of the work. Therefore we have added all the source files of + this report to the PDF document itself. To extract the files (and, if + desired, re-generate the report), run this simple script: -The analysis was executed and report was generated on Ubuntu 20.04 with only -system packages. This should be sufficient: {\tt postgis gdal-bin biber -latexmk texlive-bibtex-extra python3-geopandas python3-pygments}. +\inputminted[fontsize=\small]{bash}{extract-and-generate} -\subsection{Makefile} -This file binds all the pieces together: -\begin{itemize} - \item Prepares the PostGIS database. - \item Generates helper figures (sine waves, squares). - \item Runs analysis on input files ({\DP}, {\VW}, Chaikin). - \item Invokes {\tt latexmk} as a final report generation step. -\end{itemize} -\inputminted[fontsize=\small]{make}{Makefile} - -\subsection{layer2img.py} -This file accepts a layer (or two) and generates a PDF image suitable for embedding into the report. -\inputminted[fontsize=\small]{python}{layer2img.py} - -\subsection{db} -Manages a PostGIS database in the Docker container. That way, the database can -be torn down and re-created by automated tools like the {\tt Makefile} itself. -\inputminted[fontsize=\small]{bash}{db} +A working Docker installation, LaTeX environment \end{appendices} \end{document}