Skip to content

Commit 3480833

Browse files
committed
Use 'read_llc_to_tiles' when loading geothermal flux
1 parent 4cc85ac commit 3480833

2 files changed

Lines changed: 31 additions & 85 deletions

File tree

Tutorials_as_Jupyter_Notebooks/ECCO_v4_Heat_budget_closure.ipynb

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,8 @@
12901290
"cell_type": "markdown",
12911291
"metadata": {},
12921292
"source": [
1293-
"The geothermal flux contribution is not accounted for in any of the standard model diagnostics provided as output. Rather, this term, which is time invariant, is provided in the input file `geothermalFlux.bin` and can be downloaded from the PO.DAAC drive (https://ecco.jpl.nasa.gov/drive/files/Version4/Release3/input_init/geothermalFlux.bin)."
1293+
"The geothermal flux contribution is not accounted for in any of the standard model diagnostics provided as output. Rather, this term, which is time invariant, is provided in the input file `geothermalFlux.bin` and can be downloaded from the PO.DAAC drive (https://ecco.jpl.nasa.gov/drive/files/Version4/Release3/input_init/geothermalFlux.bin).\n",
1294+
"> **Note**: Here, `geothermalFlux.bin` has been placed in `base_dir`."
12941295
]
12951296
},
12961297
{
@@ -1299,75 +1300,48 @@
12991300
"metadata": {},
13001301
"outputs": [],
13011302
"source": [
1302-
"# Here geothermalFlux.bin has been saved in base_dir.\n",
1303-
"geoflx = np.fromfile(base_dir + '/geothermalFlux.bin', dtype=np.float32)"
1303+
"# Load the geothermal heat flux using the routine 'read_llc_to_tiles'\n",
1304+
"geoflx = ecco.read_llc_to_tiles(base_dir, 'geothermalFlux.bin')"
13041305
]
13051306
},
13061307
{
13071308
"cell_type": "markdown",
13081309
"metadata": {},
13091310
"source": [
1310-
"> **Note**: Geothermal flux needs to be saved as an xarray data array with the same format as the model output. In order to reformat the loaded data array the byte-ordering needs to be changed."
1311+
"The geothermal flux dataset needs to be saved as an xarray data array with the same format as the model output."
13111312
]
13121313
},
13131314
{
13141315
"cell_type": "code",
1315-
"execution_count": 54,
1316+
"execution_count": 56,
13161317
"metadata": {},
13171318
"outputs": [],
13181319
"source": [
1319-
"# Data and type endianness don't match. Change data to match dtype and reshape to 1d\n",
1320-
"geoflx = geoflx.byteswap().reshape([105300,1])"
1320+
"# Convert numpy array to an xarray DataArray with matching dimensions as the monthly mean fields\n",
1321+
"geoflx_llc = xr.DataArray(geoflx,coords={'tile': ecco_monthly_mean.tile.values,\n",
1322+
" 'j': ecco_monthly_mean.j.values,\n",
1323+
" 'i': ecco_monthly_mean.i.values},dims=['tile','j','i'])"
13211324
]
13221325
},
13231326
{
13241327
"cell_type": "code",
1325-
"execution_count": 55,
1328+
"execution_count": null,
13261329
"metadata": {},
13271330
"outputs": [],
13281331
"source": [
1329-
"# Reshape data for each face and save as xarray data array in LLC format\n",
1330-
"geoflx00 = xr.DataArray(geoflx[:8100,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],\n",
1331-
" dims=['j','i'])\n",
1332-
"geoflx01 = xr.DataArray(geoflx[8100:16200,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],\n",
1333-
" dims=['j','i'])\n",
1334-
"geoflx02 = xr.DataArray(geoflx[16200:24300,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],\n",
1335-
" dims=['j','i'])\n",
1336-
"geoflx03 = xr.DataArray(geoflx[24300:32400,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],\n",
1337-
" dims=['j','i'])\n",
1338-
"geoflx04 = xr.DataArray(geoflx[32400:40500,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],\n",
1339-
" dims=['j','i'])\n",
1340-
"geoflx05 = xr.DataArray(geoflx[40500:48600,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],\n",
1341-
" dims=['j','i'])\n",
1342-
"geoflx06 = xr.DataArray(geoflx[48600:56700,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],\n",
1343-
" dims=['j','i'])\n",
1344-
"\n",
1345-
"geoflx0709 = geoflx[56700:81000,0].reshape([90,270])\n",
1346-
"geoflx07 = xr.DataArray(geoflx0709[:,:90],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])\n",
1347-
"geoflx08 = xr.DataArray(geoflx0709[:,90:180],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])\n",
1348-
"geoflx09 = xr.DataArray(geoflx0709[:,180:],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])\n",
1332+
"plt.figure(figsize=(15,5));\n",
13491333
"\n",
1350-
"geoflx1012 = geoflx[81000:,0].reshape([90,270])\n",
1351-
"geoflx10 = xr.DataArray(geoflx1012[:,:90],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])\n",
1352-
"geoflx11 = xr.DataArray(geoflx1012[:,90:180],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])\n",
1353-
"geoflx12 = xr.DataArray(geoflx1012[:,180:],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])"
1354-
]
1355-
},
1356-
{
1357-
"cell_type": "code",
1358-
"execution_count": 56,
1359-
"metadata": {},
1360-
"outputs": [],
1361-
"source": [
1362-
"geoflx_llc = xr.concat([geoflx00,geoflx01,geoflx02,geoflx03,geoflx04,geoflx05,geoflx06,\n",
1363-
" geoflx07,geoflx08,geoflx09,geoflx10,geoflx11,geoflx12], 'tile')"
1334+
"ecco.plot_proj_to_latlon_grid(ecco_grid.XC, ecco_grid.YC, geoflx_llc,show_colorbar=True,cmap='magma', \n",
1335+
" user_lon_0=-67, dx=0.2, dy=0.2)\n",
1336+
"plt.title(r'Geothermal heat flux [W m$^{-2}$]', fontsize=16)\n",
1337+
"plt.show()"
13641338
]
13651339
},
13661340
{
13671341
"cell_type": "markdown",
13681342
"metadata": {},
13691343
"source": [
1370-
">**Note**: Geothermal flux needs to be a three dimensional field since the sources are distributed along the ocean floor at various depths. This requires a three dimensional mask (see below)."
1344+
"Geothermal flux needs to be a three dimensional field since the sources are distributed along the ocean floor at various depths. This requires a three dimensional mask."
13711345
]
13721346
},
13731347
{

Tutorials_as_Python_Files/ECCO_v4_Heat_budget_closure.py

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -648,61 +648,33 @@
648648
# ### Geothermal flux
649649

650650
# The geothermal flux contribution is not accounted for in any of the standard model diagnostics provided as output. Rather, this term, which is time invariant, is provided in the input file `geothermalFlux.bin` and can be downloaded from the PO.DAAC drive (https://ecco.jpl.nasa.gov/drive/files/Version4/Release3/input_init/geothermalFlux.bin).
651+
# > **Note**: Here, `geothermalFlux.bin` has been placed in `base_dir`.
651652

652653
# In[53]:
653654

654655

655-
# Here geothermalFlux.bin has been saved in base_dir.
656-
geoflx = np.fromfile(base_dir + '/geothermalFlux.bin', dtype=np.float32)
657-
656+
# Load the geothermal heat flux using the routine 'read_llc_to_tiles'
657+
geoflx = ecco.read_llc_to_tiles(base_dir, 'geothermalFlux.bin')
658658

659659
# > **Note**: Geothermal flux needs to be saved as an xarray data array with the same format as the model output. In order to reformat the loaded data array the byte-ordering needs to be changed.
660660

661-
# In[54]:
662-
663-
664-
# Data and type endianness don't match. Change data to match dtype and reshape to 1d
665-
geoflx = geoflx.byteswap().reshape([105300,1])
666-
667-
668-
# In[55]:
669-
670-
671-
# Reshape data for each face and save as xarray data array in LLC format
672-
geoflx00 = xr.DataArray(geoflx[:8100,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],
673-
dims=['j','i'])
674-
geoflx01 = xr.DataArray(geoflx[8100:16200,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],
675-
dims=['j','i'])
676-
geoflx02 = xr.DataArray(geoflx[16200:24300,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],
677-
dims=['j','i'])
678-
geoflx03 = xr.DataArray(geoflx[24300:32400,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],
679-
dims=['j','i'])
680-
geoflx04 = xr.DataArray(geoflx[32400:40500,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],
681-
dims=['j','i'])
682-
geoflx05 = xr.DataArray(geoflx[40500:48600,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],
683-
dims=['j','i'])
684-
geoflx06 = xr.DataArray(geoflx[48600:56700,0].reshape([90,90]),coords=[np.arange(0,90,1),np.arange(0,90,1)],
685-
dims=['j','i'])
686-
687-
geoflx0709 = geoflx[56700:81000,0].reshape([90,270])
688-
geoflx07 = xr.DataArray(geoflx0709[:,:90],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])
689-
geoflx08 = xr.DataArray(geoflx0709[:,90:180],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])
690-
geoflx09 = xr.DataArray(geoflx0709[:,180:],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])
691-
692-
geoflx1012 = geoflx[81000:,0].reshape([90,270])
693-
geoflx10 = xr.DataArray(geoflx1012[:,:90],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])
694-
geoflx11 = xr.DataArray(geoflx1012[:,90:180],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])
695-
geoflx12 = xr.DataArray(geoflx1012[:,180:],coords=[np.arange(0,90,1),np.arange(0,90,1)],dims=['j','i'])
696-
661+
# The geothermal flux dataset needs to be saved as an xarray data array with the same format as the model output.
697662

