GithubHelp home page GithubHelp logo

mhkit-software / mhkit-matlab Goto Github PK

View Code? Open in Web Editor NEW
15.0 15.0 23.0 389.57 MB

MHKiT-MATLAB provides the marine renewable energy (MRE) community tools for data processing, visualization, quality control, resource assessment, and device performance.

Home Page: https://mhkit-software.github.io/MHKiT/

License: BSD 3-Clause "New" or "Revised" License

MATLAB 98.58% Python 1.13% HTML 0.23% JavaScript 0.06%
marine-renewable-energy matlab mhkit mhkit-matlab quality-control visualization

mhkit-matlab's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mhkit-matlab's Issues

Environmental Contours Example Fails to Plot Environmental Contour

Description:

Attempting to run examples/environmental_contours_example.mlx results in the following error on line 35.

Unable to resolve the name 'py.mhkit.wave.resource.environmental_contour'.

Error in [environmental_contour](matlab:matlab.internal.language.introspective.errorDocCallback('environmental_contour', 'mhkit/wave/resource/environmental_contour.m', 91)) ([line 91](matlab: opentoline('mhkit/wave/resource/environmental_contour.m',91,0)))
data = py.mhkit.wave.resource.environmental_contour(py.numpy.array(x1),py.numpy.array(x2),...ttt

It appears that the call signature in MHKiT-Python for wave.contours.environmental_contours has changed significantly.

This code section handles the python call and contains the source of this bug.

QC CI tests

Develop CI tests for the MHKiT-MATLAB QC module

USGS and NOAA data requests not working

Requesting data from the USGS and NOAA servers via request_usgs_data() and request_noaa_data() almost always fail with the error:

Python Error: SSLError: HTTPSConnectionPool(host='waterservices.usgs.gov', port=443): Max retries exceeded with url:
/nwis/dv/?format=json&sites=15515500&startDT=2009-08-01&endDT=2009-08-10&statCd=00003&parameterCd=00060&siteStatus=all (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))

On rare occasions the same error occurs when running just the wrapped Python call in MHKiT-Python. This has been tested from Windows 10.

QC CI Tests

Develop CI tests for the MHKiT-MATLAB QC module

Code Compatibility: DATST Info

Code compatibility analysis is reporting the following DATST warnings:

Identifier Severity Documentation Suppression File LineNumber ColumnRange
DATST Info Details none mhkit/dolfyn/io/read_rdi.m 626 21 27
DATST Info Details none mhkit/dolfyn/io/read_rdi.m 635 21 27
DATST Info Details none mhkit/dolfyn/io/read_rdi.m 648 21 27
DATST Info Details none mhkit/dolfyn/io/read_rdi.m 680 25 31
DATST Info Details none mhkit/tests/River_TestIO.m 19 30 36
DATST Info Details none mhkit/tests/River_TestIO.m 20 25 31
DATST Info Details none mhkit/tidal/io/request_noaa_data.m 80 18 24
DATST Info Details none mhkit/tidal/io/request_noaa_data.m 81 20 26
DATST Info Details none mhkit/wave/graphics/plot_compendium.m 36 5 11
DATST Info Details none mhkit/wave/graphics/plot_compendium.m 37 5 11

Details:

DATST Details (Info):

  • 'datestr' is not recommended.
  • With appropriate code changes, use 'datetime' instead.

Code Compatibility: COLMP Warnings

The most recent code compatibility is reporting the following COLMP warnings.

Identifier Severity Documentation Suppression File LineNumber ColumnRange
COLMP Warning Details none mhkit/tidal/graphics/plot_joint_probability_distribution.m 169 10 17
COLMP Warning Details none mhkit/tidal/graphics/plot_rose.m 104 17 24
COLMP Warning Details none mhkit/wave/graphics/plot_matrix.m 38 17 19

Details:

COLMP Details (Warning):

  • In R2019a and previous releases, the default colormap size is 64.
  • Starting in R2019b, colormaps have 256 colors by default.
  • If your code depends on a colormap having 64 colors, specify the number of colors when querying the colormap.
  • For example, parula(64) queries the 64-color parula colormap.

Code Compatibility: IDISVARLOW

Code compatibility is reporting the following IDISVARLOW Warning:

Identifier Severity Documentation Suppression File LineNumber ColumnRange
IDISVARLOW Warning Details none mhkit/river/resource/Froude_number.m 28 8 14

Details:

IDISVARLOW Details (Warning):

  • To avoid a potential conflict with functions on the path, explicitly define the variable before indexing into it.

