gpfile

A module to handle 3D gnuplot datafiles.

It can be used to get information on the file, access the contents via numpy arrays and extract the ranges along the three axes.

The files are represented by the gp_file object. The class provides methods to rotate, flipp, copy and save the datafile.

Example

file = gp_file.gp_file('data.dat',(0,1,2))
file.rotate_cw()
file.report()
file.save('newdata.dat')
class colorview2d.gpfile.Gpfile(*args)

A gnuplot data file object.

Usage:

The datafile object can be initiated by the use of a filename and a column tuple. Alternatively, one can provide a 2d array of data. The axes are then just given by the index ranges.

filename:A gnuplot datafile to be read in.
columns:A tuple of three integers to specify the three columns.

or:

data:Alternatively, a 2d numpy.ndarray can be provided.

Attributes:

Variables:
  • Zdata – The two dimensional numpy arrray containing the actual data.
  • Xrange – A one dimensional array representing the x axis range.
  • Yrange – A one dimensional array representing the y axis range.
  • Xleft – The value on the left of the x axis.
  • Xright – The value on the right of the x axis.
  • Ytop – The values on the top of the y axis.
  • Ybottom – The values on the bottom of the y axis.
  • Zmin – The min values of the 2d array.
  • Zmax – The max values of the 2d array.
  • Xmin – The min values of the x axis range.
  • Xmax – The max values of the x axis range.
  • Ymin – The min values of the y axis range.
  • Ymax – The max values of the y axis range.
  • filename – The filename of the ASCII file containing the data.
crop(xleft, xright, ybottom, ytop)

Crop the datafile to a subset of the array specifiying the corners of the subset in units of the axes ranges.

Parameters:
  • xleft
  • xright
  • ybottom
  • ytop
deep_copy()

Deep copy the datafile object.

Returns:A copy of the datafile object.
flip_lr()

Flip the left and the right side of the datafile. The axes are updated as well.

flip_ud()

Flip the up and the down side of the datafile. The axes are updated as well.

get_xrange_idx(value)

Return the nearest index of a value within the x axis range.

Parameters:value (float) – A value in the range of the x axis
Returns:The closest index on the x axis range.
get_yrange_idx(value)

Return the nearest index of a value within the y axis range.

Parameters:value (float) – A value in the range of the y axis
Returns:The closest index on the y axis range.
report()

Print a datafile report to the standart output.

rotate_ccw()

Rotate the datafile counter-clockwise. The axes are updated as well.

rotate_cw()

Rotate the datafile clockwise. The axes are updated as well.

save(fname, comment='')

Saves a datafile to a file with filename in the gnuplot format.

Parameters:
  • fname (str) – The filename of the ASCII file to contain the data.
  • comment (str) – A comment that is added to the top of the file.
set_Zdata(Zdata)

Replace the 2d array containing the data. The Zmin and Zmax values are updated.

Parameters:Zdata (numpy.ndarray) – Two dimensional array to plot.
set_xyrange(Xrange, Yrange)

Specify the x and y ranges of the datafile.

Parameters:
  • Xrange (numpy.ndarray) – One dimensional numpy array with the same length as the width of the data.
  • Yrange (numpy.ndarray) – One dimensional numpy array with the same length as the height of the data.