Closed ivalaginja closed 5 years ago
Inserting the images turned out to be really hard, weasyprint
is weird when it comes to dealing with absolute paths. I tried my luck on Stackoverflow so we'll see whether there's someone who's smart with this:
https://stackoverflow.com/questions/57211774/image-ignored-in-pdf-rendering-with-jinja2-and-weasyprint
Did not work for me. I got the following error
I don't know exactly what I did, but the embedding images magically started working, although we have to use png
images instead of embedding pdf
files.
I will push my changes and then see whether I can figure out what happened on Hannah's machine in the comment above.
Did not work for me. I got the following error
The error message says image not found
, which makes sense since the images we were trying to embed exist only on my local machine and I suspect we didn't run the marginalization code in order to generate them before trying to create the PDF report, or we set the paths up in a wrong way.
Code used to test this (need to adjust the paths):
import os
from margmodule import create_pdf_report
fig2_fname ='/Users/ilaginja/Documents/data_from_repos/hst_marg_data/outputs/weights-stdr-rl_testing.png'
fig3_fname = '/Users/ilaginja/Documents/data_from_repos/hst_marg_data/outputs/residuals_best-model_testing.png'
template_vars = {'data_file': 123,
'run_name': 123,
'rl_in': 123,
'c1': 5,
'c2': 5,
'c3': 5,
'c4': 5,
'top_five_numbers': 'test',
'top_five_weights': 'test',
'top_five_sndr': 'test',
'white_noise': 'test',
'red_noise': 'test',
'photon_noise': 'test',
'rl_marg': 9,
'rl_marg_err': 9,
'epoch_marg': 9,
'epoch_marg_err': 9,
'inclin_rad_marg': 9,
'inclin_rad_marg_err': 9,
'inclin_deg_marg': 9,
'inclin_deg_marg_err': 9,
'msmpr_marg': 9,
'msmpr_marg_err': 9,
'aor_marg': 9,
'aor_marg_err': 9,
'lightcurve_figure': fig2_fname,
'systematics_figure': fig3_fname}
create_pdf_report(template_vars, os.path.join('/Users/ilaginja/', 'report.pdf'))
The only last bit that's missing are is the output for red and white noise. This will be incorporated with issue #44.
This PR implements issue #42 and the solution suggested within.
This solution requires to install the packages
jinja2
,weasyprint
,cairo
andpango
, which are all also available through conda. We will need to update theenvironment.yml
file with that.