Skip to content

Instantly share code, notes, and snippets.

@cpelley
Created September 24, 2014 13:33
Show Gist options
  • Select an option

  • Save cpelley/1269dc60c41944d9c504 to your computer and use it in GitHub Desktop.

Select an option

Save cpelley/1269dc60c41944d9c504 to your computer and use it in GitHub Desktop.
Regrid performance
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:7b4bbb0e65c338022432e38544fab05df6c64e9bbc3ba68d7ec6bedb16d08a96"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import iris"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import iris.tests.stock as stock"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cube = stock.global_pp()\n",
"\n",
"print cube\n",
"cube.coord('longitude').guess_bounds()\n",
"cube.coord('latitude').guess_bounds()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"air_temperature / (K) (latitude: 73; longitude: 96)\n",
" Dimension coordinates:\n",
" latitude x -\n",
" longitude - x\n",
" Scalar coordinates:\n",
" forecast_period: 6477 hours, bound=(-28083.0, 6477.0) hours\n",
" forecast_reference_time: 1998-03-01 03:00:00\n",
" pressure: 1000.0 hPa\n",
" time: 1998-12-01 00:00:00, bound=(1994-12-01 00:00:00, 1998-12-01 00:00:00)\n",
" Attributes:\n",
" STASH: m01s16i203\n",
" source: Data from Met Office Unified Model\n",
" Cell methods:\n",
" mean: time\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import biggus\n",
"import numpy as np\n",
"\n",
"nx, ny = 70, 70\n",
"data = biggus.ConstantArray((nx, ny), 0)\n",
"\n",
"grid_cube = iris.cube.Cube(data)\n",
"coord = cube.coord('longitude').points; lon = np.linspace(int(coord.min()), int(coord.max()), nx)\n",
"coord = cube.coord('latitude').points; lat = np.linspace(int(coord.min()), int(coord.max()), ny)\n",
"\n",
"lon_coord, lat_coord = cube.coord('longitude').copy(lon), cube.coord('latitude').copy(lat)\n",
"lon_coord.guess_bounds()\n",
"lat_coord.guess_bounds()\n",
"grid_cube.add_dim_coord(lon_coord, 1)\n",
"grid_cube.add_dim_coord(lat_coord, 0)\n",
"print grid_cube"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"unknown / (unknown) (latitude: 70; longitude: 70)\n",
" Dimension coordinates:\n",
" latitude x -\n",
" longitude - x\n"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"regridded_cube = cube.regrid(grid_cube, iris.analysis.AreaWeighted())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 2.03 s, sys: 0 ns, total: 2.03 s\n",
"Wall time: 2.03 s\n"
]
}
],
"prompt_number": 5
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment