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
LinearPotentialFlowResult
into axarray.Dataset
.Todo
The
mesh
option 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 beginers.
- 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.
- Return type:
3-ple of (np.arrays or None)
- 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_wamit
orwrite_dataset_as_tecplot_files
.
- Return type:
None
- capytaine.io.xarray.hydrostatics_dataset(bodies: Sequence[FloatingBody]) Dataset [source]¶
Create a dataset by looking for ‘inertia_matrix’ and ‘hydrostatic_stiffness’ for each of the bodies in the list passed as argument.
- 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, bodies: FloatingBody | Sequence[FloatingBody]) List[LinearPotentialFlowProblem] [source]¶
Generate a list of problems from a test matrix.
- Parameters:
dataset (xarray Dataset) – Test matrix containing the problems parameters.
bodies (FloatingBody or list of FloatingBody) – The bodies on which the computations of the test matrix will be applied. They should all have different names.
- 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