698663
# In[56]:
699664

665+
# Convert numpy array to an xarray DataArray with matching dimensions as the monthly mean fields
666+
geoflx_llc = xr.DataArray(geoflx,coords={'tile': ecco_monthly_mean.tile.values,
667+
'j': ecco_monthly_mean.j.values,
668+
'i': ecco_monthly_mean.i.values},dims=['tile','j','i'])
700669

701-
geoflx_llc = xr.concat([geoflx00,geoflx01,geoflx02,geoflx03,geoflx04,geoflx05,geoflx06,
702-
geoflx07,geoflx08,geoflx09,geoflx10,geoflx11,geoflx12], 'tile')
670+
plt.figure(figsize=(15,5));
703671

672+
ecco.plot_proj_to_latlon_grid(ecco_grid.XC, ecco_grid.YC, geoflx_llc,show_colorbar=True,cmap='magma',
673+
user_lon_0=-67, dx=0.2, dy=0.2)
674+
plt.title(r'Geothermal heat flux [W m$^{-2}$]', fontsize=16)
675+
plt.show()
704676

705-
# >**Note**: Geothermal flux needs to be a three dimensional field since the sources are distributed along the ocean floor at various depths. This requires a three dimensional mask (see below).
677+
# Geothermal flux needs to be a three dimensional field since the sources are distributed along the ocean floor at various depths. This requires a three dimensional mask (see below).
706678

707679
# In[57]:
708680

0 commit comments

Comments
 (0)