pwtools.arrayio.readtxt

pwtools.arrayio.readtxt(fh, axis=None, shape=None, header_maxlines=20, header_comment='#', maxdim=3, **kwargs)[source]

Read arrays from .txt file using np.loadtxt().

If the file stores a 3d array as consecutive 2d arrays (e.g. output from molecular dynamics code) the file header (see writetxt()) is used to determine the shape of the original 3d array and the array is reshaped accordingly.

If axis or shape is not None, then these are used instead and the header, if existing, will be ignored. This has the potential to shoot yourself in the foot. Use with care.

If axis and shape are None, then this function does not work with normal text files which have no special header. Use np.loadtxt() in this case.

Parameters:
  • fh (file_like)

  • axis (int)

  • shape (tuple)

  • **kwargs (keyword args passed to numpy.loadtxt(), e.g. comments='@@' to) – ignore weird lines etc.

Return type:

nd array