Add Python script for Fourier coefficients#1316
Add Python script for Fourier coefficients#1316cemitch99 wants to merge 18 commits intoBLAST-ImpactX:developmentfrom
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
| @@ -0,0 +1,500 @@ | |||
| 0.0000000000000000 -4.1031444226780268E-004 | |||
There was a problem hiding this comment.
@cemitch99 what are the columns and units of this data set?
There was a problem hiding this comment.
The data in the second column will be scaled internally based on the element input (e.g. bscale, escale, etc.), so the units have no physical interpretation in isolation. I usually scale the values in the second column so that the maximum value is 1. Then e.g. for a SoftSolenoid the value of bscale fixes the peak on-axis value of B_z in 1/m (if unit=0) or in T (if unit=1).
| data = read_data("onaxis_data.in") | ||
| ncoef = int(input("How many Fourier coefficients do you want? ")) | ||
| cos_coeffs, sin_coeffs, emax = calculate_coefficients(data, ncoef) | ||
| write_coefficients(cos_coeffs, sin_coeffs, "fcoef.out") | ||
| write_data(cos_coeffs, sin_coeffs, data[:, 0], emax, "onaxis_datax") |
There was a problem hiding this comment.
Memo to myself:
Move into a pytest unit test.
for more information, see https://pre-commit.ci
pandas-friendly
Consistent, alignment, no extra spaces
Vectorize the Python logic with NumPy. Replace for loops.
abd5112 to
64bf753
Compare
Not used anywhere, re-scaled anyway, arb.u.
split the 2d array into two named 1D arrays for better readability / descript variable names.
| ns = 1 # number of slices per ds in the element | ||
|
|
||
| # read in the on-axis quadrupole gradient data | ||
| z, field_or_gradient = read_data("onaxis_data.in") |
There was a problem hiding this comment.
@cemitch99 one thing I do not yet fully understand: what is the reference point of z for this data (first column)?
- Is z=0 the entrance or mid or exit of the element?
- Can it only have positive values, meaning "away from the element"?
- Are the same fringe fields applied at entry and exit of the element? Are they exactly mirrored?
| cos_coefficients=cos_coeffs, | ||
| sin_coefficients=sin_coeffs, |
There was a problem hiding this comment.
User-facing API: I will add an overload to this constructor that accepts simply z and field_or_gradient and then calls the converter below automatically for the user. Data is still stored as cos & sin coefficients internally.
We will need to very clearly document what z means, see above.
| ) | ||
|
|
||
| # Reconstruction of On-Axis Data from Coefficients ############# | ||
| # without space charge |
There was a problem hiding this comment.
Simplifying a bit in #1327
| # without space charge | |
| # |
This PR addresses Issue #1314