apphys / hpsim

GPU-accelerated Ion Linear Particle Accelerator Simulation
11 stars 6 forks source link

Matplotlib Broadcast Issues #2

Open jeinstei opened 6 years ago

jeinstei commented 6 years ago

I'm trying to run sim-lbeg.py and getting matplotlib errors. I was wondering if you've seen these before?

Twiss parameters
          Alpha       Beta       Eurms       Enrms
x :     -0.4967      1.2577      0.1195     0.18432
y :     -0.8326      1.5431      0.0270     0.04164
z :      5.9615   1938.9661 426356.7835

 4 x  3 BeamPlot object created
Traceback (most recent call last):
  File "sim-lbeg.py", line 119, in <module>
    plot.iso_phase_space('xxp', beam, mask, 1)
  File "/home/jeinstei/hpsim/pylib/hpsim.py", line 1298, in iso_phase_space
    _plot_iso_phase_space(plt, u_coor, v_coor, labels, nbins)
  File "/home/jeinstei/hpsim/pylib/hpsim.py", line 2216, in _plot_iso_phase_space
    ax.add_collection3d(poly, zs=v_bins, zdir='y')
  File "/home/jeinstei/miniconda2/envs/ml_research/lib/python2.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 2303, in add_collection3d
    art3d.poly_collection_2d_to_3d(col, zs=zs, zdir=zdir)
  File "/home/jeinstei/miniconda2/envs/ml_research/lib/python2.7/site-packages/mpl_toolkits/mplot3d/art3d.py", line 714, in poly_collection_2d_to_3d
    zs, zdir)
  File "/home/jeinstei/miniconda2/envs/ml_research/lib/python2.7/site-packages/mpl_toolkits/mplot3d/art3d.py", line 187, in paths_to_3d_segments_with_codes
    zs = _backports.broadcast_to(zs, len(paths))
  File "/home/jeinstei/miniconda2/envs/ml_research/lib/python2.7/site-packages/matplotlib/cbook/_backports.py", line 147, in broadcast_to
    return _broadcast_to(array, shape, subok=subok, readonly=True)
  File "/home/jeinstei/miniconda2/envs/ml_research/lib/python2.7/site-packages/matplotlib/cbook/_backports.py", line 101, in _broadcast_to
    op_flags=[op_flag], itershape=shape, order='C').itviews[0]
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (51,) and requested shape (50,)
Beam is freed. 
Scheff is freed.
BeamLine is freed.
jeinstei commented 6 years ago

It seems like the length of verts isn't matching the shape of v_bins. len(ps_histo) returns 50, while v_bins returns 51 in hpsim.py. Details:

p_histo.shape, v_bins.shape, u_bins.shape, nbins
(50, 50) (51,) (51,) 50
p_histo.shape, v_bins.shape, u_bins.shape, new_bins
(50, 50) (51,) (51,)
jeinstei commented 6 years ago

Bug is here: ax.add_collection3d(poly, zs=v_bins, zdir='y') Can at least plot by changing it to: ax.add_collection3d(poly, zs=v_bins[0:-1], zdir='y')