Skip to content

Commit

Permalink
black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
akeeste committed Oct 2, 2024
1 parent 8f1647f commit c0d72d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions mhkit/utils/type_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ def convert_to_dataarray(data, name="data"):
# iloc returns a Series with one value as expected.
data = data.iloc[:, 0]
else:
# With this conversion, dataframe columns always become "dim_1".
# With this conversion, dataframe columns always become "dim_1".
# Rename to "variable" to match how multiple Dataset variables get converted into a DataArray dimension
data = xr.DataArray(data)
data = data.rename({'dim_1':'variable'})
data = data.rename({"dim_1": "variable"})

# Checks xr.Dataset input and converts to xr.DataArray if possible
if isinstance(data, xr.Dataset):
Expand All @@ -174,7 +174,9 @@ def convert_to_dataarray(data, name="data"):
else:
# Allow multiple variables if they have the same dimensions
if all([data[keys[0]].dims == data[key].dims for key in keys]):
data = data.to_array().T # transpose so that the new "variable dimension" is the last dimension (matches DataFrame to DataArray behavior)
data = (
data.to_array().T
) # transpose so that the new "variable dimension" is the last dimension (matches DataFrame to DataArray behavior)
else:
raise ValueError(
"Multivariate Datasets can only be input if all variables have the same dimensions."
Expand Down
12 changes: 8 additions & 4 deletions mhkit/wave/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ def surface_elevation(

# Create dimensions and coordinates for the new dataset (frequency becomes time)
new_dims = list(S.dims)
new_dims[frequency_axis] = 'Time'
new_dims[frequency_axis] = "Time"
new_coords = S.sum(dim=frequency_dimension).coords
new_coords = new_coords.assign({'Time': time_index})
new_coords = new_coords.assign({"Time": time_index})
f = S[frequency_dimension]

if not isinstance(frequency_bins, (type(None), np.ndarray)):
Expand Down Expand Up @@ -353,7 +353,7 @@ def surface_elevation(
f"ifft method must have evenly spaced frequency bins. Setting method to less efficient `sum_of_sines` method."
)
method = "sum_of_sines"
elif method == 'sum_of_sines':
elif method == "sum_of_sines":
# For sum of sines, does not matter if there is a zero frequency or if frequency bins are evenly spaced
pass
else:
Expand All @@ -379,7 +379,11 @@ def surface_elevation(
if method == "ifft":
A_cmplx = A * (np.cos(phase) + 1j * np.sin(phase))
# eta_tmp = np.fft.irfft(0.5 * A_cmplx.values * time_index.size, time_index.size)
eta_tmp = np.fft.irfftn(0.5 * A_cmplx * time_index.size, list(time_index.shape), axes=[frequency_axis])
eta_tmp = np.fft.irfftn(
0.5 * A_cmplx * time_index.size,
list(time_index.shape),
axes=[frequency_axis],
)
eta = xr.DataArray(data=eta_tmp, dims=new_dims, coords=new_coords)

elif method == "sum_of_sines":
Expand Down

0 comments on commit c0d72d0

Please sign in to comment.