Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: streamline from_impedance method #300

Open
cmichelenstrofer opened this issue Nov 21, 2023 · 0 comments
Open

Feature request: streamline from_impedance method #300

cmichelenstrofer opened this issue Nov 21, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@cmichelenstrofer
Copy link
Member

We often start with an impedance as a numpy array and need to convert it to xarray before passing to WEC.from_impedance(). The process is repetitive and takes up many lines in notebooks... Maybe we can put a method either in core or utilities that handles this? here is the relevant code example:

# convert to xarray
freq_attr = {'long_name': 'Wave frequency', 'units': 'rad/s'}
dir_attr = {'long_name': 'Wave direction', 'units': 'rad'}
dof_attr = {'long_name': 'Degree of freedom'}
dof_names = ["Pitch",]
ndof = len(dof_names)
directions = np.atleast_1d(0.0)
ndirections = len(directions)

dims_exc = ('omega', 'wave_direction', 'influenced_dof')
coords_exc = [
    (dims_exc[0], np.squeeze(omega), freq_attr),
    (dims_exc[1], directions, dir_attr),
    (dims_exc[2], dof_names, dof_attr),
]
attrs_exc = {'units': 'N/m', 'long_name': 'Excitation Coefficient'}
exc_coeff = np.expand_dims(np.squeeze(exc_coeff), axis = [1,2])
exc_coeff = xr.DataArray(exc_coeff, dims=dims_exc, coords=coords_exc,
                        attrs=attrs_exc, name='excitation coefficient')


dims_imp = ('radiating_dof', 'influenced_dof', 'omega')
coords_imp = [
    (dims_imp[0], dof_names, dof_attr),
    (dims_imp[1], dof_names, dof_attr),
    (dims_imp[2], np.squeeze(omega), freq_attr),
]
attrs_imp = {'units': 'Ns/m', 'long_name': 'Intrinsic Impedance'}

Zi = np.expand_dims(np.squeeze(Zi), axis=[0,1])
Zi = xr.DataArray(Zi, dims=dims_imp, coords=coords_imp, attrs=attrs_imp, name='Intrinsic impedance')

I think we could make this general (any number of DOFs, any number of wave directions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants