The parset module¶
The parset module defines various functions used to handle the Rapthor parset.
Module that holds all parset-related functions
- class rapthor.lib.parset.Parset(parset_file=None)¶
This class can read a Rapthor parset file and convert its contents to a dict that can be used elsewhere.
Notes
If you want to add a new option, make sure that this option is added to the file defaults.parset. Any option used by Rapthor _must_ be defined in that file with its default value. If it is not in that file, a warning will be issued when it is used in a user-supplied parset file, and its value will be ignored. Similarly for a new section. If you want to add extra constraint checks for an option, or want to adjust its value, you need to add these checks to the method __check_and_adjust. If you want to add a new _required_ option, an extra entry must be added to the attribute self.required_options in the method __init__. Similarly for a new _required_ section.
- as_parset_dict()¶
Return the current settings as parset-dict. The parset-dict differs from the internal settings in the sense that all the key/value pairs defined in the [global] section are put at the top-level instead of under ‘global’. All other section names (like [imaging]), get a post-fix ‘_specific’.
- static config_as_dict(parser)¶
Return the current configuration as dictionary. The key is the section name, and the value is a dictionary of the options in the given section. Option values are cast to their proper type, if possible.
- Parameters:
- parser: configparser.ConfigParser
Configuration parser used to read a parset-file.
- Returns:
- settings: dict
Dictionary of the configuration: key is the section name, value is a dictionary of the options in the given section.
- read_file(parset_file)¶
Read the contents of parset_file. The format of this file is often referred to as parset format in the context of Rapthor, but is actually in the well-known Windows INI-format. A check is made for missing required sections and options. Given options values are checked against possible constraints.
- Parameters:
- parset_file: str
Name of the parset file
- Returns:
- settings: dict
A dictionary of settings, where the key is the section name, and the value is a dictionary of the options in the given section. Option values are cast to their proper type, if possible.
- Raises:
- FileNotFoundError
If parset_file does not exist
- ValueError
If parset_file cannot be parsed correctly, or if one or more required sections or options are missing, or if it contains invalid option values.
- rapthor.lib.parset.lexical_cast(string_value)¶
Try to cast string_value to a valid Python type, using ast.literal_eval. This will only work for simple expressions. If that fails, try if string_value can be interpreted as an astropy.coordinates.Angle; if so, convert to degrees. If that fails, try if string_value represents a list of more complex items, and try to lexical_cast each item separately. If that also fails, return the input string.
- rapthor.lib.parset.parset_read(parset_file, use_log_file=True)¶
Read a rapthor-formatted parset file and return dict of parameters
- Parameters:
- parset_filestr
Filename of rapthor-formated parset file
- use_log_filebool, optional
Use a log file as well as outputing to the screen
- Returns:
- parset_dictdict
Dict of parset parameters
- Raises:
- RuntimeError
If the working directory cannot be created; or if no input sky model file is given and download is not requested.
- FileNotFoundError
If no input MS files can be found; or if the sky model file cannot be found and download is not requested.