mtuq.grid.UnstructuredGrid

class mtuq.grid.UnstructuredGrid(dims=None, coords=None, start=0, stop=None, callback=None)[source]

Bases: object

An UnstructuredGrid is defined by lists of individual coordinate points, which can be irregularly spaced

Example

Unstructured grid consisting of N randomly-chosen points within the unit square:

x = np.random.rand(N)
y = np.random.rand(N)
grid = UnstructuredGrid(dims=('x', 'y'), coords=(x, y))

Iterating over grids

Iterating over an unstructured grid is similar to iterating over a list.

If start and stop arguments are given when creating an unstructured grid, iteration will begin and end at these indices. Otherwise, iteration will begin at the first index (i=0) and stop at the last index.

Accessing individual grid points

Individual grid points can be accessed through the get and get_dict methods.

get(i) returns the i-th grid point as a NumPy array.

If a callback function is given when creating an unstructured grid, then get returns the result of applying the callback to the i-th grid point. This behavior can be overridden by supplying a callback function as a keyword argument to get itself. If callback is None, then no function is applied.

get_dict(i) returns the i-th grid point as a dictionary of coordinate axis names and coordinate values without applying any callback.

Public Methods

get

Returns i-th grid point

get_dict

Returns i-th grid point as a dictionary of parameter names and values

partition

Partitions grid for parallel processing

to_array

Returns the entire set of grid points as a NumPy array

to_dataframe

Returns the entire set of grid points as a pandas.DataFrame