-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
310 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,310 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0", | ||
"metadata": {}, | ||
"source": [ | ||
"# Ozone - MSR" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "1", | ||
"metadata": {}, | ||
"source": [ | ||
"## Import Packages" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "2", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import cartopy.crs as ccrs\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import numpy as np\n", | ||
"import pandas as pd\n", | ||
"import xarray as xr\n", | ||
"from c3s_eqc_automatic_quality_control import diagnostics, download, plot, utils\n", | ||
"\n", | ||
"plt.style.use(\"seaborn-v0_8-notebook\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "3", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define parameters" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Regions\n", | ||
"region_slices = {\n", | ||
" \"global\": {\"lat_slice\": slice(-90, 90), \"lon_slice\": slice(0, 360)},\n", | ||
" \"tropics\": {\"lat_slice\": slice(-25, 25), \"lon_slice\": slice(0, 360)},\n", | ||
" \"NH mid-latitudes\": {\"lat_slice\": slice(30, 60), \"lon_slice\": slice(0, 360)},\n", | ||
" \"SH mid-latitudes\": {\"lat_slice\": slice(-30, -60), \"lon_slice\": slice(0, 360)},\n", | ||
" \"NH polar\": {\"lat_slice\": slice(60, 90), \"lon_slice\": slice(0, 360)},\n", | ||
" \"SH polar\": {\"lat_slice\": slice(-60, -90), \"lon_slice\": slice(0, 360)},\n", | ||
"}\n", | ||
"\n", | ||
"# Periods\n", | ||
"version_timeseries = {\n", | ||
" \"v0020\": {\"start\": \"1979-01\", \"stop\": \"2018-12\"},\n", | ||
" \"v0023\": {\"start\": \"1979-01\", \"stop\": \"2018-12\"},\n", | ||
" \"v0024\": {\"start\": \"2018-12\", \"stop\": \"2021-12\"},\n", | ||
" \"v0025\": {\"start\": \"2022-01\", \"stop\": \"2022-12\"},\n", | ||
"}\n", | ||
"version_maps = {\n", | ||
" \"v0023\": {\"start\": \"1979-01\", \"stop\": \"2018-12\"},\n", | ||
" \"v0024\": {\"start\": \"2019-01\", \"stop\": \"2021-12\"},\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "5", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define request" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "6", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"collection_id = \"satellite-ozone-v1\"\n", | ||
"\n", | ||
"common_request = {\n", | ||
" \"format\": \"zip\",\n", | ||
" \"processing_level\": \"level_4\",\n", | ||
" \"vertical_aggregation\": \"total_column\",\n", | ||
" \"sensor\": \"msr\",\n", | ||
" \"variable\": \"atmosphere_mole_content_of_ozone\",\n", | ||
"}\n", | ||
"\n", | ||
"requests_timeseries = {\n", | ||
" version: download.update_request_date(\n", | ||
" common_request | {\"version\": version},\n", | ||
" stringify_dates=True,\n", | ||
" **update_kwargs,\n", | ||
" )\n", | ||
" for version, update_kwargs in version_timeseries.items()\n", | ||
"}\n", | ||
"\n", | ||
"requests_maps = []\n", | ||
"for version, update_kwargs in version_maps.items():\n", | ||
" requests_maps.extend(\n", | ||
" download.update_request_date(\n", | ||
" common_request | {\"version\": version},\n", | ||
" stringify_dates=True,\n", | ||
" **update_kwargs,\n", | ||
" )\n", | ||
" )" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "7", | ||
"metadata": {}, | ||
"source": [ | ||
"## Cached functions" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "8", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def fix_coords(ds):\n", | ||
" ds = ds.swap_dims(\n", | ||
" {\n", | ||
" short: long\n", | ||
" for short, long in zip([\"Lat\", \"Lon\"], [\"latitude\", \"longitude\"])\n", | ||
" if short in ds.dims\n", | ||
" }\n", | ||
" )\n", | ||
" time = ds.attrs[\"Ozone_field_date\"]\n", | ||
" if isinstance(time, np.ndarray):\n", | ||
" time = \"-\".join(ds.attrs[\"Ozone_field_date\"].astype(str))\n", | ||
" ds = ds.assign_coords(time=[pd.to_datetime(time)])\n", | ||
" return ds\n", | ||
"\n", | ||
"\n", | ||
"def spatial_weighted_mean(ds, lon_slice, lat_slice):\n", | ||
" ds = utils.regionalise(ds, lon_slice=lon_slice, lat_slice=lat_slice)\n", | ||
" return diagnostics.spatial_weighted_mean(ds)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "9", | ||
"metadata": {}, | ||
"source": [ | ||
"## Download and transform timeseries" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "10", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"kwargs = {\n", | ||
" \"collection_id\": collection_id,\n", | ||
" \"chunks\": {\"year\": 1},\n", | ||
" \"decode_times\": False,\n", | ||
" \"preprocess\": fix_coords,\n", | ||
"}\n", | ||
"\n", | ||
"datasets = []\n", | ||
"for version, requests in requests_timeseries.items():\n", | ||
" for region, transform_func_kwargs in region_slices.items():\n", | ||
" print(f\"{version=} {region=}\")\n", | ||
" ds = download.download_and_transform(\n", | ||
" requests=requests,\n", | ||
" transform_func=spatial_weighted_mean,\n", | ||
" transform_func_kwargs=transform_func_kwargs,\n", | ||
" **kwargs,\n", | ||
" )\n", | ||
" datasets.append(ds.expand_dims(version=[version], region=[region]))\n", | ||
"ds_timeseries = xr.merge(datasets)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "11", | ||
"metadata": {}, | ||
"source": [ | ||
"## Download and transform maps" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "12", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ds_annual = download.download_and_transform(\n", | ||
" requests=requests_maps,\n", | ||
" transform_func=diagnostics.annual_weighted_mean,\n", | ||
" transform_chunks=False,\n", | ||
" **kwargs,\n", | ||
")\n", | ||
"ds_monthly = download.download_and_transform(\n", | ||
" requests=requests_maps,\n", | ||
" transform_func=diagnostics.monthly_weighted_mean,\n", | ||
" transform_chunks=False,\n", | ||
" **kwargs,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "13", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot timeseries" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "14", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"facet = ds_timeseries[\"total_ozone_column\"].plot(\n", | ||
" col=\"region\", hue=\"version\", col_wrap=2\n", | ||
")\n", | ||
"for ax in facet.axs.flatten():\n", | ||
" ax.grid()\n", | ||
"facet.fig.autofmt_xdate(rotation=45)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "15", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot monthly" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "16", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"facet = plot.projected_map(\n", | ||
" ds_monthly[\"total_ozone_column\"],\n", | ||
" col=\"month\",\n", | ||
" col_wrap=3,\n", | ||
" projection=ccrs.Robinson(),\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "17", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plot annual" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "18", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"facet = plot.projected_map(\n", | ||
" ds_monthly[\"total_ozone_column\"],\n", | ||
" col=\"year\",\n", | ||
" col_wrap=6,\n", | ||
" projection=ccrs.SouthPolarStereo(central_longitude=0),\n", | ||
")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |