LSSTDESC / firecrown

DESC Cosmology Likelihood Framework
BSD 3-Clause "New" or "Revised" License
29 stars 7 forks source link

Example des_y1_3x2pt_PT.py crashes when run as a script #272

Closed marcpaterno closed 1 year ago

marcpaterno commented 1 year ago

In addition to providing the build_likelihood factory function, the example code des_y1_3x2pt_PT.py also can be run as a script. When run as a script it crashes, e.g.:

❯  python des_y1_3x2pt_PT.py
/Users/paterno/mambaforge/envs/firecrown_developer/lib/python3.11/site-packages/sacc/sacc.py:974: UserWarning: No bandpower windows associated to these data
  warnings.warn("No bandpower windows associated to these data")
Using parameters: ['lens0_b_s', 'lens0_bias', 'ia_a_d', 'lens0_delta_z', 'src0_delta_z', 'ia_a_1', 'ia_a_2', 'lens0_b_2', 'lens0_mag_bias']
Log-like = -67.6
[('shear', 'shear'), ('shear', 'intrinsic_pt'), ('intrinsic_pt', 'shear'), ('intrinsic_pt', 'intrinsic_pt'), 'total']
[('magnification+rsd', 'shear'), ('magnification+rsd', 'intrinsic_pt'), ('galaxies', 'shear'), ('galaxies', 'intrinsic_pt'), 'total']
[('magnification+rsd', 'magnification+rsd'), ('magnification+rsd', 'galaxies'), ('galaxies', 'magnification+rsd'), ('galaxies', 'galaxies'), 'total']
Traceback (most recent call last):
  File "/Users/paterno/repos/firecrown/examples/des_y1_3x2pt/des_y1_3x2pt_PT.py", line 304, in <module>
    run_likelihood()
  File "/Users/paterno/repos/firecrown/examples/des_y1_3x2pt/des_y1_3x2pt_PT.py", line 298, in run_likelihood
    fig.savefig("plots/pt_cls.png", facecolor="white", dpi=300)
  File "/Users/paterno/mambaforge/envs/firecrown_developer/lib/python3.11/site-packages/matplotlib/figure.py", line 3343, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/Users/paterno/mambaforge/envs/firecrown_developer/lib/python3.11/site-packages/matplotlib/backend_bases.py", line 2366, in print_figure
    result = print_method(
             ^^^^^^^^^^^^^
  File "/Users/paterno/mambaforge/envs/firecrown_developer/lib/python3.11/site-packages/matplotlib/backend_bases.py", line 2232, in <lambda>
    print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
                                                                 ^^^^^
  File "/Users/paterno/mambaforge/envs/firecrown_developer/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py", line 509, in print_png
    self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)
  File "/Users/paterno/mambaforge/envs/firecrown_developer/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py", line 458, in _print_pil
    mpl.image.imsave(
  File "/Users/paterno/mambaforge/envs/firecrown_developer/lib/python3.11/site-packages/matplotlib/image.py", line 1689, in imsave
    image.save(fname, **pil_kwargs)
  File "/Users/paterno/mambaforge/envs/firecrown_developer/lib/python3.11/site-packages/PIL/Image.py", line 2429, in save
    fp = builtins.open(filename, "w+b")
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'plots/pt_cls.png'

I think the problem is that the plots subdirectory does not exist, and (at least on macOS) it doesn’t get automatically created.