write_matrix_block

mdtools.file_handler.write_matrix_block(fname, data, var1, var2, init_values1=None, init_values2=None, upper_left=None, data_name=None, data_unit=None, var1_name=None, var1_unit=None, var2_name=None, var2_unit=None, block_number=None)[source]

Save a data matrix to a text file.

Write data that are a function of two independent variables, var1 and var2, as a matrix to a text file. The dependency of the data from var1 is represented by the rows and the dependency from var2 is represented by the columns.

If the file already exists, it is appended. Otherwise is is created.

Parameters
  • fname (str) – The name of the file to write to. The file is created if it does not exist, otherwise it is appended.

  • data (array_like) – The data to write to file. Must be of shape (n, m), where n is the number of samples of the first independent variable (depicted row wise) and m is the mumber of samples of the second independent variable (depicted column wise).

  • var1 (array_like) – Array of shape (n,) containing the values of the first independent variable.

  • var2 (array_like) – Array of shape (m,) containing the values of the second independent variable.

  • init_values1 (array_like) – If supplied, the values stored in this array will be handled as special initial data values corresponding to the very first value in var1. Must be an array of shape (m,), whereas data must then be of shape (n-1, m).

  • init_values2 (array_like) – If supplied, the values stored in this array will be handled as special initial data values corresponding to the very first value in var2. Must be an array of shape (n,), whereas data must then be of shape (n, m-1).

  • upper_left (scalar) – Value to put in the upper left corner of the final matrix. If None (default), print var1_name and var2_name in the upper left corner.

  • data_name (str) – The name of the data. If supplied, it will be printed in the block header.

  • data_unit (str) – The unit of the data. If supplied, will be printed in the block header.

  • var1_name (str) – Same as data_name but for var1.

  • var1_unit (str) – Same as data_unit but for var1.

  • var2_name (str) – Same as data_name but for var2.

  • var2_unit (str) – Same as data_unit but for var2.

  • block_number (int) – The number of the data block in fname. If supplied, it will be printed in the block header.

See also

mdtools.file_handler.savetxt_matrix()

Save a data matrix to a text file

mdtools.file_handler.write_header()

Create a file and write the standard MDTools header to it