|
53 | 53 | "import cacholote\n", |
54 | 54 | "import gsw_xarray as gsw\n", |
55 | 55 | "import matplotlib.pyplot as plt\n", |
| 56 | + "import pooch\n", |
56 | 57 | "import xarray as xr\n", |
57 | 58 | "from c3s_eqc_automatic_quality_control import diagnostics, download, utils\n", |
58 | 59 | "\n", |
|
334 | 335 | "id": "13", |
335 | 336 | "metadata": {}, |
336 | 337 | "source": [ |
337 | | - "## Download and transform satellite" |
| 338 | + "## Download and transform ARGO" |
338 | 339 | ] |
339 | 340 | }, |
340 | 341 | { |
|
343 | 344 | "id": "14", |
344 | 345 | "metadata": {}, |
345 | 346 | "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": [], |
346 | 418 | "source": [ |
347 | 419 | "ds_satellite = download.download_and_transform(*request_satellite, **download_kwargs)" |
348 | 420 | ] |
|
0 commit comments