amber_utils

amber_meta.amber_utils.check_directory_exists(directory)[source]

Check if directory (string) ends with a slash.

If directory does not end with a slash, add one at the end.

Parameters:directory (str) --
Returns:directory
Return type:str
amber_meta.amber_utils.check_file_exists(file)[source]

Check if a file exists

file : str
Filename with path.
Returns:response -- Response to the question "does the file exist?".
Return type:bool
amber_meta.amber_utils.check_path_ends_with_slash(path)[source]

Check if directory (string) ends with a slash.

If directory does not end with a slash, add one at the end.

Parameters:directory (str) --
Returns:directory
Return type:str
amber_meta.amber_utils.create_rfim_configuration_thresholds(config_path, rfim_mode='time_domain_sigma_cut', original_threshold_tdsc='2.50', original_threshold_fdsc='2.50', new_threshold_tdsc='3.25', new_threshold_fdsc='2.50', duplicate=True, verbose=False, print_only=False)[source]

Create a new RFIm configuration file for specified threshold

Parameters:
  • config_path (str) -- Path to configuration files
  • rfim_mode (str (optional)) -- RFIm mode of operation. Default: 'time_domain_sigma_cut'
  • original_threshold (str (optional)) -- Threshold listed in base config file. Default: 2.50
  • new_threshold (str (optional)) -- New threshold. Default: 1.00
  • duplicate (bool) -- When True, make copies of the base configuration files adding the threshold in new filename
  • verbose (bool) -- Print extra information at run-time.
  • print_only (bool) -- Only print verbose information without running anything else.
amber_meta.amber_utils.duplicate_config_file(config_path, base_filename, copy_filename)[source]

Duplicate a configuration file using copu_filename as output nameself.

Parameters:
  • config_path (str) -- Path to configuration files
  • base_filename (str) -- Filename of file to be copied
  • copy_filename (str) -- Filename of duplicate
amber_meta.amber_utils.find_replace(filename, text_to_search, text_to_replace, inplace=True, verbose=False)[source]

Find text_to_search in filename and replace it with text_to_replace

Parameters:
  • filename (str) -- Filename of input file to modify
  • text_to_search (str) -- Text string to be searched in intput file
  • text_to_replace (str) -- Text string to replace text_to_search with in intput file
  • inplace (bool) -- Default: True
amber_meta.amber_utils.get_filterbank_header(input_file, verbose=False)[source]

Get header and header_size from filterbank.

Parameters:
  • input_file (str) -- Input filterbank file
  • verbose (bool) -- Print extra information at run-time.
Returns:

  • header (dict) -- filterbank.read_header.header
  • header_size (int) -- filterbank.read_header.header_size

amber_meta.amber_utils.get_full_output_path_and_file(output_dir, base_name, root_name=None, cpu_id=None)[source]

Get full output path and file name.

Parameters:
  • output_dir (str) --
  • base_name (str) --
  • root_name (str) --
Returns:

path_and_file

Return type:

str

amber_meta.amber_utils.get_list_as_str(command)[source]

Turn command list to pretty print.

Prints each element of the 'command' list as a string.

Parameters:command (list) --
Returns:c -- Prettified command
Return type:str
amber_meta.amber_utils.get_max_dm(scenario_dict)[source]

Compute maximum dm.

Parameters:scenario_dict (dict) -- Scenario dictionary outputed by amber_utils.parse_scenario_to_dictionary()
Returns:max_dm -- Maximum DM
Return type:float
amber_meta.amber_utils.get_nbatch(input_file, header, header_size, samples, verbose=False)[source]

Get number of batches (nbatch) available in filterbank

Parameters:
  • input_file (str) --
  • header (dict) -- filterbank.read_header.header
  • header_size (int) -- filterbank.read_header.header_size
Returns:

nbatch

Return type:

int

amber_meta.amber_utils.get_root_name(input_file)[source]

Get yaml file's root name.

Parameters:input_file (str) -- Yaml input file
Returns:root_name
Return type:str
amber_meta.amber_utils.get_scenario_file_from_root_yaml_base_dict(base, cpu_id=0)[source]

Get the scenario path and file from info in root yaml file.

Parameters:
  • base (dict) -- Base dictionary as fetched from parse_scenario_to_dictionary
  • cpu_id (int) -- Index of the step
Returns:

  • scenario_file (str)
  • Usage
  • -----
  • >>> input_yaml_file = 'yaml/root/root.yaml'
  • >>> root='subband'
  • >>> base = parse_scenario_to_dictionary(input_yaml_file)[root]
  • >>> scenario_file = get_scenario_file_from_root_yaml_base_dict(base, cpu_id=0)

amber_meta.amber_utils.list_files_in_current_path(path, extensions=None)[source]

Returns files in the current folder only

Parameters:
  • path (str) -- Path from where to list files
  • extensions (list) -- List of desired extensions to include. Default: None. Usage example: ['.txt', '.trigger']
Returns:

files

Return type:

list

amber_meta.amber_utils.list_files_with_paths_recursively(my_path)[source]

Recursively list files in my_path

Recursively list files in my_path and returns the list in the form of ['path/to/file/myfile.extension', '...']

Parameters:my_path (str) --
amber_meta.amber_utils.parse_scenario_to_dictionary(scenario_file)[source]

Parse an amber scenario file to a python dictionary

Accepted file extensions: [.yaml | .yml], and [.sh] as described in https://github.com/AA-ALERT/AMBER_setup/blob/development/examples/scenario.sh

Parameters:scenario_file (str) -- amber scenario file (including path)
Returns:scenario_dict -- parsed dictionary
Return type:dict
amber_meta.amber_utils.parse_sh_scenario_to_dictionary(scenario_file)[source]

Parse an amber scenario file to a python dictionary

File extension expected is '.sh' as described in https://github.com/AA-ALERT/AMBER_setup/blob/development/examples/scenario.sh

Note that the extension is not required per se, but the file structure should follow a shell variable structure.

Parameters:scenario_file (str) -- amber scenario file (including path)
Returns:scenario_dict -- parsed dictionary
Return type:dict
amber_meta.amber_utils.parse_yaml_scenario_to_dictionary(scenario_file, scenario_name=None)[source]

Parse an amber scenario file (yaml) to a python dictionary

Parameters:scenario_file (str) -- amber scenario file in yaml format (including path)
Returns:scenario_dict -- parsed dictionary
Return type:dict
amber_meta.amber_utils.pretty_print_command(command)[source]

Pretty print an amber command.

Prints each element of the 'command' list as a string.

Parameters:command (list) --