atompy.load_1d_from_txt#

atompy.load_1d_from_txt(fname, output_format='ndarray', transform=True, xmin=None, xmax=None, **loadtxt_kwargs)[source]#

Load a text file.

This is a wrapper function for numpy.loadtxt() that changes the output according to output_format.

Parameters:
fnamestr

Filename

output_format{"ndarray", Hist1d}, default "ndarray"

Change output format. See Returns.

transformbool, default True

Transform the loaded NumPy ndarray.

xminfloat, optional

Specify the lower x-limit of the data in fname. Only necessary if the x-values in fname are not equally spaced. Alternatively, specify xmax.

xmaxfloat, optional

Specify the upper x-limit of the data in fname. Only necessary if the x-values in fname are not equally spaced. Alternatively, specify xmin. If xmin and xmax are specified, xmax is not used.

**loadtxt_kwargs

Other numpy.loadtxt() keyword arguments. Useful if, e.g., you want to skip a certain number of lines in the text file.

Returns:
outputndarray or Hist1d

Depends on output_format.

  • output_format == "ndarray": Return a NumPy ndarray. output[0] refers to the bin-centers of the loaded histogram, output[1] to the corresponding values.

  • output_format == "Hist1d": Return a Hist1d. output.edges (output.histogram) is analogous to output[0] (output[1]) of the "ndarray" output.

Examples

x, y = ap.load_1d_from_txt("filename.txt", output_format="ndarray")
plt.plot(x, y)

hist = ap.load_1d_from_txt("filename.txt", output_format="Hist1d")
plt.plot(hist.centers, hist.histogram)