2d_variables_cdo.ipynb 71.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook was created using \"Python 2.7.12\" kernel from jupyerhub service from DKRZ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>.container { width:100% !important; }</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# this code will expand the width of the cells to fit the entire screen \n",
    "from IPython.core.display import display, HTML\n",
    "display(HTML(\"<style>.container { width:100% !important; }</style>\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# processing 2d variables using cdo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## overview\n",
    "\n",
    "- selecting variable of interest\n",
    "- setting grid information\n",
    "- selecting stations of interest\n",
    "- selecting region of interest\n",
    "- remapping to regular grid (lat, lon)\n",
    "- chaining cdo operators\n",
    "- working with multiple files, merging data-sets"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "for this exercise, we consider the following file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename = '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### selecting variable of interest"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Since, we picked 2d_cloud file, we select the following variable\n",
    "\n",
    "clwvi\n",
    " - **standard_name**: tqc_dia\n",
    " - **long_name**: total column integrated cloud water (diagnostic)\n",
    " - **units**: kg m$^{-2}$\n",
    "\n",
    "syntax:\n",
    "\n",
    "```cdo selvar,<varname>  ifile ofile```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " prw clwvi clivi clt z_pbl rain_gsp_rate ice_gsp_rate snow_gsp_rate hail_gsp_rate graupel_gsp_rate hbas_con htop_con cct t_ctop ccb t_cbase clch clcm clcl htop_dc\r\n",
      "cdo showname: Processed 20 variables ( 0.03s )\r\n"
     ]
    }
   ],
   "source": [
    "! cdo showvar $filename"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cdo selname: Processed 1336938240 values from 20 variables over 60 timesteps ( 11.96s )\r\n"
     ]
    }
   ],
   "source": [
    "#!mkdir tmp\n",
    "!cdo -O selvar,clwvi $filename tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " clwvi\r\n",
      "cdo showname: Processed 1 variable ( 0.01s )\r\n"
     ]
    }
   ],
   "source": [
    "!cdo showvar tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### setting grid information"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Typically, data files do not have grid information. Since, we the data file belongs to domain DOM03 we set the following grid file.\n",
    "\n",
    "syntax:\n",
    "\n",
    "```cdo setgrid,grid  ifile ofile```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "gridfile = \"/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cdo setgrid: Processed 1336938240 values from 1 variable over 60 timesteps ( 24.47s )\r\n"
     ]
    }
   ],
   "source": [
    "!cdo -O setgrid,$gridfile tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "netcdf \\2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid {\r\n",
      "dimensions:\r\n",
      "\tcell = 22282304 ;\r\n",
      "\tnv = 3 ;\r\n",
      "\ttime = UNLIMITED ; // (60 currently)\r\n",
      "variables:\r\n",
      "\tdouble clon(cell) ;\r\n",
      "\t\tclon:standard_name = \"longitude\" ;\r\n",
      "\t\tclon:long_name = \"center longitude\" ;\r\n",
      "\t\tclon:units = \"radian\" ;\r\n",
      "\t\tclon:bounds = \"clon_bnds\" ;\r\n",
      "\tdouble clon_bnds(cell, nv) ;\r\n",
      "\tdouble clat(cell) ;\r\n",
      "\t\tclat:standard_name = \"latitude\" ;\r\n",
      "\t\tclat:long_name = \"center latitude\" ;\r\n",
      "\t\tclat:units = \"radian\" ;\r\n",
      "\t\tclat:bounds = \"clat_bnds\" ;\r\n",
      "\tdouble clat_bnds(cell, nv) ;\r\n",
      "\tdouble time(time) ;\r\n",
      "\t\ttime:standard_name = \"time\" ;\r\n",
      "\t\ttime:units = \"day as %Y%m%d.%f\" ;\r\n",
      "\t\ttime:calendar = \"proleptic_gregorian\" ;\r\n",
      "\t\ttime:axis = \"T\" ;\r\n",
      "\tfloat clwvi(time, cell) ;\r\n",
      "\t\tclwvi:standard_name = \"tqc_dia\" ;\r\n",
      "\t\tclwvi:long_name = \"total column integrated cloud water (diagnostic)\" ;\r\n",
      "\t\tclwvi:units = \"kg m**-2\" ;\r\n",
      "\t\tclwvi:param = \"215.1.0\" ;\r\n",
      "\t\tclwvi:CDI_grid_type = \"unstructured\" ;\r\n",
      "\t\tclwvi:coordinates = \"clat clon\" ;\r\n",
      "\r\n",
      "// global attributes:\r\n",
      "\t\t:_NCProperties = \"version=1|netcdflibversion=4.4.1.1|hdf5libversion=1.8.14\" ;\r\n",
      "\t\t:CDI = \"Climate Data Interface version 1.9.0 (http://mpimet.mpg.de/cdi)\" ;\r\n",
      "\t\t:history = \"Fri Feb 09 10:16:13 2018: cdo -O setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc\\nFri Feb 09 10:15:20 2018: cdo -O selvar,clwvi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc\\nFri Feb 10 11:38:21 2017: cdo -P 12 mergetime /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_1+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_2+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/DATA3/2d_cloud_day_DOM03_ML_20130528T060000Z.nc\\n/work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/build/x86_64-unknown-linux-gnu/bin/icon at 20160912 140913\" ;\r\n",
      "\t\t:source = \"@\" ;\r\n",
      "\t\t:institution = \"Max Planck Institute for Meteorology\" ;\r\n",
      "\t\t:Conventions = \"CF-1.4\" ;\r\n",
      "\t\t:title = \"ICON simulation\" ;\r\n",
      "\t\t:references = \"see MPIM/DWD publications\" ;\r\n",
      "\t\t:comment = \"HDCP2 Sammelaccount (k203095) on m21241 (Linux 2.6.32-573.3.1.el6.x86_64 x86_64)\" ;\r\n",
      "\t\t:cdo_openmp_thread_number = 12 ;\r\n",
      "\t\t:CDO = \"Climate Data Operators version 1.9.0 (http://mpimet.mpg.de/cdo)\" ;\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "! ncdump -h tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### selecting station(s) of interest"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For some time now, I was under the impression that cdo did not have an operator to select stations from a grid file, but it turns out that it could be done using remapnn operator.\n",
    "\n",
    "The help text of this remapnn operator, totally gives it away."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NAME\r\n",
      "    remapnn, gennn - Nearest neighbor remapping\r\n",
      "\r\n",
      "SYNOPSIS\r\n",
      "    <operator>,grid  infile outfile\r\n",
      "\r\n",
      "DESCRIPTION\r\n",
      "    This module contains operators for a nearest neighbor remapping of fields between grids\r\n",
      "    in spherical coordinates.\r\n",
      "\r\n",
      "OPERATORS\r\n",
      "    remapnn  Nearest neighbor remapping\r\n",
      "             Performs a nearest neighbor remapping on all input fields.\r\n",
      "    gennn    Generate nearest neighbor remap weights\r\n",
      "             Generates nearest neighbor remapping weights for the first input field and writes the result to a file.\r\n",
      "             The format of this file is NetCDF following the SCRIP convention.\r\n",
      "             Use the operator remap to apply this remapping weights to a data file with the same source grid.\r\n",
      "\r\n",
      "PARAMETER\r\n",
      "    grid  STRING  Target grid description file or name\r\n",
      "\r\n",
      "ENVIRONMENT\r\n",
      "    REMAP_EXTRAPOLATE    \r\n",
      "        This variable is used to switch the extrapolation feature 'on' or 'off'.\r\n",
      "        By default the extrapolation is enabled for this remapping method.\r\n",
      "    CDO_GRIDSEARCH_RADIUS\r\n",
      "        Grid search radius in degree, default 180 degree.\r\n"
     ]
    }
   ],
   "source": [
    "!cdo --help remapnn"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Considering station c12 (lon=14.110, lat=52.210) for the exercise"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cdo remapnn: Nearest neighbor weights from unstructured (22282304) to lonlat (1x1) grid\n",
      "cdo remapnn:   1cdo remapnn: Processed 1336938240 values from 1 variable over 60 timesteps ( 59.96s )\n"
     ]
    }
   ],
   "source": [
    "!cdo -O remapnn,lon=14.110/lat=52.210 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_c12.nc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "verifying with ncdump"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "netcdf \\2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_c12 {\r\n",
      "dimensions:\r\n",
      "\tlon = 1 ;\r\n",
      "\tlat = 1 ;\r\n",
      "\ttime = UNLIMITED ; // (60 currently)\r\n",
      "variables:\r\n",
      "\tfloat lon(lon) ;\r\n",
      "\t\tlon:standard_name = \"longitude\" ;\r\n",
      "\t\tlon:long_name = \"longitude\" ;\r\n",
      "\t\tlon:units = \"degrees_east\" ;\r\n",
      "\t\tlon:axis = \"X\" ;\r\n",
      "\tfloat lat(lat) ;\r\n",
      "\t\tlat:standard_name = \"latitude\" ;\r\n",
      "\t\tlat:long_name = \"latitude\" ;\r\n",
      "\t\tlat:units = \"degrees_north\" ;\r\n",
      "\t\tlat:axis = \"Y\" ;\r\n",
      "\tdouble time(time) ;\r\n",
      "\t\ttime:standard_name = \"time\" ;\r\n",
      "\t\ttime:units = \"day as %Y%m%d.%f\" ;\r\n",
      "\t\ttime:calendar = \"proleptic_gregorian\" ;\r\n",
      "\t\ttime:axis = \"T\" ;\r\n",
      "\tfloat clwvi(time, lat, lon) ;\r\n",
      "\t\tclwvi:standard_name = \"tqc_dia\" ;\r\n",
      "\t\tclwvi:long_name = \"total column integrated cloud water (diagnostic)\" ;\r\n",
      "\t\tclwvi:units = \"kg m**-2\" ;\r\n",
      "\t\tclwvi:param = \"215.1.0\" ;\r\n",
      "\r\n",
      "// global attributes:\r\n",
      "\t\t:_NCProperties = \"version=1|netcdflibversion=4.4.1.1|hdf5libversion=1.8.14\" ;\r\n",
      "\t\t:CDI = \"Climate Data Interface version 1.9.0 (http://mpimet.mpg.de/cdi)\" ;\r\n",
      "\t\t:history = \"Fri Feb 09 10:16:40 2018: cdo -O remapnn,lon=14.110/lat=52.210 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_c12.nc\\nFri Feb 09 10:16:13 2018: cdo -O setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc\\nFri Feb 09 10:15:20 2018: cdo -O selvar,clwvi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc\\nFri Feb 10 11:38:21 2017: cdo -P 12 mergetime /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_1+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_2+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/DATA3/2d_cloud_day_DOM03_ML_20130528T060000Z.nc\\n/work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/build/x86_64-unknown-linux-gnu/bin/icon at 20160912 140913\" ;\r\n",
      "\t\t:source = \"@\" ;\r\n",
      "\t\t:institution = \"Max Planck Institute for Meteorology\" ;\r\n",
      "\t\t:Conventions = \"CF-1.4\" ;\r\n",
      "\t\t:title = \"ICON simulation\" ;\r\n",
      "\t\t:references = \"see MPIM/DWD publications\" ;\r\n",
      "\t\t:comment = \"HDCP2 Sammelaccount (k203095) on m21241 (Linux 2.6.32-573.3.1.el6.x86_64 x86_64)\" ;\r\n",
      "\t\t:cdo_openmp_thread_number = 12 ;\r\n",
      "\t\t:CDO = \"Climate Data Operators version 1.9.0 (http://mpimet.mpg.de/cdo)\" ;\r\n",
      "data:\r\n",
      "\r\n",
      " lon = 14.11 ;\r\n",
      "\r\n",
      " lat = 52.21 ;\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!ncdump -v lon,lat tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_c12.nc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### selecting region of interest"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We select a 10x10 km grid around Joice station (50.909, 6.414)\n",
    "\n",
    "REGION = 6.2710, 6.5559, 50.8190, 50.9979\n",
    "\n",
    "syntax:\n",
    "\n",
    "```cdo sellonlatbox,lon1,lon2,lat1,lat2  ifile ofile```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cdo sellonlatbox: Processed 1336938240 values from 1 variable over 60 timesteps ( 5.74s )\r\n"
     ]
    }
   ],
   "source": [
    "!cdo -O sellonlatbox,6.2710,6.5559,50.8190,50.9979 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "dumping the header to check 'ncells' in the dimension"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "netcdf \\2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10 {\r\n",
      "dimensions:\r\n",
      "\tcell = 16338 ;\r\n",
      "\tnv = 3 ;\r\n",
      "\ttime = UNLIMITED ; // (60 currently)\r\n",
      "variables:\r\n",
      "\tdouble clon(cell) ;\r\n",
      "\t\tclon:standard_name = \"longitude\" ;\r\n",
      "\t\tclon:long_name = \"center longitude\" ;\r\n",
      "\t\tclon:units = \"radian\" ;\r\n",
      "\t\tclon:bounds = \"clon_bnds\" ;\r\n",
      "\tdouble clon_bnds(cell, nv) ;\r\n",
      "\tdouble clat(cell) ;\r\n",
      "\t\tclat:standard_name = \"latitude\" ;\r\n",
      "\t\tclat:long_name = \"center latitude\" ;\r\n",
      "\t\tclat:units = \"radian\" ;\r\n",
      "\t\tclat:bounds = \"clat_bnds\" ;\r\n",
      "\tdouble clat_bnds(cell, nv) ;\r\n",
      "\tdouble time(time) ;\r\n",
      "\t\ttime:standard_name = \"time\" ;\r\n",
      "\t\ttime:units = \"day as %Y%m%d.%f\" ;\r\n",
      "\t\ttime:calendar = \"proleptic_gregorian\" ;\r\n",
      "\t\ttime:axis = \"T\" ;\r\n",
      "\tfloat clwvi(time, cell) ;\r\n",
      "\t\tclwvi:standard_name = \"tqc_dia\" ;\r\n",
      "\t\tclwvi:long_name = \"total column integrated cloud water (diagnostic)\" ;\r\n",
      "\t\tclwvi:units = \"kg m**-2\" ;\r\n",
      "\t\tclwvi:param = \"215.1.0\" ;\r\n",
      "\t\tclwvi:CDI_grid_type = \"unstructured\" ;\r\n",
      "\t\tclwvi:coordinates = \"clat clon\" ;\r\n",
      "\r\n",
      "// global attributes:\r\n",
      "\t\t:_NCProperties = \"version=1|netcdflibversion=4.4.1.1|hdf5libversion=1.8.14\" ;\r\n",
      "\t\t:CDI = \"Climate Data Interface version 1.9.0 (http://mpimet.mpg.de/cdi)\" ;\r\n",
      "\t\t:history = \"Fri Feb 09 10:17:43 2018: cdo -O sellonlatbox,6.2710,6.5559,50.8190,50.9979 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc\\nFri Feb 09 10:16:13 2018: cdo -O setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc\\nFri Feb 09 10:15:20 2018: cdo -O selvar,clwvi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc\\nFri Feb 10 11:38:21 2017: cdo -P 12 mergetime /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_1+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_2+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/DATA3/2d_cloud_day_DOM03_ML_20130528T060000Z.nc\\n/work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/build/x86_64-unknown-linux-gnu/bin/icon at 20160912 140913\" ;\r\n",
      "\t\t:source = \"@\" ;\r\n",
      "\t\t:institution = \"Max Planck Institute for Meteorology\" ;\r\n",
      "\t\t:Conventions = \"CF-1.4\" ;\r\n",
      "\t\t:title = \"ICON simulation\" ;\r\n",
      "\t\t:references = \"see MPIM/DWD publications\" ;\r\n",
      "\t\t:comment = \"HDCP2 Sammelaccount (k203095) on m21241 (Linux 2.6.32-573.3.1.el6.x86_64 x86_64)\" ;\r\n",
      "\t\t:cdo_openmp_thread_number = 12 ;\r\n",
      "\t\t:CDO = \"Climate Data Operators version 1.9.0 (http://mpimet.mpg.de/cdo)\" ;\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!ncdump -h tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#\r\n",
      "# gridID 1\r\n",
      "#\r\n",
      "gridtype  = unstructured\r\n",
      "gridsize  = 16338\r\n",
      "xname     = clon\r\n",
      "xdimname  = cell\r\n",
      "xlongname = \"center longitude\"\r\n",
      "xunits    = \"radian\"\r\n",
      "yname     = clat\r\n",
      "ydimname  = cell\r\n",
      "ylongname = \"center latitude\"\r\n",
      "yunits    = \"radian\"\r\n",
      "vdimname  = nv\r\n",
      "nvertex   = 3\r\n",
      "xvals     = 0.113197699174129 0.113214957106932 0.113159315049856 0.113253341760467 \r\n",
      "            0.113096771005351 0.113108851132979 0.113114027830132 0.113058384584808 \r\n",
      "            0.113164493800421 0.113147236423399 0.113202879578879 0.113152414768621 \r\n",
      "            0.113063559226833 0.113101947301689 0.11305147719576 0.113046302958092 \r\n",
      "            0.113053210389446 0.113041129166376 0.113091595162638 0.114168229417848 \r\n",
      "            0.11412984965885 0.114180285308162 0.114185511321636 0.11412462615274 \r\n",
      "            0.114112569162082 0.114163004257405 0.114235946383656 0.114218663930281 \r\n",
      "            0.114274325504936 0.114223891590975 0.114135073614791 0.114173455031543 \r\n",
      "            0.114123015818008 0.114117792266988 0.114269095789069 0.114286378796514 \r\n",
      "            0.114230718322774 0.114246403878359 0.114229119711954 0.114284786307159 \r\n",
      "            0.114234348285445 0.114279555678084 0.114241174903115 0.114291609370232 \r\n",
      "            0.114296840397846 0.114290017380741 0.114302071876861 0.114307303807685 \r\n",
      "            0.114251633307601 0.114178681095906 0.114195964703908 0.114140298025593 \r\n",
      "            0.114190737792546 0.11402375100028 0.114062131407526 0.114011691008249 \r\n",
      "            0.11400647246644 0.11406735245964 0.114079411353059 0.114084633259471 \r\n"
     ]
    }
   ],
   "source": [
    "!cdo -s griddes tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc | head -n 30"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### remapping to regular grid (lat, lon)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For remapping there are two important things\n",
    "- defining target grid description\n",
    "- kind of remapping. example: conservative, nearest-neighborhood, etc..\n",
    "\n",
    "The second one is very easy as it is just a matter of choosing the desired operator.\n",
    "\n",
    "Defining target grid description requires some work as it is completely up to the user how the target grid is defined (subjective to the use case). Fortunately, there exists a helper python script which makes it easy in generating the target grid description for a regular grid.\n",
    "\n",
    "First, checking out the --help of the python script"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "usage: gridspec.py [-h] [-o OUTFILE] (-r RESOLUTION | -d {DOM01,DOM02,DOM03})\r\n",
      "                   (-b BOUNDS | -f NCFILE)\r\n",
      "\r\n",
      "Generates description of the target grid for a given resolution and lat-lon\r\n",
      "bounds. This description is one of the input parameters for the cdo operator\r\n",
      "'remap'.\r\n",
      "\r\n",
      "optional arguments:\r\n",
      "  -h, --help            show this help message and exit\r\n",
      "  -o OUTFILE, --outfile OUTFILE\r\n",
      "                        File to which output must be written. (default: stdout)\r\n",
      "  -r RESOLUTION, --resolution RESOLUTION\r\n",
      "                        Resolution of the target grid in Kilometers.\r\n",
      "  -d {DOM01,DOM02,DOM03}, --domain {DOM01,DOM02,DOM03}\r\n",
      "                        Domain to be used for calculating resolution. In this case, the resolution of\r\n",
      "                        the target grid is most similar to the native resolution of the domain\r\n",
      "                        selected. The triangle edge lengths in the ICON grid are 625m, 312m, 156m for\r\n",
      "                        DOM01, DOM02, DOM03, respectively.\r\n",
      "  -b BOUNDS, --bounds BOUNDS\r\n",
      "                        Comma separated corner tics of region of interest given as\r\n",
      "                        'lon1,lon2,lat1,lat2'. These corner tics refer to the lower left and upper\r\n",
      "                        right corners.\r\n",
      "  -f NCFILE, --ncfile NCFILE\r\n",
      "                        Grid file from which the corner tics are to be read. Use this option if\r\n",
      "                        the full extent of grid is considered to be the region of interest.\r\n",
      "\r\n",
      "options '--resolution' and '--domain' are mutually exclusive.\r\n",
      "Provide either one of these.\r\n",
      "In case of option '--domain', the resolution obtained from the specified domain\r\n",
      "(DOM01,DOM02,DOM03) is obtained by multiplying the native triangle edge length\r\n",
      "with a factor of 0.67 which is equivalent to defining the resolution as square\r\n",
      "root of the area of the triangle.\r\n",
      "For details about this factor, please refer to:\r\n",
      "(http://onlinelibrary.wiley.com/doi/10.1002/2015MS000431/full#jame20180-app-0003)\r\n",
      "\r\n",
      "\"A. Dipankar, B. Stevens, R. Heinze, C. Moseley, G. Zängl, M. Giorgetta, and\r\n",
      "S. Brdar (2015),Large eddy simulation using the general circulation model ICON,\r\n",
      "J. Adv. Model. Earth Syst., 7, 963–986, doi:10.1002/2015MS000431.\"\r\n",
      "\r\n",
      "options '--bounds' and '--ncfile' are also mutually exclusive.\r\n",
      "Provide either one of these.\r\n",
      "\r\n",
      "Example:\r\n",
      "--------\r\n",
      "1. To generate a grid description for a 10x10 grid around joyce for DOM03\r\n",
      "\r\n",
      " python gridspec.py --outfile joyce_10x10_griddes --domain DOM03 --bounds 6.2715,6.5564,50.8191,50.9988\r\n",
      "\r\n",
      "2. To generate a grid description for entire domain for DOM03\r\n",
      "\r\n",
      " python gridspec.py -d DOM03 -f /work/bm0834/k203095/OUTPUT/GRIDS/GRID_3d_fine_DOM03_ML.nc\r\n",
      "\r\n",
      "3. To generate a grid description for a custom resolution of 400m\r\n",
      "\r\n",
      " python gridspec.py --resolution=0.4 --bounds 6.2715,6.5564,50.8191,50.9988\r\n",
      "\r\n",
      "  TIP: Leave no whitespaces between the option and its value.\r\n",
      "\r\n",
      " python gridspec.py -ogriddes -dDOM02 -b6.27,6.55,50.81,50.99\r\n",
      " python gridspec.py --outfile=griddes --domain=DOM02 --bounds=6.27,6.55,50.81,50.99\r\n"
     ]
    }
   ],
   "source": [
    "! python ../scripts/gridspec.py --help"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "The recommended way to use this script is to supply **resolution** and **bounds**\n",
    "\n",
    "Since, the file we are working with is from DOM03 we can choose resolution as 0.156 to stay close to original grid resolution. But one can choose to go coarser than that. For this demo, we will stick to 0.156\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "gridtype   = lonlat\r\n",
      "gridsize   = 16383\r\n",
      "xname      = lon\r\n",
      "xlongname  = longitude\r\n",
      "xunits     = degrees_east\r\n",
      "yname      = lat\r\n",
      "ylongname  = latitude\r\n",
      "yunits     = degrees_north\r\n",
      "xsize      = 129\r\n",
      "ysize      = 127\r\n",
      "xfirst     = 6.271\r\n",
      "xinc       = 0.0022\r\n",
      "yfirst     = 50.819\r\n",
      "yinc       = 0.0014\r\n"
     ]
    }
   ],
   "source": [
    "!/work/bm0834/k202101/utils/gridspec.py -r 0.156 -b 6.2710,6.5559,50.8190,50.9979"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "!/work/bm0834/k202101/utils/gridspec.py -r 0.156 -b 6.2710,6.5559,50.8190,50.9979 -o tmp/joyce_10x10_griddes_dom03"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### remap\n",
    "\n",
    "```cdo remapnn,griddes ifile ofile```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cdo remapnn: Nearest neighbor weights from unstructured (16338) to lonlat (129x127) grid\n",
      "cdo remapnn:                        1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 91cdo remapnn: Processed 980280 values from 1 variable over 60 timesteps ( 0.06s )\n"
     ]
    }
   ],
   "source": [
    "!cdo remapnn,tmp/joyce_10x10_griddes_dom03 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_ll.nc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### checking the grid description"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "#\r\n",
      "# gridID 1\r\n",
      "#\r\n",
      "gridtype  = lonlat\r\n",
      "gridsize  = 16383\r\n",
      "xsize     = 129\r\n",
      "ysize     = 127\r\n",
      "xname     = lon\r\n",
      "xlongname = \"longitude\"\r\n",
      "xunits    = \"degrees_east\"\r\n",
      "yname     = lat\r\n",
      "ylongname = \"latitude\"\r\n",
      "yunits    = \"degrees_north\"\r\n",
      "xfirst    = 6.271\r\n",
      "xinc      = 0.0022\r\n",
      "yfirst    = 50.819\r\n",
      "yinc      = 0.001399994\r\n",
      "cdo griddes: Processed 1 variable ( 0.00s )\r\n"
     ]
    }
   ],
   "source": [
    "!cdo griddes tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_ll.nc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Listing the file header information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "netcdf \\2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_ll {\r\n",
      "dimensions:\r\n",
      "\tlon = 129 ;\r\n",
      "\tlat = 127 ;\r\n",
      "\ttime = UNLIMITED ; // (60 currently)\r\n",
      "variables:\r\n",
      "\tfloat lon(lon) ;\r\n",
      "\t\tlon:standard_name = \"longitude\" ;\r\n",
      "\t\tlon:long_name = \"longitude\" ;\r\n",
      "\t\tlon:units = \"degrees_east\" ;\r\n",
      "\t\tlon:axis = \"X\" ;\r\n",
      "\tfloat lat(lat) ;\r\n",
      "\t\tlat:standard_name = \"latitude\" ;\r\n",
      "\t\tlat:long_name = \"latitude\" ;\r\n",
      "\t\tlat:units = \"degrees_north\" ;\r\n",
      "\t\tlat:axis = \"Y\" ;\r\n",
      "\tdouble time(time) ;\r\n",
      "\t\ttime:standard_name = \"time\" ;\r\n",
      "\t\ttime:units = \"day as %Y%m%d.%f\" ;\r\n",
      "\t\ttime:calendar = \"proleptic_gregorian\" ;\r\n",
      "\t\ttime:axis = \"T\" ;\r\n",
      "\tfloat clwvi(time, lat, lon) ;\r\n",
      "\t\tclwvi:standard_name = \"tqc_dia\" ;\r\n",
      "\t\tclwvi:long_name = \"total column integrated cloud water (diagnostic)\" ;\r\n",
      "\t\tclwvi:units = \"kg m**-2\" ;\r\n",
      "\t\tclwvi:param = \"215.1.0\" ;\r\n",
      "\r\n",
      "// global attributes:\r\n",
      "\t\t:_NCProperties = \"version=1|netcdflibversion=4.4.1.1|hdf5libversion=1.8.14\" ;\r\n",
      "\t\t:CDI = \"Climate Data Interface version 1.9.0 (http://mpimet.mpg.de/cdi)\" ;\r\n",
      "\t\t:history = \"Fri Feb 09 10:23:09 2018: cdo remapnn,tmp/joyce_10x10_griddes_dom03 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_ll.nc\\nFri Feb 09 10:17:43 2018: cdo -O sellonlatbox,6.2710,6.5559,50.8190,50.9979 tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_joice_10x10.nc\\nFri Feb 09 10:16:13 2018: cdo -O setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_withgrid.nc\\nFri Feb 09 10:15:20 2018: cdo -O selvar,clwvi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi.nc\\nFri Feb 10 11:38:21 2017: cdo -P 12 mergetime /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_1+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_2+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/DATA3/2d_cloud_day_DOM03_ML_20130528T060000Z.nc\\n/work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/build/x86_64-unknown-linux-gnu/bin/icon at 20160912 140913\" ;\r\n",
      "\t\t:source = \"@\" ;\r\n",
      "\t\t:institution = \"Max Planck Institute for Meteorology\" ;\r\n",
      "\t\t:Conventions = \"CF-1.4\" ;\r\n",
      "\t\t:title = \"ICON simulation\" ;\r\n",
      "\t\t:references = \"see MPIM/DWD publications\" ;\r\n",
      "\t\t:comment = \"HDCP2 Sammelaccount (k203095) on m21241 (Linux 2.6.32-573.3.1.el6.x86_64 x86_64)\" ;\r\n",
      "\t\t:cdo_openmp_thread_number = 12 ;\r\n",
      "\t\t:CDO = \"Climate Data Operators version 1.9.0 (http://mpimet.mpg.de/cdo)\" ;\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!ncdump -h tmp/2d_cloud_day_DOM03_ML_20130528T060000Z_clwvi_ll.nc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### chaining cdo operators"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "chaining multiple operators in a single command improves overall performance as the intermediate results are piped between operators. In other words, avoiding I/O overhead.\n",
    "\n",
    "Some times the order of the operators matter but most of the time cdo is intelligent enough to figure out what needs to be done.\n",
    "\n",
    "To demo this, we repeat the same steps as above but with variable **clivi**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cdo remapnn: Started child process \"sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc (pipe1.1)\".\n",
      "cdo(2) sellonlatbox: Started child process \"setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc (pipe2.1)\".\n",
      "cdo(3) setgrid: Started child process \"selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc (pipe3.1)\".\n",
      "cdo remapnn: Nearest neighbor weights from unstructured (16338) to lonlat (129x127) grid\n",
      "cdo remapnn:                        1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 91cdo(4) selname: Processed 1336938240 values from 20 variables over 60 timesteps ( 10.84s )\n",
      "cdo(3) setgrid: Processed 1336938240 values from 1 variable over 60 timesteps ( 17.45s )\n",
      "cdo(2) sellonlatbox: Processed 1336938240 values from 1 variable over 60 timesteps ( 17.45s )\n",
      "cdo remapnn: Processed 980280 values from 1 variable over 60 timesteps ( 17.45s )\n"
     ]
    }
   ],
   "source": [
    "!cdo -O remapnn,tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,$gridfile -selvar,clivi  $filename tmp/clivi_joice.nc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "netcdf clivi_joice {\r\n",
      "dimensions:\r\n",
      "\tlon = 129 ;\r\n",
      "\tlat = 127 ;\r\n",
      "\ttime = UNLIMITED ; // (60 currently)\r\n",
      "variables:\r\n",
      "\tfloat lon(lon) ;\r\n",
      "\t\tlon:standard_name = \"longitude\" ;\r\n",
      "\t\tlon:long_name = \"longitude\" ;\r\n",
      "\t\tlon:units = \"degrees_east\" ;\r\n",
      "\t\tlon:axis = \"X\" ;\r\n",
      "\tfloat lat(lat) ;\r\n",
      "\t\tlat:standard_name = \"latitude\" ;\r\n",
      "\t\tlat:long_name = \"latitude\" ;\r\n",
      "\t\tlat:units = \"degrees_north\" ;\r\n",
      "\t\tlat:axis = \"Y\" ;\r\n",
      "\tdouble time(time) ;\r\n",
      "\t\ttime:standard_name = \"time\" ;\r\n",
      "\t\ttime:units = \"day as %Y%m%d.%f\" ;\r\n",
      "\t\ttime:calendar = \"proleptic_gregorian\" ;\r\n",
      "\t\ttime:axis = \"T\" ;\r\n",
      "\tfloat clivi(time, lat, lon) ;\r\n",
      "\t\tclivi:standard_name = \"tqi_dia\" ;\r\n",
      "\t\tclivi:long_name = \"total column integrated cloud ice (diagnostic)\" ;\r\n",
      "\t\tclivi:units = \"kg m**-2\" ;\r\n",
      "\t\tclivi:param = \"216.1.0\" ;\r\n",
      "\r\n",
      "// global attributes:\r\n",
      "\t\t:_NCProperties = \"version=1|netcdflibversion=4.4.1.1|hdf5libversion=1.8.14\" ;\r\n",
      "\t\t:CDI = \"Climate Data Interface version 1.9.0 (http://mpimet.mpg.de/cdi)\" ;\r\n",
      "\t\t:history = \"Fri Feb 09 10:24:24 2018: cdo -O remapnn,tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc tmp/clivi_joice.nc\\nFri Feb 10 11:38:21 2017: cdo -P 12 mergetime /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_1+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/2d_cloud_day_DOM03_ML_20130528T060000Z.nc_part_2+ /work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/experiments/hdcp2_final_0528/DATA3/2d_cloud_day_DOM03_ML_20130528T060000Z.nc\\n/work/bm0834/k203095/icon-hdcp2-20150930-montse/icon-hdcp2-20150930/build/x86_64-unknown-linux-gnu/bin/icon at 20160912 140913\" ;\r\n",
      "\t\t:source = \"@\" ;\r\n",
      "\t\t:institution = \"Max Planck Institute for Meteorology\" ;\r\n",
      "\t\t:Conventions = \"CF-1.4\" ;\r\n",
      "\t\t:title = \"ICON simulation\" ;\r\n",
      "\t\t:references = \"see MPIM/DWD publications\" ;\r\n",
      "\t\t:comment = \"HDCP2 Sammelaccount (k203095) on m21241 (Linux 2.6.32-573.3.1.el6.x86_64 x86_64)\" ;\r\n",
      "\t\t:cdo_openmp_thread_number = 12 ;\r\n",
      "\t\t:CDO = \"Climate Data Operators version 1.9.0 (http://mpimet.mpg.de/cdo)\" ;\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!ncdump -h tmp/clivi_joice.nc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Multiple files"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "TASK:\n",
    "- For simulation day **28-05-2013**, collect **2d_cloud** files for **domain 03**\n",
    "- select variable **prw**\n",
    "- cut the region of interest: 10x10km around Joice (6.2710,6.5559,50.8190,50.9979)\n",
    "- remap to regular grid with target grid resolution of **200 meters**\n",
    "- merge dataset\n",
    "- resulting file should have a temporal resolution of **5 minutes**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### gathering files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "import glob\n",
    "import re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T000000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T010000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T020000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T030000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T040000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T050000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T070000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T080000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T090000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T100000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T110000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T120000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T130000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T140000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T150000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T160000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T170000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T180000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T190000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T200000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T210000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T220000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T230000Z.nc',\n",
       " '/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130529T000000Z.nc']"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_re = re.compile('(\\d{8}T\\d+)').search\n",
    "\n",
    "in_files = glob.glob(\"/work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_*_DOM03*Z.nc\")\n",
    "in_files = sorted(in_files, key=lambda x: 'day' in x)\n",
    "in_files = sorted(in_files, key=lambda x: date_re(x).group(1))\n",
    "in_files"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "prepare out-files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['./tmp/2d_cloud_night_DOM03_ML_20130528T000000Z.nc',\n",
       " './tmp/2d_cloud_night_DOM03_ML_20130528T010000Z.nc',\n",
       " './tmp/2d_cloud_night_DOM03_ML_20130528T020000Z.nc',\n",
       " './tmp/2d_cloud_night_DOM03_ML_20130528T030000Z.nc',\n",
       " './tmp/2d_cloud_night_DOM03_ML_20130528T040000Z.nc',\n",
       " './tmp/2d_cloud_night_DOM03_ML_20130528T050000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T060000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T070000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T080000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T090000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T100000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T110000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T120000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T130000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T140000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T150000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T160000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T170000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T180000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T190000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T200000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T210000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T220000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130528T230000Z.nc',\n",
       " './tmp/2d_cloud_day_DOM03_ML_20130529T000000Z.nc']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dest_dir = \"./tmp\"\n",
    "out_files = [os.path.join(dest_dir, fname) for fname in map(os.path.basename, in_files)]\n",
    "out_files"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### using the above cdo command with chaining operators "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "variable = \"clivi\"\n",
    "griddes = \"./tmp/joyce_10x10_griddes_dom03\"\n",
    "joice_bbox = \"6.2710,6.5559,50.8190,50.9979\"\n",
    "gridfile = \"/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc\"\n",
    "\n",
    "cmd_template = \"cdo -O remapnn,{griddes} -sellonlatbox,{box} -setgrid,{gridfile} -selvar,{variable} {ifile} {ofile}\".format"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "preparing commands"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T000000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T000000Z.nc'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cmds = []\n",
    "for ifile, ofile in zip(in_files, out_files):\n",
    "    cmd = cmd_template(griddes=griddes, box=joice_bbox, gridfile=gridfile, variable=variable, ifile=ifile, ofile=ofile)\n",
    "    cmds.append(cmd)\n",
    "    \n",
    "# checking out the first entry\n",
    "cmds[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "running commands"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "import subprocess as sp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T000000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T000000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T010000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T010000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T020000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T020000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T030000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T030000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T040000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T040000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_night_DOM03_ML_20130528T050000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T050000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T060000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T060000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T070000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T070000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T080000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T080000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T090000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T090000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T100000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T100000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T110000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T110000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T120000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T120000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T130000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T130000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T140000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T140000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T150000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T150000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T160000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T160000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T170000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T170000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T180000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T180000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T190000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T190000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T200000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T200000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T210000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T210000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T220000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T220000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130528T230000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T230000Z.nc\n",
      "cdo -O remapnn,./tmp/joyce_10x10_griddes_dom03 -sellonlatbox,6.2710,6.5559,50.8190,50.9979 -setgrid,/work/bm0834/k203095/OUTPUT/GRIDS/hdcp2_default_nest_R0156m_DOM03.nc -selvar,clivi /work/bm0834/k203095/OUTPUT/20130528-default/DATA/2d_cloud_day_DOM03_ML_20130529T000000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130529T000000Z.nc\n"
     ]
    }
   ],
   "source": [
    "for cmd in cmds:\n",
    "    print(cmd)\n",
    "    sp.check_output(cmd, shell=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### merging"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cdo mergetime ./tmp/2d_cloud_night_DOM03_ML_20130528T000000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T010000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T020000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T030000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T040000Z.nc ./tmp/2d_cloud_night_DOM03_ML_20130528T050000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T060000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T070000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T080000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T090000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T100000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T110000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T120000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T130000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T140000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T150000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T160000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T170000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T180000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T190000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T200000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T210000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T220000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130528T230000Z.nc ./tmp/2d_cloud_day_DOM03_ML_20130529T000000Z.nc ./tmp/prw_merged.nc\n"
     ]
    }
   ],
   "source": [
    "mergefile = \"./tmp/prw_merged.nc\"\n",
    "template =  \"cdo mergetime {0} {1}\".format\n",
    "cmd = template(\" \".join(out_files), mergefile)\n",
    "print(cmd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cdo mergetime: Processed 18889599 values from 25 variables over 1153 timesteps ( 0.35s )\r\n"
     ]
    }
   ],
   "source": [
    "! SKIP_SAME_TIME=1 $cmd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### selecting 5 minute frequency"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2013-05-28 00:00:00', '2013-05-28 00:05:00',\n",
       "               '2013-05-28 00:10:00', '2013-05-28 00:15:00',\n",
       "               '2013-05-28 00:20:00', '2013-05-28 00:25:00',\n",
       "               '2013-05-28 00:30:00', '2013-05-28 00:35:00',\n",
       "               '2013-05-28 00:40:00', '2013-05-28 00:45:00',\n",
       "               ...\n",
       "               '2013-05-28 23:51:00', '2013-05-28 23:52:00',\n",
       "               '2013-05-28 23:53:00', '2013-05-28 23:54:00',\n",
       "               '2013-05-28 23:55:00', '2013-05-28 23:56:00',\n",
       "               '2013-05-28 23:57:00', '2013-05-28 23:58:00',\n",
       "               '2013-05-28 23:59:00', '2013-05-29 00:00:00'],\n",
       "              dtype='datetime64[ns]', length=1153, freq=None)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_string = sp.check_output(\"cdo -s showtimestamp {}\".format(mergefile), shell=True)\n",
    "dates = pd.to_datetime(date_string.strip().split())\n",
    "dates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2013-05-28 00:00:00       0\n",
       "2013-05-28 00:05:00       1\n",
       "2013-05-28 00:10:00       2\n",
       "2013-05-28 00:15:00       3\n",
       "2013-05-28 00:20:00       4\n",
       "2013-05-28 00:25:00       5\n",
       "2013-05-28 00:30:00       6\n",
       "2013-05-28 00:35:00       7\n",
       "2013-05-28 00:40:00       8\n",
       "2013-05-28 00:45:00       9\n",
       "2013-05-28 00:50:00      10\n",
       "2013-05-28 00:55:00      11\n",
       "2013-05-28 01:00:00      12\n",
       "2013-05-28 01:05:00      13\n",
       "2013-05-28 01:10:00      14\n",
       "2013-05-28 01:15:00      15\n",
       "2013-05-28 01:20:00      16\n",
       "2013-05-28 01:25:00      17\n",
       "2013-05-28 01:30:00      18\n",
       "2013-05-28 01:35:00      19\n",
       "2013-05-28 01:40:00      20\n",
       "2013-05-28 01:45:00      21\n",
       "2013-05-28 01:50:00      22\n",
       "2013-05-28 01:55:00      23\n",
       "2013-05-28 02:00:00      24\n",
       "2013-05-28 02:05:00      25\n",
       "2013-05-28 02:10:00      26\n",
       "2013-05-28 02:15:00      27\n",
       "2013-05-28 02:20:00      28\n",
       "2013-05-28 02:25:00      29\n",
       "                       ... \n",
       "2013-05-28 23:31:00    1123\n",
       "2013-05-28 23:32:00    1124\n",
       "2013-05-28 23:33:00    1125\n",
       "2013-05-28 23:34:00    1126\n",
       "2013-05-28 23:35:00    1127\n",
       "2013-05-28 23:36:00    1128\n",
       "2013-05-28 23:37:00    1129\n",
       "2013-05-28 23:38:00    1130\n",
       "2013-05-28 23:39:00    1131\n",
       "2013-05-28 23:40:00    1132\n",
       "2013-05-28 23:41:00    1133\n",
       "2013-05-28 23:42:00    1134\n",
       "2013-05-28 23:43:00    1135\n",
       "2013-05-28 23:44:00    1136\n",
       "2013-05-28 23:45:00    1137\n",
       "2013-05-28 23:46:00    1138\n",
       "2013-05-28 23:47:00    1139\n",
       "2013-05-28 23:48:00    1140\n",
       "2013-05-28 23:49:00    1141\n",
       "2013-05-28 23:50:00    1142\n",
       "2013-05-28 23:51:00    1143\n",
       "2013-05-28 23:52:00    1144\n",
       "2013-05-28 23:53:00    1145\n",
       "2013-05-28 23:54:00    1146\n",
       "2013-05-28 23:55:00    1147\n",
       "2013-05-28 23:56:00    1148\n",
       "2013-05-28 23:57:00    1149\n",
       "2013-05-28 23:58:00    1150\n",
       "2013-05-28 23:59:00    1151\n",
       "2013-05-29 00:00:00    1152\n",
       "dtype: int64"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dates = pd.Series(range(dates.size), index=dates)\n",
    "dates"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Notice that the temporal frequency for the first 6 hours of the day is at 5 minutes and for the rest of the day is at 1 minute. As the required frequency is 5 minutes for the whole day, selecting relavent time indices that match this criteria."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2013-05-28 00:00:00       0\n",
       "2013-05-28 00:05:00       1\n",
       "2013-05-28 00:10:00       2\n",
       "2013-05-28 00:15:00       3\n",
       "2013-05-28 00:20:00       4\n",
       "2013-05-28 00:25:00       5\n",
       "2013-05-28 00:30:00       6\n",
       "2013-05-28 00:35:00       7\n",
       "2013-05-28 00:40:00       8\n",
       "2013-05-28 00:45:00       9\n",
       "2013-05-28 00:50:00      10\n",
       "2013-05-28 00:55:00      11\n",
       "2013-05-28 01:00:00      12\n",
       "2013-05-28 01:05:00      13\n",
       "2013-05-28 01:10:00      14\n",
       "2013-05-28 01:15:00      15\n",
       "2013-05-28 01:20:00      16\n",
       "2013-05-28 01:25:00      17\n",
       "2013-05-28 01:30:00      18\n",
       "2013-05-28 01:35:00      19\n",
       "2013-05-28 01:40:00      20\n",
       "2013-05-28 01:45:00      21\n",
       "2013-05-28 01:50:00      22\n",
       "2013-05-28 01:55:00      23\n",
       "2013-05-28 02:00:00      24\n",
       "2013-05-28 02:05:00      25\n",
       "2013-05-28 02:10:00      26\n",
       "2013-05-28 02:15:00      27\n",
       "2013-05-28 02:20:00      28\n",
       "2013-05-28 02:25:00      29\n",
       "                       ... \n",
       "2013-05-28 21:35:00    1007\n",
       "2013-05-28 21:40:00    1012\n",
       "2013-05-28 21:45:00    1017\n",
       "2013-05-28 21:50:00    1022\n",
       "2013-05-28 21:55:00    1027\n",
       "2013-05-28 22:00:00    1032\n",
       "2013-05-28 22:05:00    1037\n",
       "2013-05-28 22:10:00    1042\n",
       "2013-05-28 22:15:00    1047\n",
       "2013-05-28 22:20:00    1052\n",
       "2013-05-28 22:25:00    1057\n",
       "2013-05-28 22:30:00    1062\n",
       "2013-05-28 22:35:00    1067\n",
       "2013-05-28 22:40:00    1072\n",
       "2013-05-28 22:45:00    1077\n",
       "2013-05-28 22:50:00    1082\n",
       "2013-05-28 22:55:00    1087\n",
       "2013-05-28 23:00:00    1092\n",
       "2013-05-28 23:05:00    1097\n",
       "2013-05-28 23:10:00    1102\n",
       "2013-05-28 23:15:00    1107\n",
       "2013-05-28 23:20:00    1112\n",
       "2013-05-28 23:25:00    1117\n",
       "2013-05-28 23:30:00    1122\n",
       "2013-05-28 23:35:00    1127\n",
       "2013-05-28 23:40:00    1132\n",
       "2013-05-28 23:45:00    1137\n",
       "2013-05-28 23:50:00    1142\n",
       "2013-05-28 23:55:00    1147\n",
       "2013-05-29 00:00:00    1152\n",
       "Freq: 5T, dtype: int64"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dates = dates.groupby(pd.TimeGrouper('5min')).apply(lambda x: x[0])\n",
    "dates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,78,83,88,93,98,103,108,113,118,123,128,133,138,143,148,153,158,163,168,173,178,183,188,193,198,203,208,213,218,223,228,233,238,243,248,253,258,263,268,273,278,283,288,293,298,303,308,313,318,323,328,333,338,343,348,353,358,363,368,373,378,383,388,393,398,403,408,413,418,423,428,433,438,443,448,453,458,463,468,473,478,483,488,493,498,503,508,513,518,523,528,533,538,543,548,553,558,563,568,573,578,583,588,593,598,603,608,613,618,623,628,633,638,643,648,653,658,663,668,673,678,683,688,693,698,703,708,713,718,723,728,733,738,743,748,753,758,763,768,773,778,783,788,793,798,803,808,813,818,823,828,833,838,843,848,853,858,863,868,873,878,883,888,893,898,903,908,913,918,923,928,933,938,943,948,953,958,963,968,973,978,983,988,993,998,1003,1008,1013,1018,1023,1028,1033,1038,1043,1048,1053,1058,1063,1068,1073,1078,1083,1088,1093,1098,1103,1108,1113,1118,1123,1128,1133,1138,1143,1148,1153'"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "indices = ','.join((dates.values + 1).astype(str))\n",
    "indices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cdo seltimestep: Processed 4734687 values from 1 variable over 1153 timesteps ( 0.07s )\r\n"
     ]
    }
   ],
   "source": [
    "prw_5min = \"./tmp/prw_5min.nc\"\n",
    "template = \"cdo seltimestep,{indices} {ifile} {ofile}\".format\n",
    "cmd = template(indices=indices, ifile=mergefile, ofile=prw_5min)\n",
    "!$cmd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   File format : NetCDF4\n",
      "    -1 : Institut Source   Steptype Levels Num    Points Num Dtype : Parameter ID\n",
      "     1 : MPIMET   @        instant       1   1     16383   1  F32  : 216.1.0       \n",
      "   Grid coordinates :\n",
      "     1 : lonlat                   : points=16383 (129x127)\n",
      "                              lon : 6.271 to 6.5526 by 0.0022 degrees_east\n",
      "                              lat : 50.819 to 50.9954 by 0.001399994 degrees_north\n",
      "   Vertical coordinates :\n",
      "     1 : surface                  : levels=1\n",
      "   Time coordinate :  289 steps\n",
      "  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss\n",
      "  2013-05-28 00:00:00  2013-05-28 00:05:00  2013-05-28 00:10:00  2013-05-28 00:15:00\n",
      "  2013-05-28 00:20:00  2013-05-28 00:25:00  2013-05-28 00:30:00  2013-05-28 00:35:00\n",
      "  2013-05-28 00:40:00  2013-05-28 00:45:00  2013-05-28 00:50:00  2013-05-28 00:55:00\n",
      "  2013-05-28 01:00:00  2013-05-28 01:05:00  2013-05-28 01:10:00  2013-05-28 01:15:00\n",
      "  2013-05-28 01:20:00  2013-05-28 01:25:00  2013-05-28 01:30:00  2013-05-28 01:35:00\n",
      "  2013-05-28 01:40:00  2013-05-28 01:45:00  2013-05-28 01:50:00  2013-05-28 01:55:00\n",
      "  2013-05-28 02:00:00  2013-05-28 02:05:00  2013-05-28 02:10:00  2013-05-28 02:15:00\n",
      "  2013-05-28 02:20:00  2013-05-28 02:25:00  2013-05-28 02:30:00  2013-05-28 02:35:00\n",
      "  2013-05-28 02:40:00  2013-05-28 02:45:00  2013-05-28 02:50:00  2013-05-28 02:55:00\n",
      "  2013-05-28 03:00:00  2013-05-28 03:05:00  2013-05-28 03:10:00  2013-05-28 03:15:00\n",
      "  2013-05-28 03:20:00  2013-05-28 03:25:00  2013-05-28 03:30:00  2013-05-28 03:35:00\n",
      "  2013-05-28 03:40:00  2013-05-28 03:45:00  2013-05-28 03:50:00  2013-05-28 03:55:00\n",
      "  2013-05-28 04:00:00  2013-05-28 04:05:00  2013-05-28 04:10:00  2013-05-28 04:15:00\n",
      "  2013-05-28 04:20:00  2013-05-28 04:25:00  2013-05-28 04:30:00  2013-05-28 04:35:00\n",
      "  2013-05-28 04:40:00  2013-05-28 04:45:00  2013-05-28 04:50:00  2013-05-28 04:55:00\n",
      "   ................................................................................\n",
      "   .........\n",
      "  2013-05-28 19:20:00  2013-05-28 19:25:00  2013-05-28 19:30:00  2013-05-28 19:35:00\n",
      "  2013-05-28 19:40:00  2013-05-28 19:45:00  2013-05-28 19:50:00  2013-05-28 19:55:00\n",
      "  2013-05-28 20:00:00  2013-05-28 20:05:00  2013-05-28 20:10:00  2013-05-28 20:15:00\n",
      "  2013-05-28 20:20:00  2013-05-28 20:25:00  2013-05-28 20:30:00  2013-05-28 20:35:00\n",
      "  2013-05-28 20:40:00  2013-05-28 20:45:00  2013-05-28 20:50:00  2013-05-28 20:55:00\n",
      "  2013-05-28 21:00:00  2013-05-28 21:05:00  2013-05-28 21:10:00  2013-05-28 21:15:00\n",
      "  2013-05-28 21:20:00  2013-05-28 21:25:00  2013-05-28 21:30:00  2013-05-28 21:35:00\n",
      "  2013-05-28 21:40:00  2013-05-28 21:45:00  2013-05-28 21:50:00  2013-05-28 21:55:00\n",
      "  2013-05-28 22:00:00  2013-05-28 22:05:00  2013-05-28 22:10:00  2013-05-28 22:15:00\n",
      "  2013-05-28 22:20:00  2013-05-28 22:25:00  2013-05-28 22:30:00  2013-05-28 22:35:00\n",
      "  2013-05-28 22:40:00  2013-05-28 22:45:00  2013-05-28 22:50:00  2013-05-28 22:55:00\n",
      "  2013-05-28 23:00:00  2013-05-28 23:05:00  2013-05-28 23:10:00  2013-05-28 23:15:00\n",
      "  2013-05-28 23:20:00  2013-05-28 23:25:00  2013-05-28 23:30:00  2013-05-28 23:35:00\n",
      "  2013-05-28 23:40:00  2013-05-28 23:45:00  2013-05-28 23:50:00  2013-05-28 23:55:00\n",
      "  2013-05-29 00:00:00\n"
     ]
    }
   ],
   "source": [
    "!cdo -s sinfo $prw_5min"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "Pavan Siligam <siligam@dkrz.de>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Last updated:  Fri Feb 9 10:37:08 CET 2018\r\n"
     ]
    }
   ],
   "source": [
    "!echo \"Last updated: \" `date`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Currently Loaded Modulefiles:\r\n",
      "  1) cdo/1.9.0-gcc48        3) texlive/2016\r\n",
      "  2) netcdf_c/4.3.2-gcc48   4) python/2.7.12\r\n"
     ]
    }
   ],
   "source": [
    "!module list"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2 (using the module python/2.7.12)",
   "language": "python",
   "name": "python_2.7.12"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}