Skip to content

Commit 8a5662a

Browse files
committed
compute rho
1 parent b572558 commit 8a5662a

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

notebooks/wp5/steric_sea_level_ora5.ipynb

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"metadata": {},
2424
"outputs": [],
2525
"source": [
26+
"import gsw_xarray as gsw\n",
27+
"import xarray as xr\n",
2628
"from c3s_eqc_automatic_quality_control import download"
2729
]
2830
},
@@ -42,7 +44,7 @@
4244
"outputs": [],
4345
"source": [
4446
"year_start = 2004\n",
45-
"year_stop = 2023"
47+
"year_stop = 2004 # 2023"
4648
]
4749
},
4850
{
@@ -90,7 +92,7 @@
9092
"id": "7",
9193
"metadata": {},
9294
"source": [
93-
"## Download and transform reanalysis"
95+
"## Define functions to cache"
9496
]
9597
},
9698
{
@@ -100,15 +102,20 @@
100102
"metadata": {},
101103
"outputs": [],
102104
"source": [
103-
"ds_reanalysis = download.download_and_transform(*request_reanalysis, **download_kwargs)"
105+
"def compute_insitu_density(ds):\n",
106+
" p = gsw.p_from_z(-ds[\"deptht\"], ds[\"latitude\"])\n",
107+
" SA = gsw.SA_from_SP(ds[\"vosaline\"], p, ds[\"longitude\"], ds[\"latitude\"])\n",
108+
" CT = gsw.CT_from_pt(SA, ds[\"votemper\"])\n",
109+
" rho = gsw.rho(SA, CT, p)\n",
110+
" return xr.merge([p, SA, CT, rho])"
104111
]
105112
},
106113
{
107114
"cell_type": "markdown",
108115
"id": "9",
109116
"metadata": {},
110117
"source": [
111-
"## Download and transform satellite"
118+
"## Download and transform reanalysis"
112119
]
113120
},
114121
{
@@ -117,6 +124,28 @@
117124
"id": "10",
118125
"metadata": {},
119126
"outputs": [],
127+
"source": [
128+
"ds_reanalysis = download.download_and_transform(\n",
129+
" *request_reanalysis,\n",
130+
" transform_func=compute_insitu_density,\n",
131+
" **download_kwargs,\n",
132+
")"
133+
]
134+
},
135+
{
136+
"cell_type": "markdown",
137+
"id": "11",
138+
"metadata": {},
139+
"source": [
140+
"## Download and transform satellite"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"execution_count": null,
146+
"id": "12",
147+
"metadata": {},
148+
"outputs": [],
120149
"source": [
121150
"ds_satellite = download.download_and_transform(*request_satellite, **download_kwargs)"
122151
]

0 commit comments

Comments
 (0)