|
24 | 24 | "outputs": [], |
25 | 25 | "source": [ |
26 | 26 | "import gsw_xarray as gsw\n", |
| 27 | + "import matplotlib.pyplot as plt\n", |
27 | 28 | "import xarray as xr\n", |
28 | | - "from c3s_eqc_automatic_quality_control import download" |
| 29 | + "from c3s_eqc_automatic_quality_control import diagnostics, download" |
29 | 30 | ] |
30 | 31 | }, |
31 | 32 | { |
|
44 | 45 | "outputs": [], |
45 | 46 | "source": [ |
46 | 47 | "year_start = 2004\n", |
47 | | - "year_stop = 2004 # 2023" |
| 48 | + "year_stop = 2023" |
48 | 49 | ] |
49 | 50 | }, |
50 | 51 | { |
|
102 | 103 | "metadata": {}, |
103 | 104 | "outputs": [], |
104 | 105 | "source": [ |
105 | | - "def compute_insitu_density(ds):\n", |
| 106 | + "def compute_densities(ds):\n", |
106 | 107 | " p = gsw.p_from_z(-ds[\"deptht\"], ds[\"latitude\"])\n", |
107 | 108 | " SA = gsw.SA_from_SP(ds[\"vosaline\"], p, ds[\"longitude\"], ds[\"latitude\"])\n", |
108 | 109 | " 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])" |
| 110 | + " rho = gsw.rho(SA, CT, p).rename(\"rho\")\n", |
| 111 | + " trho = gsw.rho(SA.mean(\"time\"), CT, p).rename(\"trho\")\n", |
| 112 | + " srho = gsw.rho(SA, CT.mean(\"time\"), p).rename(\"hrho\")\n", |
| 113 | + " return diagnostics.spatial_weighted_mean(xr.merge([rho, trho, srho]))\n", |
| 114 | + "\n", |
| 115 | + "\n", |
| 116 | + "def compute_ssl(rho, rho0=1025):\n", |
| 117 | + " grouped_rho = rho.groupby(\"time.month\")\n", |
| 118 | + " delta_rho = grouped_rho - grouped_rho.mean()\n", |
| 119 | + " ssl = -(delta_rho.fillna(0) / rho0).integrate(\"deptht\")\n", |
| 120 | + " match rho.name:\n", |
| 121 | + " case \"rho\":\n", |
| 122 | + " prefix = \"\"\n", |
| 123 | + " case \"trho\":\n", |
| 124 | + " prefix = \"thermo\"\n", |
| 125 | + " case \"hrho\":\n", |
| 126 | + " prefix = \"halo\"\n", |
| 127 | + " case _:\n", |
| 128 | + " raise NotImplementedError(f\"{rho.name=}\")\n", |
| 129 | + " ssl.attrs = {\"long_name\": f\"{prefix}steric sea level\".title(), \"units\": \"m\"}\n", |
| 130 | + " return ssl.rename(rho.name.replace(\"rho\", \"ssl\"))" |
111 | 131 | ] |
112 | 132 | }, |
113 | 133 | { |
|
127 | 147 | "source": [ |
128 | 148 | "ds_reanalysis = download.download_and_transform(\n", |
129 | 149 | " *request_reanalysis,\n", |
130 | | - " transform_func=compute_insitu_density,\n", |
| 150 | + " transform_func=compute_densities,\n", |
131 | 151 | " **download_kwargs,\n", |
132 | 152 | ")" |
133 | 153 | ] |
|
137 | 157 | "id": "11", |
138 | 158 | "metadata": {}, |
139 | 159 | "source": [ |
140 | | - "## Download and transform satellite" |
| 160 | + "## Quick and dirty plot" |
141 | 161 | ] |
142 | 162 | }, |
143 | 163 | { |
|
146 | 166 | "id": "12", |
147 | 167 | "metadata": {}, |
148 | 168 | "outputs": [], |
| 169 | + "source": [ |
| 170 | + "fig, ax = plt.subplots(1, 1, figsize=(12, 5))\n", |
| 171 | + "for rho in ds_reanalysis.values():\n", |
| 172 | + " da = compute_ssl(rho, rho0=1025)\n", |
| 173 | + " da.plot(label=da.long_name)\n", |
| 174 | + "ax.set_ylabel(\"[m]\")\n", |
| 175 | + "ax.legend()\n", |
| 176 | + "ax.grid()\n", |
| 177 | + "plt.show()" |
| 178 | + ] |
| 179 | + }, |
| 180 | + { |
| 181 | + "cell_type": "markdown", |
| 182 | + "id": "13", |
| 183 | + "metadata": {}, |
| 184 | + "source": [ |
| 185 | + "## Download and transform satellite" |
| 186 | + ] |
| 187 | + }, |
| 188 | + { |
| 189 | + "cell_type": "code", |
| 190 | + "execution_count": null, |
| 191 | + "id": "14", |
| 192 | + "metadata": {}, |
| 193 | + "outputs": [], |
149 | 194 | "source": [ |
150 | 195 | "ds_satellite = download.download_and_transform(*request_satellite, **download_kwargs)" |
151 | 196 | ] |
|
0 commit comments