Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Thick elements and labels from list in FloorPlot #4

Merged
merged 14 commits into from
Feb 5, 2024
Merged

Conversation

giadarol
Copy link
Member

@giadarol giadarol commented Feb 2, 2024

This PR adds:

  • support for thick Xtrack elements (Bend, Quadrupole, Sextupole, Octupole) in FloorPlot.
  • possibility to provide a list of element names to be labeled in FloorPlot.

Here a small example (using a lattice available in the xtrack test data):

from cpymad.madx import Madx
import xtrack as xt

test_data_folder = '../../test_data/'
mad = Madx()

mad.call(test_data_folder + 'pimms/PIMM_orig.seq')
mad.call(test_data_folder + 'pimms/betatron.str')
mad.beam(particle='proton', gamma=1.21315778) # 200 MeV
mad.use('pimms')
seq = mad.sequence.pimms
def_expr = True

line = xt.Line.from_madx_sequence(seq, deferred_expressions=def_expr)
line.particle_ref = xt.Particles(gamma0=seq.beam.gamma,
                                 mass0=seq.beam.mass * 1e9,
                                 q0=seq.beam.charge)

sv = line.survey()

tt = line.get_table()
ttsext = tt.rows[tt.element_type == 'Sextupole']

import xplt
import matplotlib.pyplot as plt
plt.close('all')
xplt.FloorPlot(sv, line, labels=ttsext.name)

plt.show()
image

PS: I would like to show these features for the Xsuite tutorial at the Slow Extraction Workshop. What do you think?


My contribution follows "inbound=outbound" licensing as defined by the GitHub Terms of Service.

@giadarol
Copy link
Member Author

giadarol commented Feb 5, 2024

I just saw the test not passing because of the import of xtrack. That can be avoided. I'll update the PR

@giadarol
Copy link
Member Author

giadarol commented Feb 5, 2024

Just updated. I also commented out the alterations to the matplotlib rcParams, as this changes the aspect of all other plots within the same session, which I find a bit invasive :-)

@eltos
Copy link
Member

eltos commented Feb 5, 2024

I just saw the test not passing because of the import of xtrack. That can be avoided. I'll update the PR

Hi @giadarol and many thanks for adding support for thick elements here!
I made a few more adjustments to handle line==None properly in case of having a quick look at MAD-X survey (without the nice wedges of course). Does this work for you?

@eltos
Copy link
Member

eltos commented Feb 5, 2024

Just updated. I also commented out the alterations to the matplotlib rcParams, as this changes the aspect of all other plots within the same session, which I find a bit invasive :-)

I agree that this is invasive, however instead of uncommenting that, it should go into a matplotlib style sheet, so it can be called by the user manually (I would still like to use these "good defaults" in my Jupyter notebooks with a single line):

xplt.apply_style()

@eltos
Copy link
Member

eltos commented Feb 5, 2024

PS: I would like to show these features for the Xsuite tutorial at the Slow Extraction Workshop. What do you think?

It would be an honour :)

@eltos eltos merged commit 892d31f into xsuite:main Feb 5, 2024
6 checks passed
@giadarol
Copy link
Member Author

giadarol commented Feb 5, 2024

I just saw the test not passing because of the import of xtrack. That can be avoided. I'll update the PR

Hi @giadarol and many thanks for adding support for thick elements here! I made a few more adjustments to handle line==None properly in case of having a quick look at MAD-X survey (without the nice wedges of course). Does this work for you?

yes!

@giadarol
Copy link
Member Author

giadarol commented Feb 5, 2024

PS: I would like to show these features for the Xsuite tutorial at the Slow Extraction Workshop. What do you think?

It would be an honour :)

Thank you! Would you manage to make also a PyPI release by then? So that people will be able to run the example notebooks that I will show after a simple pip install of the packages

@eltos
Copy link
Member

eltos commented Feb 5, 2024

Yes, I can make a release in the next days.

@eltos
Copy link
Member

eltos commented Feb 6, 2024

@giadarol I pushed a new version, CI is running and it should soon appear on PyPI.
However, I noticed that there seems to be an issue in XZ-projection (projection="XZ"): for thick elements, the wedge is slightly displaced. In the default ZX-projection it works though.

xt.Multipole xt.Bend
grafik grafik

eltos added a commit that referenced this pull request Feb 6, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants