Welcome, Guest
Username: Password: Remember me

TOPIC: Python3 selafin.py script error

Python3 selafin.py script error 3 years 9 months ago #37811

  • MohdAlaa
  • MohdAlaa's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 76
  • Thank you received: 1
Hi,

I'm trying to extract time-series for several nodes using the TELEMAC extraction scripts, such as parser_selafin.

The scripts run smoothly in Python 2.7, but the Python 3 version gives me the following error when using the get_series function from selafin script:
File "C:\opentelemac-mascaret\trunk\scripts\python3\data_manip\formats\selafin.py", line 435, in get_series
    dtype=[('0', int), ('1', int)]),
TypeError: int() argument must be a string, a bytes-like object or a number, not 'zip'

Here is the line where the problem occurs:
      # ~~ Ordering the nodes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # This assumes that nodes starts at 1
        onodes = np.sort(np.array(zip(range(len(nodes)), nodes),
                                  dtype=[('0', int), ('1', int)]),
                         order='1')

Any idea what is the problem and how to fix it?

Thanks,
Mohammed
The administrator has disabled public write access.

Python3 selafin.py script error 3 years 8 months ago #37925

  • yugi
  • yugi's Avatar
  • OFFLINE
  • openTELEMAC Guru
  • Posts: 851
  • Thank you received: 244
Hi,

what version of telemac are you using ?
Could you post your code ?
There are 10 types of people in the world: those who understand binary, and those who don't.
The administrator has disabled public write access.

Python3 selafin.py script error 3 years 8 months ago #37927

  • MohdAlaa
  • MohdAlaa's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 76
  • Thank you received: 1
Hi,

I'm using V8P1r0.

Here is the code I used:
from data_manip.extraction.parser_selafin import subset_variables_slf,get_value_history
from data_manip.formats.selafin import Selafin
import os

fileName = "r3_Orkney14day130220.slf"
file3D = os.path.join(filePath, fileName)
slf = Selafin(file3D)

var_names=[item.rstrip() for item in slf.varnames]
varnames=[var_names[0:3]]
vars_indexes=[var_names.index('ELEVATION Z'),var_names.index('VELOCITY U'),var_names.index('VELOCITY V')]
times = slf.tags["times"] # print times
nodes = [246576,658083,1069590,1481097,1892604,2304111,2715618] # List of node numbers
series=slf.get_series(nodes, vars_indexes)

L1Z = series[0,0]
L2Z = series[0,1]
L3Z = series[0,2]
L4Z = series[0,3]
L5Z = series[0,4]
L6Z = series[0,5]
L7Z = series[0,6]
L1U=series[1,0]
L2U=series[1,1]
L3U=series[1,2]
L4U=series[1,3]
L5U=series[1,4]
L6U=series[1,5]
L7U=series[1,6]
L1V=series[2,0]
L2V=series[2,1]
L3V=series[2,2]
L4V=series[2,3]
L5V=series[2,4]
L6V=series[2,5]
L7V=series[2,6]

L=[times,L1U,L1V,L2U,L2V,L3U,L3V,L4U,L4V,L5U,L5V,L6U,L6V,L7U,L7V]

import numpy as np
Z=[L1Z,L2Z,L3Z,L4Z,L5Z,L6Z,L7Z]
U=[L1U,L2U,L3U,L4U,L5U,L6U,L7U]
V=[L1V,L2V,L3V,L4V,L5V,L6V,L7V]
VEL= U/np.cos(np.arctan2(V,U))
DIR= np.degrees(0.5 * np.pi-np.arctan2(V,U)) 
Time = [times]

import csv

with open('VEL.csv', 'wb') as csvfile:
    csv_writer = csv.writer(csvfile, delimiter=' ')
    csv_writer.writerow('\n')
    csv_writer.writerows(Time)
    csv_writer.writerow('\n')
    csv_writer.writerows(U)
    csv_writer.writerow('\n')
    csv_writer.writerows(V)
    csv_writer.writerow('\n')
    csv_writer.writerows(VEL)
    csv_writer.writerow('\n')
    csv_writer.writerows(DIR)
    csv_writer.writerow('\n')
    csv_writer.writerows(Z)


File Attachment:

File Name: parser_selafin.py
File Size: 21 KB


File Attachment:

File Name: selafin.py
File Size: 20 KB
The administrator has disabled public write access.

Python3 selafin.py script error 3 years 8 months ago #37928

  • yugi
  • yugi's Avatar
  • OFFLINE
  • openTELEMAC Guru
  • Posts: 851
  • Thank you received: 244
Hi,

It is indeed a bug replace the following line in selafin.py around line to solve it.
          # ~~ Ordering the nodes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                 
          # This assumes that nodes starts at 1
          onodes = np.sort(np.array(zip(range(len(nodes)), nodes),                                 
                                    dtype=[('0', int), ('1', int)]),                                     
                           order='1')  
          # ~~ Ordering the nodes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                 
          # This assumes that nodes starts at 1
          onodes = np.sort(np.array(list(zip(range(len(nodes)), nodes)),                                 
                                    dtype=[('0', int), ('1', int)]),                                     
                           order='1')  

By the way that class is deprecated we recommend using TelemacFile (from data_manip.extraction.telemac_file import TelemacFile) instead (you'll need to compile at least the hermes api).
There are 10 types of people in the world: those who understand binary, and those who don't.
The administrator has disabled public write access.
The following user(s) said Thank You: MohdAlaa, tomsail

Python3 selafin.py script error 3 years 2 weeks ago #39319

  • haozailao
  • haozailao's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 86
  • Thank you received: 1
Sorry to bother you.
I want to use TELEMAC extraction scripts to post-processing my results.
However I don't have any extract scripts.Where can I download these scripts?
Thanks advanced
The administrator has disabled public write access.

Python3 selafin.py script error 3 years 2 weeks ago #39320

  • PMV
  • PMV's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 149
  • Thank you received: 42
All python scripts are in C:\opentelemac-mascaret\v8p2r1\scripts\python3\
the extraction scripts in sub directory data_manip\extraction\

Patrick
The administrator has disabled public write access.

Python3 selafin.py script error 3 years 2 weeks ago #39328

  • haozailao
  • haozailao's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 86
  • Thank you received: 1
Thank you for your help!
It seems that I haven't download all the scripts automatically. I will download the script from the SVN.
Thanks!
The administrator has disabled public write access.
Moderators: borisb

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