Skip to content

Commit 3eae1f0

Browse files
Merge pull request #104 from raphaeldussin/RGclim_add
expand RG clim notebook with annual and monthly clim of pottemp and salt
2 parents 0f5d29e + 26578d1 commit 3eae1f0

File tree

2 files changed

+196
-55
lines changed

2 files changed

+196
-55
lines changed

data/RoemmichGilson_ARGO_based_climatology.ipynb

Lines changed: 193 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
{
1212
"cell_type": "code",
13-
"execution_count": 1,
13+
"execution_count": null,
1414
"id": "supposed-essex",
1515
"metadata": {},
1616
"outputs": [],
@@ -21,6 +21,8 @@
2121
"import requests\n",
2222
"import warnings\n",
2323
"import subprocess as sp\n",
24+
"import seawater\n",
25+
"import pandas as pd\n",
2426
"\n",
2527
"warnings.filterwarnings(\"ignore\")\n",
2628
"\n",
@@ -34,7 +36,7 @@
3436
},
3537
{
3638
"cell_type": "code",
37-
"execution_count": 2,
39+
"execution_count": null,
3840
"id": "enabling-sweet",
3941
"metadata": {},
4042
"outputs": [],
@@ -52,7 +54,7 @@
5254
},
5355
{
5456
"cell_type": "code",
55-
"execution_count": 3,
57+
"execution_count": null,
5658
"id": "classified-modification",
5759
"metadata": {},
5860
"outputs": [],
@@ -71,53 +73,10 @@
7173
},
7274
{
7375
"cell_type": "code",
74-
"execution_count": 4,
76+
"execution_count": null,
7577
"id": "rolled-uniform",
7678
"metadata": {},
77-
"outputs": [
78-
{
79-
"name": "stdout",
80-
"output_type": "stream",
81-
"text": [
82-
"retrieving RG_ArgoClim_201901_2019.nc.gz\n",
83-
"retrieving RG_ArgoClim_201902_2019.nc.gz\n",
84-
"retrieving RG_ArgoClim_201903_2019.nc.gz\n",
85-
"retrieving RG_ArgoClim_201904_2019.nc.gz\n",
86-
"retrieving RG_ArgoClim_201905_2019.nc.gz\n",
87-
"retrieving RG_ArgoClim_201906_2019.nc.gz\n",
88-
"retrieving RG_ArgoClim_201907_2019.nc.gz\n",
89-
"retrieving RG_ArgoClim_201908_2019.nc.gz\n",
90-
"retrieving RG_ArgoClim_201909_2019.nc.gz\n",
91-
"retrieving RG_ArgoClim_201910_2019.nc.gz\n",
92-
"retrieving RG_ArgoClim_201911_2019.nc.gz\n",
93-
"retrieving RG_ArgoClim_201912_2019.nc.gz\n",
94-
"retrieving RG_ArgoClim_202001_2019.nc.gz\n",
95-
"retrieving RG_ArgoClim_202002_2019.nc.gz\n",
96-
"retrieving RG_ArgoClim_202003_2019.nc.gz\n",
97-
"retrieving RG_ArgoClim_202004_2019.nc.gz\n",
98-
"retrieving RG_ArgoClim_202005_2019.nc.gz\n",
99-
"retrieving RG_ArgoClim_202006_2019.nc.gz\n",
100-
"retrieving RG_ArgoClim_202007_2019.nc.gz\n",
101-
"retrieving RG_ArgoClim_202008_2019.nc.gz\n",
102-
"retrieving RG_ArgoClim_202009_2019.nc.gz\n",
103-
"retrieving RG_ArgoClim_202010_2019.nc.gz\n",
104-
"retrieving RG_ArgoClim_202011_2019.nc.gz\n",
105-
"retrieving RG_ArgoClim_202012_2019.nc.gz\n",
106-
"retrieving RG_ArgoClim_202101_2019.nc.gz\n",
107-
"retrieving RG_ArgoClim_202102_2019.nc.gz\n",
108-
"retrieving RG_ArgoClim_202103_2019.nc.gz\n",
109-
"retrieving RG_ArgoClim_202104_2019.nc.gz\n",
110-
"retrieving RG_ArgoClim_202105_2019.nc.gz\n",
111-
"retrieving RG_ArgoClim_202106_2019.nc.gz\n",
112-
"retrieving RG_ArgoClim_202107_2019.nc.gz\n",
113-
"retrieving RG_ArgoClim_202108_2019.nc.gz\n",
114-
"retrieving RG_ArgoClim_202109_2019.nc.gz\n",
115-
"retrieving RG_ArgoClim_202110_2019.nc.gz\n",
116-
"retrieving RG_ArgoClim_202111_2019.nc.gz\n",
117-
"retrieving RG_ArgoClim_202112_2019.nc.gz\n"
118-
]
119-
}
120-
],
79+
"outputs": [],
12180
"source": [
12281
"files_ext = []\n",
12382
"lastyear = 2021\n",
@@ -138,7 +97,7 @@
13897
},
13998
{
14099
"cell_type": "code",
141-
"execution_count": 5,
100+
"execution_count": null,
142101
"id": "australian-villa",
143102
"metadata": {},
144103
"outputs": [],
@@ -157,7 +116,7 @@
157116
},
158117
{
159118
"cell_type": "code",
160-
"execution_count": 6,
119+
"execution_count": null,
161120
"id": "urban-contact",
162121
"metadata": {},
163122
"outputs": [],
@@ -167,7 +126,7 @@
167126
},
168127
{
169128
"cell_type": "code",
170-
"execution_count": 7,
129+
"execution_count": null,
171130
"id": "amber-connection",
172131
"metadata": {},
173132
"outputs": [],
@@ -185,7 +144,7 @@
185144
},
186145
{
187146
"cell_type": "code",
188-
"execution_count": 8,
147+
"execution_count": null,
189148
"id": "controversial-financing",
190149
"metadata": {},
191150
"outputs": [],
@@ -200,18 +159,197 @@
200159
},
201160
{
202161
"cell_type": "code",
203-
"execution_count": 9,
162+
"execution_count": null,
204163
"id": "pursuant-tribune",
205164
"metadata": {},
206165
"outputs": [],
207166
"source": [
208167
"ds.to_netcdf(f\"RG_ArgoClim_Extended_200401-{lastyear}12.nc\", format=\"NETCDF3_64BIT\")"
209168
]
169+
},
170+
{
171+
"cell_type": "markdown",
172+
"id": "6492543e-a4d0-428d-80bb-8ba2f08a0952",
173+
"metadata": {},
174+
"source": [
175+
"## Create Annual and Monthly clim for salt and pot_temp"
176+
]
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"id": "691ced23-046c-4810-9809-cb4625d8ab05",
182+
"metadata": {},
183+
"outputs": [],
184+
"source": [
185+
"# compute potential temperature\n",
186+
"ptemp = xr.apply_ufunc(seawater.eos80.ptmp,\n",
187+
" ds[\"ARGO_SALINITY_MEAN\"] + ds[\"ARGO_SALINITY_ANOMALY\"],\n",
188+
" ds[\"ARGO_TEMPERATURE_MEAN\"] + ds[\"ARGO_TEMPERATURE_ANOMALY\"],\n",
189+
" ds[\"PRESSURE\"],\n",
190+
" dask='parallelized',\n",
191+
" output_dtypes=[ds[\"ARGO_TEMPERATURE_MEAN\"].dtype])\n",
192+
"\n",
193+
"# reconstruct salinity (mean + anomaly)\n",
194+
"salt = ds[\"ARGO_SALINITY_MEAN\"] + ds[\"ARGO_SALINITY_ANOMALY\"]"
195+
]
196+
},
197+
{
198+
"cell_type": "code",
199+
"execution_count": null,
200+
"id": "19d1f60b-f918-40c0-b132-5b468ec45fba",
201+
"metadata": {},
202+
"outputs": [],
203+
"source": [
204+
"# create a more flexible time axis\n",
205+
"from datetime import timedelta\n",
206+
"delta = timedelta(days=15)\n",
207+
"time = pd.date_range(start='2004-01', periods=len(ds[\"TIME\"]), freq=\"1MS\") + delta"
208+
]
209+
},
210+
{
211+
"cell_type": "code",
212+
"execution_count": null,
213+
"id": "00a02b81-21bd-485b-a9af-761b33758947",
214+
"metadata": {},
215+
"outputs": [],
216+
"source": [
217+
"# replace time in arrays\n",
218+
"ptemp[\"TIME\"] = time\n",
219+
"salt[\"TIME\"] = time"
220+
]
221+
},
222+
{
223+
"cell_type": "code",
224+
"execution_count": null,
225+
"id": "2d970b36-1676-4d39-b35a-4b7e789fb726",
226+
"metadata": {},
227+
"outputs": [],
228+
"source": [
229+
"# Annual climatology\n",
230+
"ptemp_annual = ptemp.mean(dim=\"TIME\")\n",
231+
"salt_annual = salt.mean(dim=\"TIME\")"
232+
]
233+
},
234+
{
235+
"cell_type": "code",
236+
"execution_count": null,
237+
"id": "213284e0-0798-4066-932d-639452ebaa6b",
238+
"metadata": {},
239+
"outputs": [],
240+
"source": [
241+
"# Monthly climatology\n",
242+
"ptemp_monthly = ptemp.groupby(ptemp.TIME.dt.month).mean(dim=\"TIME\")\n",
243+
"salt_monthly = salt.groupby(salt.TIME.dt.month).mean(dim=\"TIME\")"
244+
]
245+
},
246+
{
247+
"cell_type": "code",
248+
"execution_count": null,
249+
"id": "980e2f0d-80ad-4dc4-a631-17f6e94e9e54",
250+
"metadata": {},
251+
"outputs": [],
252+
"source": [
253+
"# create a depth array\n",
254+
"import numpy as np\n",
255+
"pressure3d = np.broadcast_to(ds[\"PRESSURE\"].values[:, np.newaxis, np.newaxis],\n",
256+
" (len(ds[\"PRESSURE\"]),\n",
257+
" len(ds[\"LATITUDE\"]),\n",
258+
" len(ds[\"LONGITUDE\"])))\n",
259+
"latitude3d = np.broadcast_to(ds[\"LATITUDE\"].values[np.newaxis, :, np.newaxis],\n",
260+
" (len(ds[\"PRESSURE\"]),\n",
261+
" len(ds[\"LATITUDE\"]),\n",
262+
" len(ds[\"LONGITUDE\"])))\n",
263+
"\n",
264+
"depth3d = seawater.eos80.dpth(pressure3d, latitude3d)"
265+
]
266+
},
267+
{
268+
"cell_type": "code",
269+
"execution_count": null,
270+
"id": "7f665c1d-c623-4a19-8ddd-113d92a3af68",
271+
"metadata": {},
272+
"outputs": [],
273+
"source": [
274+
"annual_clim = xr.Dataset()\n",
275+
"annual_clim[\"ptemp\"] = ptemp_annual.fillna(1.e+20)\n",
276+
"annual_clim[\"salt\"] = salt_annual.fillna(1.e+20)\n",
277+
"annual_clim[\"depth\"] = xr.DataArray(depth3d, dims=(\"PRESSURE\", \"LATITUDE\", \"LONGITUDE\"))\n",
278+
"\n",
279+
"annual_clim = annual_clim.rename({\"LONGITUDE\": \"lon\", \n",
280+
" \"LATITUDE\": \"lat\",\n",
281+
" \"PRESSURE\": \"pres\"})\n"
282+
]
283+
},
284+
{
285+
"cell_type": "code",
286+
"execution_count": null,
287+
"id": "2267e443-2d68-4d5b-8dd0-be327141cca1",
288+
"metadata": {},
289+
"outputs": [],
290+
"source": [
291+
"monthly_clim = xr.Dataset()\n",
292+
"monthly_clim[\"ptemp\"] = ptemp_monthly.fillna(1.e+20)\n",
293+
"monthly_clim[\"salt\"] = salt_monthly.fillna(1.e+20)\n",
294+
"monthly_clim[\"depth\"] = xr.DataArray(depth3d, dims=(\"PRESSURE\", \"LATITUDE\", \"LONGITUDE\"))\n",
295+
"\n",
296+
"monthly_clim = monthly_clim.rename({\"LONGITUDE\": \"lon\", \n",
297+
" \"LATITUDE\": \"lat\",\n",
298+
" \"PRESSURE\": \"pres\"})\n",
299+
"\n",
300+
"monthly_clim = monthly_clim.transpose(*(\"month\", \"pres\", \"lat\", \"lon\"))"
301+
]
302+
},
303+
{
304+
"cell_type": "code",
305+
"execution_count": null,
306+
"id": "0fd0618c-2b46-4300-8d76-5fc46eb116c5",
307+
"metadata": {},
308+
"outputs": [],
309+
"source": [
310+
"annual_clim"
311+
]
312+
},
313+
{
314+
"cell_type": "code",
315+
"execution_count": null,
316+
"id": "79759369-4c10-48c7-82c5-9d93856e10da",
317+
"metadata": {},
318+
"outputs": [],
319+
"source": [
320+
"monthly_clim"
321+
]
322+
},
323+
{
324+
"cell_type": "code",
325+
"execution_count": null,
326+
"id": "a9db469c-fa3d-41ae-886a-7419ba82e78a",
327+
"metadata": {},
328+
"outputs": [],
329+
"source": [
330+
"annual_clim.to_netcdf(f\"RG_ArgoClim_Extended_200401-{lastyear}12_annual_clim_ptemp+salt.nc\",\n",
331+
" encoding = {\"ptemp\": {\"_FillValue\": 1.e+20},\n",
332+
" \"salt\": {\"_FillValue\": 1.e+20}},\n",
333+
" format=\"NETCDF3_64BIT\")"
334+
]
335+
},
336+
{
337+
"cell_type": "code",
338+
"execution_count": null,
339+
"id": "9c03e734-a6a5-4a0b-8991-3f25983a9cdd",
340+
"metadata": {},
341+
"outputs": [],
342+
"source": [
343+
"monthly_clim.to_netcdf(f\"RG_ArgoClim_Extended_200401-{lastyear}12_monthly_clim_ptemp+salt.nc\",\n",
344+
" encoding = {\"ptemp\": {\"_FillValue\": 1.e+20},\n",
345+
" \"salt\": {\"_FillValue\": 1.e+20}},\n",
346+
" format=\"NETCDF3_64BIT\", unlimited_dims=\"month\")"
347+
]
210348
}
211349
],
212350
"metadata": {
213351
"kernelspec": {
214-
"display_name": "P3-om4labs",
352+
"display_name": "om4labs",
215353
"language": "python",
216354
"name": "om4labs"
217355
},
@@ -225,7 +363,7 @@
225363
"name": "python",
226364
"nbconvert_exporter": "python",
227365
"pygments_lexer": "ipython3",
228-
"version": "3.8.6"
366+
"version": "3.8.12"
229367
}
230368
},
231369
"nbformat": 4,

data/checksums_RG_ARGOClim.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fb8837b0f2a61f25c16f4f3d2aba5378 RG_ArgoClim_Extended_200401-202112.nc
2+
49c4ccac20835fc246d04657587c611d RG_ArgoClim_Extended_200401-202112_annual_clim_ptemp+salt.nc
3+
fa1f0722b68f0971cb44eff952a250b8 RG_ArgoClim_Extended_200401-202112_monthly_clim_ptemp+salt.nc

0 commit comments

Comments
 (0)