From 2a290e5e968175f5bd9a6a67574cd4918bd52e2e Mon Sep 17 00:00:00 2001 From: Andrew Simms Date: Wed, 4 Dec 2024 13:59:56 -0700 Subject: [PATCH] Delft3d: Convert masked array output to floats 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. --- mhkit/river/IO/delft_3d/delft_3d_get_all_time.m | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mhkit/river/IO/delft_3d/delft_3d_get_all_time.m b/mhkit/river/IO/delft_3d/delft_3d_get_all_time.m index 2d0374b2..a24b30a5 100644 --- a/mhkit/river/IO/delft_3d/delft_3d_get_all_time.m +++ b/mhkit/river/IO/delft_3d/delft_3d_get_all_time.m @@ -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