Configuration of ASTRA objects¶
Astra objects have a wide number of configurable parameters, with most of them being optional (with sensible values as the default ones). Furthermore, every configurable value that the user provides will pass through a validation layer, to ensure proper initialization.
The easiest way to find all parameters, alongside their description is through a method that exist in all ASTRA objects:
from ASTRA.template_creation.StellarModel import StellarModel
StellarModel.config_help()
Configurations: Name:: SAVE_DISK_SPACE Description:: Save disk space in the outputs if different than None. Mandatory:: False Default value:: DISK_SAVE_MODE.DISABLED Constraints:: Value from list <<enum 'DISK_SAVE_MODE'>> Name:: WORKING_MODE Description:: How to store the output files. If one-shot, overwrites all files, otherwise updates products Mandatory:: False Default value:: WORKING_MODE.ONE_SHOT Constraints:: Value from list <<enum 'WORKING_MODE'>> Name:: CREATION_MODE Description:: None Mandatory:: False Default value:: STELLAR_CREATION_MODE.Sum Constraints:: Value from list <<enum 'STELLAR_CREATION_MODE'>> Name:: ALIGNEMENT_RV_SOURCE Description:: None Mandatory:: False Default value:: DRS Constraints:: Value from list <['DRS', 'SBART']> Name:: PREVIOUS_SBART_PATH Description:: None Mandatory:: False Default value:: Constraints:: Value from dtype <(<class 'str'>, <class 'pathlib.Path'>)> Name:: USE_MERGED_RVS Description:: None Mandatory:: False Default value:: False Constraints:: Value from dtype <(<class 'bool'>,)>
Then, the configuration of the ASTRA objects will be done through a argument called user_configs at the time of instantiation. If the keyword is either marked as Mandatory or the provided value does not meet the constraint, then an Exception will be raised.
All enum items are stored in the following sub-package:
from ASTRA.utils import choices
dir(choices)
['DISK_SAVE_MODE', 'Enum', 'FLUX_SMOOTH_CONFIGS', 'FLUX_SMOOTH_ORDER', 'INTERPOLATION_ERR_PROP', 'SPECTRA_INTERPOL_MODE', 'SPLINE_INTERPOL_MODE', 'STELLAR_CREATION_MODE', 'TELLURIC_APPLICATION_MODE', 'TELLURIC_CREATION_MODE', 'TELLURIC_EXTENSION', 'WORKING_MODE', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']
After instantiation, we can still update any of ASTRA configurations, through the update_user_configs method. Once again, the new config values will be parsed through the validation layer to ensure compliance with the parameter guidelines.
from ASTRA.Instruments import ESPRESSO
frame = ESPRESSO(file_path="/home/amiguel/spectra_collection/ESPRESSO/proxima/r.ESPRE.2019-07-03T01:43:39.634_S2D_A.fits",
user_configs={}
)
frame.generate_root_path("tmp")
for fluxcorr in [True,
False,
None # It will fail, as the apply_FluxCorr configuration only accepts boolean values
]:
print("Update ASTRA config value to", fluxcorr)
frame.update_user_configs({"apply_FluxCorr": fluxcorr})
2025-04-14 22:35:09.082 | INFO | ASTRA.base_models.Frame:__init__:253 - Creating frame from: /home/amiguel/spectra_collection/ESPRESSO/proxima/r.ESPRE.2019-07-03T01:43:39.634_S2D_A.fits 2025-04-14 22:35:09.084 | WARNING | ASTRA.Components.SpectrumComponent:regenerate_order_status:96 - Resetting order status of Frame - ESPRESSO 2025-04-14 22:35:09.103 | DEBUG | ASTRA.base_models.Frame:assess_bad_orders:711 - Rejecting spectral orders 2025-04-14 22:35:09.106 | INFO | ASTRA.base_models.Frame:assess_bad_orders:741 - Frame None rejected 37 orders for having SNR smaller than 5: 0-36 2025-04-14 22:35:09.108 | CRITICAL | ASTRA.utils.UserConfigs:update_configs_with_values:191 - User-given parameter apply_FluxCorr does not meet the constraints
Update ASTRA config value to True Update ASTRA config value to False Update ASTRA config value to None
--------------------------------------------------------------------------- InvalidConfiguration Traceback (most recent call last) File ~/development/ASTRA/src/ASTRA/utils/UserConfigs.py:189, in InternalParameters.update_configs_with_values(self, user_configs) 188 try: --> 189 parameter_def_information.apply_constraints_to_value(key, value) 190 except InvalidConfiguration as exc: File ~/development/ASTRA/src/ASTRA/utils/UserConfigs.py:68, in UserParam.apply_constraints_to_value(self, param_name, value) 61 """Apply the constraints of this parameter to a given value. 62 63 Args: (...) 66 67 """ ---> 68 self._valueConstraint.check_if_value_meets_constraint(value) File ~/development/ASTRA/src/ASTRA/utils/parameter_validators.py:67, in Constraint.check_if_value_meets_constraint(self, value) 66 for evaluator in self._constraint_list: ---> 67 evaluator(value) File ~/development/ASTRA/src/ASTRA/utils/parameter_validators.py:135, in ValueFromDtype._evaluate(self, value) 134 msg = f"Config value ({value}) not from" f"the valid dtypes: {type(value)} vs {self.valid_dtypes}" --> 135 raise InvalidConfiguration( 136 msg, 137 ) InvalidConfiguration: Config value (None) not fromthe valid dtypes: <class 'NoneType'> vs (<class 'bool'>,) The above exception was the direct cause of the following exception: InternalError Traceback (most recent call last) Cell In[10], line 10 8 for fluxcorr in [True, False, None]: 9 print("Update ASTRA config value to", fluxcorr) ---> 10 frame.update_user_configs({"apply_FluxCorr": fluxcorr}) File ~/development/ASTRA/src/ASTRA/Components/Modelling.py:156, in Spectral_Modelling.update_user_configs(self, new_configs) 154 def update_user_configs(self, new_configs: dict[str, Any]) -> None: 155 """Propagates update of configs to the interpolation interface.""" --> 156 super().update_user_configs(new_configs) 157 self.interpolation_interface.set_interpolation_properties(new_configs) File ~/development/ASTRA/src/ASTRA/utils/BASE.py:88, in BASE.update_user_configs(self, new_configs) 86 def update_user_configs(self, new_configs: dict[str, Any]) -> None: 87 """Update the current configurations with new values.""" ---> 88 self._internal_configs.update_configs_with_values(new_configs) File ~/development/ASTRA/src/ASTRA/utils/UserConfigs.py:192, in InternalParameters.update_configs_with_values(self, user_configs) 190 except InvalidConfiguration as exc: 191 logger.critical("User-given parameter {} does not meet the constraints", key) --> 192 raise InternalError from exc 194 self._user_configs[key] = value 196 if not self.no_logs: InternalError: