-
Notifications
You must be signed in to change notification settings - Fork 29
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
Bug fix in atgeometry #667
Conversation
atmat/lattice/survey/atgeometry.m
Outdated
if centered | ||
yy=yy+radius; | ||
xx=xx-radius*sin(theta0); |
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 i'm missing something. But why not do
xcenter = (max(xx) + min(xx) )/2;
ycenter = (max(yy) + min(yy) )/2;
xx=xx-xcenter;
yy=yy-ycenter;
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.
@lcarver would work only for full SR.
Dear @lfarv, the centered option seems to 'center' on ~2.5*10^5 rather than on ~140. may be you are already looking at this issue. best regards |
@simoneliuzzo : see my previous answer: the present geometric computation cannot work for full lattices. So
|
Dear @lfarv, |
pyAT suffers from exactly the same problem ! As I already wrote, for a full ring, you cannot determine the center by looking at both ends. The radius being defined as the intersection of the perpendiculars to both end of the lattice, for a full ring it goes to infinity. If because of rounding errors the ring does not close exactly, then you get any crazy value for the radius, it depends on your ring… If we go for a special case for full rings, it will of course be applied to both Matlab and python. |
Since we are looking into this it would probably make sense to fix it here. I could not find the proposed solutions mentioned in a previous message but since the radius is not constant I suppose we would have to compute some kind of average, was this the proposed solution? This could be quite heavy calculation no? |
I think what @lcarver proposed is the best: the centre would be the average of max and min xx and yy positions. |
My proposal: if the input is a cell of a periodic ring, the centre is non-ambiguous and the present solution is correct, we keep it. If fails in 2 cases: full ring and half-ring, when the perpendiculars to both ends coincide. So we need 2 special cases:
I can't help until next week, so if anyone wants to deal with that, he's welcome ! |
Finally, centring now works in most cases, including full rings and half rings. The fix is applied to both Matlab and python. It's now ready for merging. @lcarver and @simoneliuzzo, any comment? |
I looked at the python and this seems fine, I just have one cosmetic comment |
@swhite2401: defining the threshold globally makes it visible in case one wants to modify it, and makes it assigned once at import rather that each time the function is called. To avoid the ambiguity that you pointed out, I renamed it to Waiting for approval ! @simoneliuzzo ? |
The python version gives me this error:
I installed with these commands: I will try the matlab version now. |
@simoneliuzzo: for your Matlab test: apparently you are running an old version. The |
@simoneliuzzo: Python test I reproduced exactly your commands, and I get no problem (see record below). On which platform did you run?
|
@simoneliuzzo : I may have an explanation for you python problem: in the command
you are not calling the python from your virtual environment, but the system one. AT is not installed there (or badly, it seems: While your virtual environment is activated, just call
|
Dear @lfarv , python solved. I forgot to set the interpreter. now it is ok. |
contrary to atgetgeometry, python get_geometry, does not accept refpts as input. it is usefull, sometimes, to get the coordinates of a single point or a few, along the lattice. |
I did a gitshow in my at_geom_25Oct (named so, since I cloned it fresh just for this test.
commit d843aa3 (HEAD -> fix_atgeometry, origin/fix_atgeometry)�[m Author: Laurent Farvacque laurent.farvacque@esrf.fr�[m Date: Tue Oct 24 17:44:21 2023 +0200
I clean my path before doing the test. And add only the at in at_geom_25Oct I check edit atgeometry and it seems the one of this branch. |
The lattice I use is may be an old one. /machfs/liuzzo/EBS/beamdyn/matlab/optics/sr/S28F_restart/betamodel.mat |
@simoneliuzzo: even old lattices should work! I corrected the θ threshold detecting a full ring. |
Thanks @lfarv , also matlab is ok for centered option. |
That's done. @simoneliuzzo, could you approve again? Thanks |
Fixes a bug in
atgeometry
reported by @simoneliuzzo.The
centered
flag now works as expected.However, the computation of the radius is made using the 1st and last points. For a full ring, these points almost coincide, which makes the computation very imprecise. This happens for both Matlab and python.
For better results, the computation of the radius should be completely rewritten by taking all points into account (noting that this "polygonal" radius is not a constant…). This if left for another pull request.