-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreportGeneratorHFRadar.py
162 lines (145 loc) · 8.49 KB
/
reportGeneratorHFRadar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from report_utils import get_years_and_months_ranges
import report_configuration as c
from HFRadar import HFRadar
from pylatex import Document, Package, NoEscape, Section, Itemize
from pylatex.base_classes import Options
import calendar
import sys
import os
__author__ = "Andreas Krietemeyer"
__copyright__ = "Copyright 2016, SOCIB Sistema d observacio i prediccio costaner de les Illes Balears"
__license__ = "GNU GPL v 3"
__version__ = "1.0"
__maintainer__ = ["Charles Troupin", "Andreas Krietemeyer"]
__email__ = "[email protected]"
__status__ = "Production"
class HFReportGenerator:
def __init__(self, year, month):
self.year = int(year)
self.month = int(month)
self.month_str = calendar.month_name[self.month]
self.doc = None
self.set_up_document()
HFRadar(self.year, self.month, self.doc)
#self.doc.generate_tex()
self.doc.generate_pdf(extra_compiler_args='--xelatex')
def write_introduction(self):
with self.doc.create(Section('Introduction', numbering=False)):
self.doc.append('This monthly report aims to extract useful and meaningful information from the HF radar'
' data using qualitative and quantitative data analysis methods. The document is'
' automatically generated based on the information available in the THREDDS Data Server'
' (TDS) Catalog for the HF Radar managed by SOCIB.')
self.doc.append('Automatic data processing includes:')
with self.doc.create(Itemize()) as itemize:
itemize.add_item('Monthly means of the direction vectors, statistics (time series and data tables)')
itemize.add_item(NoEscape(r'Comparisons of the horizontal current components derived from HF radar and'
r' the pointwise subsurface currents from the current-meter (1.5 m) deployed'
r' in the Ibiza Channel (at location 38$^{\circ}$49.46$^\prime$N and'
r' 0$^{\circ}$47.02$^\prime$W), which allow us to evaluate the radar'
r' performance and identify temporal periods or malfunctioning of the radar'
r' (or the current-meter).'))
itemize.add_item('Note that figures are using the oceanographic convention (currents pointing in the'
' direction the flow is toward). ')
def write_title_page(self):
self.doc.append(NoEscape(r'\thispagestyle{empty}\begin{titlepage}\centering'))
self.doc.append(NoEscape(r''))
self.doc.append(NoEscape(r'\vspace*{3.5cm}'))
self.doc.append(NoEscape(r''))
self.doc.append(NoEscape(r'{\Huge \thetitle}'))
self.doc.append(NoEscape(r''))
self.doc.append(NoEscape(r'\vspace{1cm}'))
self.doc.append(NoEscape(r''))
self.doc.append(NoEscape(r'\includegraphics[height=1.5cm]{' + c.settings.socib_logo_path + r'}'))
self.doc.append(NoEscape(r''))
self.doc.append(NoEscape(r'\vspace{1cm}'))
self.doc.append(NoEscape(r''))
self.doc.append(NoEscape(r'{\large\theauthor}'))
self.doc.append(NoEscape(r''))
self.doc.append(NoEscape(r'\vspace{1cm}'))
self.doc.append(NoEscape(r''))
self.doc.append(NoEscape(r'{\LARGE ' + self.month_str + ' ' + str(self.year) + r' Monthly Report}'))
self.doc.append(NoEscape(r''))
self.doc.append(NoEscape(r'{\normalsize Document generated on \thedate}'))
self.doc.append(NoEscape(r'\end{titlepage}'))
self.doc.append(NoEscape(r'\pagestyle{fancy}'))
def write_header_preamble(self):
self.doc.documentclass.options = Options('a4paper', 'svgnames', 'final')
self.doc.packages.append(Package('hyperref'))
self.doc.packages.append(Package('caption', options=['justification=centering']))
self.doc.packages.append(Package('titling'))
self.doc.packages.append(Package('sectsty'))
self.doc.packages.append(Package('xcolor'))
self.doc.packages.append(Package('booktabs'))
self.doc.packages.append(Package('url,doi'))
self.doc.packages.append(Package('lastpage'))
self.doc.packages.append(Package('helvet'))
self.doc.packages.append(Package('fancyhdr'))
self.doc.packages.append(Package('datetime'))
self.doc.packages.append(Package('graphicx'))
self.doc.preamble.append(NoEscape(r'\definecolor{bluesocib}{rgb}{0.3411,0.7804,0.804}'
r'\sectionfont{\color{bluesocib}}'))
self.doc.preamble.append(NoEscape(r'\title{SOCIB HF Radar Data Report}'))
self.doc.preamble.append(NoEscape(r'\author{SOCIB Data Center}'))
self.doc.preamble.append(NoEscape(r'\date{\today}'))
self.doc.preamble.append(NoEscape(r'\ddmmyyyydate'))
self.doc.preamble.append(NoEscape(r'\hypersetup{bookmarksopen=true,bookmarksnumbered=true, pdffitwindow=false,'
r' pdfstartview=FitH,pdftoolbar=true,pdfmenubar=true,pdfwindowui=true,'
r'pdfauthor=\theauthor,pdftitle=\thetitle,pdfsubject=SOCIB Documentation,'
r'bookmarksopenlevel=2,colorlinks=true,breaklinks=true,'
r'linkcolor=black,anchorcolor=black,citecolor=black,filecolor=black,'
r'menucolor=black,urlcolor=black}'))
self.doc.preamble.append(NoEscape(r'\DeclareGraphicsExtensions{.jpg,.pdf,.png,.eps}'
r'\renewcommand{\captionfont}{\it \small}'))
self.doc.preamble.append(NoEscape(r'\setlength{\textwidth}{16cm}\setlength{\textheight}{23.5cm}'
r'\setlength{\headheight}{50.3pt}\setlength{\footskip}{45pt}'
r'\setlength{\hoffset}{-1.5cm}\setlength{\voffset}{-2.5cm}'
r'\setlength{\unitlength}{1cm}\setlength{\parindent}{0pt}'
r'\parskip 0.25cm\setcounter{tocdepth}{2}'
r'\fancyhf{}\lhead{ \fancyplain{}{\hspace{-1.cm}'
r'\includegraphics[height=1.25cm]{' + c.settings.socib_logo_path + r'}} }'
r'\cfoot{\hspace*{.9\textwidth}\sffamily \bfseries '
r'\thepage\ / \pageref{LastPage}}\renewcommand{\headrulewidth}{0pt} '
r'\fancyfoot[L]{ '
r'\parbox[b]{\dimexpr\linewidth\relax}'
r'{\sffamily \bfseries \hspace*{.05\textwidth}'
r'\textcolor{bluesocib}{www.socib.es} \hfill \\ '
r'{\color{bluesocib}\rule{\dimexpr\linewidth\relax}{2pt}}\\}}'
r'\fancyfootoffset{0.2\textwidth}'))
def set_up_document(self):
self.doc = Document(c.settings.document_output_directory + 'SOCIB_HFRadar_Report' + str(self.year) +
str(self.month).zfill(2))
self.write_header_preamble()
self.write_title_page()
self.doc.append(NoEscape(r'\pagebreak'))
self.write_introduction()
self.doc.append(NoEscape(r'\pagebreak'))
self.doc.append(NoEscape(r'\tableofcontents'))
self.doc.append(NoEscape(r'\pagebreak'))
def main():
"""
Requires year and month as input parameters.
year: YYYY
month: MM
Example:
python main 2016 3
OR
python main 2013 2016 8 7
will process all monts in the timespan
"""
#create output directory
if not os.path.exists(os.path.join(os.getcwd(), 'Reports')):
os.makedirs(os.path.join(os.getcwd(), 'Reports'))
#pass current working directory to configuration file
c.settings.prepare_output_directory(os.getcwd())
if len(sys.argv) == 3:
# single station
HFReportGenerator(sys.argv[1], sys.argv[2])
elif len(sys.argv) == 5:
# process time span
years, months = get_years_and_months_ranges(*map(int, sys.argv[1:5]))
for i in range(0, len(years)):
HFReportGenerator(years[i], months[i])
else:
print("Not enough arguments supplied")
if __name__ == "__main__":
main()