Skip to content

Commit

Permalink
fix ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Jan 3, 2024
1 parent cdf3520 commit 508b878
Showing 1 changed file with 79 additions and 11 deletions.
90 changes: 79 additions & 11 deletions notebooks/wp5/urban_heat_islands.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"outputs": [],
"source": [
"import matplotlib.colors as mcolors\n",
"import matplotlib.dates as mdates\n",
"import matplotlib.pyplot as plt\n",
"import xarray as xr\n",
"from c3s_eqc_automatic_quality_control import diagnostics, download, plot, utils\n",
Expand Down Expand Up @@ -282,22 +283,33 @@
" ax2.tick_params(axis=\"y\", labelcolor=color)\n",
" ax2.grid()\n",
"\n",
" ax2.xaxis.set_major_formatter(mdates.DateFormatter(\"%Y-%b\"))\n",
" fig.autofmt_xdate(rotation=45)\n",
" return fig, (ax1, ax2)\n",
"\n",
"\n",
"def plot_maps(da, **kwargs):\n",
"def plot_maps(da, lon_slice=None, lat_slice=None, area=area, **kwargs):\n",
" if lon_slice is None:\n",
" lon_slice = slice(*sorted([area[1], area[3]]))\n",
" if lat_slice is None:\n",
" lat_slice = slice(*sorted([area[0], area[2]]))\n",
"\n",
" kwargs.setdefault(\"row\", \"satellite\" if \"satellite\" in da.dims else None)\n",
" kwargs.setdefault(\"col\", \"season\" if \"season\" in da.dims else None)\n",
" da[\"longitude\"] = da[\"longitude\"].astype(\"float32\")\n",
" da[\"latitude\"] = da[\"latitude\"].astype(\"float32\")\n",
" da = utils.regionalise(da, lon_slice=lon_slice, lat_slice=lat_slice)\n",
"\n",
" if da.name == \"t2m\":\n",
" with xr.set_options(keep_attrs=True):\n",
" da = da - 273.15\n",
" da.attrs[\"units\"] = \"°C\"\n",
"\n",
" facet = plot.projected_map(da, **kwargs)\n",
"\n",
" da = utils.regionalise(da, lon_slice=lon_slice, lat_slice=lat_slice)\n",
" facet = plot.projected_map(da, **kwargs)\n",
" for ax in facet.axs.flatten():\n",
" ax.set_extent(\n",
" [lon_slice.start, lon_slice.stop, lat_slice.start, lat_slice.stop]\n",
" )\n",
" return facet"
]
},
Expand All @@ -306,7 +318,7 @@
"id": "7024d5d6",
"metadata": {},
"source": [
"## Plot maps"
"## Plot albedo"
]
},
{
Expand All @@ -321,8 +333,36 @@
" [\"blue\", \"skyblue\", \"cyan\", \"lightgreen\", \"yellow\", \"orange\", \"red\", \"maroon\"],\n",
")\n",
"facet_albedo = plot_maps(ds_albedo_maps[\"AL_BH_BB\"], cmap=custom_cmap_s)\n",
"plt.show()\n",
"facet_temperature = plot_maps(ds_temperature_maps[\"t2m\"], cmap=\"YlOrRd\")"
"facet_albedo_zoom = plot_maps(\n",
" ds_albedo_maps[\"AL_BH_BB\"],\n",
" lon_slice=lon_slice,\n",
" lat_slice=lat_slice,\n",
" cmap=custom_cmap_s,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "cd360c86-f820-4895-b533-2b107973ebc5",
"metadata": {},
"source": [
"## Plot temperature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "88f67d98-d137-40ad-9cf1-5ac8c3475844",
"metadata": {},
"outputs": [],
"source": [
"facet_albedo = plot_maps(ds_temperature_maps[\"t2m\"], cmap=\"YlOrRd\")\n",
"facet_albedo_zoom = plot_maps(\n",
" ds_temperature_maps[\"t2m\"],\n",
" lon_slice=lon_slice,\n",
" lat_slice=lat_slice,\n",
" cmap=\"YlOrRd\",\n",
")"
]
},
{
Expand Down Expand Up @@ -356,19 +396,47 @@
"id": "40611e98",
"metadata": {},
"source": [
"## Plot seasonal maps"
"## Plot seasonal albedo"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a0215421-5d91-43ec-a669-0285be1ad8db",
"id": "4506582e-4c11-4a0a-8338-c074817a9c0d",
"metadata": {},
"outputs": [],
"source": [
"facet_albedo = plot_maps(ds_albedo_season_maps[\"AL_BH_BB\"], cmap=custom_cmap_s)\n",
"plt.show()\n",
"facet_temperature = plot_maps(ds_temperature_season_maps[\"t2m\"], cmap=\"YlOrRd\")"
"facet_albedo_zoom = plot_maps(\n",
" ds_albedo_season_maps[\"AL_BH_BB\"],\n",
" lon_slice=lon_slice,\n",
" lat_slice=lat_slice,\n",
" cmap=custom_cmap_s,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "20246941-2cd1-4b95-86c8-67715f8b1174",
"metadata": {},
"source": [
"## Plot seasonal temperature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c261066a-f6bf-434c-a676-dd448a567bf8",
"metadata": {},
"outputs": [],
"source": [
"facet_albedo = plot_maps(ds_temperature_season_maps[\"t2m\"], cmap=\"YlOrRd\")\n",
"facet_albedo_zoom = plot_maps(\n",
" ds_temperature_season_maps[\"t2m\"],\n",
" lon_slice=lon_slice,\n",
" lat_slice=lat_slice,\n",
" cmap=\"YlOrRd\",\n",
")"
]
}
],
Expand Down

0 comments on commit 508b878

Please sign in to comment.