Project

General

Profile

Assembling a chain with python bindings

Added by Brendan DeTracey over 3 years ago

I have looked at the python examples here (https://github.com/Try2Code/cdo-bindings/blob/master/python/test/test_cdo.py) . What is missing for me is an example of how to build a chain whose operators are determined conditionally. Is there a way to initialize a chain, successively add operators, and then start it? An illogical dummy example:

cdo = Cdo()
ofile = cdo.setname("veloc")
if dark_matter:
    cdo.append_to_chain(copy.random("r1x1"))
else:
    cdo.append_to_chain(copy.topo("r1x1"))
cdo.append_to_chain(add_option("-f nc"))
cdo.run()

Not knowing how to do this, or whether it is possible, is one reason I have not started using the python bindings. The ability to do this would also allow using function pointers and python's functools when assembling chains.
I also do not see how to use braket with the new chaining method.

Lastly, in the example test_pychain2, why is it:

ofile1 = cdo.setname("veloc").copy.random("r1x1").add_option("-f nc").run()

instead of:
ofile1 = cdo.setname("veloc").random("r1x1").add_option("-f nc").run()

Is copy required between each link in the chain?


Replies (2)

RE: Assembling a chain with python bindings - Added by Brendan DeTracey over 3 years ago

Would it be:

cdo = Cdo()
ofile = cdo.setname("veloc")
if dark_matter:
    cdo.copy.random("r1x1")
else:
    cdo.copy.topo("r1x1")
cdo.add_option("-f nc")
cdo.run()

?

    (1-2/2)