Coordinate Categorisation by latitude or longitude (or how change the cube resolution)

324 views
Skip to first unread message

Arsène

unread,
Jul 2, 2015, 5:12:37 AM7/2/15
to scitoo...@googlegroups.com
Hi all,

I would like to be able to change the change the resolution of my cube (on latitude) to be able to plot some latitude transects at other (larger) scale. The idea was to do the same transformation than "categorization by year" but by latitude. 

After identify the good (?) function, iris.coord_categorisation.add_categorised_coord() and find an example, the tests were false.

If you have another idea to do that, or a solution to fix this one... thanks a lot.

See below the "most advanced" code...

Regards,

Arsène

The cube:

print cube
Total living biomass / (0.001 meter^-2-kilogram) (latitude: 360)
     Dimension coordinates:
          latitude                                        x
     Scalar coordinates:
          longitude: 22.5 degrees, bound=(22.25, 22.75) degrees
          model_level_number: 15.0
          month: Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Ju...
          time: 2006-12-29 12:00:00, bound=(2000-01-01 00:00:00, 2013-12-27 00:00:00)
          year: 2006, bound=(2000, 2013)
     Attributes:
          Conventions: CF-1.1
          TimeStamp: 2015-JUN-24 15:14:05 GMT-0000
          file_name: stomate_history_Y1000.nc
          history: ...
          interval_operation: 3600.0
          interval_write: 2.592e+06
          nco_openmp_thread_number: 1
          online_operation: ave(scatter(X))
          production: An IPSL model
     Cell methods:
          mean: year, longitude



The code and the result

def latitude1to10(coord, point):
    lat = coord[point].points
    return  (lat/10) *10

iris.coord_categorisation.add_categorised_coord(cube, 'latitude_10', 'latitude', latitude1to10)

cube_lat10=cube.aggregated_by('latitude_10', iris.analysis.MEAN)


 print cube_lat10
Total living biomass / (0.001 meter^-2-kilogram) (latitude: 179)
     Dimension coordinates:
          latitude                                        x
     Auxiliary coordinates:
          latitude_10                                     x
     Scalar coordinates:
          longitude: 22.5 degrees, bound=(22.25, 22.75) degrees
          model_level_number: 15.0
          month: Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Ju...
          time: 2006-12-29 12:00:00, bound=(2000-01-01 00:00:00, 2013-12-27 00:00:00)
          year: 2006, bound=(2000, 2013)
     Attributes:
          Conventions: CF-1.1
          TimeStamp: 2015-JUN-24 15:14:05 GMT-0000
          file_name: stomate_history_Y1000.nc
          history: ...
          interval_operation: 3600.0
          interval_write: 2.592e+06
          invalid_standard_name: Total living biomass
          invalid_units: gC/m^2/pft
          nco_openmp_thread_number: 1
          online_operation: ave(scatter(X))
          production: An IPSL model
     Cell methods:
          mean: year, longitude
          mean: latitude_10



==> of course it's not running. That impact the resolution but without any control by latitude1to10 function :

print cube_lat10.aux_coords
(DimCoord(array([ 22.5], dtype=float32), bounds=array([[ 22.25,  22.75]], dtype=float32), standard_name=u'longitude', units=Unit('degrees'), long_name=u'Longitude', var_name='lon', attributes={'nav_model': 'Default grid'}), DimCoord(array([ 15.], dtype=float32), standard_name=u'model_level_number', units=Unit('1'), long_name=u'Plant functional type', var_name='PFT', attributes={'title': 'PFT'}), AuxCoord(array([ 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec'], 
      dtype='|S671'), standard_name=None, units=Unit('no_unit'), long_name=u'month', attributes={'title': 'Time', 'time_origin': ' 1979-JAN-01 00:00:00'}), DimCoord(array([  8.82792000e+08]), bounds=array([[  6.62256000e+08,   1.10332800e+09]]), standard_name=u'time', units=Unit('seconds since 1979-01-01 00:00:00', calendar='noleap'), long_name=u'Time axis', var_name='time_counter', attributes={'title': 'Time', 'time_origin': ' 1979-JAN-01 00:00:00'}), AuxCoord(array([2006]), bounds=array([[2000, 2013]]), standard_name=None, units=Unit('1'), long_name=u'year', attributes={'title': 'Time', 'time_origin': ' 1979-JAN-01 00:00:00'}), AuxCoord(array([ 45.25,  45.75,  46.25,  46.75,  47.25,  47.75,  48.25,  48.75,
        49.25,  49.75,  50.25,  50.75,  51.25,  51.75,  52.25,  52.75,
        53.25,  53.75,  54.25,  54.75,  55.25,  55.75,  56.25,  56.75,
        57.25,  57.75,  58.25,  58.75,  59.25,  59.75,  60.25,  60.75,
        61.25,  61.75,  62.25,  62.75,  63.25,  63.75,  64.25,  64.75,
        65.25,  65.75,  66.25,  66.75,  67.25,  67.75,  68.25,  68.75,
        69.25,  69.75,  70.25,  70.75,  71.25,  71.75,  72.25,  72.75,
        73.25,  73.75,  74.25,  74.75,  75.25,  75.75,  76.25,  76.75,
        77.25,  77.75,  78.25,  78.75,  79.25,  79.75,  80.25,  80.75,
        81.25,  81.75,  82.25,  82.75,  83.25,  83.75,  84.25,  84.75,
        85.25,  85.75,  86.25,  86.75,  87.25,  87.75,  88.25,  88.75,
        89.25,  89.75, -89.75, -89.25, -88.75, -88.25, -87.75, -87.25,
       -86.75, -86.25, -85.75, -85.25, -84.75, -84.25, -83.75, -83.25,
       -82.75, -82.25, -81.75, -81.25, -80.75, -80.25, -79.75, -79.25,
       -78.75, -78.25, -77.75, -77.25, -76.75, -76.25, -75.75, -75.25,
       -74.75, -74.25, -73.75, -73.25, -72.75, -72.25, -71.75, -71.25,
       -70.75, -70.25, -69.75, -69.25, -68.75, -68.25, -67.75, -67.25,
       -66.75, -66.25, -65.75, -65.25, -64.75, -64.25, -63.75, -63.25,
       -62.75, -62.25, -61.75, -61.25, -60.75, -60.25, -59.75, -59.25,
       -58.75, -58.25, -57.75, -57.25, -56.75, -56.25, -55.75, -55.25,
       -54.75, -54.25, -53.75, -53.25, -52.75, -52.25, -51.75, -51.25,
       -50.75, -50.25, -49.75, -49.25, -48.75, -48.25, -47.75, -47.25,
       -46.75, -46.25, -45.75], dtype=float32), standard_name=None, units=Unit('1'), long_name=u'latitude_10', attributes={'nav_model': 'Default grid'}))

print cube_lat10.coord('latitude')
DimCoord(array([ 89.5,  88.5,  87.5,  86.5,  85.5,  84.5,  83.5,  82.5,  81.5,
        80.5,  79.5,  78.5,  77.5,  76.5,  75.5,  74.5,  73.5,  72.5,
        71.5,  70.5,  69.5,  68.5,  67.5,  66.5,  65.5,  64.5,  63.5,
        62.5,  61.5,  60.5,  59.5,  58.5,  57.5,  56.5,  55.5,  54.5,
        53.5,  52.5,  51.5,  50.5,  49.5,  48.5,  47.5,  46.5,  45.5,
        44.5,  43.5,  42.5,  41.5,  40.5,  39.5,  38.5,  37.5,  36.5,
        35.5,  34.5,  33.5,  32.5,  31.5,  30.5,  29.5,  28.5,  27.5,
        26.5,  25.5,  24.5,  23.5,  22.5,  21.5,  20.5,  19.5,  18.5,
        17.5,  16.5,  15.5,  14.5,  13.5,  12.5,  11.5,  10.5,   9.5,
         8.5,   7.5,   6.5,   5.5,   4.5,   3.5,   2.5,   1.5,   0. ,
        -1.5,  -2.5,  -3.5,  -4.5,  -5.5,  -6.5,  -7.5,  -8.5,  -9.5,
       -10.5, -11.5, -12.5, -13.5, -14.5, -15.5, -16.5, -17.5, -18.5,
       -19.5, -20.5, -21.5, -22.5, -23.5, -24.5, -25.5, -26.5, -27.5,
       -28.5, -29.5, -30.5, -31.5, -32.5, -33.5, -34.5, -35.5, -36.5,
       -37.5, -38.5, -39.5, -40.5, -41.5, -42.5, -43.5, -44.5, -45.5,
       -46.5, -47.5, -48.5, -49.5, -50.5, -51.5, -52.5, -53.5, -54.5,
       -55.5, -56.5, -57.5, -58.5, -59.5, -60.5, -61.5, -62.5, -63.5,
       -64.5, -65.5, -66.5, -67.5, -68.5, -69.5, -70.5, -71.5, -72.5,
       -73.5, -74.5, -75.5, -76.5, -77.5, -78.5, -79.5, -80.5, -81.5,
       -82.5, -83.5, -84.5, -85.5, -86.5, -87.5, -88.5, -89.5], dtype=float32), bounds=array([[ 89.75,  89.25],
       [ 88.75,  88.25],
       [ 87.75,  87.25],
       [ 86.75,  86.25],
       [ 85.75,  85.25],
       [ 84.75,  84.25],
       [ 83.75,  83.25],
       [ 82.75,  82.25],
       [ 81.75,  81.25],
       [ 80.75,  80.25],
       [ 79.75,  79.25],
       [ 78.75,  78.25],
       [ 77.75,  77.25],
       [ 76.75,  76.25],
       [ 75.75,  75.25],
       [ 74.75,  74.25],
       [ 73.75,  73.25],
       [ 72.75,  72.25],
       [ 71.75,  71.25],
       [ 70.75,  70.25],
       [ 69.75,  69.25],
       [ 68.75,  68.25],
       [ 67.75,  67.25],
       [ 66.75,  66.25],
       [ 65.75,  65.25],
       [ 64.75,  64.25],
       [ 63.75,  63.25],
       [ 62.75,  62.25],
       [ 61.75,  61.25],
       [ 60.75,  60.25],
       [ 59.75,  59.25],
       [ 58.75,  58.25],
       [ 57.75,  57.25],
       [ 56.75,  56.25],
       [ 55.75,  55.25],
       [ 54.75,  54.25],
       [ 53.75,  53.25],
       [ 52.75,  52.25],
       [ 51.75,  51.25],
       [ 50.75,  50.25],
       [ 49.75,  49.25],
       [ 48.75,  48.25],
       [ 47.75,  47.25],
       [ 46.75,  46.25],
       [ 45.75,  45.25],
       [ 44.75,  44.25],
       [ 43.75,  43.25],
       [ 42.75,  42.25],
       [ 41.75,  41.25],
       [ 40.75,  40.25],
       [ 39.75,  39.25],
       [ 38.75,  38.25],
       [ 37.75,  37.25],
       [ 36.75,  36.25],
       [ 35.75,  35.25],
       [ 34.75,  34.25],
       [ 33.75,  33.25],
       [ 32.75,  32.25],
       [ 31.75,  31.25],
       [ 30.75,  30.25],
       [ 29.75,  29.25],
       [ 28.75,  28.25],
       [ 27.75,  27.25],
       [ 26.75,  26.25],
       [ 25.75,  25.25],
       [ 24.75,  24.25],
       [ 23.75,  23.25],
       [ 22.75,  22.25],
       [ 21.75,  21.25],
       [ 20.75,  20.25],
       [ 19.75,  19.25],
       [ 18.75,  18.25],
       [ 17.75,  17.25],
       [ 16.75,  16.25],
       [ 15.75,  15.25],
       [ 14.75,  14.25],
       [ 13.75,  13.25],
       [ 12.75,  12.25],
       [ 11.75,  11.25],
       [ 10.75,  10.25],
       [  9.75,   9.25],
       [  8.75,   8.25],
       [  7.75,   7.25],
       [  6.75,   6.25],
       [  5.75,   5.25],
       [  4.75,   4.25],
       [  3.75,   3.25],
       [  2.75,   2.25],
       [  1.75,   1.25],
       [  0.75,  -0.75],
       [ -1.25,  -1.75],
       [ -2.25,  -2.75],
       [ -3.25,  -3.75],
       [ -4.25,  -4.75],
       [ -5.25,  -5.75],
       [ -6.25,  -6.75],
       [ -7.25,  -7.75],
       [ -8.25,  -8.75],
       [ -9.25,  -9.75],
       [-10.25, -10.75],
       [-11.25, -11.75],
       [-12.25, -12.75],
       [-13.25, -13.75],
       [-14.25, -14.75],
       [-15.25, -15.75],
       [-16.25, -16.75],
       [-17.25, -17.75],
       [-18.25, -18.75],
       [-19.25, -19.75],
       [-20.25, -20.75],
       [-21.25, -21.75],
       [-22.25, -22.75],
       [-23.25, -23.75],
       [-24.25, -24.75],
       [-25.25, -25.75],
       [-26.25, -26.75],
       [-27.25, -27.75],
       [-28.25, -28.75],
       [-29.25, -29.75],
       [-30.25, -30.75],
       [-31.25, -31.75],
       [-32.25, -32.75],
       [-33.25, -33.75],
       [-34.25, -34.75],
       [-35.25, -35.75],
       [-36.25, -36.75],
       [-37.25, -37.75],
       [-38.25, -38.75],
       [-39.25, -39.75],
       [-40.25, -40.75],
       [-41.25, -41.75],
       [-42.25, -42.75],
       [-43.25, -43.75],
       [-44.25, -44.75],
       [-45.25, -45.75],
       [-46.25, -46.75],
       [-47.25, -47.75],
       [-48.25, -48.75],
       [-49.25, -49.75],
       [-50.25, -50.75],
       [-51.25, -51.75],
       [-52.25, -52.75],
       [-53.25, -53.75],
       [-54.25, -54.75],
       [-55.25, -55.75],
       [-56.25, -56.75],
       [-57.25, -57.75],
       [-58.25, -58.75],
       [-59.25, -59.75],
       [-60.25, -60.75],
       [-61.25, -61.75],
       [-62.25, -62.75],
       [-63.25, -63.75],
       [-64.25, -64.75],
       [-65.25, -65.75],
       [-66.25, -66.75],
       [-67.25, -67.75],
       [-68.25, -68.75],
       [-69.25, -69.75],
       [-70.25, -70.75],
       [-71.25, -71.75],
       [-72.25, -72.75],
       [-73.25, -73.75],
       [-74.25, -74.75],
       [-75.25, -75.75],
       [-76.25, -76.75],
       [-77.25, -77.75],
       [-78.25, -78.75],
       [-79.25, -79.75],
       [-80.25, -80.75],
       [-81.25, -81.75],
       [-82.25, -82.75],
       [-83.25, -83.75],
       [-84.25, -84.75],
       [-85.25, -85.75],
       [-86.25, -86.75],
       [-87.25, -87.75],
       [-88.25, -88.75],
       [-89.25, -89.75]], dtype=float32), standard_name=u'latitude', units=Unit('degrees'), long_name=u'Latitude', var_name='lat', attributes={'nav_model': 'Default grid'})




If you need some others informations... please do not hesitate


Thanks again, 

Arsène




Andrew Dawson

unread,
Jul 2, 2015, 5:22:02 AM7/2/15
to scitoo...@googlegroups.com
I don't think I understand your question properly. However, if you want to change the resolution of a cube you should look at the interpolate and regrid methods of the cube. You can also refer to the User Guide section on interpolation and regridding which has some good examples of the various options available to you. Is that the kind of thing you wanted?

Andrew

Arsène

unread,
Jul 2, 2015, 8:51:53 AM7/2/15
to scitoo...@googlegroups.com
Hi Andrew.

Thanks a lot for your answer. 

The idea is to reduce the scale by meaning data on latitudes bounds. If I think that my way is possible theoretically, in fact I don't find a solution to fix that.

In your proposals, the regrid requires to made a cube defining the grid and in this case is not the easiest way. The best and good solution was to interpolate. 
If that could be helpful for someone, see below the code.

Thanks a lot,

Arsène

Fo to reduce the scale by 2:

scale = 2
lat
=cube.coord('latitude').points

sample_points = [('latitude', np.linspace(lat.min(), lat.max(), lat.size/scale ))]

cube_lat = cube.interpolate(sample_points, iris.analysis.Linear())


Yes... is very efficient ;)

Reply all
Reply to author
Forward
0 new messages