Skip to content

Commit

Permalink
Update land TCI notebook to add scatter and fix formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
megandevlan committed Dec 11, 2024
1 parent d01486c commit e1f2496
Showing 1 changed file with 59 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -930,58 +930,77 @@
"metadata": {},
"outputs": [],
"source": [
"def plotScatter(seasonstr, caseSel = None): \n",
"def plotScatter(seasonstr, caseSel=None):\n",
" node_lats = uxgrid.face_lat.values\n",
" node_lons = uxgrid.face_lon.values\n",
"\n",
" predictions = []\n",
" \n",
" fig,axs = plt.subplots(1,1,figsize=(8,8))\n",
" \n",
" \n",
" CI_model = (\n",
" couplingIndex_DS[\"CouplingIndex\"]\n",
" .sel(season=seasonstr)\n",
" )\n",
" \n",
" iSeason = np.where(seasons == seasonstr)[0]\n",
"\n",
" fig, axs = plt.subplots(1, 1, figsize=(8, 8))\n",
"\n",
" CI_model = couplingIndex_DS[\"CouplingIndex\"].sel(season=seasonstr)\n",
"\n",
" iSeason = np.where(seasons == seasonstr)[0]\n",
" iStations = np.where(np.isfinite(terraCI_fluxnetConverted[:, iSeason]) == True)[0]\n",
" \n",
"\n",
" for iPoint in range(len(iStations)):\n",
" this_lon = lon_fluxnet[iStations[iPoint]] # lon1\n",
" this_lat = lat_fluxnet[iStations[iPoint]] # lat1\n",
" obs_point = np.array((this_lon, this_lat))\n",
" \n",
" # Get subset of relevant points \n",
" i = np.where( (node_lats>=(this_lat-2)) & (node_lats<=(this_lat+2)) & \n",
" (node_lons>=(this_lon-2)) & (node_lons<=(this_lon+2)))[0]\n",
" \n",
"\n",
" # Get subset of relevant points\n",
" i = np.where(\n",
" (node_lats >= (this_lat - 2))\n",
" & (node_lats <= (this_lat + 2))\n",
" & (node_lons >= (this_lon - 2))\n",
" & (node_lons <= (this_lon + 2))\n",
" )[0]\n",
"\n",
" minDistance = 100\n",
" for iSelClose in range(len(i)): \n",
" # Find point in uxarray? Use euclidian distance \n",
" distance = np.linalg.norm(obs_point - np.array((node_lons[i[iSelClose]], node_lats[i[iSelClose]])) )\n",
" \n",
" if ( (distance<minDistance) & \n",
" (np.isfinite(couplingIndex_DS[\"CouplingIndex\"].sel(season='JJA').values[i[iSelClose]])==True) ): \n",
" minDistance = distance \n",
" for iSelClose in range(len(i)):\n",
" # Find point in uxarray? Use euclidian distance\n",
" distance = np.linalg.norm(\n",
" obs_point - np.array((node_lons[i[iSelClose]], node_lats[i[iSelClose]]))\n",
" )\n",
"\n",
" if (distance < minDistance) & (\n",
" np.isfinite(\n",
" couplingIndex_DS[\"CouplingIndex\"]\n",
" .sel(season=\"JJA\")\n",
" .values[i[iSelClose]]\n",
" )\n",
" == True\n",
" ):\n",
" minDistance = distance\n",
" selLon = node_lons[i[iSelClose]]\n",
" selLat = node_lats[i[iSelClose]]\n",
" selLoc = i[iSelClose]\n",
" \n",
" predictions = np.append( predictions, couplingIndex_DS[\"CouplingIndex\"].sel(season=seasonstr).values[selLoc] )\n",
" axs.plot(terraCI_fluxnetConverted[iPoint, iSeason], couplingIndex_DS[\"CouplingIndex\"].sel(season=seasonstr).values[selLoc], \n",
" 'bo', alpha=0.5)\n",
" \n",
" axs.set_xlabel('FLUXNET CI Value',fontsize=12)\n",
" axs.set_ylabel('CESM CI Value',fontsize=12)\n",
" axs.set_title('Individual station CI vs. nearest gridcell CI: '+seasonstr, fontsize=14)\n",
" axs.set_xlim([-25,25])\n",
" axs.set_ylim([-25,25])\n",
" axs.plot(np.arange(-25,26), np.arange(-25,26),'k--')\n",
" \n",
" rmse = np.sqrt(((predictions - terraCI_fluxnetConverted[iStations, iSeason]) ** 2).mean())\n",
" axs.text(0.05,0.95, \"RMSE: \"+str(rmse), transform=axs.transAxes)\n",
" \n",
"\n",
" predictions = np.append(\n",
" predictions,\n",
" couplingIndex_DS[\"CouplingIndex\"].sel(season=seasonstr).values[selLoc],\n",
" )\n",
" axs.plot(\n",
" terraCI_fluxnetConverted[iPoint, iSeason],\n",
" couplingIndex_DS[\"CouplingIndex\"].sel(season=seasonstr).values[selLoc],\n",
" \"bo\",\n",
" alpha=0.5,\n",
" )\n",
"\n",
" axs.set_xlabel(\"FLUXNET CI Value\", fontsize=12)\n",
" axs.set_ylabel(\"CESM CI Value\", fontsize=12)\n",
" axs.set_title(\n",
" \"Individual station CI vs. nearest gridcell CI: \" + seasonstr, fontsize=14\n",
" )\n",
" axs.set_xlim([-25, 25])\n",
" axs.set_ylim([-25, 25])\n",
" axs.plot(np.arange(-25, 26), np.arange(-25, 26), \"k--\")\n",
"\n",
" rmse = np.sqrt(\n",
" ((predictions - terraCI_fluxnetConverted[iStations, iSeason]) ** 2).mean()\n",
" )\n",
" axs.text(0.05, 0.95, \"RMSE: \" + str(rmse), transform=axs.transAxes)\n",
"\n",
" return axs"
]
},
Expand Down Expand Up @@ -1012,7 +1031,7 @@
" plotTCI_case(\"DJF\", iCase)\n",
"\n",
" plotScatter(\"JJA\", iCase)\n",
" plotScatter(\"DJF\", iCase)\n"
" plotScatter(\"DJF\", iCase)"
]
}
],
Expand Down

0 comments on commit e1f2496

Please sign in to comment.