Skip to content

Commit

Permalink
change binder example location
Browse files Browse the repository at this point in the history
  • Loading branch information
shenyulu committed Mar 5, 2024
1 parent 096df48 commit 448b397
Show file tree
Hide file tree
Showing 11 changed files with 1,435 additions and 42 deletions.
23 changes: 12 additions & 11 deletions .binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ channels:
- conda-forge
dependencies:
- python=3.10
- numpy >= 1.24.3
- xarray >= 0.17.0,<=2023.12.0
- cartopy >= 0.20
- matplotlib
- pandas
- intel-fortran-rt
- scipy >=1.8.0
- statsmodels
- dask
- pip:
- easyclimate
- geocat.viz <= 2023.10.0
- numpy >= 1.24.3
- xarray >= 0.17.0,<=2023.12.0
- geocat.viz
- cartopy >= 0.20
- xeofs >= 2.2.2
- matplotlib
- pandas
- fast-barnes-py
- oceans
- intel-fortran-rt
- scipy >=1.8.0
- statsmodels
- geocat-comp
- pyspharm-syl
- windspharm-syl
- dask
- pymannkendall
- flox
- xarray-datatree
Expand All @@ -29,3 +29,4 @@ dependencies:
- tqdm
- zarr
- metpy
- easyclimate
3 changes: 3 additions & 0 deletions docs/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rm -r ".\source\auto_gallery_output\*"
rm ".\source\api_index\generated\*"
rm ".\source\sg_execution_times.rst"
2 changes: 2 additions & 0 deletions docs/copy_ipynb2example.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove-Item .\example\*.ipynb -Recurse
Copy-Item .\source\auto_gallery_output\*.ipynb -Destination .\example -Recurse
2 changes: 2 additions & 0 deletions docs/copy_ipynb2example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rm -r ./example/*.ipynb
cp -r ./source/auto_gallery_output/*.ipynb ./example
576 changes: 576 additions & 0 deletions docs/example/plot_basic_statistical_analysis.ipynb

Large diffs are not rendered by default.

259 changes: 259 additions & 0 deletions docs/example/plot_formatting_coordinates.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Formatting Coordinates\n\nBefore proceeding with all the steps, first import some necessary libraries and packages\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import easyclimate as ecl\nimport matplotlib.pyplot as plt\nimport matplotlib.ticker as ticker\nimport cartopy.crs as ccrs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The data we use here is monthly data from Jan 2022 to Feb 2022 and contains 17 vertical levels.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"u_data = ecl.tutorial.open_tutorial_dataset(\"uwnd_202201_mon_mean\").sortby(\"lat\").uwnd\nu_data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Formatting of the Latitude and Lontitude Tickes\n`draw_data1` is extracted from time level 0 and 500hPa vertical level.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"draw_data1 = u_data.isel(time=0).sel(level=500)\ndraw_data1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we call :py:func:`xarray.plot.pcolormesh <xarray.plot.pcolormesh>` to plot the latitudinal wind field on the 500hPa isobaric surface.\nNoting that the x-axis and y-axis are not in standard geographic coordinate format, our next step is to format these coordinates.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 1)\n\ndraw_data1.plot.pcolormesh(\n ax=ax,\n)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
":py:func:`easyclimate.plot.set_lon_format_axis <easyclimate.plot.set_lon_format_axis>`,\n:py:func:`easyclimate.plot.set_lat_format_axis <easyclimate.plot.set_lat_format_axis>` can help us quickly\nformat the coordinates on the x-axis and y-axis, respectively, into a geographic coordinate format.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 1)\n\ndraw_data1.plot.pcolormesh(\n ax=ax,\n)\n\necl.plot.set_lon_format_axis(ax, axis=\"x\")\necl.plot.set_lat_format_axis(ax, axis=\"y\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is worth mentioning that the :py:func:`easyclimate.plot.set_lon_format_axis <easyclimate.plot.set_lon_format_axis>`,\n:py:func:`easyclimate.plot.set_lat_format_axis <easyclimate.plot.set_lat_format_axis>` methods contain a parameter `dmi`\nwhich helps us to convert DD (Decimal Degrees) format to DMS (Degrees Minutes Seconds) format.\n\nNow let's start by selecting a smaller area\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"draw_data1_1 = (\n u_data.isel(time=0).sel(level=500).sel(lon=slice(100, 110), lat=slice(20, 23))\n)\ndraw_data1_1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note the difference in geo-labeling on the x-axis.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 2, figsize=(15, 5))\n\nfor axi in ax.flat:\n draw_data1_1.plot(ax=axi, cmap=\"Reds\")\n axi.xaxis.set_major_locator(ticker.LinearLocator(5))\n\necl.plot.set_lon_format_axis(ax[0], axis=\"x\")\necl.plot.set_lat_format_axis(ax[0], axis=\"y\")\nax[0].set_title(\"dms = False\")\n\necl.plot.set_lon_format_axis(ax[1], axis=\"x\", dms=True)\necl.plot.set_lat_format_axis(ax[1], axis=\"y\", dms=True)\nax[1].set_title(\"dms = True\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Barometric Profile Label Formatting\nHere we choose the longitudinally averaged latitudinal direction at time level 0 to plot the profile\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"draw_data2 = u_data.isel(time=0).mean(dim=\"lon\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice that the x-axis and y-axis labels are unformatted, so we'll take care of that next.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 1)\n\ndraw_data2.plot.contourf(ax=ax, levels=21, yincrease=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
":py:func:`easyclimate.plot.set_p_format_axis <easyclimate.plot.set_p_format_axis>` can help us format barometric vertical labels\nand similarly :py:func:`easyclimate.plot.set_lat_format_axis <easyclimate.plot.set_lat_format_axis>` can help us format latitude labels.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, 1)\n\ndraw_data2.plot.contourf(ax=ax, levels=21, yincrease=False)\n\necl.plot.set_lat_format_axis(ax, axis=\"x\")\necl.plot.set_p_format_axis(ax, axis=\"y\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Polar Stereo of the Circle Boundary\nFor the sake of illustration, we use here the sea ice concentration (SIC) data from the Barents-Kara Seas (30\u00b0\u221290\u00b0E, 65\u00b0\u221285\u00b0N).\nThe results of the data under the 10th time level are described below.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"sic_data = ecl.tutorial.open_tutorial_dataset(\"mini_HadISST_ice\").sic.isel(time=10)\nsic_data.plot.contourf(cmap=\"Blues\", levels=11)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
":py:func:`easyclimate.plot.draw_Circlemap_PolarStereo <easyclimate.plot.draw_Circlemap_PolarStereo>` helps us to easily\nestablish the boundary of the circle under the projection of the polar stereo.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig, ax = plt.subplots(subplot_kw={\"projection\": ccrs.NorthPolarStereo()})\n\nax.coastlines(edgecolor=\"black\", linewidths=0.5)\nax.stock_img()\n\necl.plot.draw_Circlemap_PolarStereo(\n ax=ax,\n lon_step=30,\n lat_step=10,\n lat_range=[50, 90],\n draw_labels=True,\n gridlines_kwargs={\"color\": \"grey\", \"alpha\": 0.5, \"linestyle\": \"--\"},\n)\n\nsic_data.plot.contourf(cmap=\"Blues\", levels=11, transform=ccrs.PlateCarree())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Adjusting `north_pad` and `south_pad` appropriately can help us compensate for not completing the circle boundaries.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig, ax = plt.subplots(subplot_kw={\"projection\": ccrs.NorthPolarStereo()})\n\nax.coastlines(edgecolor=\"black\", linewidths=0.5)\nax.stock_img()\n\necl.plot.draw_Circlemap_PolarStereo(\n ax=ax,\n lon_step=30,\n lat_step=10,\n lat_range=[50, 90],\n draw_labels=True,\n set_map_boundary_kwargs={\"north_pad\": 0.3, \"south_pad\": 0.4},\n gridlines_kwargs={\"color\": \"grey\", \"alpha\": 0.5, \"linestyle\": \"--\"},\n)\n\nsic_data.plot(cmap=\"Blues\", levels=11, transform=ccrs.PlateCarree())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.10.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading

0 comments on commit 448b397

Please sign in to comment.