Welcome, Guest
Username: Password: Remember me

TOPIC: MEAN DIRECTION AS ARROWS

MEAN DIRECTION AS ARROWS 1 year 6 months ago #41508

  • josiastud
  • josiastud's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 132
  • Thank you received: 2
HI everybody,
Is it possible to have or see the results of directions (mean direction...) in the form of arrows too.
The administrator has disabled public write access.

MEAN DIRECTION AS ARROWS 1 year 6 months ago #41510

  • tfouquet
  • tfouquet's Avatar
  • OFFLINE
  • Moderator
  • Posts: 287
  • Thank you received: 105
Hello,

I found this script in my python scripts that should do the job.

replace the extension txt by py

hope it helps

Thierry
Attachments:
The administrator has disabled public write access.
The following user(s) said Thank You: josiastud

MEAN DIRECTION AS ARROWS 1 year 6 months ago #41520

  • josiastud
  • josiastud's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 132
  • Thank you received: 2
Hi Thierry,
thx for your script, in fact I am not accustom to scripting, so I install ninja-IDE, made some modification till no error message, run the script and I see an input bar, what do I do next please, or Have I done something wrong or forgot a step??

#!/usr/bin/env python3
# -*- coding: utf-8 -*
"""
plot results as arrow.
"""
import numpy as np
from postel.plot2d import plot2d_scalar_map, plot2d_vectors
from data_manip.extraction.telemac_file import TelemacFile
import matplotlib.pyplot as plt

file_toma = '/home/ben/telemac/v8p3r1/CAS_PASP/FS_T3D_TOM/RT_L23DS5ds1_U.slf'
res_toma = TelemacFile(file_toma, access='r')
hm0 = res_toma.get_data_value("WAVE HEIGHT HM0", -1)
theta = res_toma.get_data_value("MEAN DIRECTION", -1)
dirx_wave = np.sin(theta*np.pi/180.)
diry_wave = np.cos(theta*np.pi/180.)
fig, axes = plt.subplots(1, 1, figsize=(14, 12))
plot2d_scalar_map(fig, axes,
res_toma.tri, hm0, data_name='Wave Height Hm0 (m)')
plot2d_vectors(fig, axes, res_toma.tri, dirx_wave, diry_wave,
grid_resolution=[25, 25],
data_name='wave direction', colorbar=False)
name = 'hm0.png'
fig.savefig(name)
plt.close(1)
Attachments:
The administrator has disabled public write access.

MEAN DIRECTION AS ARROWS 1 year 6 months ago #41511

  • NZrigat
  • NZrigat's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 65
  • Thank you received: 15
Hi,

I normally write a script to generate a selafin file-using PPUTILS Python toolkit- with a new variable named "wave significant height along xy", where I read HM0 & Mean direction from the simulation results selafin then rearrange that into wave height along x and y- I took inspiration from how wind files are written. Then you can view the selafin using Blue Kenue and it'll give you the direction and magnitude of your wave. Hope that helps- cant still provide further help with the script if needed.

Cheers,
Nayef
The administrator has disabled public write access.
The following user(s) said Thank You: josiastud

MEAN DIRECTION AS ARROWS 1 year 6 months ago #41519

  • josiastud
  • josiastud's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 132
  • Thank you received: 2
Hi Nayef,
Yes It is needed please,
thx
The administrator has disabled public write access.

MEAN DIRECTION AS ARROWS 1 year 6 months ago #41522

  • NZrigat
  • NZrigat's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 65
  • Thank you received: 15
Hi Josias,

First you need to install/clone PPUTILS tool kit from the following GitHub Repository (hope you're familiar with Git)

github.com/pprodano/pputils

Normally I place all contents of this repo (directly) in this directory: C:\opentelemac-mascaret\v8p3\scripts\python3 because I'd want to add these tools to my TELEMAC scripts. Then create a new folder and name it "posttools" and place the attached script in it (HS_VEC.py). Also, Add the file (myscript.py) to the python3 (script that you'll be running). You should edit the content of myscript.py to match your Selafin file name and number of days wanted (you can use fractions for hours). For example: (name of selafin:SELAFIN.slf and 2 days of simulation is needed)

from posttools.HS_VEC import *
HS_VEC('SELAFIN.slf', 2)


Finally, open you command prompt window (cmd) and change directory to python3 folder then type in: python myscript.py

After a minute you'll find your new selafin with directional wave heights. probably there are shorter ways to do this but here's one that's guaranteed to work. Hope this helps..

Cheers,
Nayef
Attachments:
The administrator has disabled public write access.
The following user(s) said Thank You: josiastud

MEAN DIRECTION AS ARROWS 1 year 6 months ago #41523

  • NZrigat
  • NZrigat's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 65
  • Thank you received: 15
Here's the other file I forgot to attach it I guess..
Attachments:
The administrator has disabled public write access.
The following user(s) said Thank You: josiastud

MEAN DIRECTION AS ARROWS 1 year 6 months ago #41570

  • josiastud
  • josiastud's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 132
  • Thank you received: 2
hi everybody,
Hi Tfouquet,
when trying to run your script I got this error
(<class 'ModuleNotFoundError'>, ModuleNotFoundError("No module named 'postel'",), <traceback object at 0x7f7750712108>)


Screenshotfrom2022-11-1707-53-28.png



The only one thread I found about this kind of error is www.opentelemac.co.uk/index.php/communit...ermes?start=50#38552
#38552

I don't know How to adapt it to my case, or even if it is efficient...

anyway


sources_postel3d_direct_.png



scripts_python3_postel.png
The administrator has disabled public write access.

MEAN DIRECTION AS ARROWS 1 year 6 months ago #41571

  • josiastud
  • josiastud's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 132
  • Thank you received: 2
Hi everybody,
Sorry TFouquet, I run successfully your script, thx to the instructions given by nayef to put the script in the directory /home/ben/telemac/v8p3r1/scripts/python3 ,

sorry for not being familiar with python scripting due to my previous numerous fails to properly learn python and programming languages by myself, Now I think it is different, I am encouraged to do so, thank you both guys.

In fact Nayef I am not familiar with installing and cloning from git :laugh:

thx for your help

Josias
The administrator has disabled public write access.
Moderators: tfouquet

The open TELEMAC-MASCARET template for Joomla!2.5, the HTML 4 version.