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

TelescopeParameterLookup does not check wether telescope is in attaached subarray #2233

Closed
nbiederbeck opened this issue Jan 24, 2023 · 5 comments · Fixed by #2429
Closed

Comments

@nbiederbeck
Copy link
Contributor

The following code fails:

TelescopeParamtereLookup.tel[0]
*** KeyError: "TelescopeParameterLookup: no parameter value was set for telescope with tel_id=0. Please set it explicitly, or by telescope type or '*'."

which is ok, because it was really not set by '*', because it is not in the attached subarray.

The error message could be improved though, because 0 is a nonsenical telescope id.

I would prefer that for those cases the error message would be

KeyError: "TelescopeParameterLookup: telescope with tel_id=0 is not in attached subarray.

if isinstance(tel, (int, np.integer)):
try:
return self._value_for_tel_id[tel]
except KeyError:
raise KeyError(
f"TelescopeParameterLookup: no "
f"parameter value was set for telescope with tel_id="
f"{tel}. Please set it explicitly, "
f"or by telescope type or '*'."
)

@Tobychev
Copy link
Contributor

As I don't know of a way of getting a KeyError from a dict than asking for a missing key, I agree that having the error message say anything but "telescope with id {id} not found in provided subarray" is confusing.

But are you also asking for a check before the try catch that handles the special case tel=0?

@maxnoe
Copy link
Member

maxnoe commented Jan 25, 2023

0 is a special case in that we basically always know that it is an invalid tel_id, however, with our subselected arrays, any tel id might actually be not in the subarray

@nbiederbeck
Copy link
Contributor Author

nbiederbeck commented Jan 25, 2023

[...] might actually be not in the subarray

Yes and I'm asking for a distinction of these two cases, 1) not having set a parameter value and 2) asking for a telescope that is not there.

This came up during debugging, I think it might actually not be a problem in normal operations, since we just loop over all telescopes in a subarray (that then are there by definition)?

@maxnoe
Copy link
Member

maxnoe commented Jan 25, 2023

Yes, that is the right thing to do, however, I was arguing that we shouldn't just treat 0 specially, but we should check.

I would suggest to check only in in the except block if the telescope is in the subarray, as that would be expensive otherwise.

E.g.:

try:
    return self._value_for_tel_id[tel]
except KeyError:
    if tel not in self.subarray.tel:
        raise KeyError(f"Unknown telescope id: {tel_id}")
    else:
        raise KeyError("No value configured vor telescope id: {tel_id}")

Maybe introduce new exception classes for the two cases, i.e. MissingConfigValue and UnknownTelescope

@maxnoe
Copy link
Member

maxnoe commented Oct 21, 2023

The code to be changed in the way described above is here:

if isinstance(tel, (int, np.integer)):
try:
return self._value_for_tel_id[tel]
except KeyError:
raise KeyError(
f"TelescopeParameterLookup: no "
f"parameter value was set for telescope with tel_id="
f"{tel}. Please set it explicitly, "
f"or by telescope type or '*'."
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants