atcollab / at

Accelerator Toolbox
Apache License 2.0
48 stars 31 forks source link

zero length elements in lifetime calculation #577

Closed swhite2401 closed 1 year ago

swhite2401 commented 1 year ago

This PR is a bugfix in response to issue #575. The following corrective action are impleted: -if zero-length elements are provided, they are automatically remove with a warning -if the user provides the momentum aperture the zero-lenght elements are also remove from the momentum aperture such that refpts and momap always remain consistent -the momentum aperture and refpts used for the lifetime calculation (with elements removed) are returned by the function

oscarxblanco commented 1 year ago

@swhite2401 the mask you implemented is working. The warning output, however, seems to be shredded

touschek.py:153: AtWarning: zero-length elements removed from lifetime calculation
  warnings.warn(AtWarning('zero-length elements removed '
swhite2401 commented 1 year ago

Yes I could never find a way out of this problem: for multi-line string (required by PEP8) the message is first printed out and then the line at which it is issued is shown, this for multi-line messages results in printing only the first line....

If you have a solution for this I'dd be very happy to hear it! Or maybe @lfarv ?

swhite2401 commented 1 year ago

@oscarxblanco I have implemented the requested changes

oscarxblanco commented 1 year ago

@swhite2401 Unfortunately this modification introduced a bug when calculating the lifetime without the momap input.

 ... acceptance/touschek.py", line 156, in get_lifetime
    refpts = refpts[mask]
TypeError: range indices must be integers or slices, not list

It could be fixed by making refpts a numpy array.

refpts = numpy.array(refpts[mask])