Skip to content

Commit

Permalink
more notes on regridding notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
wwieder committed Jan 30, 2025
1 parent 5927e4b commit 61be533
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions scripts/regridding/regrid_conservative.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@
"- Regrid, then\n",
"- Divide by regridded landfrac\n",
"- Calculate global and regional sums\n",
"- For plotting add destination landmask to get rid of bloated coastlines"
"- For plotting add destination landmask to get rid of bloated coastlines\n",
"\n",
"#### At the end of the day we want to write out a destination grid .nc file with:\n",
"- regridded field\n",
"- regridded land frac\n",
"- wall to wall area (currently from CAM history file)\n",
"- destination grid land mask\n"
]
},
{
Expand All @@ -98,34 +104,43 @@
}
],
"source": [
"# Dummy source file to regrid (for now this can be from climo files made by adf)\n",
"gppfile='/glade/derecho/scratch/wwieder/ADF/b.e30_beta04.BLT1850.ne30_t232_wgx3.121/climo/b.e30_beta04.BLT1850.ne30_t232_wgx3.121_GPP_climo.nc'\n",
"ds_con = xr.open_dataset(gppfile)\n",
"\n",
"# Weighting file needed for regridding, keep this hard coded for now.\n",
"con_weight_file = \"/glade/work/wwieder/map_ne30pg3_to_fv0.9x1.25_scripgrids_conserve_nomask_c250108.nc\"\n",
"\n",
"# dummy destination grid\n",
"fv_t232_file = '/glade/derecho/scratch/wwieder/ctsm5.3.018_SP_f09_t232_mask/run/ctsm5.3.018_SP_f09_t232_mask.clm2.h0.0001-01.nc'\n",
"fv_t232 = xr.open_dataset(fv_t232_file)\n",
"\n",
"# Fill in with missing values\n",
"ds_con['GPP'] = ds_con['GPP'].fillna(0) # fill in missing values with 0 for this test\n",
"ds_con['test'] = ((ds_con.GPP)*0+1.)\n",
"ds_con['landfrac']= ds_con['landfrac'].fillna(0) # fill in missing values with 0 for this test\n",
"ds_con['GPP'] = ds_con.GPP * ds_con.landfrac\n",
"ds_con['test'] = ds_con.test * ds_con.landfrac\n",
"# Fill in missing values with zeros\n",
"ds_con['GPP'] = ds_con['GPP'].fillna(0) \n",
"ds_con['landfrac']= ds_con['landfrac'].fillna(0) \n",
"ds_con['GPP'] = ds_con.GPP * ds_con.landfrac # weight flux by land frac\n",
"\n",
"# not used for actually regridding\n",
"#ds_con['test'] = ((ds_con.GPP)*0+1.)\n",
"#ds_con['test'] = ds_con.test * ds_con.landfrac\n",
"\n",
"# These are the calls to regrid the souce data\n",
"regridder = regrid_se_to_fv.make_se_regridder(weight_file=con_weight_file, \n",
" s_data = ds_con.landmask.isel(time=0), \n",
" d_data = fv_t232.landmask,\n",
" Method = 'coservative',\n",
" )\n",
"ds_out_con = regrid_se_to_fv.regrid_se_data_conservative(regridder, ds_con).load()\n",
"\n",
"# Post processing to finish the conversion correctly:\n",
"ds_out_con['GPP'] = (ds_out_con.GPP / ds_out_con.landfrac)\n",
"ds_out_con['test'] = (ds_out_con.test / ds_out_con.landfrac)\n",
"#ds_out_con['test'] = (ds_out_con.test / ds_out_con.landfrac)\n",
"\n",
"# drop time variables\n",
"ds_out_con['landfrac'] = ds_out_con['landfrac'].isel(time=0) \n",
"ds_out_con['area'] = ds_out_con['area'].isel(time=0) \n",
"ds_out_con['landmask'] = ds_out_con['landmask'].isel(time=0) \n",
"\n",
"# TODO, add a global area and landmask field from the destination grid for calculating sums and plotting.\n",
"# TODO save this as a .nc file\n",
"# TODO, drop the test field from this once integrated into ADF\n",
Expand All @@ -136,7 +151,9 @@
{
"cell_type": "markdown",
"id": "e42505aa-4d41-42d3-8311-497209386c38",
"metadata": {},
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"#### Bilinear regridding\n",
"- Include a mask\n",
Expand Down

0 comments on commit 61be533

Please sign in to comment.