Grids#

class up4.Grid(data=None, num_cells=[50, 50, 50], grid_style='cartesian', cell_size=None, limits=None, xlim=None, ylim=None, zlim=None)[source]#

Bases: RustGrid

static cartesian3d(cells, limit)#

Create a 3D cartesian grid with limits and spacing provided by user.

Parameters:
cellsList(int)

A list containing the number of cells in each direction. Must be of length 3

limitList(float)

A list containing the limits of the grid in each direction. Must be of length 6 The order is [xmin, xmax, ymin, ymax, zmin, zmax]

Returns:
gridGrid

A up4.Grid object with the same dimensions dimensions defined by user

static cartesian3d_from_data(pydata, cells)#

Create a 3D cartesian grid with limits and spacing from a PyData object.

Parameters:
pydataPyData

A PyData object containing the data to be used to generate the grid

cellsList(int)

A list containing the number of cells in each direction. Must be of length 3

Returns:
gridGrid

A up4.Grid object with the same dimensions as the input data

cell_id(x, y, z)#

Return the cell id of a given position.

Parameters:
xfloat

The x-position of the cell

yfloat

The y-position of the cell

zfloat

The z-position of the cell

Returns:
cell_idlist

The cell id of the given position

cell_positions()#

Return the positions of all cells in the grid.

Returns:
positionsTuple(np.ndarray)

A tuple containing the 1D arrays of the x, y and z positions of the cells

collapse(axis)#

Collapse the grid along an axis.

This is basically cell based depth averaging

Parameters:
axisint

The axis to collapse the grid on

Returns:
gridndarray

A numpy array containing the collapsed grid

collapse_two(axis1, axis2)#

Collaps the grid along an axis This is basically cell based depth averaging.

Parameters:
axis1int

The first axis to collapse the grid on

axis2int

The second axis to collapse the grid on

Returns:
gridndarray

A numpy array containing the collapsed grid

static cylindrical3d(cells, limit, mode='volume')#

Create a 3D cylindrical grid with limits provided by user.

Parameters:
cellsList(int)

A list containing the number of cells in each direction. Must be of length 3

limitList(float)

A list containing the limits of the grid in each direction. Must be of length 6 The order is [rmin, rmax, zmin, zmax, phimin, phimax]

modestr, optional

The mode of the grid. Can be “volume”. Other methods are not implemented yet, by default “volume”

Returns:
gridGrid

A up4.Grid object with the same dimensions dimensions defined by user

static cylindrical3d_from_data(pydata, cells, mode='volume')#

Create a 3D cylindrical grid with limits and spacing from a PyData object.

Parameters:
pydataPyData

A PyData object containing the data to be used to generate the grid

cellsList(int)

A list containing the number of cells in each direction. Must be of length 3

modestr, optional

The mode of the grid. Can be “volume”. Other methods are not implemented yet, by default “volume”

Returns:
gridGrid

A up4.Grid object with the same dimensions as the input data

is_inside(position)#

Check if the particle is within the grid.

Parameters:
positionList(float)

A list containing the position of the particle. Must be of length 3

Returns:
is_insidebool

True if the particle is inside the grid, False otherwise

plot(axis)#

Plot the grid using plotly plotter. A simple depth averaged plot.

Parameters:
axisint, optional

The axis to plot the grid on, by default 0

Returns:
None
remove_outliers(mode, threshold)#

Detect outliers and remove them depending on the mode Three different modes are available: 1. Set the outlier to zero 2. Set the outlier to the threshold 3. Set the outlier to the mean of surrounding cells.

Parameters:
modeint

The mode to use for outlier detection

thresholdfloat

The threshold to use for outlier detection

Returns:
None
shape()#

Return the shape of the grid.

Returns:
shapeList(int)

A list containing the number of cells in each dimension.

slice(axis, index)#

Return a slice of the grid as a numpy array.

Parameters:
axisint

The axis to slice the grid on

indexint

The index of the slice

slice_pos(axis, position)#

Return a slice of the grid as a numpy array at a given position and axis.

Parameters:
axisint

The axis to slice the grid on

positionf64

The position of the slice

to_numpy()#

Return the grid as a numpy array.

Returns:
gridndarray

A numpy array containing the grid-data with the same shape as grid

weights_to_numpy()#

Return the weights of each cell as a numpy array.

Returns:
weightsndarray

A numpy array containing the weights of each cell with the same shape as grid

xpositions()#

Return the x-positions of the grid.

Returns:
xndarray

A numpy array containing the x-positions of the grid

ypositions()#

Return the y-positions of the grid.

Returns:
yndarray

A numpy array containing the y-positions of the grid

zpositions()#

Return the z-positions of the grid.

Returns:
zndarray

A numpy array containing the z-positions of the grid