|
112 | 112 | "import numpy as np\n", |
113 | 113 | "import xarray as xr\n", |
114 | 114 | "import sys\n", |
115 | | - "import glob" |
| 115 | + "import glob\n", |
| 116 | + "\n", |
| 117 | + "\n", |
| 118 | + "# indicate whether you are working in a cloud instance (True if yes, False otherwise)\n", |
| 119 | + "incloud_access = True" |
116 | 120 | ] |
117 | 121 | }, |
118 | 122 | { |
|
530 | 534 | "ECCO_dir = join(user_home_dir,'Downloads','ECCO_V4r4_PODAAC')" |
531 | 535 | ] |
532 | 536 | }, |
| 537 | + { |
| 538 | + "cell_type": "code", |
| 539 | + "execution_count": null, |
| 540 | + "metadata": {}, |
| 541 | + "outputs": [], |
| 542 | + "source": [ |
| 543 | + "## if working in the AWS cloud, access datasets needed for this tutorial\n", |
| 544 | + "\n", |
| 545 | + "ShortNames_list = [\"ECCO_L4_GEOMETRY_LLC0090GRID_V4R4\",\\\n", |
| 546 | + " \"ECCO_L4_OCEAN_3D_TEMPERATURE_FLUX_LLC0090GRID_MONTHLY_V4R4\",\\\n", |
| 547 | + " \"ECCO_L4_HEAT_FLUX_LLC0090GRID_MONTHLY_V4R4\",\\\n", |
| 548 | + " \"ECCO_L4_SSH_LLC0090GRID_SNAPSHOT_V4R4\",\\\n", |
| 549 | + " \"ECCO_L4_TEMP_SALINITY_LLC0090GRID_SNAPSHOT_V4R4\"]\n", |
| 550 | + "if incloud_access == True:\n", |
| 551 | + " # apply fixes to xgcm (you might have to do this manually if not on a cloud instance,\n", |
| 552 | + " # see \"Horizontal convergence of advective heat flux section)\n", |
| 553 | + " import xgcm\n", |
| 554 | + " xgcm_path = xgcm.__path__[0]\n", |
| 555 | + " if xgcm.__version__ == '0.8.1':\n", |
| 556 | + " import os\n", |
| 557 | + " os.remove(join(xgcm_path,'grid_ufunc.py'))\n", |
| 558 | + " os.system('cp ../misc/xgcm_fixes/grid_ufunc.py '+xgcm_path+'/')\n", |
| 559 | + " os.remove(join(xgcm_path,'padding.py'))\n", |
| 560 | + " os.system('cp ../misc/xgcm_fixes/padding.py '+xgcm_path+'/')\n", |
| 561 | + "\n", |
| 562 | + " # re-import xgcm\n", |
| 563 | + " import importlib\n", |
| 564 | + " importlib.reload(xgcm)\n", |
| 565 | + " \n", |
| 566 | + " from ecco_s3_retrieve import ecco_podaac_s3_get_diskaware\n", |
| 567 | + " files_dict = ecco_podaac_s3_get_diskaware(ShortNames=ShortNames_list,\\\n", |
| 568 | + " StartDate='1993-01',EndDate='2016-12',\\\n", |
| 569 | + " max_avail_frac=0.5,\\\n", |
| 570 | + " download_root_dir=ECCO_dir)" |
| 571 | + ] |
| 572 | + }, |
533 | 573 | { |
534 | 574 | "cell_type": "code", |
535 | 575 | "execution_count": 8, |
|
539 | 579 | "outputs": [], |
540 | 580 | "source": [ |
541 | 581 | "## Load the model grid\n", |
542 | | - "ecco_grid = xr.open_dataset(glob.glob(join(ECCO_dir,'*GEOMETRY*','*.nc'))[0])" |
| 582 | + "if incloud_access == True:\n", |
| 583 | + " ecco_grid = xr.open_dataset(files_dict[ShortNames_list[0]])\n", |
| 584 | + "else:\n", |
| 585 | + " ecco_grid = xr.open_dataset(glob.glob(join(ECCO_dir,'*GEOMETRY*','*.nc'))[0])" |
543 | 586 | ] |
544 | 587 | }, |
545 | 588 | { |
|
569 | 612 | }, |
570 | 613 | { |
571 | 614 | "cell_type": "code", |
572 | | - "execution_count": 10, |
573 | | - "metadata": { |
574 | | - "scrolled": false |
575 | | - }, |
| 615 | + "execution_count": null, |
| 616 | + "metadata": {}, |
576 | 617 | "outputs": [], |
577 | 618 | "source": [ |
578 | | - "year_start = 1993\n", |
| 619 | + "## year_start = 1993\n", |
579 | 620 | "year_end = 2017\n", |
580 | 621 | "\n", |
581 | 622 | "# open ETAN and THETA snapshots (beginning of each month)\n", |
582 | | - "ecco_monthly_SSH = xr.open_mfdataset(join(ECCO_dir,'*SSH*SNAPSHOT*','*-01T*.nc'),\\\n", |
583 | | - " data_vars='minimal',coords='minimal',compat='override')\n", |
584 | | - "ecco_monthly_TS = xr.open_mfdataset(join(ECCO_dir,'*TEMP_SALINITY*SNAPSHOT*','*-01T*.nc'),\\\n", |
585 | | - " data_vars='minimal',coords='minimal',compat='override')\n", |
| 623 | + "if incloud_access == True:\n", |
| 624 | + " ecco_monthly_SSH = xr.open_mfdataset(files_dict[ShortNames_list[-2]],\\\n", |
| 625 | + " data_vars='minimal',coords='minimal',compat='override')\n", |
| 626 | + " ecco_monthly_TS = xr.open_mfdataset(files_dict[ShortNames_list[-1]],\\\n", |
| 627 | + " data_vars='minimal',coords='minimal',compat='override')\n", |
| 628 | + "else:\n", |
| 629 | + " ecco_monthly_SSH = xr.open_mfdataset(join(ECCO_dir,'*SSH*SNAPSHOT*','*-01T*.nc'),\\\n", |
| 630 | + " data_vars='minimal',coords='minimal',compat='override')\n", |
| 631 | + " ecco_monthly_TS = xr.open_mfdataset(join(ECCO_dir,'*TEMP_SALINITY*SNAPSHOT*','*-01T*.nc'),\\\n", |
| 632 | + " data_vars='minimal',coords='minimal',compat='override')\n", |
586 | 633 | "ecco_monthly_snaps = xr.merge((ecco_monthly_SSH['ETAN'],ecco_monthly_TS['THETA']))\n", |
587 | 634 | "\n", |
588 | 635 | "# time mask for snapshots\n", |
|
646 | 693 | "outputs": [], |
647 | 694 | "source": [ |
648 | 695 | "## Open ECCO monthly mean variables\n", |
649 | | - "ecco_vars_int = xr.open_mfdataset(join(ECCO_dir,'*_OCEAN_3D_TEMPERATURE_FLUX*MONTHLY*','*.nc'),\\\n", |
650 | | - " data_vars='minimal',coords='minimal',compat='override')\n", |
651 | | - "ecco_vars_sfc = xr.open_mfdataset(join(ECCO_dir,'*_HEAT_FLUX*MONTHLY*','*.nc'),\\\n", |
652 | | - " data_vars='minimal',coords='minimal',compat='override')\n", |
| 696 | + "if incloud_access == True:\n", |
| 697 | + " ecco_vars_int = xr.open_mfdataset(files_dict[ShortNames_list[1]],\\\n", |
| 698 | + " data_vars='minimal',coords='minimal',compat='override')\n", |
| 699 | + " ecco_vars_sfc = xr.open_mfdataset(files_dict[ShortNames_list[2]],\\\n", |
| 700 | + " data_vars='minimal',coords='minimal',compat='override')\n", |
| 701 | + "else:\n", |
| 702 | + " ecco_vars_int = xr.open_mfdataset(join(ECCO_dir,'*_OCEAN_3D_TEMPERATURE_FLUX*MONTHLY*','*.nc'),\\\n", |
| 703 | + " data_vars='minimal',coords='minimal',compat='override')\n", |
| 704 | + " ecco_vars_sfc = xr.open_mfdataset(join(ECCO_dir,'*_HEAT_FLUX*MONTHLY*','*.nc'),\\\n", |
| 705 | + " data_vars='minimal',coords='minimal',compat='override')\n", |
653 | 706 | "ecco_monthly_mean = xr.merge((ecco_vars_int,\\\n", |
654 | 707 | " ecco_vars_sfc[['TFLUX','oceQsw']]))\n", |
655 | 708 | "\n", |
|
2808 | 2861 | "outputs": [], |
2809 | 2862 | "source": [ |
2810 | 2863 | "# Load terms from zarr dataset\n", |
2811 | | - "G_total = xr.open_zarr(join(save_dir,'eccov4r4_budg_heat')).G_total\n", |
2812 | | - "G_advection = xr.open_zarr(join(save_dir,'eccov4r4_budg_heat')).G_advection\n", |
2813 | | - "G_diffusion = xr.open_zarr(join(save_dir,'eccov4r4_budg_heat')).G_diffusion\n", |
2814 | | - "G_forcing = xr.open_zarr(join(save_dir,'eccov4r4_budg_heat')).G_forcing\n", |
2815 | | - "Qnet = xr.open_zarr(join(save_dir,'eccov4r4_budg_heat')).Qnet\n", |
2816 | | - "SWpen = xr.open_zarr(join(save_dir,'eccov4r4_budg_heat')).SWpen" |
| 2864 | + "G_budget = xr.open_zarr(join(save_dir,'eccov4r4_budg_heat'))\n", |
| 2865 | + "G_total = G_budget.G_total\n", |
| 2866 | + "G_advection = G_budget.G_advection\n", |
| 2867 | + "G_diffusion = G_budget.G_diffusion\n", |
| 2868 | + "G_forcing = G_budget.G_forcing\n", |
| 2869 | + "Qnet = G_budget.Qnet\n", |
| 2870 | + "SWpen = G_budget.SWpen" |
2817 | 2871 | ] |
2818 | 2872 | }, |
2819 | 2873 | { |
|
3355 | 3409 | "name": "python", |
3356 | 3410 | "nbconvert_exporter": "python", |
3357 | 3411 | "pygments_lexer": "ipython3", |
3358 | | - "version": "3.9.13" |
| 3412 | + "version": "3.11.8" |
3359 | 3413 | } |
3360 | 3414 | }, |
3361 | 3415 | "nbformat": 4, |
3362 | | - "nbformat_minor": 2 |
| 3416 | + "nbformat_minor": 4 |
3363 | 3417 | } |
0 commit comments