-
Notifications
You must be signed in to change notification settings - Fork 34
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
bugfix NxN ID table in atidtable_dat.m, update second order kick variables in C, include first order kick in pyat #683
Conversation
Dear all, this is a bug fix to issue #683 where I reported an error when trying to load in matlab a kickmap with a square grid (N by N points per table). The function atidtable_dat needs only three values (L,Nx,Ny) from mhdrload_bis. However, mhdrload_bis returns data_mat which is of varying length depending on the table grid size. The expression in at/atintegrators/mhdrload_bis.m Line 158 in 52298a9
divides length(data) which is (cols+rows(1+cols)), by cols. For a rectangular grid this is not a integer, the entire reshape is skipped and nothing is assigned to data_mat. But in the case of N=cols=rows, an NxN grid, the expression returns an integer which is a valid shape and more data is returned. The proposed solution is to explicitly catch in atidtable_dat only the three required values (L,Nx,Ny). L=data_mat(1,1,1);
Nx=data_mat(1,1,2);
Ny=data_mat(1,1,3); I add to this message two Insertion Device tables, one with a rectangular and one with a squared grid for verification, and two lines to execute a test. [idtable_rectangulargrid.txt](https://github.com/atcollab/at/files/13186828/idtable_rectangulargrid.txt)
[idtable_squaregrid.txt](https://github.com/atcollab/at/files/13186829/idtable_squaregrid.txt)
utest1 = atidtable_dat('utest',10,'idtable_rectangulargrid.txt',3,'IdTablePass')
utest2 = atidtable_dat('utest',10,'idtable_squaregrid.txt',2.75,'IdTablePass') o |
For me, the whole file scanning process looks much too complicated, and the problem here seems more in the behaviour of |
Dear @lfarv , I agree that I tried to see what was the reason for it and it seems that the early development tried to adapt another script 'mhdrload' to the needs of the Insertion Device table. However, the formats are incompatible, the header in the insertion device file has a different format, and the values in the header do not coincide with the column and rows on the table. At the end most of it fails and it only returns data when it is in format nxn which is the case of a single value in a line (a 1x1, i.e. 1row,1column data), and incidentally ID tables with a square grid. Therefore, I decided to cherry-pick only the data strictly necessary, and ignore whatever other stuff is in the return from I am not familiar with matlab text reading functionalities, and I have only a few examples of ID tables at hand. If there is a better way to read text files in matlab I could have a look for a replacement of |
Dear @lfarv , having a quick look it seems that If you consider this ok, I would replace |
Dear @lfarv , I have removed the calls to |
@oscarxblanco : I did not want to trigger large modifications, but just say that if there are in the future other decoding problems, it could be wise to review the whole thing, But for now, if this solution solves your problem, that's fine for me. If there are no comments from the other reviewers, I'm ready to approve. |
Dear @simoneliuzzo , would you mind to review this Merge Request ? I have made a change in the matlab method to readout ID table files assuming data is on specific rows. This was already the case of the previous implementation but done in a convoluted way, so, this modification does not add or loose any flexibility in the file format, it just make explicit the rigidity of the input file format. If you have the time, and you still have some ID files at hand, could you try the following lines of matlab code and check that the ID is loaded ? utest1 = atidtable_dat('utest',integrationslices,'somefilename',mybeamenergy,'IdTablePass') |
Dear @orblancog, Reviewing the code, I have several remarks and questions
|
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 propose some changes for improving the code.
Dear @lnadolski , @ZeusMarti also mentioned he had the idea of using hdf5 file formats which might be richer, but, it seems that it also needs some interest from the ID modelling community due to possible incompatibilities of hdf5 file format with older versions of mathematica, and additional development in mathematica and python interfaces to Radia. For pyat it would mean to include an hdf5 package (like h5py) on the dependency list, while for matlab I think it is already there but I would not know which is the oldest matlab version who supports it. |
For python, no problem to add For this PR, I let you and @lnadolski decide if the element attribute names must be changed, possibly breaking backward compatibility, |
Dear @lnadolski , kick1 keeps its name, it should not be modified, but needs to be implemented in python. I will have a look on the necessary changes. |
Dear @orblancog , I have tryed the code line you asked. It gives me an error at line 76 of atidtable_dat.m, while parsing the file. I attach here the kickmap file I am using for the test. I hope this is of help. let me know and I will test again. |
Thank you @simoneliuzzo, now I know that in addition to spaces as separators, it could also be TABS. |
Dear @lnadolski , the first order kickmaps are now implemented in pyat as in AT matlab. The input file in pyat is a text file as before, only with two more optional kicktables (i.e. two or 4 tables are admitted). No other input formats are supported in pyat for the moment, while in AT matlab it could be a text file, or a mat file. The example files in at/atmat/atdemos/IDModelling has been changed accordingly with the new variable names. These modifications also keep backwards compatibility. For python and matlab users there will be warnings when required, otherwise the name swapping is done on the code, and new files will contain kick1 and kick2 as requested. The biggest change was in the IdTablePass for matlab, because rings loaded through .mat files could only be checked once a calculation is started, while, in python the variable check is done while reading the input files. I have added a folder with automatic tests for several input/output combinations between pyat and matlab, added tests for new file formats, and backwards compatibility. You will need to configure the file setatversion.m, and have this branch of pyat installed. After that, you could launch |
Dear @lnadolski , while checking the sign of the first order kick map I think there is a decision to take wrt to the convention. The implementation used thus far assumes same sign for both transverse kicks while the article by Elleaume explicitely says they should be opposite. We could either leave the code as it is and apply the difference in sign in the input table, or, implement in the code the equations as P. Elleaume wrote them and the sign of saved kick1 measurements should be inverted. I have written it in more detail here #703 Please, other Insertion Device users, (@ZeusMarti , @simoneliuzzo , others), feel free to comment. o |
Dear all, Best regards, |
These changes have been included
I think this could be reviewed. |
Dear @lnadolski and @lfarv , I will close this Pull Request and open smaller ones. It seems that it started from a small modification and ended on many additions, making it complicated to review. Best regards, |
This PR resolves issue #682 when reading an Insertion Device table in matlab through atidtable_dat where the kick maps are of N by N dimensions.