Skip to main content

I have successfully created an FME Workspace Runner Python script that will launch Workbench (Desktop) and start an FME conversion process. This is an effort on my part to eventually sell the idea of purchasing FME Server.

Everything works quite well, with exception to one small glitch. I cannot seem to get the script to automatically retrieve the appropriate files (based on date as per below) to include in the process. Currently, before I run the Workspace Runner I need to first (manually) include all of the files that I would like FME to convert in an FME Reader, but I would like this step to run entirely from the Python script.

I think I know where the problem is (see below in blue), but I don't know how to remedy the parameters (if it's even possible).

The data in question is referred to as NMEA data (National Marine Electronics Association) and is basically Ship born GPS data that is standard in most GPS units today. Below is an example of the data files in the raw format as it comes in from our AIS (Automatic Identification System) feed. FME has no problem converting the data:

 

 

As mentioned, everything else in this script works exactly how it's supposed to work, but it would certainly be nice if I could get it to retrieve the appropriate NMEA files automatically.

 

Suggestions?

 

Thank you

I know there are many ways to do this, but if you want to use python to call the workspace, here is one option.

 

 

First I have my python script setup to run the workspace and pass the query date and the log file folder directory. FME will find all of the files in the folder directory that match the query date.

 

import sys
sys.path.append(r"C:\Program Files\FME\fmeobjects\python36")
import fmeobjects

# Initiate Runner
runner = fmeobjects.FMEWorkspaceRunner()

# Set workspace
workspace = r'PATH TO WORKSPACE'

# Date used for querying the log files YYYY-MM
query_date = '2020-01'

# Folder containing log files
log_file_folder = r'PATH TO LOG FILE FOLDER'

# Parameters to pass to workspace
parameters = {}
parameters '_date'] = query_date
parameterss'_log_file_folder'] = log_file_folder

try:
    runner.runWithParameters(workspace, parameters)
except fmeobjects.FMEException as ex:
    print(ex.message)
else:
    print('Workspace ran successfully.')
runner = None

 

Now in FME I'm using the Directory and File Pathnames reader with path filter of Log $(_date)*.nmea.

FME will only return the log files that match the date in the filename that you can send to the reader. I have it connected to a logger, but that would be the feature reader for NMEA. I hope this helps a little.

0684Q00000ArKFuQAN.png


I know there are many ways to do this, but if you want to use python to call the workspace, here is one option.

 

 

First I have my python script setup to run the workspace and pass the query date and the log file folder directory. FME will find all of the files in the folder directory that match the query date.

 

import sys
sys.path.append(r"C:\Program Files\FME\fmeobjects\python36")
import fmeobjects

# Initiate Runner
runner = fmeobjects.FMEWorkspaceRunner()

# Set workspace
workspace = r'PATH TO WORKSPACE'

# Date used for querying the log files YYYY-MM
query_date = '2020-01'

# Folder containing log files
log_file_folder = r'PATH TO LOG FILE FOLDER'

# Parameters to pass to workspace
parameters = {}
parameters '_date'] = query_date
parameterss'_log_file_folder'] = log_file_folder

try:
    runner.runWithParameters(workspace, parameters)
except fmeobjects.FMEException as ex:
    print(ex.message)
else:
    print('Workspace ran successfully.')
runner = None

 

Now in FME I'm using the Directory and File Pathnames reader with path filter of Log $(_date)*.nmea.

FME will only return the log files that match the date in the filename that you can send to the reader. I have it connected to a logger, but that would be the feature reader for NMEA. I hope this helps a little.

0684Q00000ArKFuQAN.png

Thanks very much Warren.  This actually does make sense, so I will spend some time working through your example and see if I can get it to work with my current FMW.  I'm still very much an FME rookie so it may take me a while to put the pieces in place, but then that's all a part of the learning process :-).

I have managed to make the appropriate changes to my Python script...I just need to make the addition to my FMW and then give it a try.

I will post again when I have something working...thanks again.


OK, I'm muddling my way through this, but I'm still missing some key elements, but would greatly appreciate a second set of eyes looking at what I have done. Would you be able to take a quick look?

I felt that adding images of my current FME FMW with your processes isolated as well as my Python script would help. As mentioned, I'm still very much an FME newbie and although I do get the gist of what is supposed to be happening here I'm still not sure of how to put it all together.

 

This is a layout of my main NMEA conversion FMW, and it does work; however, I just need to configure this so that when I run my FME Python script (below) it will read the necessary Log files:

The properties for each of the processes I got from you are:

Do I add your three processes to my already existing ones, or do I need to rewrite the entire conversion steps to make this work? I'm guessing I just need to add your 3 process steps to the beginning, but when I ran the FMW it wasn't reading anything...so obviously my configuration is leaving a lot to be desired 🙂.

My Python script looks like this (the additional libraries are here because this is really taken from a grand Python script that post processes all of our data before publishing to Portal):

Am I on the right path here?

Thank You.


OK, I'm muddling my way through this, but I'm still missing some key elements, but would greatly appreciate a second set of eyes looking at what I have done.  Would you be able to take a quick look?

I felt that adding images of my current FME FMW with your processes isolated as well as my Python script would help.  As mentioned, I'm still very much an FME newbie and although I do get the gist of what is supposed to be happening here I'm still not sure of how to put it all together.

 

This is a layout of my main NMEA conversion FMW, and it does work; however, I just need to configure this so that when I run my FME Python script (below) it will read the necessary Log files:

0684Q00000ArKJLQA3.png

The properties for each of the processes I got from you are:

0684Q00000ArJcdQAF.png

Do I add your three processes to my already existing ones, or do I need to rewrite the entire conversion steps to make this work?  I'm guessing I just need to add your 3 process steps to the beginning, but when I ran the FMW it wasn't reading anything...so obviously my configuration is leaving a lot to be desired :-).

My Python script looks like this (the additional libraries are here because this is really taken from a grand Python script that post processes all of our data before publishing to Portal):

0684Q00000ArKCwQAN.png

Am I on the right path here?

Thank You.

@prpa_gis,

I have attached an example workspace that will hopefully give you an idea of how to do it. Of course there are many ways to accomplish this, so this is one of them. 

The python script is passing the values of the folder path and the date string to the FME workspace user parameters.

import sys
sys.path.append(r"C:\Program Files\FME\fmeobjects\python36")
import fmeobjects
 
# Initiate Runner
runner = fmeobjects.FMEWorkspaceRunner()
 
# Set workspace
workspace = r'PATH TO WORKSPACE HERE'
 
# Date used for querying the log files YYYY-MM
query_date = '2020-01'
 
# Folder containing log files
log_file_folder = r'PATH TO LOG FOLDER HERE'
 
# Parameters to pass to workspace
parameters = {}
parameterse'_date'] = query_date
parametersP'_log_file_folder'] = log_file_folder
 
try:
    runner.runWithParameters(workspace, parameters)
except fmeobjects.FMEException as ex:
    print(ex.message)
else:
    print(f'{workspace} workspace ran successfully.')
runner = None

 

The FME workspace will read the log file paths in the feature reader with the filter of: 

0684Q00000ArMPLQA3.png

 

This will return only the .nmea files that contain the date string that was set in our python script. These file paths will then be sent to the NMEA reader. From there you will need to connect your additional processing. This way all files that match the date string of year and month will be processed in the workspace.

 

The example below shows my folder containing 3 .nmea log files. Only 2 of the files match the date string in my python script of 2020-01, so only the 2 files are processed in the workspace. The file labeled in February is skipped.

0684Q00000ArMMNQA3.png

 

0684Q00000ArMPQQA3.png

 

nmea_reader.fmw


Reply