Created
February 11, 2015 10:24
-
-
Save bjlittle/66561ad418f6f06a20f1 to your computer and use it in GitHub Desktop.
epm-766
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:0b74d38fd9ccace2ca048eed2176cf3f0b87cdcaaf368d58dcdac98dea264e59" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "heading", | |
"level": 4, | |
"metadata": {}, | |
"source": [ | |
"Let's load your data into a cube and inspect the range of latitudes and longitudes associated with it ..." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import numpy as np\n", | |
"\n", | |
"import iris" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stderr", | |
"text": [ | |
"/net/home/h05/itwl/projects/git/iris/lib/iris/config.py:97: UserWarning: Ignoring config item 'Resources':'sample_data_dir' (section:option) as '/home/h05/itwl/projects/git/iris-sample-data/sample_data' is not a valid directory path.\n", | |
" warnings.warn(msg.format(section, option, c_path))\n", | |
"/net/home/h05/itwl/projects/git/iris/lib/iris/config.py:97: UserWarning: Ignoring config item 'Resources':'test_data_dir' (section:option) as '/home/h05/itwl/projects/git/iris-test-data/test_data' is not a valid directory path.\n", | |
" warnings.warn(msg.format(section, option, c_path))\n" | |
] | |
} | |
], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"fname = '/data/local/itwl/support/epm-766/ETXZ80_201407030045.ff'" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"cube = iris.load_cube(fname)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stderr", | |
"text": [ | |
"/net/home/h05/itwl/projects/git/iris/lib/iris/fileformats/ff.py:697: UserWarning: The STASH code m00s00i000 was not found in the STASH to grid type mapping. Picking the P position as the cell type\n", | |
" 'position as the cell type'.format(stash))\n" | |
] | |
} | |
], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print cube" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"unknown / (unknown) (latitude: 641; longitude: 641)\n", | |
" Dimension coordinates:\n", | |
" latitude x -\n", | |
" longitude - x\n", | |
" Scalar coordinates:\n", | |
" forecast_period: 0.0 hours\n", | |
" forecast_reference_time: 2014-07-03 00:45:00\n", | |
" time: 2014-07-03 00:45:00\n" | |
] | |
} | |
], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print cube.coord('latitude')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"DimCoord(array([ 80. , 79.75, 79.5 , 79.25, 79. , 78.75, 78.5 , 78.25,\n", | |
" 78. , 77.75, 77.5 , 77.25, 77. , 76.75, 76.5 , 76.25,\n", | |
" 76. , 75.75, 75.5 , 75.25, 75. , 74.75, 74.5 , 74.25,\n", | |
" 74. , 73.75, 73.5 , 73.25, 73. , 72.75, 72.5 , 72.25,\n", | |
" 72. , 71.75, 71.5 , 71.25, 71. , 70.75, 70.5 , 70.25,\n", | |
" 70. , 69.75, 69.5 , 69.25, 69. , 68.75, 68.5 , 68.25,\n", | |
" 68. , 67.75, 67.5 , 67.25, 67. , 66.75, 66.5 , 66.25,\n", | |
" 66. , 65.75, 65.5 , 65.25, 65. , 64.75, 64.5 , 64.25,\n", | |
" 64. , 63.75, 63.5 , 63.25, 63. , 62.75, 62.5 , 62.25,\n", | |
" 62. , 61.75, 61.5 , 61.25, 61. , 60.75, 60.5 , 60.25,\n", | |
" 60. , 59.75, 59.5 , 59.25, 59. , 58.75, 58.5 , 58.25,\n", | |
" 58. , 57.75, 57.5 , 57.25, 57. , 56.75, 56.5 , 56.25,\n", | |
" 56. , 55.75, 55.5 , 55.25, 55. , 54.75, 54.5 , 54.25,\n", | |
" 54. , 53.75, 53.5 , 53.25, 53. , 52.75, 52.5 , 52.25,\n", | |
" 52. , 51.75, 51.5 , 51.25, 51. , 50.75, 50.5 , 50.25,\n", | |
" 50. , 49.75, 49.5 , 49.25, 49. , 48.75, 48.5 , 48.25,\n", | |
" 48. , 47.75, 47.5 , 47.25, 47. , 46.75, 46.5 , 46.25,\n", | |
" 46. , 45.75, 45.5 , 45.25, 45. , 44.75, 44.5 , 44.25,\n", | |
" 44. , 43.75, 43.5 , 43.25, 43. , 42.75, 42.5 , 42.25,\n", | |
" 42. , 41.75, 41.5 , 41.25, 41. , 40.75, 40.5 , 40.25,\n", | |
" 40. , 39.75, 39.5 , 39.25, 39. , 38.75, 38.5 , 38.25,\n", | |
" 38. , 37.75, 37.5 , 37.25, 37. , 36.75, 36.5 , 36.25,\n", | |
" 36. , 35.75, 35.5 , 35.25, 35. , 34.75, 34.5 , 34.25,\n", | |
" 34. , 33.75, 33.5 , 33.25, 33. , 32.75, 32.5 , 32.25,\n", | |
" 32. , 31.75, 31.5 , 31.25, 31. , 30.75, 30.5 , 30.25,\n", | |
" 30. , 29.75, 29.5 , 29.25, 29. , 28.75, 28.5 , 28.25,\n", | |
" 28. , 27.75, 27.5 , 27.25, 27. , 26.75, 26.5 , 26.25,\n", | |
" 26. , 25.75, 25.5 , 25.25, 25. , 24.75, 24.5 , 24.25,\n", | |
" 24. , 23.75, 23.5 , 23.25, 23. , 22.75, 22.5 , 22.25,\n", | |
" 22. , 21.75, 21.5 , 21.25, 21. , 20.75, 20.5 , 20.25,\n", | |
" 20. , 19.75, 19.5 , 19.25, 19. , 18.75, 18.5 , 18.25,\n", | |
" 18. , 17.75, 17.5 , 17.25, 17. , 16.75, 16.5 , 16.25,\n", | |
" 16. , 15.75, 15.5 , 15.25, 15. , 14.75, 14.5 , 14.25,\n", | |
" 14. , 13.75, 13.5 , 13.25, 13. , 12.75, 12.5 , 12.25,\n", | |
" 12. , 11.75, 11.5 , 11.25, 11. , 10.75, 10.5 , 10.25,\n", | |
" 10. , 9.75, 9.5 , 9.25, 9. , 8.75, 8.5 , 8.25,\n", | |
" 8. , 7.75, 7.5 , 7.25, 7. , 6.75, 6.5 , 6.25,\n", | |
" 6. , 5.75, 5.5 , 5.25, 5. , 4.75, 4.5 , 4.25,\n", | |
" 4. , 3.75, 3.5 , 3.25, 3. , 2.75, 2.5 , 2.25,\n", | |
" 2. , 1.75, 1.5 , 1.25, 1. , 0.75, 0.5 , 0.25,\n", | |
" 0. , -0.25, -0.5 , -0.75, -1. , -1.25, -1.5 , -1.75,\n", | |
" -2. , -2.25, -2.5 , -2.75, -3. , -3.25, -3.5 , -3.75,\n", | |
" -4. , -4.25, -4.5 , -4.75, -5. , -5.25, -5.5 , -5.75,\n", | |
" -6. , -6.25, -6.5 , -6.75, -7. , -7.25, -7.5 , -7.75,\n", | |
" -8. , -8.25, -8.5 , -8.75, -9. , -9.25, -9.5 , -9.75,\n", | |
" -10. , -10.25, -10.5 , -10.75, -11. , -11.25, -11.5 , -11.75,\n", | |
" -12. , -12.25, -12.5 , -12.75, -13. , -13.25, -13.5 , -13.75,\n", | |
" -14. , -14.25, -14.5 , -14.75, -15. , -15.25, -15.5 , -15.75,\n", | |
" -16. , -16.25, -16.5 , -16.75, -17. , -17.25, -17.5 , -17.75,\n", | |
" -18. , -18.25, -18.5 , -18.75, -19. , -19.25, -19.5 , -19.75,\n", | |
" -20. , -20.25, -20.5 , -20.75, -21. , -21.25, -21.5 , -21.75,\n", | |
" -22. , -22.25, -22.5 , -22.75, -23. , -23.25, -23.5 , -23.75,\n", | |
" -24. , -24.25, -24.5 , -24.75, -25. , -25.25, -25.5 , -25.75,\n", | |
" -26. , -26.25, -26.5 , -26.75, -27. , -27.25, -27.5 , -27.75,\n", | |
" -28. , -28.25, -28.5 , -28.75, -29. , -29.25, -29.5 , -29.75,\n", | |
" -30. , -30.25, -30.5 , -30.75, -31. , -31.25, -31.5 , -31.75,\n", | |
" -32. , -32.25, -32.5 , -32.75, -33. , -33.25, -33.5 , -33.75,\n", | |
" -34. , -34.25, -34.5 , -34.75, -35. , -35.25, -35.5 , -35.75,\n", | |
" -36. , -36.25, -36.5 , -36.75, -37. , -37.25, -37.5 , -37.75,\n", | |
" -38. , -38.25, -38.5 , -38.75, -39. , -39.25, -39.5 , -39.75,\n", | |
" -40. , -40.25, -40.5 , -40.75, -41. , -41.25, -41.5 , -41.75,\n", | |
" -42. , -42.25, -42.5 , -42.75, -43. , -43.25, -43.5 , -43.75,\n", | |
" -44. , -44.25, -44.5 , -44.75, -45. , -45.25, -45.5 , -45.75,\n", | |
" -46. , -46.25, -46.5 , -46.75, -47. , -47.25, -47.5 , -47.75,\n", | |
" -48. , -48.25, -48.5 , -48.75, -49. , -49.25, -49.5 , -49.75,\n", | |
" -50. , -50.25, -50.5 , -50.75, -51. , -51.25, -51.5 , -51.75,\n", | |
" -52. , -52.25, -52.5 , -52.75, -53. , -53.25, -53.5 , -53.75,\n", | |
" -54. , -54.25, -54.5 , -54.75, -55. , -55.25, -55.5 , -55.75,\n", | |
" -56. , -56.25, -56.5 , -56.75, -57. , -57.25, -57.5 , -57.75,\n", | |
" -58. , -58.25, -58.5 , -58.75, -59. , -59.25, -59.5 , -59.75,\n", | |
" -60. , -60.25, -60.5 , -60.75, -61. , -61.25, -61.5 , -61.75,\n", | |
" -62. , -62.25, -62.5 , -62.75, -63. , -63.25, -63.5 , -63.75,\n", | |
" -64. , -64.25, -64.5 , -64.75, -65. , -65.25, -65.5 , -65.75,\n", | |
" -66. , -66.25, -66.5 , -66.75, -67. , -67.25, -67.5 , -67.75,\n", | |
" -68. , -68.25, -68.5 , -68.75, -69. , -69.25, -69.5 , -69.75,\n", | |
" -70. , -70.25, -70.5 , -70.75, -71. , -71.25, -71.5 , -71.75,\n", | |
" -72. , -72.25, -72.5 , -72.75, -73. , -73.25, -73.5 , -73.75,\n", | |
" -74. , -74.25, -74.5 , -74.75, -75. , -75.25, -75.5 , -75.75,\n", | |
" -76. , -76.25, -76.5 , -76.75, -77. , -77.25, -77.5 , -77.75,\n", | |
" -78. , -78.25, -78.5 , -78.75, -79. , -79.25, -79.5 , -79.75, -80. ], dtype=float32), standard_name='latitude', units=Unit('degrees'), coord_system=GeogCS(6371229.0))\n" | |
] | |
} | |
], | |
"prompt_number": 5 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print cube.coord('longitude')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"DimCoord(array([ 280. , 280.25, 280.5 , 280.75, 281. , 281.25, 281.5 ,\n", | |
" 281.75, 282. , 282.25, 282.5 , 282.75, 283. , 283.25,\n", | |
" 283.5 , 283.75, 284. , 284.25, 284.5 , 284.75, 285. ,\n", | |
" 285.25, 285.5 , 285.75, 286. , 286.25, 286.5 , 286.75,\n", | |
" 287. , 287.25, 287.5 , 287.75, 288. , 288.25, 288.5 ,\n", | |
" 288.75, 289. , 289.25, 289.5 , 289.75, 290. , 290.25,\n", | |
" 290.5 , 290.75, 291. , 291.25, 291.5 , 291.75, 292. ,\n", | |
" 292.25, 292.5 , 292.75, 293. , 293.25, 293.5 , 293.75,\n", | |
" 294. , 294.25, 294.5 , 294.75, 295. , 295.25, 295.5 ,\n", | |
" 295.75, 296. , 296.25, 296.5 , 296.75, 297. , 297.25,\n", | |
" 297.5 , 297.75, 298. , 298.25, 298.5 , 298.75, 299. ,\n", | |
" 299.25, 299.5 , 299.75, 300. , 300.25, 300.5 , 300.75,\n", | |
" 301. , 301.25, 301.5 , 301.75, 302. , 302.25, 302.5 ,\n", | |
" 302.75, 303. , 303.25, 303.5 , 303.75, 304. , 304.25,\n", | |
" 304.5 , 304.75, 305. , 305.25, 305.5 , 305.75, 306. ,\n", | |
" 306.25, 306.5 , 306.75, 307. , 307.25, 307.5 , 307.75,\n", | |
" 308. , 308.25, 308.5 , 308.75, 309. , 309.25, 309.5 ,\n", | |
" 309.75, 310. , 310.25, 310.5 , 310.75, 311. , 311.25,\n", | |
" 311.5 , 311.75, 312. , 312.25, 312.5 , 312.75, 313. ,\n", | |
" 313.25, 313.5 , 313.75, 314. , 314.25, 314.5 , 314.75,\n", | |
" 315. , 315.25, 315.5 , 315.75, 316. , 316.25, 316.5 ,\n", | |
" 316.75, 317. , 317.25, 317.5 , 317.75, 318. , 318.25,\n", | |
" 318.5 , 318.75, 319. , 319.25, 319.5 , 319.75, 320. ,\n", | |
" 320.25, 320.5 , 320.75, 321. , 321.25, 321.5 , 321.75,\n", | |
" 322. , 322.25, 322.5 , 322.75, 323. , 323.25, 323.5 ,\n", | |
" 323.75, 324. , 324.25, 324.5 , 324.75, 325. , 325.25,\n", | |
" 325.5 , 325.75, 326. , 326.25, 326.5 , 326.75, 327. ,\n", | |
" 327.25, 327.5 , 327.75, 328. , 328.25, 328.5 , 328.75,\n", | |
" 329. , 329.25, 329.5 , 329.75, 330. , 330.25, 330.5 ,\n", | |
" 330.75, 331. , 331.25, 331.5 , 331.75, 332. , 332.25,\n", | |
" 332.5 , 332.75, 333. , 333.25, 333.5 , 333.75, 334. ,\n", | |
" 334.25, 334.5 , 334.75, 335. , 335.25, 335.5 , 335.75,\n", | |
" 336. , 336.25, 336.5 , 336.75, 337. , 337.25, 337.5 ,\n", | |
" 337.75, 338. , 338.25, 338.5 , 338.75, 339. , 339.25,\n", | |
" 339.5 , 339.75, 340. , 340.25, 340.5 , 340.75, 341. ,\n", | |
" 341.25, 341.5 , 341.75, 342. , 342.25, 342.5 , 342.75,\n", | |
" 343. , 343.25, 343.5 , 343.75, 344. , 344.25, 344.5 ,\n", | |
" 344.75, 345. , 345.25, 345.5 , 345.75, 346. , 346.25,\n", | |
" 346.5 , 346.75, 347. , 347.25, 347.5 , 347.75, 348. ,\n", | |
" 348.25, 348.5 , 348.75, 349. , 349.25, 349.5 , 349.75,\n", | |
" 350. , 350.25, 350.5 , 350.75, 351. , 351.25, 351.5 ,\n", | |
" 351.75, 352. , 352.25, 352.5 , 352.75, 353. , 353.25,\n", | |
" 353.5 , 353.75, 354. , 354.25, 354.5 , 354.75, 355. ,\n", | |
" 355.25, 355.5 , 355.75, 356. , 356.25, 356.5 , 356.75,\n", | |
" 357. , 357.25, 357.5 , 357.75, 358. , 358.25, 358.5 ,\n", | |
" 358.75, 359. , 359.25, 359.5 , 359.75, 360. , 360.25,\n", | |
" 360.5 , 360.75, 361. , 361.25, 361.5 , 361.75, 362. ,\n", | |
" 362.25, 362.5 , 362.75, 363. , 363.25, 363.5 , 363.75,\n", | |
" 364. , 364.25, 364.5 , 364.75, 365. , 365.25, 365.5 ,\n", | |
" 365.75, 366. , 366.25, 366.5 , 366.75, 367. , 367.25,\n", | |
" 367.5 , 367.75, 368. , 368.25, 368.5 , 368.75, 369. ,\n", | |
" 369.25, 369.5 , 369.75, 370. , 370.25, 370.5 , 370.75,\n", | |
" 371. , 371.25, 371.5 , 371.75, 372. , 372.25, 372.5 ,\n", | |
" 372.75, 373. , 373.25, 373.5 , 373.75, 374. , 374.25,\n", | |
" 374.5 , 374.75, 375. , 375.25, 375.5 , 375.75, 376. ,\n", | |
" 376.25, 376.5 , 376.75, 377. , 377.25, 377.5 , 377.75,\n", | |
" 378. , 378.25, 378.5 , 378.75, 379. , 379.25, 379.5 ,\n", | |
" 379.75, 380. , 380.25, 380.5 , 380.75, 381. , 381.25,\n", | |
" 381.5 , 381.75, 382. , 382.25, 382.5 , 382.75, 383. ,\n", | |
" 383.25, 383.5 , 383.75, 384. , 384.25, 384.5 , 384.75,\n", | |
" 385. , 385.25, 385.5 , 385.75, 386. , 386.25, 386.5 ,\n", | |
" 386.75, 387. , 387.25, 387.5 , 387.75, 388. , 388.25,\n", | |
" 388.5 , 388.75, 389. , 389.25, 389.5 , 389.75, 390. ,\n", | |
" 390.25, 390.5 , 390.75, 391. , 391.25, 391.5 , 391.75,\n", | |
" 392. , 392.25, 392.5 , 392.75, 393. , 393.25, 393.5 ,\n", | |
" 393.75, 394. , 394.25, 394.5 , 394.75, 395. , 395.25,\n", | |
" 395.5 , 395.75, 396. , 396.25, 396.5 , 396.75, 397. ,\n", | |
" 397.25, 397.5 , 397.75, 398. , 398.25, 398.5 , 398.75,\n", | |
" 399. , 399.25, 399.5 , 399.75, 400. , 400.25, 400.5 ,\n", | |
" 400.75, 401. , 401.25, 401.5 , 401.75, 402. , 402.25,\n", | |
" 402.5 , 402.75, 403. , 403.25, 403.5 , 403.75, 404. ,\n", | |
" 404.25, 404.5 , 404.75, 405. , 405.25, 405.5 , 405.75,\n", | |
" 406. , 406.25, 406.5 , 406.75, 407. , 407.25, 407.5 ,\n", | |
" 407.75, 408. , 408.25, 408.5 , 408.75, 409. , 409.25,\n", | |
" 409.5 , 409.75, 410. , 410.25, 410.5 , 410.75, 411. ,\n", | |
" 411.25, 411.5 , 411.75, 412. , 412.25, 412.5 , 412.75,\n", | |
" 413. , 413.25, 413.5 , 413.75, 414. , 414.25, 414.5 ,\n", | |
" 414.75, 415. , 415.25, 415.5 , 415.75, 416. , 416.25,\n", | |
" 416.5 , 416.75, 417. , 417.25, 417.5 , 417.75, 418. ,\n", | |
" 418.25, 418.5 , 418.75, 419. , 419.25, 419.5 , 419.75,\n", | |
" 420. , 420.25, 420.5 , 420.75, 421. , 421.25, 421.5 ,\n", | |
" 421.75, 422. , 422.25, 422.5 , 422.75, 423. , 423.25,\n", | |
" 423.5 , 423.75, 424. , 424.25, 424.5 , 424.75, 425. ,\n", | |
" 425.25, 425.5 , 425.75, 426. , 426.25, 426.5 , 426.75,\n", | |
" 427. , 427.25, 427.5 , 427.75, 428. , 428.25, 428.5 ,\n", | |
" 428.75, 429. , 429.25, 429.5 , 429.75, 430. , 430.25,\n", | |
" 430.5 , 430.75, 431. , 431.25, 431.5 , 431.75, 432. ,\n", | |
" 432.25, 432.5 , 432.75, 433. , 433.25, 433.5 , 433.75,\n", | |
" 434. , 434.25, 434.5 , 434.75, 435. , 435.25, 435.5 ,\n", | |
" 435.75, 436. , 436.25, 436.5 , 436.75, 437. , 437.25,\n", | |
" 437.5 , 437.75, 438. , 438.25, 438.5 , 438.75, 439. ,\n", | |
" 439.25, 439.5 , 439.75, 440. ], dtype=float32), standard_name='longitude', units=Unit('degrees'), coord_system=GeogCS(6371229.0), circular=True)\n" | |
] | |
} | |
], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 4, | |
"metadata": {}, | |
"source": [ | |
"Define a function that will calculate all the ranges required over the latitude or longitude coordinate for the provided <font color=\"green\">step</font> size ..." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"def make_range_funcs(coord, step, debug=False):\n", | |
" '''\n", | |
" coord - the latitude/longitude coordinate\n", | |
" step - the desired target grid step size\n", | |
" debug - set this to True for debug output\n", | |
" '''\n", | |
" a, b = coord.points[0], coord.points[-1]\n", | |
" start, stop = (a, b) if a < b else (b, a)\n", | |
" diff = stop - start\n", | |
" num = diff / float(step)\n", | |
" num = int(num + 1)\n", | |
" if debug:\n", | |
" print coord.name()\n", | |
" print 'start: {}\\nstop: {}\\nstep: {}\\nnum: {}\\n'.format(start, stop, step, num)\n", | |
" interval = np.linspace(start, stop, num)\n", | |
" funcs = []\n", | |
" for i, value in enumerate(interval[:-1]):\n", | |
" if (i + 1) < (num - 1):\n", | |
" if debug:\n", | |
" print '{} <= v < {}'.format(value, interval[i + 1])\n", | |
" func = (lambda v, lo=value, hi=interval[i + 1]: lo <= v.point < hi)\n", | |
" else:\n", | |
" if debug:\n", | |
" print '{} <= v <= {}'.format(value, interval[-1])\n", | |
" func = (lambda v, lo=value, hi=interval[-1]: lo <= v.point <= hi)\n", | |
" funcs.append(func)\n", | |
" print\n", | |
" return funcs" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 7 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"# Test with a target grid step of 20 degrees ...\n", | |
"lat_range_funcs = make_range_funcs(cube.coord('latitude'), 20, True)\n", | |
"lon_range_funcs = make_range_funcs(cube.coord('longitude'), 20, True)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"latitude\n", | |
"start: -80.0\n", | |
"stop: 80.0\n", | |
"step: 20\n", | |
"num: 9\n", | |
"\n", | |
"-80.0 <= v < -60.0\n", | |
"-60.0 <= v < -40.0\n", | |
"-40.0 <= v < -20.0\n", | |
"-20.0 <= v < 0.0\n", | |
"0.0 <= v < 20.0\n", | |
"20.0 <= v < 40.0\n", | |
"40.0 <= v < 60.0\n", | |
"60.0 <= v <= 80.0\n", | |
"\n", | |
"longitude\n", | |
"start: 280.0\n", | |
"stop: 440.0\n", | |
"step: 20\n", | |
"num: 9\n", | |
"\n", | |
"280.0 <= v < 300.0\n", | |
"300.0 <= v < 320.0\n", | |
"320.0 <= v < 340.0\n", | |
"340.0 <= v < 360.0\n", | |
"360.0 <= v < 380.0\n", | |
"380.0 <= v < 400.0\n", | |
"400.0 <= v < 420.0\n", | |
"420.0 <= v <= 440.0\n", | |
"\n" | |
] | |
} | |
], | |
"prompt_number": 8 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 4, | |
"metadata": {}, | |
"source": [ | |
"Perform a test extraction for the first lat/lon range ..." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"result = cube.extract(iris.Constraint(latitude=lat_range_funcs[0], longitude=lon_range_funcs[0]))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 9 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print result" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"unknown / (unknown) (latitude: 80; longitude: 80)\n", | |
" Dimension coordinates:\n", | |
" latitude x -\n", | |
" longitude - x\n", | |
" Scalar coordinates:\n", | |
" forecast_period: 0.0 hours\n", | |
" forecast_reference_time: 2014-07-03 00:45:00\n", | |
" time: 2014-07-03 00:45:00\n" | |
] | |
} | |
], | |
"prompt_number": 10 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print result.coord('latitude')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"DimCoord(array([-60.25, -60.5 , -60.75, -61. , -61.25, -61.5 , -61.75, -62. ,\n", | |
" -62.25, -62.5 , -62.75, -63. , -63.25, -63.5 , -63.75, -64. ,\n", | |
" -64.25, -64.5 , -64.75, -65. , -65.25, -65.5 , -65.75, -66. ,\n", | |
" -66.25, -66.5 , -66.75, -67. , -67.25, -67.5 , -67.75, -68. ,\n", | |
" -68.25, -68.5 , -68.75, -69. , -69.25, -69.5 , -69.75, -70. ,\n", | |
" -70.25, -70.5 , -70.75, -71. , -71.25, -71.5 , -71.75, -72. ,\n", | |
" -72.25, -72.5 , -72.75, -73. , -73.25, -73.5 , -73.75, -74. ,\n", | |
" -74.25, -74.5 , -74.75, -75. , -75.25, -75.5 , -75.75, -76. ,\n", | |
" -76.25, -76.5 , -76.75, -77. , -77.25, -77.5 , -77.75, -78. ,\n", | |
" -78.25, -78.5 , -78.75, -79. , -79.25, -79.5 , -79.75, -80. ], dtype=float32), standard_name='latitude', units=Unit('degrees'), coord_system=GeogCS(6371229.0))\n" | |
] | |
} | |
], | |
"prompt_number": 11 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print result.coord('longitude')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"DimCoord(array([ 280. , 280.25, 280.5 , 280.75, 281. , 281.25, 281.5 ,\n", | |
" 281.75, 282. , 282.25, 282.5 , 282.75, 283. , 283.25,\n", | |
" 283.5 , 283.75, 284. , 284.25, 284.5 , 284.75, 285. ,\n", | |
" 285.25, 285.5 , 285.75, 286. , 286.25, 286.5 , 286.75,\n", | |
" 287. , 287.25, 287.5 , 287.75, 288. , 288.25, 288.5 ,\n", | |
" 288.75, 289. , 289.25, 289.5 , 289.75, 290. , 290.25,\n", | |
" 290.5 , 290.75, 291. , 291.25, 291.5 , 291.75, 292. ,\n", | |
" 292.25, 292.5 , 292.75, 293. , 293.25, 293.5 , 293.75,\n", | |
" 294. , 294.25, 294.5 , 294.75, 295. , 295.25, 295.5 ,\n", | |
" 295.75, 296. , 296.25, 296.5 , 296.75, 297. , 297.25,\n", | |
" 297.5 , 297.75, 298. , 298.25, 298.5 , 298.75, 299. ,\n", | |
" 299.25, 299.5 , 299.75], dtype=float32), standard_name='longitude', units=Unit('degrees'), coord_system=GeogCS(6371229.0))\n" | |
] | |
} | |
], | |
"prompt_number": 12 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 4, | |
"metadata": {}, | |
"source": [ | |
"Seems to work just fine! Now let's clobber the data payload with random binary values to mimic your input cubes ..." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from numpy.random import random_integers" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 13 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"shape = cube.shape\n", | |
"data = random_integers(0, 1, shape)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 14 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print data" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"[[1 0 0 ..., 0 0 0]\n", | |
" [0 0 1 ..., 0 0 0]\n", | |
" [1 0 1 ..., 1 1 1]\n", | |
" ..., \n", | |
" [1 0 1 ..., 1 1 1]\n", | |
" [1 1 0 ..., 0 1 0]\n", | |
" [1 0 0 ..., 1 1 1]]\n" | |
] | |
} | |
], | |
"prompt_number": 15 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"cube._my_data = data" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 16 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print cube" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"unknown / (unknown) (latitude: 641; longitude: 641)\n", | |
" Dimension coordinates:\n", | |
" latitude x -\n", | |
" longitude - x\n", | |
" Scalar coordinates:\n", | |
" forecast_period: 0.0 hours\n", | |
" forecast_reference_time: 2014-07-03 00:45:00\n", | |
" time: 2014-07-03 00:45:00\n" | |
] | |
} | |
], | |
"prompt_number": 17 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print cube.data" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"[[1 0 0 ..., 0 0 0]\n", | |
" [0 0 1 ..., 0 0 0]\n", | |
" [1 0 1 ..., 1 1 1]\n", | |
" ..., \n", | |
" [1 0 1 ..., 1 1 1]\n", | |
" [1 1 0 ..., 0 1 0]\n", | |
" [1 0 0 ..., 1 1 1]]\n" | |
] | |
} | |
], | |
"prompt_number": 18 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"----" | |
] | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 4, | |
"metadata": {}, | |
"source": [ | |
"Now we extract the regions from the cube, perform an aggregation over the region (I've opted to just do a SUM) ..." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import iris\n", | |
"from iris.util import new_axis\n", | |
"from itertools import product\n", | |
"\n", | |
"cubes = iris.cube.CubeList()\n", | |
"\n", | |
"for ranges in product(lat_range_funcs, lon_range_funcs):\n", | |
" lats, lons = ranges\n", | |
" constraint = iris.Constraint(latitude=lats, longitude=lons)\n", | |
" region = cube.extract(constraint)\n", | |
" collapsed = region.collapsed(['latitude', 'longitude'], iris.analysis.SUM)\n", | |
" cubes.append(new_axis(new_axis(collapsed, 'longitude'), 'latitude'))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stderr", | |
"text": [ | |
"/net/home/h05/itwl/projects/git/iris/lib/iris/cube.py:2858: UserWarning: Collapsing spatial coordinate 'latitude' without weighting\n", | |
" warnings.warn(msg.format(coord.name()))\n", | |
"/net/home/h05/itwl/projects/git/iris/lib/iris/coords.py:955: UserWarning: Collapsing a non-contiguous coordinate. Metadata may not be fully descriptive for 'latitude'.\n", | |
" warnings.warn(msg.format(self.name()))\n", | |
"/net/home/h05/itwl/projects/git/iris/lib/iris/coords.py:955: UserWarning: Collapsing a non-contiguous coordinate. Metadata may not be fully descriptive for 'longitude'.\n", | |
" warnings.warn(msg.format(self.name()))\n" | |
] | |
} | |
], | |
"prompt_number": 19 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print cubes" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"0: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"1: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"2: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"3: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"4: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"5: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"6: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"7: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"8: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"9: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"10: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"11: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"12: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"13: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"14: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"15: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"16: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"17: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"18: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"19: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"20: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"21: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"22: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"23: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"24: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"25: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"26: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"27: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"28: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"29: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"30: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"31: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"32: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"33: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"34: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"35: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"36: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"37: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"38: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"39: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"40: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"41: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"42: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"43: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"44: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"45: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"46: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"47: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"48: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"49: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"50: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"51: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"52: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"53: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"54: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"55: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"56: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"57: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"58: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"59: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"60: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"61: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"62: unknown / (unknown) (latitude: 1; longitude: 1)\n", | |
"63: unknown / (unknown) (latitude: 1; longitude: 1)\n" | |
] | |
} | |
], | |
"prompt_number": 20 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 4, | |
"metadata": {}, | |
"source": [ | |
"Now concatenate the regional aggregated cubes back into one cube ..." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"result = cubes.concatenate()[0]" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 21 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print result" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"unknown / (unknown) (latitude: 8; longitude: 8)\n", | |
" Dimension coordinates:\n", | |
" latitude x -\n", | |
" longitude - x\n", | |
" Scalar coordinates:\n", | |
" forecast_period: 0.0 hours\n", | |
" forecast_reference_time: 2014-07-03 00:45:00\n", | |
" time: 2014-07-03 00:45:00\n", | |
" Cell methods:\n", | |
" sum: latitude, longitude\n" | |
] | |
} | |
], | |
"prompt_number": 22 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 4, | |
"metadata": {}, | |
"source": [ | |
"This is the final result ..." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print result.data" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"[[3235 3202 3224 3227 3173 3216 3194 3217]\n", | |
" [3182 3183 3205 3239 3192 3191 3165 3237]\n", | |
" [3164 3171 3194 3222 3204 3183 3216 3260]\n", | |
" [3223 3203 3103 3221 3178 3176 3265 3187]\n", | |
" [3207 3200 3202 3288 3158 3181 3156 3264]\n", | |
" [3271 3208 3222 3144 3220 3213 3285 3264]\n", | |
" [3224 3204 3113 3220 3208 3163 3187 3167]\n", | |
" [3241 3172 3311 3241 3278 3277 3228 3324]]\n" | |
] | |
} | |
], | |
"prompt_number": 23 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print result.coord('latitude')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"DimCoord(array([-70.125, -50.125, -30.125, -10.125, 9.875, 29.875, 49.875, 70. ], dtype=float32), bounds=array([[-80. , -60.25],\n", | |
" [-60. , -40.25],\n", | |
" [-40. , -20.25],\n", | |
" [-20. , -0.25],\n", | |
" [ 0. , 19.75],\n", | |
" [ 20. , 39.75],\n", | |
" [ 40. , 59.75],\n", | |
" [ 60. , 80. ]], dtype=float32), standard_name='latitude', units=Unit('degrees'), coord_system=GeogCS(6371229.0))\n" | |
] | |
} | |
], | |
"prompt_number": 24 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print result.coord('longitude')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"DimCoord(array([ 289.875, 309.875, 329.875, 349.875, 369.875, 389.875,\n", | |
" 409.875, 430. ], dtype=float32), bounds=array([[ 280. , 299.75],\n", | |
" [ 300. , 319.75],\n", | |
" [ 320. , 339.75],\n", | |
" [ 340. , 359.75],\n", | |
" [ 360. , 379.75],\n", | |
" [ 380. , 399.75],\n", | |
" [ 400. , 419.75],\n", | |
" [ 420. , 440. ]], dtype=float32), standard_name='longitude', units=Unit('degrees'), coord_system=GeogCS(6371229.0))\n" | |
] | |
} | |
], | |
"prompt_number": 25 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 4, | |
"metadata": {}, | |
"source": [ | |
"Seems to be working ..." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 25 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment