pyscal.utils.string

Utility functions for creating strings from pyscal

pyscal.utils.string.comment_formatter(multiline, prefix='-- ')[source]

Prepends comment characters to every line in input

Parameters:
  • multiline (str) – String that can contain newlines

  • prefix (str) – Comment characters to prepend every line with Default is the Eclipse comment syntax ‘– ‘

Returns:

string with newlines preserved, and where each line starts with the given prefix. Always ends with a newline.

pyscal.utils.string.df2str(dframe, digits=7, roundlevel=9, header=False, monotonicity=None)[source]

Make a string representation of a dataframe with proper rounding.

This is used to print the tables in the SWOF/SGOF include files, explicit rounding is necessary to avoid monotonicity errors from truncation. Examples in test code.

Capillary pressure must be strictly monotone if nonzero, and if a column name is provided, the string representation of that column is ensured to be strictly monotone decreasing

Parameters:
  • dframe (DataFrame) – A dataframe to print, all columns are included

  • digits (int) – Number of digits used in floating point format f.ex “.7f” It is not recommended to deviate from the default 7 uncritically for pyscal output, other code have to be tuned to ensure numerical robustness to the deviation.

  • roundlevel (int) – To how many digits should we round prior to print. Recommended to be > digits + 1, see test code.

  • header (bool) – If the dataframe column header should be included

  • monotonicity (Optional[Dict[str, MonotonicitySpec]]) – Column names in dframe are the keys, pointing to a specification for monotonicity to be enforced.

Return type:

str