capytaine.io.xarray module¶
Tools to use xarray Datasets as inputs and outputs.
Todo
This module could be tidied up a bit and some methods merged or uniformized.
- capytaine.io.xarray.assemble_dataset(results, omega=True, freq=True, wavenumber=True, wavelength=True, period=True, mesh=False, hydrostatics=True, attrs=None) Dataset[source]¶
Transform a list of
LinearPotentialFlowResultinto axarray.Dataset.Todo
The
meshoption to store information on the mesh could be improved. It could store the full mesh in the dataset to ensure the reproducibility of the results.- Parameters:
results (list of LinearPotentialFlowResult or BEMIO dataset) – The results that will be read.
omega (bool, optional) – If True, the coordinate ‘omega’ will be added to the output dataset.
freq (bool, optional) – If True, the coordinate ‘freq’ will be added to the output dataset.
wavenumber (bool, optional) – If True, the coordinate ‘wavenumber’ will be added to the output dataset.
wavelength (bool, optional) – If True, the coordinate ‘wavelength’ will be added to the output dataset.
period (bool, optional) – If True, the coordinate ‘period’ will be added to the output dataset.
mesh (bool, optional) – If True, store some infos on the mesh in the output dataset.
hydrostatics (bool, optional) – If True, store the hydrostatic data in the output dataset if they exist.
attrs (dict, optional) – Attributes that should be added to the output dataset.
- capytaine.io.xarray.assemble_matrices(results)[source]¶
Simplified version of assemble_dataset, returning only bare matrices. Meant mainly for teaching without introducing Xarray to beginners.
- Parameters:
results (list of LinearPotentialFlowResult) – The results that will be read.
- Returns:
The added mass matrix, the radiation damping matrix and the excitation force. If the data are no available in the results, returns None instead.
The matrices are ordered along their frequency axis in the same order as the frequencies appear in
results, rather than sorted by increasing frequency as in the dataset returned byassemble_dataset().- Return type:
3-ple of (np.arrays or None)
- capytaine.io.xarray.compute_hydrostatics_dataset(body: AbstractBody, *, g: float | Sequence[float] = 9.81, rho: float | Sequence[float] = 1000.0, only_dofs: List[str] | None = None)[source]¶
- Parameters:
body (AbstractBody)
g (float or sequence of floats, optional) – Gravitational acceleration(s) to consider. If a sequence is provided, the output dataset will contain one entry per value of g.
rho (float or sequence of floats, optional) – Fluid density(ies) to consider. If a sequence is provided, the output dataset will contain one entry per value of rho.
only_dofs (list of strings, optional) – If provided, only the radiating dofs in this list will be kept in the output dataset. By default, all dofs of the body are kept. Meant to mimic the behavior of fill_dataset when the test matrix has only some of the possible radiating dofs.
- Return type:
xarray.Dataset
- capytaine.io.xarray.export_dataset(filename, dataset, format=None, **kwargs)[source]¶
Save dataset into a format, provided by the format argument or inferred by the filename.
- Parameters:
filename (str or Path) – Where to store the data
dataset (xarray.Dataset) – Dataset, which is assumed to have been computed by Capytaine
format (str, optional) – Format of output. Accepted values: “netcdf”
**kwargs (optional) – Remaining argument are passed to the specific export function, such as
save_dataset_as_netcdf,export_to_wamitorwrite_dataset_as_tecplot_files.
- Return type:
None
- capytaine.io.xarray.kochin_data_array(results: Sequence[LinearPotentialFlowResult], theta_range: Sequence[float], **kwargs) Dataset[source]¶
Compute the Kochin function for a list of results and fills a dataset.
See also
compute_kochin()The present function is just a wrapper around
compute_kochin.
- capytaine.io.xarray.merge_complex_values(ds: Dataset) Dataset[source]¶
Return a new Dataset where real-valued arrays of shape (2, …) have been replaced by complex-valued arrays of shape (…).
See also
separate_complex_values()The invert operation
- capytaine.io.xarray.problems_from_dataset(dataset: Dataset, body: AbstractBody) List[LinearPotentialFlowProblem][source]¶
Generate a list of problems from a test matrix.
- Parameters:
dataset (xarray Dataset) – Test matrix containing the problems parameters.
body (AbstractBody) – The body on which the computations of the test matrix will be applied.
- Return type:
list of LinearPotentialFlowProblem
- Raises:
ValueError – if required fields are missing in the dataset
- capytaine.io.xarray.save_dataset_as_netcdf(filename, dataset)[source]¶
Save dataset as a NetCDF file with name (or path) filename
- capytaine.io.xarray.separate_complex_values(ds: Dataset) Dataset[source]¶
Return a new Dataset where complex-valued arrays of shape (…) have been replaced by real-valued arrays of shape (2, …).
See also
merge_complex_values()The invert operation