Skip to main content
Question

Read Hierarchical in Python

  • July 29, 2018
  • 7 replies
  • 21 views

danilo_fme
Celebrity
Forum|alt.badge.img+51

Hi ,

I have a script Python to read the Hierarchical from a format. First I extract this format with the library and after try to read the folder. In Pycharm is works:

result = Format [subfolder]

My question is: how can I do this structure in PythonCaller? I did try without success:

feature.setAttribute('Format[subfolder]',result)

 

Thanks,

Danilo

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

danilo_fme
Celebrity
Forum|alt.badge.img+51
  • Author
  • Celebrity
  • August 1, 2018
:)

 

 


takashi
Celebrity
  • August 1, 2018

I cannot understand what you intend to achieve with this code.

feature.setAttribute('Format[subfolder]',result)
If the 'feature' is an instance of fmeobjects.FMEFeature class, the code above performs to assign the value contained by a variable called 'result' to a feature attribute named 'Format[subfolder]'.

Is it actually your intention? If so, what value does the variable 'result' contain, and how did you create the value in the script?


danilo_fme
Celebrity
Forum|alt.badge.img+51
  • Author
  • Celebrity
  • August 1, 2018

Hi @takashi

 

My example is read Hierarchical from a file :

Format = Brasilia.dat

Subfolder = /Month / Day ( Hierarchical from Brasilia.dat )

How can I read this structure in PythonCaller, instead in PyCharm it works :

result = Format [subfolder]

Thanks your help

 


takashi
Celebrity
  • August 1, 2018

Hi @takashi

 

My example is read Hierarchical from a file :

Format = Brasilia.dat

Subfolder = /Month / Day ( Hierarchical from Brasilia.dat )

How can I read this structure in PythonCaller, instead in PyCharm it works :

result = Format [subfolder]

Thanks your help

 

I don't know what the Hierarchical is, but the same codes should also work with a PythonCaller, if those work as expected with PyCharm debugger. Of course, you have to import the same module(s) that you are using in the source tested with PyCharm.

 


danilo_fme
Celebrity
Forum|alt.badge.img+51
  • Author
  • Celebrity
  • August 4, 2018

I cannot understand what you intend to achieve with this code.

feature.setAttribute('Format[subfolder]',result)
If the 'feature' is an instance of fmeobjects.FMEFeature class, the code above performs to assign the value contained by a variable called 'result' to a feature attribute named 'Format[subfolder]'.

Is it actually your intention? If so, what value does the variable 'result' contain, and how did you create the value in the script?

Hi @takashi

 

My code is:

 

def processFeature(feature):

 with h5py.File(Format,'r') as f:

feature.setAttribute('f[subfolder]',result) 
But the attribute result doenst show nothing. 

 

 

Thanks,

 

Danilo

 


takashi
Celebrity
  • August 5, 2018

I cannot understand what you intend to achieve with this code.

feature.setAttribute('Format[subfolder]',result)
If the 'feature' is an instance of fmeobjects.FMEFeature class, the code above performs to assign the value contained by a variable called 'result' to a feature attribute named 'Format[subfolder]'.

Is it actually your intention? If so, what value does the variable 'result' contain, and how did you create the value in the script?

Looks like you intend to retrieve a group called 'subfolder' recorded in an HDF5 file using the 'h5py' module.

 

Assuming that the input feature has an attribute called "_hdf5filepath" storing file path to the source HDF5 file which contains a group named 'subfolder', this script retrieves the content of 'subfolder' group and saves it as a string value into a new attribute called "f[subfolder]".

 

import h5py
def processFeature(feature):
    Format = feature.getAttribute('_hdf5filepath')
    with h5py.File(Format, 'r') as f:
        group = f['subfolder']
        feature.setAttribute('f[sobfolder]', '%s' % group) 
Since FME Desktop doesn't bundle the 'h5py' module by default, you have to install the package to your FME Desktop.

 

Installing Python Packages to FME Desktop

 

And see here to learn more how to use the 'h5py' module: HDF5 for Python

 


danilo_fme
Celebrity
Forum|alt.badge.img+51
  • Author
  • Celebrity
  • August 6, 2018
Looks like you intend to retrieve a group called 'subfolder' recorded in an HDF5 file using the 'h5py' module.

 

Assuming that the input feature has an attribute called "_hdf5filepath" storing file path to the source HDF5 file which contains a group named 'subfolder', this script retrieves the content of 'subfolder' group and saves it as a string value into a new attribute called "f[subfolder]".

 

import h5py
def processFeature(feature):
    Format = feature.getAttribute('_hdf5filepath')
    with h5py.File(Format, 'r') as f:
        group = f['subfolder']
        feature.setAttribute('f[sobfolder]', '%s' % group) 
Since FME Desktop doesn't bundle the 'h5py' module by default, you have to install the package to your FME Desktop.

 

Installing Python Packages to FME Desktop

 

And see here to learn more how to use the 'h5py' module: HDF5 for Python

 

Excellent. Thanks!