Slices with save 'append=True ' does not recognise scalar Dim Coord

65 views
Skip to first unread message

Peter Willetts

unread,
Jun 4, 2014, 5:55:46 AM6/4/14
to scitoo...@googlegroups.com
Hi

For memory reasons, I am slicing a cube, performing a few operations, then trying to save with append =True.  The slices are along pressure levels, so when I slice, pressure is still showing as a Dim Coord.

>>> pressure_cube =(u.slices(['time', 'grid_latitude', 'grid_longitude'])).next()
>>> pressure_cube.coord('pressure')
DimCoord(array([ 100.], dtype=float32), standard_name=None, units=Unit('hPa'), long_name='pressure')

But also as a scalar coordinate.

>>> pressure_cube
<iris 'Cube' of eastward_wind / (m s-1) (forecast_reference_time: 84; forecast_period: 6; grid_latitude: 199; grid_longitude: 200)>
>>> print pressure_cube
eastward_wind / (m s-1)             (forecast_reference_time: 84; forecast_period: 6; grid_latitude: 199; grid_longitude: 200)
     Dimension coordinates:
          forecast_reference_time                           x                    -                 -                    -
          forecast_period                                   -                    x                 -                    -
          grid_latitude                                     -                    -                 x                    -
          grid_longitude                                    -                    -                 -                    x
     Auxiliary coordinates:
          time                                              x                    x                 -                    -
     Scalar coordinates:
          pressure: 100.0 hPa
     Attributes:
          STASH: m01s30i201
          source: Data from Met Office Unified Model 8.02

When I try to save with 'append =True' at the end of each loop, the pressure coord is not being recognised and all are saved at the same pressure.

Below is an example of what the cubes look like before saving.

print D_save
iris.save(D_save, '%s%s/%s/divergence.pp' % (pp_file_path, expmin1, experiment_id), append=True)
unknown / (unknown)                 (time: 477; latitude: 219; longitude: 169)
     Dimension coordinates:
          time                           x              -               -
          latitude                       -              x               -
          longitude                      -              -               x
     Auxiliary coordinates:
          forecast_period                x              -               -
          forecast_reference_time        x              -               -
     Scalar coordinates:
          pressure: 100.0 hPa
     Attributes:
          history: unknown * array
DimCoord(array([ 100.], dtype=float32), standard_name=None, units=Unit('hPa'), long_name='pressure')
unknown / (unknown)                 (time: 477; latitude: 219; longitude: 169)
     Dimension coordinates:
          time                           x              -               -
          latitude                       -              x               -
          longitude                      -              -               x
     Auxiliary coordinates:
          forecast_period                x              -               -
          forecast_reference_time        x              -               -
     Scalar coordinates:
          pressure: 150.0 hPa
     Attributes:
          history: unknown * array
DimCoord(array([ 150.], dtype=float32), standard_name=None, units=Unit('hPa'), long_name='pressure')
unknown / (unknown)                 (time: 477; latitude: 219; longitude: 169)
     Dimension coordinates:
          time                           x              -               -
          latitude                       -              x               -
          longitude                      -              -               x
     Auxiliary coordinates:
          forecast_period                x              -               -
          forecast_reference_time        x              -               -
     Scalar coordinates:
          pressure: 200.0 hPa
     Attributes:
          history: unknown * array
DimCoord(array([ 200.], dtype=float32), standard_name=None, units=Unit('hPa'), long_name='pressure')

Thanks

Peter

Richard Hattersley

unread,
Jun 4, 2014, 11:22:32 AM6/4/14
to scitoo...@googlegroups.com
This is very confusing. I'm unable to re-create the problem.

What do you get if you run the following test script:

from iris.coords import DimCoord
from iris.cube import Cube
import iris
import numpy as np

def simple(pressure):
    c
= Cube(np.zeros((20, 30), 'f4'))
    c
.add_dim_coord(DimCoord(range(20), 'latitude', units='degrees'), 0)
    c
.add_dim_coord(DimCoord(range(30), 'longitude', units='degrees'), 1)
    c
.add_aux_coord(DimCoord(pressure, long_name='pressure', units='hPa'))
   
return c

if __name__ == '__main__':
    iris
.save(simple(100), 'test.pp')
    iris
.save(simple(150), 'test.pp', append=True)
   
for cube in iris.load('test.pp'):
       
print cube
        print cube.coord('pressure')

I get the following:

unknown / (unknown)                 (pressure: 2; latitude: 20; longitude: 30)
     Dimension coordinates:
          pressure                           x            -              -

          latitude                           -            x              -
          longitude                          -            -              x
DimCoord(array([ 100.,  150.], dtype=float32), standard_name=None, units=Unit('hPa'), long_name='pressure')

Which shows the pressure values have survived the process.
Reply all
Reply to author
Forward
0 new messages