Skip to content

Commit

Permalink
Merge pull request #67 from vincelhx/master
Browse files Browse the repository at this point in the history
review of windspeed.py
  • Loading branch information
agrouaze authored May 29, 2024
2 parents 5df8b2d + c1f3571 commit a5c1e80
Show file tree
Hide file tree
Showing 10 changed files with 415 additions and 316 deletions.
15 changes: 14 additions & 1 deletion docs/examples/gmfs_and_luts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,22 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"pygments_lexer": "ipython3"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
145 changes: 137 additions & 8 deletions docs/examples/windspeed_inversion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@
"source": [
"sarwing_owi_file = xsarsea.get_test_file('s1a-iw-owi-xx-20210909t130650-20210909t130715-039605-04AE83.nc')\n",
"sarwing_ds = xsarsea.read_sarwing_owi(sarwing_owi_file)\n",
"sarwing_ds\n",
"\n"
"sarwing_ds"
]
},
{
Expand Down Expand Up @@ -174,11 +173,12 @@
"metadata": {},
"outputs": [],
"source": [
"windspeed_co = windspeed.invert_from_model(\n",
"wind_co = windspeed.invert_from_model(\n",
" sarwing_ds.owiIncidenceAngle,\n",
" sarwing_ds.owiNrcs,\n",
" ancillary_wind = -np.conj(sarwing_ds.owi_ancillary_wind),\n",
" model='cmod5n')\n"
" model='cmod5n')\n",
"windspeed_co = np.abs(wind_co)"
]
},
{
Expand Down Expand Up @@ -292,15 +292,15 @@
"sarwing_luts_subset_path = xsarsea.get_test_file('sarwing_luts_subset')\n",
"windspeed.register_all_sarwing_luts(sarwing_luts_subset_path)\n",
"\n",
"windspeed_co, windspeed_dual = windspeed.invert_from_model(\n",
"wind_co, wind_dual = windspeed.invert_from_model(\n",
" sarwing_ds.owiIncidenceAngle,\n",
" sarwing_ds.owiNrcs,\n",
" sarwing_ds.owiNrcs_cross,\n",
" ancillary_wind=-np.conj(sarwing_ds.owi_ancillary_wind),\n",
" dsig_cr = dsig_cr,\n",
" model=('cmod5n','cmodms1ahw'))\n",
"windspeed_co = np.abs(windspeed_co)\n",
"windspeed_dual = np.abs(windspeed_dual)"
"windspeed_co = np.abs(wind_co)\n",
"windspeed_dual = np.abs(wind_dual)"
]
},
{
Expand All @@ -326,19 +326,148 @@
").opts(hv.opts.Image(colorbar=True, tools=['hover']))"
]
},
{
"cell_type": "markdown",
"id": "d79a3983-5c50-4ba4-a4df-61cb6b9ef955",
"metadata": {},
"source": [
"## direction output"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d21b329b-0218-4b81-8994-0e9317fe11a7",
"metadata": {},
"outputs": [],
"source": [
"sarwing_ds[\"winddir_dual\"] = (90 - (np.angle(-np.conj(wind_dual),deg=True)) + sarwing_ds.owiHeading)%360\n",
"sub_sarwing_ds = sarwing_ds.isel(line=slice(None, None, 10), sample=slice(None, None, 10))\n",
"\n",
"vectorfield = hv.VectorField(\n",
" (\n",
" sub_sarwing_ds.sample, sub_sarwing_ds.line,\n",
" xsarsea.dir_geo_to_sample(sarwing_ds[\"winddir_dual\"] ,sub_sarwing_ds.owiHeading),\n",
" np.abs(wind_dual).isel(line=slice(None, None, 10), sample=slice(None, None, 10))\n",
" )\n",
")\n",
"\n",
"hv.Image(windspeed_dual, kdims=['sample','line']).opts(title='speed and dir', clim=(0,50), cmap='jet') * vectorfield\n"
]
},
{
"cell_type": "markdown",
"id": "974eaccb-619a-4316-b8d0-3e751d4e964d",
"metadata": {},
"source": [
"### sarwing direction output"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6dc527c2-1f19-447e-9bd3-7e43acaf1a66",
"metadata": {},
"outputs": [],
"source": [
"sub_sarwing_ds = sarwing_ds.isel(line=slice(None, None, 10), sample=slice(None, None, 10))\n",
"\n",
"vectorfield = hv.VectorField(\n",
" (\n",
" sub_sarwing_ds.sample, sub_sarwing_ds.line,\n",
" xsarsea.dir_geo_to_sample(sub_sarwing_ds.owiWindDirection ,sub_sarwing_ds.owiHeading),\n",
" sub_sarwing_ds.owiWindSpeed\n",
" )\n",
")\n",
"\n",
"hv.Image(sarwing_ds.owiWindSpeed, kdims=['sample','line']).opts(title='speed and dir', clim=(0,50), cmap='jet') * vectorfield\n"
]
},
{
"cell_type": "markdown",
"id": "e4016131-62f2-4557-a57f-795741f9cad0",
"metadata": {},
"source": [
"## direction difference"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0a48cad7-f888-4d13-8df7-a9191690d7bb",
"metadata": {},
"outputs": [],
"source": [
"def normalize_angle(diff):\n",
" return (diff + 180) % 360 - 180\n",
" \n",
"angle_diff = normalize_angle(sarwing_ds[\"winddir_dual\"] - sarwing_ds.owiWindDirection_Tab_dualpol_2steps)\n",
"\n",
"(\n",
" (hv.Image(sarwing_ds[\"winddir_dual\"]).opts(title='xsarsea') + \n",
" hv.Image(sarwing_ds.owiWindDirection_Tab_dualpol_2steps).opts(title='sarwing' )).opts(hv.opts.Image(cmap='jet', clim=(0,360))) + \n",
" hv.Image(normalize_angle(angle_diff)).opts(cmap='jet', clim=(-5,5), title='xsarsea-sarwing\\nmean=%.4f std=%.4f' % (np.mean(angle_diff), np.std(angle_diff)))\n",
").opts(hv.opts.Image(colorbar=True, tools=['hover']))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aa425555-299c-4ce2-8987-5e27fd8d0af8",
"metadata": {},
"outputs": [],
"source": [
"np.angle(wind_co)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e4c10815-be94-4470-9fe6-1760c82bacc8",
"metadata": {},
"outputs": [],
"source": [
"wphi_co = 15.0\n",
"wspd_co = 30\n",
"sol = wspd_co * np.exp(1j * np.deg2rad(wphi_co))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c321f8c9-fd00-4d1c-a7e4-058ccb81df52",
"metadata": {},
"outputs": [],
"source": [
"np.rad2deg(np.angle(sol))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f408e45f-b188-4937-9725-8daacb6629b2",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"pygments_lexer": "ipython3"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit a5c1e80

Please sign in to comment.