example integration time exception
Closed this issue · 6 comments
hi @FKirton,
got the calculator installed in a conda environment, and have been going through the calculations on the 'Using the calculator' page.
towards the end, there's a block where the sensitivity is set, and the integration time is calculated. copy/pasting the text from the page results in the following 'ValueOutOfRangeException':
ValueOutOfRangeException: The parameter 't_int' must be in the range 1 to inf s.
which suggests there's something circular going on in that calculation.. Full stack trace below, but should be reproducible from the instructions on the user guide page.
NOTE: I tried specifying 't_int' (=100*u.s) just to see if it breaks me out of the loop. it does not.
`In [24]: sens = 10*u.mJy
...: calculated_t_int = calculator.calculate_t_integration(sens)
ValueOutOfRangeException Traceback (most recent call last)
Cell In[24], line 2
1 sens = 10*u.mJy
----> 2 calculated_t_int = calculator.calculate_t_integration(sens)
File ~/opt/anaconda3/envs/sens-calc-install-test/lib/python3.10/site-packages/atlast_sc/calculator.py:327, in Calculator.calculate_t_integration(self, sensitivity, update_calculator)
325 # Update the integration time stored in the calculator
326 if update_calculator:
--> 327 self.t_int = t_int
329 return t_int
File ~/opt/anaconda3/envs/sens-calc-install-test/lib/python3.10/site-packages/atlast_sc/utils.py:32, in Decorators.validate_update..do_validation(calculator, value, **kwargs)
21 """
22 Validates the type, value and units of the value for the target
23 parameter.
(...)
28 :type value: int, float or Quantity
29 """
31 # Validate the new value
---> 32 Decorators._do_validation(calculator, func.name, value)
34 # Update the parameter
35 func(calculator, value, **kwargs)
File ~/opt/anaconda3/envs/sens-calc-install-test/lib/python3.10/site-packages/atlast_sc/utils.py:99, in Decorators._do_validation(calculator, param_name, value)
96 calculator.calculation_inputs.
97 validate_update(param_name, value)
98 except ValueError as e:
---> 99 raise e
File ~/opt/anaconda3/envs/sens-calc-install-test/lib/python3.10/site-packages/atlast_sc/utils.py:97, in Decorators._do_validation(calculator, param_name, value)
94 # Validate the new value
95 try:
96 calculator.calculation_inputs.
---> 97 validate_update(param_name, value)
98 except ValueError as e:
99 raise e
File ~/opt/anaconda3/envs/sens-calc-install-test/lib/python3.10/site-packages/atlast_sc/models.py:271, in CalculationInput.validate_update(self, value_to_update, new_value)
269 Validator.validate_field(value_to_update, new_value)
270 except ValueError as e:
--> 271 raise e
273 return self
File ~/opt/anaconda3/envs/sens-calc-install-test/lib/python3.10/site-packages/atlast_sc/models.py:269, in CalculationInput.validate_update(self, value_to_update, new_value)
263 """
264 Custom validator called manually (i.e., not as part of the Pydantic
265 framework), e.g., when one of the user input values is updated.
266 """
268 try:
--> 269 Validator.validate_field(value_to_update, new_value)
270 except ValueError as e:
271 raise e
File ~/opt/anaconda3/envs/sens-calc-install-test/lib/python3.10/site-packages/atlast_sc/models.py:46, in Validator.validate_field(key, val)
43 Validator.validate_in_range(value_to_validate,
44 key, data_type)
45 except ValueOutOfRangeException as e:
---> 46 raise e
File ~/opt/anaconda3/envs/sens-calc-install-test/lib/python3.10/site-packages/atlast_sc/models.py:43, in Validator.validate_field(key, val)
41 # Validate value is in permitted range
42 try:
---> 43 Validator.validate_in_range(value_to_validate,
44 key, data_type)
45 except ValueOutOfRangeException as e:
46 raise e
File ~/opt/anaconda3/envs/sens-calc-install-test/lib/python3.10/site-packages/atlast_sc/models.py:90, in Validator.validate_in_range(value, param, data_type)
86 raise ValueTooHighException(param, data_type.upper_value,
87 data_type.default_unit)
89 if not (data_type.lower_value <= value <= data_type.upper_value):
---> 90 raise ValueOutOfRangeException(param,
91 data_type.lower_value,
92 data_type.upper_value,
93 data_type.default_unit)
ValueOutOfRangeException: The parameter 't_int' must be in the range 1 to inf s.
`
@astroklaassen The issue is that for a sensitivity of 10 mJy (the value suggested in the example), the resulting integration time is about 0.09s, which is less than the permitted minimum value of 1s. There's no upper bound on the sensitivity, so currently no way to prevent users specifying some unrealistically large value and running into this error. We can either 1) impose an upper bound on the sensitivity (I'd have to play with the numbers to make sure the integration time was always >= 1s), or 2) relax the restriction on the integration time permitted value and make this >0s. A third option - keep the permitted values as they are and provide a more meaningful error message. This might be the preferred option, given that there are likely to be other permitted combinations of input values that result in an integration time < 1s. It would be the most time-consuming to implement, however.
How would you prefer to handle this?
@FKirton : Yes, option 3 does sound best... but given effort/time constraints on the development, option 2 is probably the way to go.
I would also suggest changing the sensitivity limit in the example then, to something that returns a longer integration time, say 5*mJy, which doesn't give this error.
@FKirton : Yes, option 3 does sound best... but given effort/time constraints on the development, option 2 is probably the way to go.
I would also suggest changing the sensitivity limit in the example then, to something that returns a longer integration time, say 5*mJy, which doesn't give this error.
Okay, in that case I'll implement option 2 and change the example. I'll keep this issue open for now in case there's time to look at option 3.
Great. thank you :)
Minor correction to my previous comment - it's actually the combination of setting the bandwidth to 10GHz and the sensitivity to 10mJy that causes the problem. I've updated the worked expample so the suggested value to update the bandwidth to is 150MHz. The suggested sensitivity stays as it is.
@astroklaassen I've added you as a reviewer on the pull request so you can take a proper look at the changes I've made and confirm you're happy with them.
I've now implemented a version of option 3. If a calculated value is outside the permitted range for the parameter and the calculator attempts to store that value, a warning will be raised and the value will not be stored by the calculator. Raising a warning rather than an error allows this scenario to play out without breaking the code. Since the web client does not try to write the calculated value back to the Calculator object, the user can provide input values that result in "invalid" values (e.g., an integration time < 1s) without encountering an error.