Skip to content
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

at.get_value_refpts fails if the field value is scalar and an index 0 is provided #468

Open
simoneliuzzo opened this issue Aug 27, 2022 · 1 comment
Labels
Python For python AT code

Comments

@simoneliuzzo
Copy link
Contributor

simoneliuzzo commented Aug 27, 2022

get_value_refpts(ring, array_of_indexes, 'PolynomB', 0)
works, giving the first element of PolynomB for the elements of ring with indexes in array_of_indexes.

get_value_refpts(ring, array_of_indexes, 'Length', 0)
instead fails, as Length is a scalar.

I had this second line in my code, the index 0 being there from copy-paste. I did not expect it to fail, Length has length 1, so index 0 did not seem to be possibly generating an error.

The help of get_value_refpts says it: " ... IF attr_name is an array"

I find this somehow strange that the user has to remember if the specific attribute is an array or not when using the command get_value_refpts.

The error message is a python error and it is not very immediate. It could be caught and translated to a warning. For example: "For scalar attributes index is ignored".

This action, would also recover a usage similar to the matlab equivalent of this function atgetfieldvalues, that does not fail in the case atgetfieldvalues(r, ind, 'Length', 0).

@simoneliuzzo simoneliuzzo changed the title at.get_value_refpts fails if the field value is scalar and an index is provided at.get_value_refpts fails if the field value is scalar and an index 0 is provided Aug 27, 2022
@lfarv
Copy link
Contributor

lfarv commented Sep 5, 2022

@simoneliuzzo:

Unlike in Matlab, scalar and numpy arrays are completely different python objects ! You indeed need to know what is the attribute. But I doubt that you would extract attribute values without knowing what they mean…

Anyway, I very much prefer using a simple python command rather that using get_value_refpts: in your example, you would write

b0=[elem.PolynomB[0] for elem in ring.select(array_of_indexes)]

or

lengths=[elem.Length for elem in ring.select(array_of_indexes)]

It's more efficient, it works for integer or boolean indices (get_value_refpts also, of course) and it's self-explanatory for a python developer… The function does not bring anything, but it's a matter of taste.

@lfarv lfarv added the Python For python AT code label Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Python For python AT code
Projects
None yet
Development

No branches or pull requests

2 participants