Skip to content

Commit dbfe7d8

Browse files
committed
add argo
1 parent 27483f4 commit dbfe7d8

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

notebooks/wp5/steric_sea_level_ora5.ipynb

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"import cacholote\n",
5454
"import gsw_xarray as gsw\n",
5555
"import matplotlib.pyplot as plt\n",
56+
"import pooch\n",
5657
"import xarray as xr\n",
5758
"from c3s_eqc_automatic_quality_control import diagnostics, download, utils\n",
5859
"\n",
@@ -334,7 +335,7 @@
334335
"id": "13",
335336
"metadata": {},
336337
"source": [
337-
"## Download and transform satellite"
338+
"## Download and transform ARGO"
338339
]
339340
},
340341
{
@@ -343,6 +344,77 @@
343344
"id": "14",
344345
"metadata": {},
345346
"outputs": [],
347+
"source": [
348+
"def preprocess(ds):\n",
349+
" # Naming\n",
350+
" ds = ds.rename({var: var.lower() for var in ds.variables})\n",
351+
" # Time\n",
352+
" ds[\"time\"].attrs[\"calendar\"] = \"360_day\"\n",
353+
" ds = xr.decode_cf(ds)\n",
354+
" # Depth\n",
355+
" ds[\"depth\"] = -gsw.z_from_p(ds[\"pressure\"], ds[\"latitude\"]).mean(\n",
356+
" \"latitude\", keep_attrs=True\n",
357+
" )\n",
358+
" ds[\"depth\"].attrs.update({\"positive\": \"down\", \"long_name\": \"Depth from pressure\"})\n",
359+
" return ds.swap_dims(pressure=\"depth\")\n",
360+
"\n",
361+
"\n",
362+
"# First dataset\n",
363+
"filenames = []\n",
364+
"for var in [\"Temperature\", \"Salinity\"]:\n",
365+
" url = f\"https://sio-argo.ucsd.edu/RG/RG_ArgoClim_{var}_2019.nc.gz\"\n",
366+
" filename = pooch.retrieve(url=url, known_hash=None, processor=pooch.Decompress())\n",
367+
" filenames.append(filename)\n",
368+
"with xr.set_options(use_new_combine_kwarg_defaults=True):\n",
369+
" ds_argo_1 = xr.open_mfdataset(filenames, preprocess=preprocess, decode_times=False)\n",
370+
"\n",
371+
"# Second dataset\n",
372+
"filenames = []\n",
373+
"for year in range(2019, year_stop + 1):\n",
374+
" for month in range(1, 13):\n",
375+
" url = f\"https://sio-argo.ucsd.edu/RG/RG_ArgoClim_{year}{month:02d}_2019.nc.gz\"\n",
376+
" filename = pooch.retrieve(\n",
377+
" url=url, known_hash=None, processor=pooch.Decompress()\n",
378+
" )\n",
379+
" filenames.append(filename)\n",
380+
"with xr.set_options(use_new_combine_kwarg_defaults=True):\n",
381+
" ds_argo_2 = xr.open_mfdataset(filename, preprocess=preprocess, decode_times=False)\n",
382+
"\n",
383+
"# Combine\n",
384+
"dataarrays = []\n",
385+
"for var in [\"salinity\", \"temperature\"]:\n",
386+
" da = ds_argo_1[f\"argo_{var}_mean\"]\n",
387+
" units = da.units\n",
388+
" da = xr.combine_by_coords(\n",
389+
" [\n",
390+
" da + ds_argo_1[f\"argo_{var}_anomaly\"],\n",
391+
" da + ds_argo_2[f\"argo_{var}_anomaly\"],\n",
392+
" ]\n",
393+
" )\n",
394+
" da.attrs[\"units\"] = units\n",
395+
" dataarrays.append(da.rename(var))\n",
396+
"with xr.set_options(use_new_combine_kwarg_defaults=True):\n",
397+
" ds_argo = xr.merge(dataarrays)\n",
398+
"\n",
399+
"# Selection\n",
400+
"ds_argo = ds_argo.sel(time=slice(str(year_start), str(year_stop)))\n",
401+
"ds_argo = utils.regionalise(ds_argo, lon_slice=lon_slice, lat_slice=lat_slice)"
402+
]
403+
},
404+
{
405+
"cell_type": "markdown",
406+
"id": "15",
407+
"metadata": {},
408+
"source": [
409+
"## Download and transform satellite"
410+
]
411+
},
412+
{
413+
"cell_type": "code",
414+
"execution_count": null,
415+
"id": "16",
416+
"metadata": {},
417+
"outputs": [],
346418
"source": [
347419
"ds_satellite = download.download_and_transform(*request_satellite, **download_kwargs)"
348420
]

0 commit comments

Comments
 (0)