-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emittance Measurement Class #198
Conversation
shamin-slac
commented
Sep 26, 2024
- This class provides a measure() method for computing the emittance given magnet and screen/wire settings
- Beam size is retrieved directly from the screen/wire
- rmats are taken from the Model (imported from meme.model) initialized for some beamline
- Initialize attributes as properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just writing out comments that we discussed last week. LMK if you have any questions before the end of the week
from meme.model import Model | ||
|
||
class QuadScanEmittance(Measurement): | ||
model_beamline: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing model_beamline, magnet_area, magnet_name, I would define a field
magnet_collection: MagnetCollection
, same for the measurement_device class (which will have the area attribute inside of it). These can be public attributes that get dumped with everything else since they are pydantic objects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these fields should be required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also make it so that we can pass a string to these attributes, for that you would use the following code for example in the magnet_collection class
@field_validator("magnet_collection", mode="before")
def validate_magnet_collection(cls, value):
if isinstance(value, str):
value = create_magnet_collection(value)
return value
- Replace device attribute with device_measurement - Replace get_beamsize() method with device_measurement.measure() method
…nce measurement class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly looks good to me, added a few comments. Lets discuss those here and wait for Dylan to put together his prototype measurement notebook to see if we are missing anything obvious
gets the rmat and twiss parameters, then computes and returns the emittance and BMAG | ||
measure_beamsize: take measurement from measurement device, store beam sizes | ||
""" | ||
name: str = "emittance_profile" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just name it emittance? emittance_profile
doesn't mean much
@dylanmkennedy can you draft a prototype run notebook for diag0 using the current code in Shamin's branch to see if we are missing anything? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good to me, I only made minor comments.
tests/unit_tests/lcls_tools/common/measurements/test_emittance_measurement.py
Show resolved
Hide resolved
- Add x_rms and y_rms to output of emittance measure method - Raise NotImplementedError for MultiDeviceEmittance measure method and compute_emit_bmag - Shorten mock values in test_emittance_measurement
- Get rmats at 'mid' of from_device (the magnet) - Get twiss at measurement_device (the screen) - Use just x rmat and y rmat for compute_emit_bmag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see anything major to prevent merging. Checks were also passed. If Ryan or Eloise also approve, one of them can close the PR.
self.beam_sizes["x_rms"] = [] | ||
if "y_rms" not in self.beam_sizes: | ||
self.beam_sizes["y_rms"] = [] | ||
self.beam_sizes["x_rms"].append(np.mean(results["Sx"])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is Sx coming from? and why the mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sx is coming from the GaussianFit method, a separate PR can be used to change this. I've added in a n_shots key to the emittance measurement class to allow for averaging over multiple shots
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will merge as is and can you please write two issues related to this:
- address the Sx
- We need to return error bars when averaging (or am I missing that here?)
tests/unit_tests/lcls_tools/common/measurements/test_emittance_measurement.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to address Nicole's comments and Qs on Slack, I can make the changes since Shamin is at accelerator school
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok merging this as is for the opportunity to test this week. Please write up those issues, and let me know if you need anything else from me.
|
||
results = { | ||
"emittance": emittance, | ||
"BMAG": bmag, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does BMAG need to be capitalized?
self.beam_sizes["x_rms"] = [] | ||
if "y_rms" not in self.beam_sizes: | ||
self.beam_sizes["y_rms"] = [] | ||
self.beam_sizes["x_rms"].append(np.mean(results["Sx"])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will merge as is and can you please write two issues related to this:
- address the Sx
- We need to return error bars when averaging (or am I missing that here?)