Skip to content

Error in generating multi-page pdf plots with eis_pointing.eis_aia_registration.plot_intensity() #5

@yjzhu-solar

Description

@yjzhu-solar

When I ran compute_eis_pointing in command lines, I got an error when plot_intensity() failed to generate the multi-page pdf plot to compare EIS and AIA synthetic rasters:

Traceback (most recent call last):
  File "/home/yjzhu/anaconda3/envs/eis_pointing/bin/compute_eis_pointing", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/eis_pointing/driver_cli.py", line 38, in main
    compute(
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/eis_pointing/driver.py", line 193, in compute
    make(filenames['pointing'], filenames['eis_aia_emission'],
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/eis_pointing/driver.py", line 78, in make
    return_value = method(
                   ^^^^^^^
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/eis_pointing/driver.py", line 149, in compute_pointing
    pointing = eis_aia_registration.optimal_pointing(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/eis_pointing/eis_aia_registration.py", line 485, in optimal_pointing
    verif.save_all()
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/eis_pointing/eis_aia_registration.py", line 69, in save_all
    self.save_figures()
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/eis_pointing/eis_aia_registration.py", line 159, in save_figures
    self.plot_intensity(pointing, name=name, diff_norm=diff_norm)
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/eis_pointing/eis_aia_registration.py", line 244, in plot_intensity
    plt.savefig(pp)
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/matplotlib/pyplot.py", line 1134, in savefig
    res = fig.savefig(*args, **kwargs)  # type: ignore[func-returns-value]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/matplotlib/figure.py", line 3390, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/matplotlib/backends/backend_qtagg.py", line 75, in print_figure
    super().print_figure(*args, **kwargs)
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/matplotlib/backend_bases.py", line 2193, in print_figure
    result = print_method(
             ^^^^^^^^^^^^^
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/matplotlib/backend_bases.py", line 2043, in <lambda>
    print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
                                                                 ^^^^^
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/matplotlib/backends/backend_agg.py", line 497, in print_png
    self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/matplotlib/backends/backend_agg.py", line 446, in _print_pil
    mpl.image.imsave(
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/matplotlib/image.py", line 1656, in imsave
    image.save(fname, **pil_kwargs)
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/PIL/Image.py", line 2439, in save
    save_handler(self, fp, filename)
  File "/home/yjzhu/anaconda3/envs/eis_pointing/lib/python3.12/site-packages/PIL/PngImagePlugin.py", line 1287, in _save
    fp.write(_MAGIC)
    ^^^^^^^^
AttributeError: 'PdfPages' object has no attribute 'write'

The error is caused by plt.savefig(pp) in lines 244, 295, and 309. Replacing plt.savefig(pp) by pp.savefig() solves the problem. See the example: https://matplotlib.org/stable/gallery/misc/multipage_pdf.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions