ocelot
ocelot copied to clipboard
Bugs in optics plotting script and suggested fixes
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
- The calculation of the variable
ncols
is missing a termnp.sign(len(s))
such that solenoids are missed -> gives wrong number of legend columns - 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"] = ""
bydict_copy[Bend]["label"] = ""
dict_copy[RBend]["label"] = ""
dict_copy[SBend]["label"] = ""
like for correctors. - Cavity edge color is hard-coded light green - does not read from the
dict_plot
- Related is also that
edgecolor
is not given for elements bend, sext, und, mult. - I would suggest to add
bbox_to_anchor=(0.5, -0.5)
or so to theax.legend
on the last line to move the legend away from the plot area (always blocks the elements for me). - 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 theelse
case inplot_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.
Hope this is of any use.
- Jonas
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.
Hi,
Very true, I've calculated the slice parameters for fix-width bins!
- Jonas