Skip to main content
Solved

accessing published parameters in custom transformer with pythoncaller


pruiter
Contributor
Forum|alt.badge.img
Hi All,

 

 

I've been working all day on the following issue (fme2009). I have a small custom transformer to log some information to a seperate log, this logging is done using a pythoncaller. I want to use this custom transformer on several places in my model, and retreive custom messages using published parameters.

 

 

How do I access these published parameters, I know that within custom transformers I should use FME_MacroValues['transformer name_published parameter name'], however the transformer name is the name of the transformer in the main model, and as such always unique.

 

 

Does anyone have suggestions to solve this issue?

 

 

Paul

Best answer by david_r

Hi Paul,

 

 

it won't make any difference if you upgrade FME, the behaviour is the same in FME2013.

 

 

The easiest solution is to use a ParameterFetcher to get the parameter as an attribute. You can then get the value the same way as your other attributes inside the PythonCaller.

 

 

I also recommend using an AttributeRemover at the end of the custom transformer to remove this temporary attribute (best practice).

 

 

David
View original
Did this help you find an answer to your question?
<strong>This post is closed to further activity.</strong><br /> It may be a question with a best answer, an implemented idea, or just a post needing no comment.<br /> If you have a follow-up or related question, please <a href="https://community.safe.com/topic/new">post a new question or idea</a>.<br /> If there is a genuine update to be made, please contact us and request that the post is reopened.

8 replies

fmelizard
Safer
Forum|alt.badge.img+19
  • Safer
  • May 28, 2013
Hi Paul,

 

 

It seems to me you are doing it correctly, the only suggestion I can think of is to upgrade FME, since there are bound to be some major improvements from 2009 to 2013.

 

 

david_r
Celebrity
  • Best Answer
  • May 28, 2013
Hi Paul,

 

 

it won't make any difference if you upgrade FME, the behaviour is the same in FME2013.

 

 

The easiest solution is to use a ParameterFetcher to get the parameter as an attribute. You can then get the value the same way as your other attributes inside the PythonCaller.

 

 

I also recommend using an AttributeRemover at the end of the custom transformer to remove this temporary attribute (best practice).

 

 

David

pruiter
Contributor
Forum|alt.badge.img
  • Author
  • Contributor
  • May 29, 2013
I'm bound at 2009 untill the customer upgrades. I've implemented the parameterfetcher and this indeed works! Thanks for the suggestion.

 

 

I'm running in another small issue now, I  log a closing message in close(self). However it seems close is called only when the whole model ends, so I get multiple close messages at the end of the log from the different custom transformers. Is this expected behaviour and is there a way to fix this?

 


takashi
Evangelist
  • May 29, 2013
Hi Paul,

 

 

the close(self) method will be called at the end of each PythonCaller processing. It's normal behavior. When do you need to log messages?

 

 

Takashi

pruiter
Contributor
Forum|alt.badge.img
  • Author
  • Contributor
  • May 29, 2013
Hi Takashi,

 

 

I need to log messages at the start and end of the pythoncaller.

 

the pythoncaller uses the python logger to log to an external log file and looks something like:

 

class CustomLogger(object):     def __init__(self):         path = <logfile location>         logging.basicConfig(<>)         self.logger = logging.getLogger("test1")         #self.logger.info("start test log")              def input(self,feature): <do something>         self.pyoutput(feature)

 

      def close(self):         self.logger.info('end test log')

 

 

this is in a custom transformer, that is used twice. When i look at the output log file, it shows

 

start test log

 

start test log

 

end test log

 

end test log

 

 

instead of

 

start test log

 

end test log

 

start test log

 

end test log

 

 

I assume all features are passed through a transformer before they continue to another transformer?

 

 

peter_s
Contributor
Forum|alt.badge.img+4
  • Contributor
  • May 29, 2013
>I assume all features are passed through a transformer before they continue to another transformer?

 

- It really depends on how you connect things and what transformers are used. You can find some input on this behavior here: http://fmepedia.safe.com/articles/FAQ/Group-Based-Transformers

 

 

Also a good way to investigate how features are passed around is using inspection points in FME Workbench.

 

 

If, for example, the two custom transformers are connected in series with a sorter in between you might get the second behavior:

 

>start test log

 

>end test log

 

>start test log

 

>end test log

takashi
Evangelist
  • May 29, 2013
Hi Paul,

 

 

Peter is right. That is concerned with how features flow.       def input(self, feature):         <do something>         self.pyoutput(feature)   This coding does process and output features one by one, so features can go to the next transformer before processing of this transformer finishes. The following example behaves like Group-Based transformer, it would generate your expected result if you connect two transformers in a series. But, note this might cause decline in efficiency a little.   class CustomLogger(object):     def __init__(self):         ...         self.logger.info("start test log")         self.featureList = []              def input(self, feature):         <do somthing>         self.featureList.append(feature)       def close(self):         self.logger.info('end test log')         for feature in self.featureList:             self.pyoutput(feature)

 

 

Takashi

pruiter
Contributor
Forum|alt.badge.img
  • Author
  • Contributor
  • May 29, 2013
Ah ok now I understand, was under the impression it would always go through the transformers 1 by 1.

 

 

I will do some tests to see how big the effect on performance is. At least now I can explain why the order of entries in the logfile might look unexpected.

 

 

Thanks all,

 

Paul

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings