utils.py

utils.py#

aviary.interface.utils.find_variable_in_problem(var_name, problem, metadata)[source]

Find the value and units of a variable in an AviaryProblem. Priority is to directly find the value via problem.get_val(), followed by searching in problem.aviary_inputs.

Parameters:
  • var_name (str) – The name of the variable to find.

  • problem (AviaryProblem) – The AviaryProblem to search for var_name in.

  • metadata (dict) – The dictionary that contains the metadata of the data with desired units. Used to get default units if unit information cannot be found.

aviary.interface.utils.round_it(x, sig=None)[source]

Round a float to a specified significance. If the number is equal to zero, “0” will be returned, regardless of the number of significant digits specified If the number is NaN, directly returns it (stays NaN).

Parameters:
  • x (str or float) – the float that needs to be rounded.

  • sig (int) – the number of significant digits to include (If this is unspecified, the number will be rounded to two decimal places).

Returns:

  • The rounded number, or provided string if not convertible to float, or original

  • number if it is NaN

aviary.interface.utils.set_warning_format(verbosity)[source]
aviary.interface.utils.write_markdown_variable_table(open_file, problem, outputs, metadata)[source]

Writes a table of the provided variable names in outputs. Converts units to defaults from metadata if available.

Parameters:
  • open_file (Path) – The output file to be written to. This file should have been opened for writing.

  • problem (dict) – The dictionary that contains the data.

  • outputs (list) – The list of keywords that will go to outputs file.

  • metadata (dict) – The dictionary that contains the metadata of the data with desired units.