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, wavenumber=True, wavelength=True, period=True, mesh=False, hydrostatics=True, attrs=None) Dataset[source]

Transform a list of LinearPotentialFlowResult into a xarray.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) – The results that will be read.

  • omega (bool, optional) – If True, the coordinate ‘omega’ 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.collect_records(results)[source]
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.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