Skip to content

Problems writing nontationary SWAN 2D spec files #20

@mwandres

Description

@mwandres

Hi,

First of all thanks for this great Toolbox and sorry about the rather long message.
I'm having issues trying to write nonstationary 2D spectra files for SWAN and I'm not sure if I'm doing something wrong or if there's a bug but also haven't dug into the code too much.

The first issues I'm having is to include nonstat directions into my spectra:

frequency = np.arange(0.03,1.,.01)
direction = np.arange(0,360,1)
time = [datetime(2013,12,1), datetime(2013,12,2)]
Hs = [3.,5.]
Tp = [11.,13.]
theta_p = [200,250]

ow = oceanwaves.OceanWaves(time = time)#, frequency = frequency, direction = direction)
ow['_energy'].values = Hs
ow_spc = ow.as_spectral(frequency,Tp = Tp)
ow_dir = ow_spc.as_directional(direction, theta_peak = theta_p)

Gives me the following error

C:\ProgramData\Anaconda3\lib\site-packages\oceanwaves\oceanwaves.py:206: RuntimeWarning: invalid value encountered in greater
if self._isvalid(frequency, mask=frequency>0) and spectral:
Traceback (most recent call last):

File "", line 11, in
ow_dir = ow_spc.as_directional(direction, theta_peak = theta_p)

File "C:\ProgramData\Anaconda3\lib\site-packages\oceanwaves\oceanwaves.py", line 883, in as_directional
expand_dims=ix_direction

File "C:\ProgramData\Anaconda3\lib\site-packages\oceanwaves\utils.py", line 85, in expand_and_repeat
'dimensions (%d).' % (len(shape) - mtx.ndim, len(expand_dims)))

ValueError: Dimensionality of the target shape minus the number of matrix dimensions (2) should match the number of expanding dimensions (1).

Not sure why it won't allow me to enter 2 different values of theta_p?

Irrespective of that - if I leave theta_p alone and just do

ow_dir = ow_spc.as_directional(direction)

It works but if I go on to try to do

ow_dir.to_swan('TEST.SP2')

I get

C:\ProgramData\Anaconda3\lib\site-packages\oceanwaves\oceanwaves.py:206: RuntimeWarning: invalid value encountered in greater
if self._isvalid(frequency, mask=frequency>0) and spectral:
Traceback (most recent call last):

File "", line 14, in
ow_dir.to_swan('TEST.SP2')

File "C:\ProgramData\Anaconda3\lib\site-packages\oceanwaves\swan.py", line 556, in call
self.write(fpath)

File "C:\ProgramData\Anaconda3\lib\site-packages\oceanwaves\swan.py", line 563, in write
k = self._key_lookup('_time')

AttributeError: 'SwanSpcWriter' object has no attribute '_key_lookup'

I had a look at the source code swan.py as this is where the error appears to be and I think line 563 should be

k = self.obj._key_lookup('_time') rather than k = self._key_lookup('_time')

When changing that it actually writes out my .SP2 file however it splits them in TEST_000.SP2 and TEST_001.SP2. Both files have the long header with the direction and frequency information but without any time info. Any idea what's happening or any suggestions what I could do differently?

Any help is much appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions