ocelot icon indicating copy to clipboard operation
ocelot copied to clipboard

Bugs in optics plotting script and suggested fixes

Open jonasbjorklundsvensson opened this issue 2 years ago • 2 comments

Hi,

I've found some bugs in some plotting scripts, and also have some suggestions for small improvements.

plot_elems used by plot_opt_func

  1. The calculation of the variable ncols is missing a term np.sign(len(s)) such that solenoids are missed -> gives wrong number of legend columns
  2. Somewhat related to this is that different bend types are plotted multiple times with just 'bend' in the legend -> also causes multiple legend lines and can be solved by replacing dict_copy[elem.__class__]["label"] = "" by dict_copy[Bend]["label"] = "" dict_copy[RBend]["label"] = "" dict_copy[SBend]["label"] = "" like for correctors.
  3. Cavity edge color is hard-coded light green - does not read from the dict_plot
  4. Related is also that edgecolor is not given for elements bend, sext, und, mult.
  5. I would suggest to add bbox_to_anchor=(0.5, -0.5) or so to the ax.legend on the last line to move the legend away from the plot area (always blocks the elements for me).
  6. Edit: I also found that when implementing the above changes, somehow the end of cavities would be interpreted as UnknownElement. To solve it, I commented out the else case in plot_elems reading (possibly requiring additional code elsewhere) if elem.__class__ in dict_copy: ... else: scale = dict_copy[UnknownElement]["scale"] color = dict_copy[UnknownElement]["color"] label = dict_copy[UnknownElement]["label"] ecolor = dict_copy[UnknownElement]["edgecolor"]

The slice energy spread shown with show_e_beam is not correct - don't know what causes this but might be an issue with the analysis rather than the plotting itself. I've attached two pictures below that show the same beam - one plotted with show_e_beam and one with my own script. image image

Hope this is of any use.

  • Jonas

jonasbjorklundsvensson avatar Jun 21 '22 14:06 jonasbjorklundsvensson

Hi, forgot to write it here. I fixed most of the plotting issues and thanks for reporting. Regarding the plotting of he slice parameters, they are calculated correctly, at least to my knowledge. The point is that in our case we calculated slice parameters for FIXED number of the macro particles (default 5000). That is why at the tail and head of the beam you have such picture. But if you calculate slice parameters with fixed time window the picture should be different. That is probably what you did. It will be good if someone implement also this possibility.

sergey-tomin avatar Aug 17 '22 13:08 sergey-tomin

Hi,

Very true, I've calculated the slice parameters for fix-width bins!

  • Jonas

jonasbjorklundsvensson avatar Aug 17 '22 14:08 jonasbjorklundsvensson