A library of CDO decorators

For those that use both Python and CDO, I wrote a library of function decorators that tries to make it easier to read, write and understand CDO command chains.

The motivation was that CDO commands can be long and confusing (it’s my no.1 criticism of CDO). Because of the shell syntax of command input output, in order to read/write them, you have to start at the end of the command and read backwards. Filenames can also be very long. The python bindings don’t make this much easier because you have to pass the shell formatted command chain to the input keyword argument of the CDO commands and it just ends up looking the same.

The python CDO interface developers are working on a new object oriented syntax that uses method calls that are chained together, but that’s just not ready yet. I wanted something where I could list the chained commands vertically and be able to see everything in the same page and the exact order in which they are done.

If you’re comfortable with using function decorators in python, maybe you will find this useful.


Cc @atteggiani

Nice idea and implementation @tammasloughran.

I’ve only used cdo sporadically, but one of it’s “killer features” was operator chaining, which offers the possibility of doing away with the lots of intermediate files (that’s my no.1 criticism of nco and cdo if chaining isn’t used).

The larger the files being operated on, the greater the incentive to chain operations and avoid large amounts of of temporary files.

Unfortunately I found operator chaining consumed outsized amounts of memory such that it became unusable. I wish I could provide details, but it was some time ago. Are you aware if this is still a problem?

Summary: the data for which operator chaining was most useful was also too large and caused memory issues.

I haven’t run into this problem. Perhaps the data I typically use is not so large (lower resolution ESMs). In which case, it suited me well for rote operations that I don’t want to think too hard about. I’m sure mileage varies for different folk.

1 Like