jacopo-chevallard / PyP-BEAGLE

4 stars 1 forks source link

Error when trying to plot the residual for a full spectroscopic fit #40

Open eclake opened 3 years ago

eclake commented 3 years ago

Two errors when using --show-residual for plotting the marginal for a full spectroscopic fit

First error:

Traceback (most recent call last):
  File "/mnt/globalNS/tmp/curtis/bin/pyp_beagle", line 8, in <module>
    sys.exit(main())
  File "/mnt/globalNS/tmp/curtis/lib/python2.7/site-packages/pyp_beagle/command_line.py", line 247, in main
    my_spectrum.plot_marginal(ID, file_names[i])
  File "/mnt/globalNS/tmp/curtis/lib/python2.7/site-packages/pyp_beagle/beagle_spectra.py", line 419, in plot_marginal
    axs = axs_[0,:]
IndexError: too many indices for array

Which I managed to fix by changing these lines to read

        if self.show_residual:
            print axs_.shape
            axs = axs_[0]
        else:
            axs = axs_

        if self.show_residual:
            residual_axs = axs_[1]

instead.

When I was trying to add the residual to the output spectrum marginal plot, I got the following error

(2,)
/mnt/globalNS/tmp/curtis/lib/python2.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Passing one of 'on', 'true', 'off', 'false' as a boolean is deprecated; use an actual boolean (True/False) instead.
  warnings.warn(message, mplDeprecation, stacklevel=1)
Traceback (most recent call last):
  File "/mnt/globalNS/tmp/curtis/bin/pyp_beagle", line 8, in <module>
    sys.exit(main())
  File "/mnt/globalNS/tmp/curtis/lib/python2.7/site-packages/pyp_beagle/command_line.py", line 247, in main
    my_spectrum.plot_marginal(ID, file_names[i])
  File "/mnt/globalNS/tmp/curtis/lib/python2.7/site-packages/pyp_beagle/beagle_spectra.py", line 691, in plot_marginal
    residual = (data_flux_-median_flux)/data_flux_
ValueError: operands could not be broadcast together with shapes (33,) (940,)

If I changed these lines to read

            data_flux_ = data_flux[np.isclose(data_wl, model_wl, rtol=1e-6, atol=0.0, equal_nan=False)]
            data_mask_ = data_mask[np.isclose(data_wl, model_wl, rtol=1e-6, atol=0.0, equal_nan=False)]
            data_flux_err_ = data_flux_err[np.isclose(data_wl, model_wl, rtol=1e-6, atol=0.0, equal_nan=False)]

instead, it worked.

The example I was running pyp-beagle on is on neogal at /mnt/globalNS/tmp/curtis/BEAGLE_workdir/results/NIRCam_NIRSpec_data_challenge_1/fit_R100_photom_poly_1_7340_test/

Happy to put together a pull request for these fixes if they look right!

jacopo-chevallard commented 3 years ago

hi @eclake, the first error seems to be related to a new default option of pyplot.subplots

squeeze : bool, default: True

Your solution will break the code when n_outer and n_ranges are > 1, so the best option is probably to set explicitly squeeze=False in the plt.subplots calls in these lines, can you perhaps test it?

jacopo-chevallard commented 3 years ago

The solution to the second issue seems fine ! :) I'll take a look at pyp-beagle right now, I'd like to update it to Python 3, and in the meantime I can integrate these changes...

eclake commented 2 years ago

OK, it looks like the changes I suggested that could break things got included when my calibration axes plots got added... This means the newest version of pyp_beagle is working for me, but might break in other instances as @jacopo-chevallard mentioned earlier. I will see if I can improve this