Refactor or deprecate `Wave_TestResourceMetrics` tests that call `environmental_contour`

Description

test_environmental_contour, test_plot_environmental, and test_plot_environmental_contour_multiyear tests are failing. This issue initiates discussions on whether to refactor or deprecate these tests.

Context

  • Failing Tests: test_environmental_contour, test_plot_environmental, test_plot_environmental_contour_multiyear
  • Status: Specified tests fail with error:
    'MATLAB:Python:PyException'
    --------------
    Error Details:
    --------------
    Error using Wave_TestResourceMetrics/test_plot_environmental_contour
    Python Error: TypeError: environmental_contours() missing 1 required positional argument: 'method'

Options:

  • Modify/Update:
    • Revise or update tests that call environmental_contour.
  • Deprecate:
    • Remove tests that call environmental_contour.

Additional Information

The specified tests call wave/resource/environmental_contour. The current version MHKiT-Python tests environmental contours here. In MHKIT-Python v0.6.0 this test was split from test_resource_metrics.py. To keep parity with MKHIT-Python, it may make sense to split these tests into a new file called Wave_TestContours and utilize a similar testing methodology as MHKiT-Python.

The root of this issue looks to be a the addition of the method argument to the environmental_contours function in MHKiT-Python, and changes to the structure of the returned dictionary.

The fix will require adding a new argument to environmental_contour and updating the code that converts the output of this function into a type that is useable in MATLAB.

MHKiT with MATLAB R2022b , Anaconda, Python 3.9, on Ubuntu 22.04 LTS

I'm trying to get MHKiT working with MATLAB R2022b and Anaconda with Python 3.9 on Ubuntu 22.04 LTS, but I'm having some problems.

I cloned both MHKiT-Python and MHKiT-MATLAB and then installed them both (i.e., mhkit and mhkit-python-utils) into my Anaconda environment using pip install -e .

Then I start MATLAB R2022b and installed the MHKiT toolbox which reports success, however, the following does not work in MATLAB:

[x,y]=circular(30)

Error using _linprog_highs><module>
Python Error: ImportError: /opt/MATLAB/R2022b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6:
version `GLIBCXX_3.4.29' not found (required by
~/anaconda3/lib/python3.9/site-packages/scipy/optimize/_highs/_highs_wrapper.cpython-39-x86_64-linux-gnu.so)

I have GLIBCXX_3.4.29 in ~/anaconda3/lib/libstdc++.so.6 but GLIBCXX_3.4.28 is highest version in
/opt/MATLAB/R2022b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6

If I try to tell MATLAB to use ~/anaconda3/lib/libstdc++.so.6 by doing

LD_PRELOAD=/home/ps/anaconda3/lib/libstdc++.so.6 /opt/MATLAB/R2022b/bin/matlab

MATLAB crashes when I run the circular(30) command.

I also tried to make the pip install build against
/opt/MATLAB/R2022b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6
by uninstalling mhkit, mhkit-python-utils and the MHKit toolbox and repeating the whole process above after first setting

export LD_PRELOAD=/opt/MATLAB/R2022b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6

However, this made no difference to the error message above.

I'd welcome any suggestions on how to fix the problem or what to try next, thanks.

MHKiT-Matlab Python recognition issues

I successfully installed python,pycharm,mhkit,and the related packages and ran the example river code from the installation page with no issues.
However I am having quite a bit of trouble with matlab recognizing mhkit. Using gitbash I cloned MHKiT-MATLAB, put it in my Matlab path, and then navigated to that folder in my windows terminal and ran pip install -e .
As per instructions. In matlab I ran pyversion and read out what the installation page notes. I double checked the place executable, library, and home were going to and they are correct. Finally I double clicked mhkit.mltbx and installed it with a note telling me that it got installed and was enabled. Unfortunately, when I try the test code from the installation page, I get multiple different errors.

I have repeated the Python and Matlab installation multiple times to make sure I didn't overlook anything, yet this didn't help.
Any ideas?

  • Chris

Supplementary info -->

Python version: 3.9
Matlab version: 2020b update 4

Specific errors I get upon opening Matlab right away:
[x,y]=circular(30) Error using h5>init h5py.h5 (line 1) Python Error: ImportError: DLL load failed while importing defs: The specified procedure could not be found. Error in version><module> (line 15) Error in __init__><module> (line 33) Error in multi_file_resource><module> (line 5) Error in __init__><module> (line 8) Error in hindcast><module> (line 3) Error in __init__><module> (line 3) Error in __init__><module> (line 2) Error in __init__><module> (line 1) Error in <frozen importlib>_call_with_frames_removed (line 228) Error in <frozen importlib>exec_module (line 790) Error in <frozen importlib>_load_unlocked (line 680) Error in <frozen importlib>_find_and_load_unlocked (line 986) Error in <frozen importlib>_find_and_load (line 1007) Error in <frozen importlib>_gcd_import (line 1030) Error in __init__>import_module (line 127)

Code Compatibility: GETFMT

Code compatibility is reporting the following GETFMT Info:

Identifier Severity Documentation Suppression File LineNumber ColumnRange
GETFMT Info Details none mhkit/tests/Dolfyn_TestIO.m 290 28 35
GETFMT Info Details none mhkit/tests/Dolfyn_Test_Rotate.m 395 28 35

Details:

GETFMT Details (Info):

  • Using get for retrieving values of numeric display format is not recommended.
  • With appropriate code changes, use 'settings' object instead.

Code Compatibility: LEGPVPAIR

Code compatibility is reporting the following LEGPVPAIR Warning:

Identifier Severity Documentation Suppression File LineNumber ColumnRange
LEGPVPAIR Warning Details none mhkit/wave/graphics/plot_chakrabarti.m 71 40 51

Details:

LEGPVPAIR Details (Warning):

  • 'legend' has changed and might interpret the name of an argument as a legend property instead of a label.
  • To include a label with the same name as a legend property, specify the labels using a cell array or string array.
  • Refer to the documentation for a list of affected property names.

Matlab Parity with Python

MHKiT-Software/MHKiT-Python#130 - WDRT (Chris)
MHKiT-Software/MHKiT-Python#132 - Delft3D (Andrew)
MHKiT-Software/MHKiT-Python#141 - WDRT(Chris)
MHKiT-Software/MHKiT-Python#152 - NDBC Metocean
MHKiT-Software/MHKiT-Python#168 - Delf3D (Andrew)
MHKiT-Software/MHKiT-Python#187 - metocean module (Chris)
MHKiT-Software/MHKiT-Python#193 - loads module (Chris)
MHKiT-Software/MHKiT-Python#197 - Directional NDBC
MHKiT-Software/MHKiT-Python#199 - Delft3d example notebook (Andrew)
MHKiT-Software/MHKiT-Python#205 - graphics bug fix
MHKiT-Software/MHKiT-Python#210 - wave resource update
MHKiT-Software/MHKiT-Python#212 - DOLfYN updates (Andrew)
MHKiT-Software/MHKiT-Python#220 - WPTO hindcast (Chris)
MHKiT-Software/MHKiT-Python#232) - DOLfYN (Andrew)
MHKiT-Software/MHKiT-Python#235 - Mooring (Chris)
MHKiT-Software/MHKiT-Python#236 - Tidal Power Performance (Andrew)
MHKiT-Software/MHKiT-Python#239 - NDBC station metadata
MHKiT-Software/MHKiT-Python#248 - Delft3D (Andrew)
MHKiT-Software/MHKiT-Python#250 - surface elevation
MHKiT-Software/MHKiT-Python#252 - uncrossing analysis
MHKiT-Software/MHKiT-Python#271 - Delft3D (Andrew)
MHKiT-Software/MHKiT-Python#280 - DOLfYN (Andrew)

1st Time user error log

Matlab 2021b
Python 3.9

running runTest for 1st time

I just wanted to pass along the results. I have not tried to troubleshoot myself because I am a new user of the MHKit

test_results.pdf

Code Compatibility: DATNM Info

The most recent code compatibility analysis is reporting the following DATNM warnings:

Identifier Severity Documentation Suppression File LineNumber ColumnRange
DATNM Info Details none mhkit/dolfyn/io/read_rdi.m 626 13 19
DATNM Info Details none mhkit/dolfyn/io/read_rdi.m 635 13 19
DATNM Info Details none mhkit/dolfyn/io/read_rdi.m 648 13 19
DATNM Info Details none mhkit/dolfyn/io/read_rdi.m 680 17 23
DATNM Info Details none mhkit/tests/QC_Test.m 45 24 30
DATNM Info Details none mhkit/tests/QC_Test.m 46 24 30
DATNM Info Details none mhkit/tests/QC_Test.m 71 24 30
DATNM Info Details none mhkit/tests/QC_Test.m 72 24 30
DATNM Info Details none mhkit/tests/QC_Test.m 162 28 34
DATNM Info Details none mhkit/tests/QC_Test.m 162 53 59
DATNM Info Details none mhkit/tests/River_TestIO.m 20 51 57

Details:

DATNM Details (Info):

  • 'datenum' is not recommended.
  • With appropriate code changes, use 'datetime' instead.

Some tests are failing on MHKiT-Python v0.8.0

The following MHKiT-MATLAB test cases are failing with the new MHKiT-Python v0.8.0

 Name                                                                Failed  Incomplete  Reason(s)
=================================================================================================================
 Loads_TestLoads/test_bin_statistics                                   X         X       Failed by assertion.
-----------------------------------------------------------------------------------------------------------------
 Loads_TestLoads/test_damage_equivalent_loads                          X         X       Errored.
-----------------------------------------------------------------------------------------------------------------
 Power_TestDevice/test_TCHD_sine_wave                                  X         X       Errored.
-----------------------------------------------------------------------------------------------------------------
 Wave_TestPerformance/test_capture_length                              X         X       Errored.
-----------------------------------------------------------------------------------------------------------------
 Wave_TestPerformance/test_capture_length_matrix                       X         X       Errored.
-----------------------------------------------------------------------------------------------------------------
 Wave_TestPerformance/test_power_matrix                                X         X       Errored.
-----------------------------------------------------------------------------------------------------------------
 Wave_TestPerformance/test_mean_annual_energy_production               X         X       Errored.
-----------------------------------------------------------------------------------------------------------------
 Wave_TestPerformance/test_power_performance_workflow                  X         X       Errored.
-----------------------------------------------------------------------------------------------------------------
 Wave_TestResourceMetrics/test_kfromw                                  X         X       Failed by assertion.
-----------------------------------------------------------------------------------------------------------------
 Wave_TestResourceSpectrum/test_surface_elevation_seed                 X         X       Errored.
-----------------------------------------------------------------------------------------------------------------
 Wave_TestResourceSpectrum/test_surface_elevation_phasing              X         X       Errored.
-----------------------------------------------------------------------------------------------------------------
 Wave_TestResourceSpectrum/test_surface_elevation_moments              X         X       Errored.
-----------------------------------------------------------------------------------------------------------------
 Wave_TestResourceSpectrum/testSurfaceElevationMethod                  X         X       Errored.

These errors need to get broken out by function. Initially, many of the errors seem caused improper type conversion.

Necessary Matlab Libraries

Hello,

Do you know what Matlab libraries/add-ons are required to use the full functionality of the Matlab version of MHKiT? I saw that a minimum of Matlab 2019b is required, but are there any additional requirements?

Thank you.

Code Compatibility: HISTC

Code compatibility analysis is reporting the following HISTC Info:

Identifier Severity Documentation Suppression File LineNumber ColumnRange
HISTC Info Details none mhkit/dolfyn/io/read_signature.m 1514 22 26

Details:

HISTC Details (Info):

  • 'histc' is not recommended.
  • With appropriate code changes, use 'histcounts' instead.

Updates for docstring links

While combing through our documentation and API, I noticed a few links that should be updated, specifically in mhkit.tidal.io.noaa.request_noaa_data.m

Code Compatibility: DISPPROG

Code compatibility is reporting the following DISPLAYPROG Info:

Identifier Severity Documentation Suppression File LineNumber ColumnRange
DISPLAYPROG Info Details none mhkit/tests/runCodeCompatibilityReport.m 11 5 11

Details:

DISPLAYPROG Details (Info):

  • Programmatic use of DISPLAY is not recommended.
  • Use DISP or FPRINTF instead.

Wave elevation generation

Hello,

I am trying to make a Pierson Moskowitz wave elevation 20 minute time series with a peak period of 16s and a significant wave height of 1.5 meters. The code below is what I have but I know it has several issues.
What is the frequency input supposed to look like in the "pierson_moskowitz_spectrum" function? Should it be linearly spaced? Include a zero frequency? Right now it is based on having 32 frequencies between 2 and 30 seconds which is based on how model data reports frequencies. The "surface_elevation" code requires a 0 frequency for the ifft, do you suggest padding with a zero? Example code for this function would be helpful as well!

swell_Tp = 16; %s
swell_Hs = 1.5; %m
swell_S = pierson_moskowitz_spectrum(linspace(1/30,1/2,32),swell_Tp,swell_Hs);

t = 0:dt:20*60; % seconds
swell_eta = surface_elevation(swell_S,t,"seed",1);

Thank you,
Courtney

Fix STRUCT warnings

Fix the following warning thrown during CI runs:

"Warning: Calling STRUCT on an object prevents the object from hiding its
implementation details and should thus be avoided. Use DISP or DISPLAY to see
the visible public details of an object."

...caused by the following file:
read_NDBC_file (line 64)

Failure to load Python modules

Running the function circular(30) to test for a successful installation results in a few different errors, depending on the state of the Python environment. Errors thrown on call to:
py.importlib.import_module('mhkit');

No errors occurred when running the same function in Python (MHKiT-MATLAB)

Environment
Python = 3.9
Fresh Conda virtual environment (not base environment)

Errors
Error using _backend_tk> (line 22)
Python Error: RuntimeError: Failed to load Tk_FindPhoto
or
Python Error: RuntimeError: Failed to load Tcl_SetVar
or
Importing the numpy C-extensions failed

Add older releases of MATLAB to Github Actions

We should include a Github Action that tests the oldest MATLAB release that we claim is compatible with MHKiT-MATLAB.

I have found several compatibility issues running my 2020b release with some of the newer code.

Code Compatibility: VERLESSMATLAB

Code compatibility is reporting the following VERLESSMATLAB Info:

Identifier Severity Documentation Suppression File LineNumber ColumnRange
VERLESSMATLAB Info Details none mhkit/dolfyn/rotate/tensorproduct_core.m 6 5 15

Details:

VERLESSMATLAB Details (Info):

  • verLessThan('matlab', ...) is not recommended.
  • With appropriate code changes, use 'isMATLABReleaseOlderThan' instead.

jonswap_spectrum bug

Hello,

I found a bug in the jonswap_spectrum code for MHKiT Matlab. The elseif nargin == 4 line has the gamma value placed into the Hs and gamma part of the function. This causes incorrect formulation of the Jonswap function. The correct code is below as the Hs needs to be in the Hs spot of the python function. The gamma value should only change the peakiness of the spectrum, this can be easily seen when plotting the spectrum.

elseif nargin == 4
        S_py=py.mhkit.wave.resource.jonswap_spectrum(frequency,Tp,Hs,pyargs('gamma',varargin{1}));

Cheers,
Courtney

MHKiT-Matlab installation issues

Rebecca, I am having some trouble getting MHKiT-Matlab going. I have followed the installation instructions but no luck.

Pip show
image
mhkit-python in on origin master branch
mhkit-matlab is on the origin master as well

Add-On Manager shows the toolbox installed correctly
image

I am using python 3.8 with matlab 2020b (this was working before).

If I call the circular command I get an error with h5py.
image

Update Environmental Contour Code

The calls to Python code needs to be updated for the environmental_contours function and possibly other related contours functions.

MHKiT-MATLAB WPTO Hindcast Returns 503 Service Unavailable while MHKiT-Python Working Just Fine with the same API

Describe the bug:
I am using the same API for the exact location, requested parameter, and year, as mentioned in the example both using python and MATLAB. The Python module worked just fine, whereas the MATLAB module returned with 503 Service unavailable:
Error using Matlab.internal.webservices.HTTPConnector/copyContentToByteArray The server returned the status 503 with message "Service Unavailable" in response to the request to URL https://developer.nrel.gov/api/hsds/?api_key=qiaxEl3sgvbvvolnjTLelLTw2zZHPbvwu7uXJaKh&domain=%2Fnrel%2FUS_wave%2FWest_Coast%2FWest_Coast_wave_1995.h5.

Error in readContentFromWebService (line 46) byteArray = copyContentToByteArray(connection);

Error in webread (line 125) [varargout{1:nargout}] = readContentFromWebService(connection, options);

Error in request_wpto (line 72) root = webread(baseURL);

Unfortunately, I have to use MATLAB to streamline all the data traffic for the current project. Would you happen to have any idea to fix this?

To reproduce:
Using the same code provided in the example, just with a different API key:

data_type = '3-hour'; % setting the data type to the 3-hour dataset
year = (1995)';
lat_lon = [44.624076,-124.280097];
parameter = "significant_wave_height";
api_key ='qiaxEl3sgvbvvolnjTLelLTw2zZHPbvwu7uXJaKh';

Hs = request_wpto(data_type,parameter,lat_lon,year,api_key);

Expected behavior:
Returning struct file with Hs in timeseries format.

Hs.metadata

ans = struct with fields:
water_depth: 77.429496765136719
latitude: 44.624298095703125
longitude: -1.242789993286133e+02
distance_to_shore: 1.562217578125000e+04
timezone: -8
jurisdiction: 'Federal'

Desktop:
Windows Ver: Win 10
Matlab Ver: 2023a
Python Ver: 3.10
Mhkit Ver: 0.6.0

Thank you!
Danu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.