write_matrix_block

mdtools.file_handler.write_matrix_block(fname, data, var1, var2, init_values1=None, init_values2=None, upper_left=0, fmt='>16.9e', data_name='z', data_unit=None, var1_name='x', var2_name='y', var1_unit=None, var2_unit=None, block_number=None, **kwargs)[source]

Save a data matrix as block 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.

Parameters:
  • fname (str or bytes or os.PathLike) – Name of the file to write to.

  • data (array_like) – 2-dimensional array of 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 number of samples of the second independent variable (depicted column wise).

  • var1, var2 (array_like) – Array of shape (n,) (var1) or (m,) (var2) containing the values of the first or second independent variable at which the data were sampled.

  • init_values1, init_values2 (array_like, optional) – If supplied, the values stored in this array will be handled as special initial data values corresponding to the very first value in var1 or var2. Must be an array of shape (m,) (init_values1) or (n,) (init_values2). If given, data must be of shape (n-1, m) or (n, m-1) or (n-1, m-1) if both are given.

  • upper_left (scalar, optional) – Value to put in the upper left corner of the final data matrix. Usually, this value is meaningless and set to zero.

  • fmt (str, optional) – format specifier.

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

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

  • var1_name, var2_name (str, optional) – The names of the independent variables. If supplied, they will be printed in the block header.

  • var1_unit, var2_unit (str, optional) – The units of the independent variables. If supplied, they will be printed in the block header.

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

  • kwargs (dict, optional) – Additional keyword arguments to parse to mdtools.file_handler.xopen(). See there for possible arguments and their description. By default, mode is set to 'wt' (open file for writing in text mode, truncating the file first).

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