|
254 | 254 | "source": [
|
255 | 255 | "# Our control simulation\n",
|
256 | 256 | "ctrl = ds_dict[\"CMIP.NCAR.CESM2.piControl.Amon.gn\"].isel(\n",
|
257 |
| - " time=slice(-600,None)).squeeze().chunk({\"plev\":1,\"time\":-1})\n", |
| 257 | + " time=slice(-600,None)).squeeze().compute()\n", |
258 | 258 | "\n",
|
259 | 259 | "# The increase CO2 aka \"perturbed\" simulation\n",
|
260 | 260 | "pert = ds_dict[\"CMIP.NCAR.CESM2.abrupt-4xCO2.Amon.gn\"].isel(\n",
|
261 |
| - " time=slice(-360,None)).squeeze().chunk({\"plev\":1,\"time\":-1})" |
| 261 | + " time=slice(-360,None)).squeeze().compute()" |
262 | 262 | ]
|
263 | 263 | },
|
264 | 264 | {
|
|
366 | 366 | "cell_type": "markdown",
|
367 | 367 | "metadata": {},
|
368 | 368 | "source": [
|
369 |
| - "Finally, let's plot the time average surface albedo feedback on a map, first as just the perturbation." |
| 369 | + "This function allows for the quick creation of a pre-configured map, eliminating the need to repeat setup code by setting up the figure, axes, and Cartopy Robinson projection." |
370 | 370 | ]
|
371 | 371 | },
|
372 | 372 | {
|
|
375 | 375 | "metadata": {},
|
376 | 376 | "outputs": [],
|
377 | 377 | "source": [
|
378 |
| - "# Set a few variables\n", |
379 |
| - "proj = ccrs.Robinson()\n", |
| 378 | + "def base_map():\n", |
| 379 | + " proj= ccrs.Robinson() #select Robinson projection\n", |
380 | 380 | "\n",
|
381 |
| - "# Create figure and axis\n", |
382 |
| - "fig, ax = plt.subplots(subplot_kw=dict(projection=proj),\n", |
383 |
| - " layout=\"constrained\")\n", |
| 381 | + " fig, ax = plt.subplots(subplot_kw=dict(projection=proj)) #Create the figure and axis \n", |
| 382 | + " \n", |
| 383 | + " ax.coastlines() # Add coastlines\n", |
384 | 384 | "\n",
|
385 |
| - "# Plot surface albedo feedback & add coastlines\n", |
386 |
| - "alb.mean(dim=\"time\").plot(ax=ax,transform=ccrs.PlateCarree(),\n", |
387 |
| - " cbar_kwargs={\"orientation\": \"horizontal\", \"shrink\": 0.7,\n", |
388 |
| - " \"label\":\"W/m$^2$\"})\n", |
389 |
| - "ax.coastlines()\n", |
| 385 | + " return fig, ax\n", |
| 386 | + "\n" |
| 387 | + ] |
| 388 | + }, |
| 389 | + { |
| 390 | + "cell_type": "markdown", |
| 391 | + "metadata": {}, |
| 392 | + "source": [ |
| 393 | + "Similar to the function above, these dictionaries encapsulate the repetitive code setup and provide a set of reusable arguments to simplify the plotting of data onto this map. " |
| 394 | + ] |
| 395 | + }, |
| 396 | + { |
| 397 | + "cell_type": "code", |
| 398 | + "execution_count": null, |
| 399 | + "metadata": {}, |
| 400 | + "outputs": [], |
| 401 | + "source": [ |
| 402 | + "plotargs = {'transform': ccrs.PlateCarree(),\n", |
| 403 | + " 'cbar_kwargs': {\"orientation\": \"horizontal\", \"shrink\": 0.7, \n", |
| 404 | + " \"label\":\"W/m$^2$\"}\n", |
| 405 | + " }" |
| 406 | + ] |
| 407 | + }, |
| 408 | + { |
| 409 | + "cell_type": "code", |
| 410 | + "execution_count": null, |
| 411 | + "metadata": {}, |
| 412 | + "outputs": [], |
| 413 | + "source": [ |
| 414 | + "plotargs_2 = {'transform': ccrs.PlateCarree(),\n", |
| 415 | + " 'cbar_kwargs': {\"orientation\": \"horizontal\", \"shrink\": 0.7,\n", |
| 416 | + " \"label\":\"W/m$^2$/K\"}\n", |
| 417 | + " }" |
| 418 | + ] |
| 419 | + }, |
| 420 | + { |
| 421 | + "cell_type": "markdown", |
| 422 | + "metadata": {}, |
| 423 | + "source": [ |
| 424 | + "Finally, let's plot the time average surface albedo feedback on a map, first as just the perturbation." |
| 425 | + ] |
| 426 | + }, |
| 427 | + { |
| 428 | + "cell_type": "code", |
| 429 | + "execution_count": null, |
| 430 | + "metadata": {}, |
| 431 | + "outputs": [], |
| 432 | + "source": [ |
| 433 | + "# Create the base map\n", |
| 434 | + "fig, ax = base_map()\n", |
390 | 435 | "\n",
|
391 |
| - "# Add a title\n", |
392 |
| - "ax.set_title(\"Time-averaged Surface Albedo Feedback\")\n", |
| 436 | + "# Plot the surface albedo feedback \n", |
| 437 | + "alb.mean(dim=\"time\").plot(ax=ax, **plotargs)\n", |
393 | 438 | "\n",
|
394 |
| - "plt.show()" |
| 439 | + "# Add a title\n", |
| 440 | + "ax.set_title(\"Time-averaged Surface Albedo Feedback\");" |
395 | 441 | ]
|
396 | 442 | },
|
397 | 443 | {
|
|
407 | 453 | "metadata": {},
|
408 | 454 | "outputs": [],
|
409 | 455 | "source": [
|
410 |
| - "# Set a few variables\n", |
411 |
| - "proj = ccrs.Robinson()\n", |
412 |
| - "\n", |
413 |
| - "# Create figure and axis\n", |
414 |
| - "fig, ax = plt.subplots(subplot_kw=dict(projection=proj),\n", |
415 |
| - " layout=\"constrained\")\n", |
| 456 | + "# Create the base map\n", |
| 457 | + "fig, ax = base_map()\n", |
416 | 458 | "\n",
|
417 | 459 | "# Plot surface albedo feedback & add coastlines\n",
|
418 |
| - "(alb.mean(dim=\"time\")/Δts.mean(dim=\"time\")).plot(ax=ax,transform=ccrs.PlateCarree(),\n", |
419 |
| - " cbar_kwargs={\"orientation\": \"horizontal\", \"shrink\": 0.7,\n", |
420 |
| - " \"label\":\"W/m$^2$/K\"})\n", |
421 |
| - "ax.coastlines()\n", |
| 460 | + "(alb.mean(dim=\"time\")/Δts.mean(dim=\"time\")).plot(ax=ax, **plotargs_2)\n", |
422 | 461 | "\n",
|
423 | 462 | "# Add a title\n",
|
424 |
| - "ax.set_title(\"Time-averaged Surface Albedo Feedback\")\n", |
425 |
| - "\n", |
426 |
| - "plt.show()" |
| 463 | + "ax.set_title(\"Time-averaged Surface Albedo Feedback\");" |
427 | 464 | ]
|
428 | 465 | },
|
429 | 466 | {
|
|
498 | 535 | "metadata": {},
|
499 | 536 | "outputs": [],
|
500 | 537 | "source": [
|
501 |
| - "# Set a few variables\n", |
502 |
| - "proj = ccrs.Robinson()\n", |
503 |
| - "\n", |
504 |
| - "# Create figure and axis\n", |
505 |
| - "fig, ax = plt.subplots(subplot_kw=dict(projection=proj),\n", |
506 |
| - " layout=\"constrained\")\n", |
| 538 | + "# Create the base map\n", |
| 539 | + "fig, ax = base_map()\n", |
507 | 540 | "\n",
|
508 |
| - "# Plot surface albedo feedback & add coastlines\n", |
509 |
| - "lr.mean(dim=\"time\").plot(ax=ax,transform=ccrs.PlateCarree(),\n", |
510 |
| - " cbar_kwargs={\"orientation\": \"horizontal\", \"shrink\": 0.7,\n", |
511 |
| - " \"label\":\"W/m$^2$\"})\n", |
512 |
| - "ax.coastlines()\n", |
| 541 | + "# Plot the surface albedo feedback \n", |
| 542 | + "lr.mean(dim=\"time\").plot(ax=ax, **plotargs)\n", |
513 | 543 | "\n",
|
514 | 544 | "# Add a title\n",
|
515 |
| - "ax.set_title(\"Time-averaged Lapse Rate Feedback\")\n", |
516 |
| - "\n", |
517 |
| - "plt.show()" |
| 545 | + "ax.set_title(\"Time-averaged Lapse Rate Feedback\");" |
518 | 546 | ]
|
519 | 547 | },
|
520 | 548 | {
|
|
523 | 551 | "metadata": {},
|
524 | 552 | "outputs": [],
|
525 | 553 | "source": [
|
526 |
| - "# Set a few variables\n", |
527 |
| - "proj = ccrs.Robinson()\n", |
| 554 | + "# Create the base map\n", |
| 555 | + "fig, ax = base_map()\n", |
528 | 556 | "\n",
|
529 |
| - "# Create figure and axis\n", |
530 |
| - "fig, ax = plt.subplots(subplot_kw=dict(projection=proj),\n", |
531 |
| - " layout=\"constrained\")\n", |
532 |
| - "\n", |
533 |
| - "# Plot surface albedo feedback & add coastlines\n", |
534 |
| - "(lr.mean(dim=\"time\")/Δts.mean(dim=\"time\")).plot(ax=ax,transform=ccrs.PlateCarree(),\n", |
535 |
| - " cbar_kwargs={\"orientation\": \"horizontal\", \"shrink\": 0.7,\n", |
536 |
| - " \"label\":\"W/m$^2$/K\"})\n", |
537 |
| - "ax.coastlines()\n", |
| 557 | + "# Plot surface albedo feedback\n", |
| 558 | + "(lr.mean(dim=\"time\")/Δts.mean(dim=\"time\")).plot(ax=ax, **plotargs_2)\n", |
538 | 559 | "\n",
|
539 | 560 | "# Add a title\n",
|
540 |
| - "ax.set_title(\"Time-averaged Lapse Rate Feedback\")\n", |
541 |
| - "\n", |
542 |
| - "plt.show()" |
| 561 | + "ax.set_title(\"Time-averaged Lapse Rate Feedback\");" |
543 | 562 | ]
|
544 | 563 | },
|
545 | 564 | {
|
|
548 | 567 | "metadata": {},
|
549 | 568 | "outputs": [],
|
550 | 569 | "source": [
|
551 |
| - "# Set a few variables\n", |
552 |
| - "proj = ccrs.Robinson()\n", |
| 570 | + "# Create the base map\n", |
| 571 | + "fig, ax = base_map()\n", |
553 | 572 | "\n",
|
554 |
| - "# Create figure and axis\n", |
555 |
| - "fig, ax = plt.subplots(subplot_kw=dict(projection=proj),\n", |
556 |
| - " layout=\"constrained\")\n", |
557 |
| - "\n", |
558 |
| - "# Plot surface albedo feedback & add coastlines\n", |
559 |
| - "pl.mean(dim=\"time\").plot(ax=ax,transform=ccrs.PlateCarree(),cmap=\"Blues_r\",\n", |
560 |
| - " cbar_kwargs={\"orientation\": \"horizontal\", \"shrink\": 0.7,\n", |
561 |
| - " \"label\":\"W/m$^2$\"})\n", |
562 |
| - "ax.coastlines()\n", |
| 573 | + "# Plot surface albedo feedback\n", |
| 574 | + "pl.mean(dim=\"time\").plot(ax=ax, cmap=\"Blues_r\", **plotargs)\n", |
563 | 575 | "\n",
|
564 | 576 | "# Add a title\n",
|
565 |
| - "ax.set_title(\"Time-averaged Planck Feedback\")\n", |
566 |
| - "\n", |
567 |
| - "plt.show()" |
| 577 | + "ax.set_title(\"Time-averaged Planck Feedback\");" |
568 | 578 | ]
|
569 | 579 | },
|
570 | 580 | {
|
|
573 | 583 | "metadata": {},
|
574 | 584 | "outputs": [],
|
575 | 585 | "source": [
|
576 |
| - "# Set a few variables\n", |
577 |
| - "proj = ccrs.Robinson()\n", |
| 586 | + "# Create the base map\n", |
| 587 | + "fig, ax = base_map()\n", |
578 | 588 | "\n",
|
579 |
| - "# Create figure and axis\n", |
580 |
| - "fig, ax = plt.subplots(subplot_kw=dict(projection=proj),\n", |
581 |
| - " layout=\"constrained\")\n", |
582 |
| - "\n", |
583 |
| - "# Plot surface albedo feedback & add coastlines\n", |
584 |
| - "(pl.mean(dim=\"time\")/Δts.mean(dim=\"time\")).plot(\n", |
585 |
| - " ax=ax,transform=ccrs.PlateCarree(),cmap=\"Blues_r\",\n", |
586 |
| - " cbar_kwargs={\"orientation\": \"horizontal\", \"shrink\": 0.7,\"label\":\"W/m$^2$\"}\n", |
587 |
| - ")\n", |
588 |
| - "ax.coastlines()\n", |
| 589 | + "# Plot surface albedo feedback\n", |
| 590 | + "(pl.mean(dim=\"time\")/Δts.mean(dim=\"time\")).plot(ax=ax,cmap=\"Blues_r\", **plotargs_2)\n", |
589 | 591 | "\n",
|
590 | 592 | "# Add a title\n",
|
591 |
| - "ax.set_title(\"Time-averaged Planck Feedback\")\n", |
592 |
| - "\n", |
593 |
| - "plt.show()" |
| 593 | + "ax.set_title(\"Time-averaged Planck Feedback\");" |
594 | 594 | ]
|
595 | 595 | },
|
596 | 596 | {
|
|
670 | 670 | "metadata": {},
|
671 | 671 | "outputs": [],
|
672 | 672 | "source": [
|
673 |
| - "# Set a few variables\n", |
674 |
| - "proj = ccrs.Robinson()\n", |
| 673 | + "# Create the base map\n", |
| 674 | + "fig, ax = base_map()\n", |
675 | 675 | "\n",
|
676 |
| - "# Create figure and axis\n", |
677 |
| - "fig, ax = plt.subplots(subplot_kw=dict(projection=proj),\n", |
678 |
| - " layout=\"constrained\")\n", |
679 |
| - "\n", |
680 |
| - "# Plot the longwave water vapor feedback and add coastlines\n", |
681 |
| - "qlw.mean(dim=\"time\").plot(ax=ax,transform=ccrs.PlateCarree(),cmap=\"Reds\",\n", |
682 |
| - " cbar_kwargs={\"orientation\": \"horizontal\", \"shrink\": 0.7,\n", |
683 |
| - " \"label\":\"W/m$^2$\"})\n", |
684 |
| - "ax.coastlines()\n", |
| 676 | + "# Plot the longwave water vapor feedback\n", |
| 677 | + "qlw.mean(dim=\"time\").plot(ax=ax,cmap=\"Reds\", **plotargs)\n", |
685 | 678 | "\n",
|
686 | 679 | "# Add a title\n",
|
687 |
| - "ax.set_title(\"Time-averaged LW Water Vapor Feedback\")\n", |
688 |
| - "\n", |
689 |
| - "plt.show()" |
| 680 | + "ax.set_title(\"Time-averaged LW Water Vapor Feedback\");" |
690 | 681 | ]
|
691 | 682 | },
|
692 | 683 | {
|
|
695 | 686 | "metadata": {},
|
696 | 687 | "outputs": [],
|
697 | 688 | "source": [
|
698 |
| - "# Set a few variables\n", |
699 |
| - "proj = ccrs.Robinson()\n", |
700 |
| - "\n", |
701 |
| - "# Create figure and axis\n", |
702 |
| - "fig, ax = plt.subplots(subplot_kw=dict(projection=proj),\n", |
703 |
| - " layout=\"constrained\")\n", |
| 689 | + "# Create the base map\n", |
| 690 | + "fig, ax = base_map()\n", |
704 | 691 | "\n",
|
705 |
| - "# Plot the longwave water vapor feedback and add coastlines\n", |
706 |
| - "(qlw.mean(dim=\"time\")/Δts.mean(dim=\"time\")).plot(\n", |
707 |
| - " ax=ax,transform=ccrs.PlateCarree(),cmap=\"Reds\",\n", |
708 |
| - " cbar_kwargs={\"orientation\": \"horizontal\", \"shrink\": 0.7,\n", |
709 |
| - " \"label\":\"W/m$^2$/K\"}\n", |
710 |
| - ")\n", |
| 692 | + "# Plot the longwave water vapor feedback \n", |
| 693 | + "(qlw.mean(dim=\"time\")/Δts.mean(dim=\"time\")).plot(ax=ax,cmap=\"Reds\", **plotargs_2)\n", |
711 | 694 | "ax.coastlines()\n",
|
712 | 695 | "\n",
|
713 | 696 | "# Add a title\n",
|
714 |
| - "ax.set_title(\"Time-averaged LW Water Vapor Feedback\")\n", |
715 |
| - "\n", |
716 |
| - "plt.show()" |
| 697 | + "ax.set_title(\"Time-averaged LW Water Vapor Feedback\");" |
717 | 698 | ]
|
718 | 699 | },
|
719 | 700 | {
|
|
729 | 710 | "metadata": {},
|
730 | 711 | "outputs": [],
|
731 | 712 | "source": [
|
732 |
| - "# Set a few variables\n", |
733 |
| - "proj = ccrs.Robinson()\n", |
734 |
| - "\n", |
735 |
| - "# Create figure and axis\n", |
736 |
| - "fig, ax = plt.subplots(subplot_kw=dict(projection=proj),\n", |
737 |
| - " layout=\"constrained\")\n", |
| 713 | + "# Create the base map\n", |
| 714 | + "fig, ax = base_map()\n", |
738 | 715 | "\n",
|
739 | 716 | "# Plot the longwave water vapor feedback and add coastlines\n",
|
740 |
| - "qsw.mean(dim=\"time\").plot(ax=ax,transform=ccrs.PlateCarree(),cmap=\"Reds\",\n", |
741 |
| - " cbar_kwargs={\"orientation\": \"horizontal\", \"shrink\": 0.7,\n", |
742 |
| - " \"label\":\"W/m$^2$\"})\n", |
743 |
| - "ax.coastlines()\n", |
| 717 | + "qsw.mean(dim=\"time\").plot(ax=ax,cmap=\"Reds\", **plotargs)\n", |
744 | 718 | "\n",
|
745 |
| - "# Add a title\n", |
746 |
| - "ax.set_title(\"Time-averaged SW Water Vapor Feedback\")\n", |
747 | 719 | "\n",
|
748 |
| - "plt.show()" |
| 720 | + "# Add a title\n", |
| 721 | + "ax.set_title(\"Time-averaged SW Water Vapor Feedback\");" |
749 | 722 | ]
|
750 | 723 | },
|
751 | 724 | {
|
|
754 | 727 | "metadata": {},
|
755 | 728 | "outputs": [],
|
756 | 729 | "source": [
|
757 |
| - "# Set a few variables\n", |
758 |
| - "proj = ccrs.Robinson()\n", |
759 |
| - "\n", |
760 |
| - "# Create figure and axis\n", |
761 |
| - "fig, ax = plt.subplots(subplot_kw=dict(projection=proj),\n", |
762 |
| - " layout=\"constrained\")\n", |
| 730 | + "# Create the base map\n", |
| 731 | + "fig, ax = base_map()\n", |
763 | 732 | "\n",
|
764 | 733 | "# Plot the longwave water vapor feedback and add coastlines\n",
|
765 |
| - "(qsw.mean(dim=\"time\")/Δts.mean(dim=\"time\")).plot(\n", |
766 |
| - " ax=ax,transform=ccrs.PlateCarree(),cmap=\"Reds\",\n", |
767 |
| - " cbar_kwargs={\"orientation\": \"horizontal\", \"shrink\": 0.7,\n", |
768 |
| - " \"label\":\"W/m$^2$/K\"}\n", |
769 |
| - ")\n", |
770 |
| - "ax.coastlines()\n", |
| 734 | + "(qsw.mean(dim=\"time\")/Δts.mean(dim=\"time\")).plot(ax=ax,cmap=\"Reds\", **plotargs_2)\n", |
771 | 735 | "\n",
|
772 | 736 | "# Add a title\n",
|
773 |
| - "ax.set_title(\"Time-averaged SW Water Vapor Feedback\")\n", |
774 |
| - "\n", |
775 |
| - "plt.show()" |
| 737 | + "ax.set_title(\"Time-averaged SW Water Vapor Feedback\");" |
776 | 738 | ]
|
777 | 739 | },
|
778 | 740 | {
|
|
0 commit comments