MHKiT-Software / MHKiT-Python

MHKiT-Python provides the marine renewable energy (MRE) community tools for data processing, visualization, quality control, resource assessment, and device performance.
https://mhkit-software.github.io/MHKiT/
BSD 3-Clause "New" or "Revised" License
51 stars 45 forks source link

Feature Request: Directional Spectra from NDBC buoys #191

Closed pbranson closed 2 years ago

pbranson commented 2 years ago

A comment raised in OREC workshop was about getting directional spectral data from NDBC and it sounded like there was some code available. I would be interested in learning how to do that and helping to create a function.

Thanks!

ssolson commented 2 years ago

Hey, @pbranson thanks for dropping by and for your interest in MHKiT!

My name is sters and I would love to show you around and help get you up to speed on MHKiT-python. The API Docs are here where you can see NDBC under the wave module, io submodule.

The best way to get started using the NDBC code is by running the Environmental Contours example notebook here.

The specific function you are interested in is wave.io.ndbc.request_data(). This function calls on data hosted by NDBC here. Adding any of the variables to MHKiT on this page is quite easy (see #152 for an example where we added the cwind parameter).

So I think the first step is to familiarize yourself with the example notebook linked above and then if you can show me what data you are specifically looking to use we can work from there. Thanks again @pbranson and I look forward to helping you create this function.

cmichelenstrofer commented 2 years ago

@ssolson This is an important feature request. I got it from at least 3 different people at the OREC workshop. Currently we are only getting the (omnidirectional) spectrum from NDBC (the SWDEN file). Getting the directional spectrum requires pulling 5 different files and processing them (there's an equation in the NDBC website). I have done this for myself in Julia. I can take on implementing it in MHKiT/Python. Hopefully, I have some time next week.

Also, I think in general we need to improve our directional data gathering from different sources. This seems to be something more and more people have an interest in now. See also #166 and #65

cmichelenstrofer commented 2 years ago

from: https://www.ndbc.noaa.gov/measdes.shtml

Directional Wave Spectrum = C11(f) * D(f,A),

  • f=frequency (Hz), A=Azimuth angle measured clockwise from true North to the direction wave is from.
  • D(f,A) = (1/PI)(0.5+R1COS(A-ALPHA1)+R2COS(2(A-ALPHA2))).
  • R1 and R2 are the first and second normalized polar coordinates of the Fourier coefficients and are nondimensional.
  • ALPHA1 and ALPHA2 are respectively mean and principal wave directions.In terms of Longuet-Higgins Fourier Coefficients

with:

  • R1 = (S QRT(a1a1+b1b1))/a0
  • R2 = (SQRT(a2a2+b2b2))/a0
  • ALPHA1 = 270.0-ARCTAN(b1,a1)
  • ALPHA2 = 270.0-(0.5*ARCTAN(b2,a2)+{0. or 180.})

Notes:

  • The R1 and R2 values in the monthly and yearly historical data files are scaled by 100, a carryover from how the data are transported to the archive centers. The units are hundredths, so the R1 and R2 values in those files should be multiplied by 0.01.
  • D(f,A) can take on negative values because of the trigonometric sine and cosine functions. There are several approaches to prevent or deal with the negative values. For more information and discussion of some approaches see: Use of advanced directional wave spectra analysis methods, M. D. Earle, K. E. Steele, and D. W. C. Wang, Ocean Engineering, Volume 26, Issue 12, December 1999, Pages 1421-1434.
  • ALPHA2 has ambiguous results in using the arctangent function with the Fourier Coefficients,b 2 ,a 2 . When necessary, NDBC adds 180 degrees to ALPHA2 in order to minimize the difference between ALPHA 1 and ALPHA2.