Asagi

class geoteqpy.Asagi(x: ndarray | None = None, y: ndarray | None = None, z: ndarray | None = None, fields: dict | None = None, fname: str | None = None)

Class to write and read data in the ASAGI format. ASAGI uses the netCDF4 format.

Parameters:
  • x (np.ndarray) – 1D array of the x-coordinates. Shape (nx,).

  • y (np.ndarray) – 1D array of the y-coordinates. Shape (ny,).

  • z (np.ndarray) – 1D array of the z-coordinates. Shape (nz,).

  • fields (dict) – Dictionary of the fields to write. The keys are the names of the fields and the values are the data arrays. Data arrays must be of shape (nz,ny,nx).

  • fname (str) – Name of the netCDF file to read.

Attributes:

x: np.ndarray

1D array of the x-coordinates. Shape (nx,). Default: None.

y: np.ndarray

1D array of the y-coordinates. Shape (ny,). Default: None.

z: np.ndarray

1D array of the z-coordinates. Shape (nz,). Default: None.

fields: dict

Dictionary of the fields to write. The keys are the names of the fields and the values are the data arrays. Data arrays must be of shape (nz,ny,nx). Default: None.

shape: tuple

Shape of the data arrays. Default: None, if a file is passed, the shape is set from the coordinates in the file.

fname: str

Name of the netCDF file to read. Default: None.

Example:

Read data from a file, coordinates and fields are stored in the class attributes:

>>> asagi = Asagi(fname='test_netcdf.nc')

Create an instance of the class with coordinates and fields:

O = np.array([0,-1,0],dtype=np.float32)
L = np.array([3,1,2],dtype=np.float32)
n = np.array([3,4,5],dtype=np.int32)

cds = []
for i in range(3):
  cds.append(np.linspace(O[i],L[i],n[i]))

density = np.ones(shape=(n[2],n[1],n[0]), dtype=np.float32)*3000.0
fields = {"density": density}
asagi = Asagi(cds[0],cds[1],cds[2],fields)

Write the data to a netCDF file for ASAGI:

>>> asagi.write_netcdf('test_asagi.nc')

Write the data to a netCDF file for ParaView:

>>> asagi.write_paraview('test_paraview.nc')
check_size(field: ndarray) bool

Check if the given field has the same shape as the coordinates.

Parameters:

field (np.ndarray) – Field to check.

Returns:

True if the field has the same shape as the coordinates, False otherwise.

Return type:

bool

fields_to_tuple(dtype: dtype) ndarray

Reshape the fields to a tuple of the given data type.

Parameters:

dtype (np.dtype) – Numpy data type object. Use the get_fields_dtype method to get the data type.

Returns:

Numpy array of the reshaped fields.

Return type:

np.ndarray

get_fields_dtype() dtype

Get the data type of the fields and store it in a numpy dtype object with the following format: [ ("field1",dtype1), ("field2",dtype2), ... ] where "field1" are the keys of the field dictionary and dtype1 are the data type of the corresponding keys.

Returns:

Numpy data type object.

Return type:

np.dtype

read_netcdf(fname: str) None

Read the data from a netCDF file. Set the class attributes values from the read netCDF file.

Parameters:

fname (str) – Name of the netCDF file to read.

write_netcdf(fname: str, dimensions=('z', 'y', 'x')) None

Write the data to a netCDF file for ASAGI.

Parameters:
  • fname (str) – Name of the netCDF file to write.

  • dimensions (tuple) – Tuple of the dimensions names. Default is ('z','y','x').

write_paraview(fname: str) None

Write the data to a netCDF file for ParaView.

Parameters:

fname (str) – Name of the netCDF file to write.