I am trying to process some netcdf files while operator chaining for speed in python. When I chain more than two operators, I get an "too many inputs" error.
Testing the generated cdo command shows that the problem is the dash ('-') in front of the first operator. If I remove the dash and then run the command manually, it completes. Similarly, if I only use one chain (outcomment the "f'{terms} '" line in the code below), the script completes successfully.
I have not tested it without the sellonlatbox operator. But reordering the operators leads to the same result.
How can I successfully chain more than two operators?
- Code + output is below.
- Code extracted from some longer piece, therefore contains var-names to keep the original structure / combining code in case something is obviously wrong there. Sorry for the non-runability.
- cdo 2.1.1 on (K)Ubuntu 23.04
The code:
terms = '-mulc,0.1'
bounding_box = '-2.2,-1.4,34.8,35.2'
str_chname = (
f'-chname,{source_name},{target_name} '
f'{terms} '
f"{os.path.join(dir_input, f'fn_in}_{year}.nc')}"
)
cdo.sellonlatbox(bounding_box,
input=str_chname,
output=os.path.join(output_dir,
f'{fn_out}.nc'))
Results in:
Error in calling operator sellonlatbox with:
>>> cdo -O -s -sellonlatbox,-2.2,-1.4,34.8,35.2 -chname,strd,lwdown −mulc,0.1 in/input.nc out/output.nc<<<
<snip>
^ To many inputs
Thank you for your help.