Skip to content

Commit

Permalink
Delft3d: Convert masked array output to floats
Browse files Browse the repository at this point in the history
The MHKiT-Python d3d.get_all_time function uses a masked array. This
type is not natively convertible to a double array in matlab. This
handles the conversion in using the python wrapper to ensure that the
result is converted to a compatible numpy array.
  • Loading branch information
simmsa committed Dec 12, 2024
1 parent e26b86d commit 2a290e5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mhkit/river/IO/delft_3d/delft_3d_get_all_time.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,17 @@

python_result = py.mhkit.river.io.d3d.get_all_time(delft_3d_py_object);

result = double(py.list(python_result));
% Handle masked arrays using numpy.ma.getdata
if isa(python_result, 'py.numpy.ma.MaskedArray')
% Extract the underlying data
data_array = py.numpy.ma.getdata(python_result);
else
% Convert directly if not masked
data_array = py.numpy.array(python_result);
end

% Ensure data is of type float
float_array = data_array.astype('float');

result = double(float_array);
end

0 comments on commit 2a290e5

Please sign in to comment.