JortBox / Halo-FDCA

Radio halo Flux Density Calculation Algorithm
Other
8 stars 2 forks source link

Plotting bug? #12

Closed AstroRipples closed 2 years ago

AstroRipples commented 2 years ago

Hi y'all. After some encouragement from @botteon (and fighting with my conda distribution over a stupid issue...) I finally got Halo-FDCA installed 🎉

I'm running it on a MeerKAT image of MS1455, which has a pretty asymmetric mini-halo. I'm pretty confident that the fit won't be "good" but I'm curious to try the skewed exponential fit functionality. Anyway, I set HaloFitting.py going on my laptop, and after 90 minutes of runtime it crashed on trying to plot:

$ python HaloFitting.py -z 0.258 -model skewed -frame fk5 -loc '14:57:15.1078 +22:20:34.393' \
>     -m True -m_file ms1455_exclusion_zones.reg -spectr_idx -0.97 -walkers 150 -steps 150 \
>     -max_radius 350 -freq 1283 MS1455.0+2232 \
>     ms1455_meerkat.fits

100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 150/150 [1:36:44<00:00, 38.70s/it]
Traceback (most recent call last):
  File "/Users/cjriseley/Desktop/Work/software/Halo-FDCA/FDCA/markov_chain_monte_carlo.py", line 769, in cornerplot
    quantiles=[0.160, 0.5, 0.840], show_titles=True, max_n_ticks=3, title_fmt=self.fmt)
  File "/Users/cjriseley/miniconda3/lib/python3.7/site-packages/corner/corner.py", line 290, in corner
    **hist2d_kwargs,
  File "/Users/cjriseley/miniconda3/lib/python3.7/site-packages/corner/arviz_corner.py", line 163, in arviz_corner
    **hist2d_kwargs,
  File "/Users/cjriseley/miniconda3/lib/python3.7/site-packages/corner/core.py", line 223, in corner_impl
    title = title.format(fmt(q_50), fmt(q_m), fmt(q_p))
ValueError: Invalid format specifier

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/cjriseley/miniconda3/lib/python3.7/site-packages/corner/core.py", line 756, in _get_fig_axes
    return np.array(fig.axes).reshape((K, K))
ValueError: cannot reshape array of size 64 into shape (10,10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "HaloFitting.py", line 146, in <module>
    processing.plot_results()
  File "/Users/cjriseley/Desktop/Work/software/Halo-FDCA/FDCA/markov_chain_monte_carlo.py", line 639, in plot_results
    self.cornerplot()
  File "/Users/cjriseley/Desktop/Work/software/Halo-FDCA/FDCA/markov_chain_monte_carlo.py", line 772, in cornerplot
    quantiles=[0.160, 0.5, 0.840], show_titles=True, max_n_ticks=3, title_fmt='1.2g')
  File "/Users/cjriseley/miniconda3/lib/python3.7/site-packages/corner/corner.py", line 290, in corner
    **hist2d_kwargs,
  File "/Users/cjriseley/miniconda3/lib/python3.7/site-packages/corner/arviz_corner.py", line 163, in arviz_corner
    **hist2d_kwargs,
  File "/Users/cjriseley/miniconda3/lib/python3.7/site-packages/corner/core.py", line 377, in corner_impl
    overplot_lines(fig, truths, color=truth_color)
  File "/Users/cjriseley/miniconda3/lib/python3.7/site-packages/corner/core.py", line 702, in overplot_lines
    axes = _get_fig_axes(fig, K)
  File "/Users/cjriseley/miniconda3/lib/python3.7/site-packages/corner/core.py", line 762, in _get_fig_axes
    ).format(len(fig.axes), K)
ValueError: Provided figure has 64 axes, but data has dimensions K=10

I have no clue what's going on, so thought I'd post up here as it certainly looks like a pretty spectacular plotting bug... Any thoughts?

botteon commented 2 years ago

I can respond on the first issue: I think that you should remove the colons when you pass the string with the coordinates -loc '14:57:15.1078 +22:20:34.393' -> -loc '14 57 15.1078 +22 20 34.393'. For the other issue, I think that it is related to some specifics of the MeerKAT image (64 axes?) Could you check that this does not happen if you use the LOFAR image?

AstroRipples commented 2 years ago

Thanks Andrea. Hm, good point about the colons -- though if that was actually a problem, I'm surprised it went through the whole fitting routine before complaining.

This MeerKAT image is just an MFS image I've produced with WSclean. It only has the standard four axes of a FITS image (RA / Dec / Frequency / Stokes), and the Frequency & Stokes axes are just a single plane.

botteon commented 2 years ago

That's indeed a good point, the crash occurs at the plotting stage (corner plot)...the fit seems to be done and you should be able to check the (numerical) results in the log directory. For the rest, @JortBox is required :)

AstroRipples commented 2 years ago

Yep indeed, I get some numbers... The routine finds some best-fit parameters that seem reasonable -- based on azimuthally-averaged profiles I fitted previously, the numbers look "similar". Need to see the fit and the residuals to go any further, so we'll need Jort's assistance for the plotting issue 😅

ktrehaeven commented 2 years ago

Hi. I'm a masters student at Rhodes University, South Africa. I actually get the exact same issue. Thanks to the OP for opening the issue.

I'm trying to fit the skewed model to mini halos observed by MeerKAT L-band. The FITS files are produced by DDFacet.

I run HaloFitting.py Abell3444 zoom250.A3444.DD.pt_sub.app.restored_mfs.fits -z 0.254 -spectr_idx -1.3 -model skewed -loc '10 23 50.3216 -27 15 21.005' -out_path skewed/ 2>&1 | tee A3444.log and get the error at the bottom of the attached log file. A3444.log

I've also attached the log file created by the package itself. zoom250.A3444.DD.pt_sub.app.restored_mfs.fits_2021-11-27_12:08:45.log

JortBox commented 2 years ago

Hi, Plotting issues have occurred before. I believe Matplotlib has removed/changed some plotting objects in recent versions. I will try to reproduce the issue and find a fix.

JortBox commented 2 years ago

There was an issue where the corner plot could not be made with the newer version of corner (v2.2 and up). de code has been updated to wrok with this version.