Comments (7)
Ok, I take care of this in #99, almost ready!
from at.
Hello @abdomit,
I thought of that, but I figured out that you can get the same thing either as an iterator with:
qd_iter=(elem for elem in ring if fnmatch.fnmatch(elem.FamName, 'QD*'))
for a single usage, or as a list with:
qd_list=[elem for elem in ring if fnmatch.fnmatch(elem.FamName, 'QD*')]
if you want to use the list several times… And as elements are indeed references, modifying the element in qd_list
does modify it in ring
. Modifying lattices using only simple commands give something like:
qd_strength = [elem.PolynomB[1] for elem in ring if fnmatch.fnmatch(elem.FamName, 'QD*')]
or in the other direction:
qd_iter=(elem for elem in ring if fnmatch.fnmatch(elem.FamName, 'QD*'))
for elem, strength in zip(qd_iter, qd_strength):
elem.PolynomB[1] = strength
I have 2 comments on indexing directly the lattice:
- It creates a new list, which you can avoid using iterators if you do not need to keep the list
- It is restricted to a match on
FamName
, while you can imagine any other selection criteria
However, if there is a need for it, why not!
P.S. selecting focusing quads looking for 'QD*' might give surprising results!
from at.
Hello Laurent,
I have 2 comments on indexing directly the lattice:
- It creates a new list, which you can avoid using iterators if you do not need to keep the list
Ok, but an iterator is not very user-friendy. You cannot address the nth element with
qd_list[n]
Moreover this list will not take much place in memory because it is basically just a list of references.
- It is restricted to a match on
FamName
, while you can imagine any other selection criteria
We could also have to possibility to give an Element class, for instance asking all the BPMs with
ring[at.Monitor]
Then concerning the possibility to select elements using other criteria, that would be interesting, but I think it should more look like this:
qd_list[qd_list.PolynomB[1] > 1.0]
However, if there is a need for it, why not!
In my opinion it is very very useful! I would be interested to know if other at-users feel the same.
P.S. selecting focusing quads looking for 'QD*' might give surprising results!
Now you know why I am not in the beam dynamics group!
from at.
If I may weigh in, I had a similar need, to get elements by class, and created a local utility function for the task when I first started using AT. As for implementation, supporting things like 'QD*' and element instances/types as valid arguments to __getitem__
makes me uncomfortable for a number of reasons. In Pytac we have a method on the lattice that gets elements by family; so might I suggest something similar for class and family name in this case.
from at.
Done in #103
from at.
Sorry to reopen this issue. I realized (a bit too late) that something was missing.
Now we have a get_elements
function, but it would be even better to have in addition to this a corresponding method for Lattice
object (as suggested by @lfarv: #102 (comment)).
from at.
get_elements
is now a method of Lattice
object (#99).
Thanks @lfarv!
from at.
Related Issues (20)
- pyAT 'Multipole has no attribute PolynomB' exception for loading multipoles from a .mat file with both PolynomB and K value defined HOT 1
- ATX makes matlab crash when Exact* integrators are used. HOT 3
- python get_1d_acceptance: return 0.0 instead of error if no particle survives HOT 2
- np.float gives error in acceptance/touschek.py HOT 1
- Improve element rotation help HOT 1
- python windows version installation HOT 4
- synoptics not visible in atplot when vertical values are above zero HOT 1
- pyat shift_elem ignores R1,R2 and the effect of bending angles HOT 5
- pyAT Distinguish between a sector bending magnet and a rectangular bending magnet HOT 1
- Reduce behaves differently in Matlab and python
- B0 added twice in exactkickrad HOT 2
- python: ringparam not well identified by lattice_load HOT 6
- bug is saving lattice HOT 3
- Bug: atwiggler HOT 13
- problem with display of correctly initialised VariableMultipole element HOT 1
- Change Legend Labels for plot_trajectory() function HOT 12
- fast_ring when having harmonic cavities in the lattice HOT 4
- AT_2_Elegant uses deprecated N_KICKS
- Factor 4 missing in Touschek scattering B2 expression HOT 5
- pyAT Error when calculating damping ring HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from at.