09-08-2021 02:55 AM
The python node reads the input path as input to the python node. Then python script reads a txt file and extracts some information and, finally, converts the file type into another format (mseed). The python node non return value so I leave it unattached and python error complains. Kindly, download the attached file for more information.
Solved! Go to Solution.
09-08-2021 02:54 PM - edited 09-08-2021 03:50 PM
The python node reads the input path as input to the python node. Then python script reads a txt file and extracts some information and, finally, converts the file type into another format (mseed). The python node in Labview non return value so I leave it unattached and python node gives the following error.
from __future__ import print_function
from __future__ import print_function
import numpy as np
from obspy import UTCDateTime, read, Trace, Stream
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
def lvm_to_mseed(file_path):
file_path="file_path"
f = open(file_path, "r")
for i in range (23):
line=f.readline()
if i==20:
line=line.strip()
t,delta=line.split()
sr=int(1/float(delta)) #sr: sampling rate
print(sr)
data=[]
for line in f :
line=line.strip()
#R=print(line.split())
value=line.split()
data.append(value[0])
#S=f.read()
data=np.array(data,dtype='float64')
#print(data)
f = open("test_287.lvm", "r")
for i in range (24):
line=f.readline()
if i==23:
line=line.strip()
#print(line.split())
V,x,c,v,b,L,lat,long,S,D,T=line.split()
L=c
latitude=lat
longitude=long
#print('latitude=',latitude)
#print('longitude=',longitude)
date=D
time=T[0:11]
#print("date: ",date)
#print("Time: ",time)
stats = {'network': 'HL', 'station': 'Test', 'location': '',
'channel': 'HHZ', 'npts': len(data), 'sampling_rate':sr,
'mseed': {'dataquality': 'D'}}
# set current time
stats['starttime'] = UTCDateTime().strptime(date+" "+time,format="%d/%m/%Y %H:%M:%S.%f") #formate is needed for date to convert / to - in date
st = Stream([Trace(data=data, header=stats)])
# write as ASCII file (encoding=0)
st.write("event.mseed", format='MSEED')
09-08-2021 03:35 PM
I believe that at your function definition line, file_path should not be in quotes. Also should not be in quotes in the line below that, unless you happen to be trying to open an extension-less file called "file_path" right there.
Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.
09-08-2021 03:47 PM
Great Thanks, Eng. Redhawk for your cooperation. I edit your notes but the error still appears.
09-08-2021 03:57 PM
@Emad_NRIAG wrote:def lvm_to_mseed(file_path): file_path="file_path" f = open(file_path, "r")
Now you're just taking whatever you put for file_path, and replacing it with the literal string "file_path" before you try to open it. Remove that second line.
Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.
09-08-2021 04:07 PM
I removed the second line and run the python node, but same error appears (Python returned the following error: <class 'TypeError'> lvm_to_mseed() missing 1 required positional argument: 'file_path').
09-08-2021 04:22 PM
I do believe all that needed to be fixed or it wouldn't work, but after looking at the Detailed Help for Python Node, I believe the issue is with the way it's being wired. The gray input terminal is just meant to specify a return value data type, and the Help says it should be unwired if the function doesn't return anything. The white terminals (which you have to drag down on the Python Node to make) are where you wire your input parameters.
If that's not your issue, then I'm at a loss.
Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.
09-08-2021 04:40 PM
Thank you so much, Eng. Redhawk. Your suggestion solve my problem and make me happy 🙂
Best Regards