File I/O

This module holds several methods for standard file I/O for the data formats that we work with regularly. Much of this regarding Grid objects in inherrited directly into the Grid class.

GridFileIO

class wtools.fileio.GridFileIO[source]

Bases: object

This class is inherrited by the Grid class and all these methods should be called from Grid. For example, If you have a file to read:

Example

>>> import wtools
>>> grid = wtools.Grid.read_sgems_grid('path/to/data/file.sgems')
>>> grid.validate()
True
classmethod load_mesh(filename)[source]

Open a json file and load the mesh into the Grid class

Parameters:filename (str) – name of file to read in
classmethod read_sgems_grid(fname, origin=[0.0, 0.0, 0.0], spacing=[1.0, 1.0, 1.0])[source]

Reads an SGeMS grid file where grid shape is defined in the header as three integers seperated by whitespace. Data arrays are treated as 3D and given in <x, y, z> indexing to a Grid object.

Parameters:
  • fname (str) – the string file name of the data to load. This can be a relative or abslute file path.
  • origin (iter(float)) – the southwest-bottom corner of the grid.
  • spacing (iter(float)) – the cell spacings for each axial direction
Returns:

The SGeMS data loaded onto a Grid object.

Return type:

Grid

save_sgems(filename)[source]

This will save the grid in the SGeMS gridded data file format

classmethod table_to_grid(df, shp, origin=[0.0, 0.0, 0.0], spacing=[1.0, 1.0, 1.0], order='F')[source]

Converts a pandas DataFrame table to a Grid object.

Parameters:
  • shp (tuple(int)) – length 3 tuple of integers sizes for the data grid dimensions.
  • origin (iter(float)) – the southwest-bottom corner of the grid.
  • spacing (iter(float)) – the cell spacings for each axial direction.
  • order ('C', 'F', 'A') – the reshape order.
Returns:

The data table loaded onto a Grid object.

Return type:

Grid

writeUBC(fileName, directory='', comment_lines='')[source]

load_models

wtools.fileio.load_models(filename)[source]

Open a json file and loads the models into the target class As long as there are no namespace conflicts, the target __class__ will be stored on the properties.HasProperties registry and may be fetched from there. :param str filename: name of file to read in

load_pickle

wtools.fileio.load_pickle(filename)[source]

Reads a pickled data object

read_gslib

wtools.fileio.read_gslib(filename)[source]

This will read a standard GSLib or GeoEAS data file to a pandas DataFrame.

Parameters:filename (str) – the string file name of the data to load. This can be a relative or abslute file path.
Returns:A table containing the all data arrays. Note that an attribute called header is added to the data frame contianing the string header line of the file.
Return type:pandas.DataFrame

save_gslib

wtools.fileio.save_gslib(filename, dataframe, header=None)[source]

This will save a pandas dataframe to a GSLib file

save_pickle

wtools.fileio.save_pickle(filename, data)[source]

Pickles a data object in a Python 2 AND 3 friendly manner