Input and Output Files

The FileHelper class provides methods for reading input data from a file and writing input parameters and calculated values to a file. The sections that follow describe the process for using input data files, their format and creating output data files.

Reading data from an input file

The Sensitivity Calculator can be initialized with your own input values from a file. The FileHelper class can be used to read data from a file and generate an input data dictionary.

First, import the file helper class from the utils module:

from atlast_sc.utils import FileHelper

Next, call read_from_file, passing the directory (provide an absolute path, or a path relative to directory in which your Python script is running) and the name of the data file:

input_data = FileHelper.read_from_file('<directory>', '<file name>')

This returns a dictionary that can be used to initialize the Calculator object:

calculator = Calculator(input_data)

Input files and formats

The read_from_file method of the FileHelper class can read input parameters from a file. See User input for the list of expected input parameters. Any parameters not provided in the input file will be assigned their default value.

The file reader supports plain-text, YAML, or JSON formatted file. The expected structure for each file type is described in more detail below.

Plain-text files

Plain-text files should have the extension .txt or .TXT. Each line of the file should be of the following format:

<param-name> = <value> <unit>

An example file might contain the following lines:

t_int = 100 s
bandwidth = 7.5 GHz
n_pol = 2

For the above to work, there must be a space between <value> and <unit> and <value> must be numeric (integer or float). Spaces around “=” are optional.

YAML files

YAML files should have the extension yaml, yml, YAML, or YML.

An example YAML file might contain the following:

---
t_int: {value: 100, unit: s}
bandwidth: {value: 7.5, unit: GHz}
n_pol: {value: 2}

This formatting is very similar to the formatting of a python dictionary, but for the yaml format, quotation marks are not required on the units, and individual entries are specified by line, not with commas.

JSON files

JSON files should have the extension json or JSON.

An example JSON file might contain the following:

{
  "t_int": {
    "value": 100,
    "unit": "s"
  },
  "bandwidth": {
    "value": 7.5,
    "unit": "GHz"
  },
  "n_pol": {
    "value": 2
  }
}

User parameters can be read in via all three input file types, and the input values interpreted for use within the calculation. This is useful for reproducibility of outcomes. These same file formats are used by the sensitivity calculator to output parameter sets.

Writing parameters to a file

The FileHelper method write_to_file writes all user inputs and derived parameters to a plain-text, YAML, or JSON formatted file. The structure of the output file for a given format is the same as the input file of the same format, as described in the previous section.

For example, to write data to a YAML file called output_parameters.yml in the directory logs:

FileHelper.write_to_file(calculator, "logs", "output_parameters", "yml")

Below is an example of a YAML-formatted output file:

t_int           : {value:      100.0, unit: s}
sensitivity     : {value: 0.0016932450280061624, unit: Jy}
bandwidth       : {value:      100.0, unit: MHz}
obs_freq        : {value:      100.0, unit: GHz}
n_pol           : {value:        2.0}
weather         : {value:       25.0}
elevation       : {value:       45.0, unit: deg}
tau_atm         : {value: 0.027620396974877098}
T_atm           : {value:   7.757599, unit: K}
T_rx            : {value: 23.996215366831105, unit: K}
eta_a           : {value: 0.6995318165809129}
eta_s           : {value:       0.99}
T_sys           : {value: 114.70931842978237, unit: K}
sefd            : {value: 2.306081307192973e-24, unit: J / m2}