Project

General

Profile

Problem creating temp data with python bindings when forceOutput is False

Added by XR Chua about 1 year ago

I found that setting forceOutput as false leads to problems creating a file and using returnXDataset=True. Not sure if it is a bug, but documenting it here in any case.

With forceOutput=False:
```

import cdo as Cdo
cdo = Cdo.Cdo(forceOutput=False)
cdo.topo("r240x120",returnXDataset=True)

[]
```
With forceOutput=True:
```

import cdo as Cdo
cdo = Cdo.Cdo(forceOutput=True)
cdo.topo("r240x120",returnXDataset=True)

<xarray.Dataset>
Dimensions: (lon: 240, lat: 120)
Coordinates: * lon (lon) float64 0.0 1.5 3.0 4.5 6.0 ... 352.5 354.0 355.5 357.0 358.5 * lat (lat) float64 -89.25 -87.75 -86.25 -84.75 ... 86.25 87.75 89.25
Data variables:
topo (lat, lon) float32 ...
Attributes:
CDI: Climate Data Interface version 2.1.1 (https://mpimet.mpg.de...
Conventions: CF-1.6
history: Tue Mar 28 15:34:57 2023: cdo -O -s -f nc -topo,r240x120 /t...
CDO: Climate Data Operators version 2.1.1 (https://mpimet.mpg.de...

```

This is from version 1.5.7 of the bindings and v2.1.1 of CDO.


Replies (4)

RE: Problem creating temp data with python bindings when forceOutput is False - Added by Ralf Mueller about 1 year ago

hi!
thx for the report. I will check this. The forceOutput keyword is designed to work with real output files on disk, though.

cheers
ralf

RE: Problem creating temp data with python bindings when forceOutput is False - Added by XR Chua about 1 year ago

Hi Ralf,

Thanks. It would be nice to be able to have both temporary files with forceOutput set to False so that a script can have both conditional processing and tempfile handling.

I wonder if removing the kwargs['force'] in line 508 of https://github.com/Try2Code/cdo-bindings/blob/master/python/cdo.py would do it.

Unless you recommend doing something like the following instead?

import cdo as Cdo
cdo_force_false = Cdo.Cdo(forceOutput=False)
cdo_force_true = Cdo.Cdo(forceOutput=True)
cdo_force_true.topo("r240x120",returnXDataset=True)
cdo_force_false.seltimestep("-1",input=files_from_running_expt)

RE: Problem creating temp data with python bindings when forceOutput is False - Added by Ralf Mueller about 1 year ago

XR Chua wrote in RE: Problem creating temp data with python bindings when ...:

Hi Ralf,

Thanks. It would be nice to be able to have both temporary files with forceOutput set to False so that a script can have both conditional processing and tempfile handling.

hi!

temporary files are always newly created. forceOutput cannot be in the way of that by design - it only can work, if you provide a target output file.

the bug your reported about the combination of forceOutput and returnXDataset/returnXArray needs a fix - that's all IMO.

I wonder if removing the kwargs['force'] in line 508 of https://github.com/Try2Code/cdo-bindings/blob/master/python/cdo.py would do it.

the point is: I want to have a global switch like forceOutput and a switch that works on a single operator (kwargs['force'])

Unless you recommend doing something like the following instead?

import cdo as Cdo
cdo_force_false = Cdo.Cdo(forceOutput=False)
cdo_force_true = Cdo.Cdo(forceOutput=True)
cdo_force_true.topo("r240x120",returnXDataset=True)
cdo_force_false.seltimestep("-1",input=files_from_running_expt)

So what you want, is that cdo.topo("r240x120",returnXDataset=True) always works no matter what value is set to forceOutput, right?

RE: Problem creating temp data with python bindings when forceOutput is False - Added by XR Chua about 1 year ago

So what you want, is that cdo.topo("r240x120",returnXDataset=True) always works no matter what value is set to forceOutput, right?

Yes, exactly.

    (1-4/4)