Skip to content

Commit e6c4170

Browse files
authored
Merge pull request #79 from vincelhx/master
updating documentation
2 parents 72673b7 + b9bbd78 commit e6c4170

18 files changed

Lines changed: 520 additions & 769 deletions

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ ________________
4646
Documentation and examples
4747
--------------------------
4848

49-
https://cyclobs.ifremer.fr/static/sarwing_datarmor/xsarsea
49+
https://cerweb.ifremer.fr/datarmor/doc_sphinx/xsarsea/

docs/examples/create_hh_lut.ipynb

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Create HH LUT\n",
8+
"\n",
9+
"This notebook will show how we create HH LUTs"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"import numpy as np\n",
19+
"import matplotlib.pyplot as plt\n",
20+
"import xarray as xr\n",
21+
"\n",
22+
"# optional debug messages\n",
23+
"import logging\n",
24+
"logging.basicConfig()\n",
25+
"logging.getLogger('xsarsea.windspeed').setLevel(logging.DEBUG) #or .setLevel(logging.INFO)"
26+
]
27+
},
28+
{
29+
"cell_type": "markdown",
30+
"metadata": {},
31+
"source": [
32+
"## Definition Zhang & Mouche "
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"inc_angle = np.arange(17,50,0.5)\n",
42+
"ar = [1.3794, -3.19e-2, 1.4e-3]\n",
43+
"br = [-0.1711, 2.6e-3]\n",
44+
" \n",
45+
"\n",
46+
"def get_pol_ratio_zhangA(inc_angle,wind_speed):\n",
47+
" # do not force the ratio to be greater than 1\n",
48+
" ars2 = np.polynomial.polynomial.polyval(inc_angle, ar)\n",
49+
" brs2 = np.polynomial.polynomial.polyval(inc_angle, br)\n",
50+
"\n",
51+
" pol_ratio = ars2 * (wind_speed ** brs2)\n",
52+
" return pol_ratio\n",
53+
"\n",
54+
"def get_pol_ratio_zhangB(inc_angle,wind_speed):\n",
55+
" # do force the ratio to be greater than 1\n",
56+
" ars2 = np.polynomial.polynomial.polyval(inc_angle, ar)\n",
57+
" brs2 = np.polynomial.polynomial.polyval(inc_angle, br)\n",
58+
"\n",
59+
" pol_ratio = ars2 * (wind_speed ** brs2)\n",
60+
" # we force the ratio to be greater than 1\n",
61+
" pol_ratio = np.where(pol_ratio < 1, 1, pol_ratio)\n",
62+
" return pol_ratio\n",
63+
"\n",
64+
"\n",
65+
"def get_pol_ratio_mouche(inc_angle, wind_dir, wind_speed=None):\n",
66+
"\n",
67+
" theta=inc_angle\n",
68+
" phi=wind_dir\n",
69+
" # Alexis Mouche, D. Hauser,\n",
70+
" # V. Kudryavtsev and JF. Daloze,\n",
71+
" # \"Multi polarization ocean radar\n",
72+
" # cross-section from ENVISAT ASAR\n",
73+
" # observations, airborne polarimetric\n",
74+
" # radar measurements and empirical or\n",
75+
" # semi-empirical models\", ESA\n",
76+
" # ERS/ENVISAT Symposium, Salzburg,\n",
77+
" # September 2004\n",
78+
" A0 = 0.00650704\n",
79+
" B0 = 0.128983\n",
80+
" C0 = 0.992839\n",
81+
" Api2 = 0.00782194\n",
82+
" Bpi2 = 0.121405\n",
83+
" Cpi2 = 0.992839\n",
84+
" Api = 0.00598416\n",
85+
" Bpi = 0.140952\n",
86+
" Cpi = 0.992885\n",
87+
"\n",
88+
" P0_theta = A0*np.exp(B0*theta)+C0\n",
89+
" Ppi2_theta = Api2*np.exp(Bpi2*theta)+Cpi2\n",
90+
" Ppi_theta = Api*np.exp(Bpi*theta)+Cpi\n",
91+
"\n",
92+
" C0_theta = (P0_theta+Ppi_theta+2*Ppi2_theta)/4\n",
93+
" C1_theta = (P0_theta-Ppi_theta)/2\n",
94+
" C2_theta = (P0_theta+Ppi_theta-2*Ppi2_theta)/4\n",
95+
"\n",
96+
" polrat = C0_theta + C1_theta*np.cos(np.deg2rad(phi)) + C2_theta*np.cos(2*np.deg2rad(phi))\n",
97+
"\n",
98+
" return polrat\n",
99+
"\n"
100+
]
101+
},
102+
{
103+
"cell_type": "markdown",
104+
"metadata": {},
105+
"source": [
106+
"## Plot"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"metadata": {},
113+
"outputs": [],
114+
"source": [
115+
"plt.figure(figsize=(10,5))\n",
116+
"\n",
117+
"for wspd in [3,7,10,15,20]:\n",
118+
" plt.plot(inc_angle, 10*np.log10(get_pol_ratio_zhangB(inc_angle,wspd)), label=f'Wspd = {wspd} m/s')\n",
119+
" \n",
120+
"plt.legend(loc=\"lower right\")\n",
121+
"plt.title(f'ZhangB Polarization Ratio vs Incidence Angle')\n",
122+
"plt.xlabel('Incidence Angle [deg]')\n",
123+
"plt.ylabel('Polarization Ratio [dB]')\n",
124+
"plt.xlim([17,50])\n",
125+
"plt.grid()\n",
126+
"\n",
127+
"\n",
128+
"plt.figure(figsize=(10,5))\n",
129+
"\n",
130+
"for phi in [30, 60, 90, 120, 150, 180]:\n",
131+
" plt.plot(inc_angle, 10*np.log10(get_pol_ratio_mouche(inc_angle,phi)), label=f'Phi = {phi} deg')\n",
132+
" \n",
133+
"plt.legend(loc=\"upper left\")\n",
134+
"plt.title(f'Mouche1 Polarization Ratio vs Incidence Angle')\n",
135+
"plt.xlabel('Incidence Angle [deg]')\n",
136+
"plt.ylabel('Polarization Ratio [dB]')\n",
137+
"plt.xlim([17,50])\n",
138+
"plt.grid()"
139+
]
140+
},
141+
{
142+
"cell_type": "markdown",
143+
"metadata": {},
144+
"source": [
145+
"## create HH LUT "
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": null,
151+
"metadata": {},
152+
"outputs": [],
153+
"source": [
154+
"def create_gmfHH(fct, vv_name, pr_name, mod, res):\n",
155+
" pol_ratio_data = xr.apply_ufunc(\n",
156+
" fct,\n",
157+
" mod.incidence, mod.wspd,\n",
158+
" vectorize=True\n",
159+
" )\n",
160+
" pol_ratio_data_extended = pol_ratio_data.expand_dims({'phi': mod.phi}).broadcast_like(mod)\n",
161+
"\n",
162+
" mod_hh = (mod/pol_ratio_data_extended)\n",
163+
" mod_hh.name = 'sigma0_model'\n",
164+
" mod_hh = mod_hh.to_dataset()\n",
165+
" mod_hh.attrs['units'] = 'linear'\n",
166+
" mod_hh.attrs['construction'] = f'{vv_name} / {pr_name}'\n",
167+
" mod_hh.attrs['description'] = f'Backscatter coefficient in HH polarization build from {vv_name.upper()} model and {pr_name[0].upper() + pr_name[1:]} Polarization Ratio model'\n",
168+
" mod_hh.attrs['resolution'] = f'{res}'\n",
169+
" mod_hh.attrs['pol'] = 'HH'\n",
170+
" \n",
171+
" \n",
172+
" if vv_name == \"cmod7\":\n",
173+
" \n",
174+
" mod_hh.attrs['inc_range'] = np.array([16.,66.])\n",
175+
" mod_hh.attrs['wspd_range'] = np.array([0.2,50.])\n",
176+
" mod_hh.attrs['phi_range'] = np.array([0., 180.])\n",
177+
" \n",
178+
" elif vv_name == \"cmod5n\":\n",
179+
" \n",
180+
" mod_hh.attrs['inc_range'] = np.array([17.,50.])\n",
181+
" mod_hh.attrs['wspd_range'] = np.array([0.2, 50.])\n",
182+
" mod_hh.attrs['phi_range'] = np.array([0., 180.])\n",
183+
" \n",
184+
" else : \n",
185+
" raise ValueError(\"vv_name must be cmod7 or cmod5n\")\n",
186+
" \n",
187+
" mod_hh.attrs['model'] = f'{vv_name}_R{res}_hh_{pr_name}'\n",
188+
"\n",
189+
"\n",
190+
" mod_hh.attrs['wspd_step'] = np.round(\n",
191+
" np.unique(np.diff(mod_hh.wspd)), decimals=2)[0]\n",
192+
" mod_hh.attrs['inc_step'] = np.round(\n",
193+
" np.unique(np.diff(mod_hh.incidence)), decimals=2)[0]\n",
194+
" mod_hh.attrs['phi_step'] = np.round(\n",
195+
" np.unique(np.diff(mod_hh.phi)), decimals=2)[0]\n",
196+
" fname = f'./nc_lut_gmf_{vv_name}_R{res}_hh_{pr_name}.nc'\n",
197+
" mod_hh.to_netcdf(fname, mode=\"w\")\n",
198+
" print(\"model saved at \", fname)\n",
199+
" mod_hh.close()\n"
200+
]
201+
},
202+
{
203+
"cell_type": "code",
204+
"execution_count": null,
205+
"metadata": {},
206+
"outputs": [],
207+
"source": [
208+
"vv_name = \"cmod5n\"\n",
209+
"#create_gmfHH(get_pol_ratio_zhangB, vv_name, \"zhangB\", xsarsea.windspeed.get_model(f\"gmf_{vv_name}\").to_lut(**{'resolution':'high'}), 'high')\n"
210+
]
211+
}
212+
],
213+
"metadata": {
214+
"kernelspec": {
215+
"display_name": "Python 3 (ipykernel)",
216+
"language": "python",
217+
"name": "python3"
218+
},
219+
"language_info": {
220+
"codemirror_mode": {
221+
"name": "ipython",
222+
"version": 3
223+
},
224+
"file_extension": ".py",
225+
"mimetype": "text/x-python",
226+
"name": "python",
227+
"nbconvert_exporter": "python",
228+
"pygments_lexer": "ipython3",
229+
"version": "3.10.12"
230+
}
231+
},
232+
"nbformat": 4,
233+
"nbformat_minor": 4
234+
}

0 commit comments

Comments
 (0)