LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Having problem with python node

Solved!
Go to solution

 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.

 

0 Kudos
Message 1 of 8
(3,761 Views)

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')

 

 

 

Capture.PNGLabview error.PNG

 

 

0 Kudos
Message 2 of 8
(3,716 Views)

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.

Redhawk
Test Engineer at Moog Inc.

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.

0 Kudos
Message 3 of 8
(3,705 Views)

Great Thanks, Eng. Redhawk for your cooperation. I edit your notes but the error still appears.

0 Kudos
Message 4 of 8
(3,699 Views)

@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. 

Redhawk
Test Engineer at Moog Inc.

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.

0 Kudos
Message 5 of 8
(3,692 Views)

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').

0 Kudos
Message 6 of 8
(3,687 Views)
Solution
Accepted by topic author Emad_NRIAG

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.

 

Spoiler
FireFistRedhawk_0-1631136140753.png

 

Redhawk
Test Engineer at Moog Inc.

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.

0 Kudos
Message 7 of 8
(3,682 Views)

Thank you so much, Eng. Redhawk. Your suggestion solve my problem and make me happy 🙂

Best Regards

0 Kudos
Message 8 of 8
(3,676 Views)