Code Monkey home page Code Monkey logo

Comments (7)

lfarv avatar lfarv commented on July 20, 2024 1

Ok, I take care of this in #99, almost ready!

from at.

lfarv avatar lfarv commented on July 20, 2024

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:

  1. It creates a new list, which you can avoid using iterators if you do not need to keep the list
  2. 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.

abdomit avatar abdomit commented on July 20, 2024

Hello Laurent,

I have 2 comments on indexing directly the lattice:

  1. 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.

  1. 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.

T-Nicholls avatar T-Nicholls commented on July 20, 2024

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.

abdomit avatar abdomit commented on July 20, 2024

Done in #103

from at.

abdomit avatar abdomit commented on July 20, 2024

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.

abdomit avatar abdomit commented on July 20, 2024

get_elements is now a method of Lattice object (#99).

Thanks @lfarv!

from at.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.