Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Climatology #140

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 161 additions & 14 deletions ncl/ncl_entries/climatology_functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
"\n",
"- [calcDayAnomTLL](https://www.ncl.ucar.edu/Document/Functions/Contributed/calcDayAnomTLL.shtml)\n",
"- [calcMonAnomTLL](https://www.ncl.ucar.edu/Document/Functions/Contributed/calcMonAnomTLL.shtml)\n",
"- [clmDayHourTll](https://www.ncl.ucar.edu/Document/Functions/Contributed/clmDayHourTLL.shtml)\n",
"- [clmDayTLL](https://www.ncl.ucar.edu/Document/Functions/Contributed/clmDayTLL.shtml)\n",
"- [clmMon2clmDay](https://www.ncl.ucar.edu/Document/Functions/Contributed/clmMon2clmDay.shtml)\n",
"- [clmMonTLL](https://www.ncl.ucar.edu/Document/Functions/Contributed/clmMonTLL.shtml)\n",
"- [month_to_season](https://www.ncl.ucar.edu/Document/Functions/Contributed/month_to_season.shtml)\n",
"- [month_to_season12](https://www.ncl.ucar.edu/Document/Functions/Contributed/month_to_season12.shtml)\n",
"- [month_to_seasonN](https://www.ncl.ucar.edu/Document/Functions/Contributed/month_to_seasonN.shtml)\n",
"- [rmMonAnnCycTLL](https://www.ncl.ucar.edu/Document/Functions/Contributed/rmMonAnnCycTLL.shtml)\n",
"- [smthClmDayTll](https://www.ncl.ucar.edu/Document/Functions/Contributed/smthClmDayTLL.shtml)\n",
"- [stdMonTLL](https://www.ncl.ucar.edu/Document/Functions/Contributed/stdMonTLL.shtml)\n"
]
},
Expand All @@ -28,7 +33,7 @@
"metadata": {},
"source": [
"## calcDayAnomTLL\n",
"`calcDayAnomTLL` calculates daily anomalies from a daily data climatology"
"`calcDayAnomTLL` calculates daily anomalies from a daily data climatology."
]
},
{
Expand Down Expand Up @@ -64,7 +69,7 @@
"metadata": {},
"source": [
"## calcMonAnomTLL\n",
"`calcMonAnomTLL` calculates monthly anomalies by subtracting the long-term mean from each point"
"`calcMonAnomTLL` calculates monthly anomalies by subtracting the long-term mean from each point."
]
},
{
Expand Down Expand Up @@ -96,12 +101,34 @@
"calcMonAnomTLL[0, :, :].plot();"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## clmDayHourTll\n",
"`clmDayHourTll` calculates climatological day-hour means at user specified hours for each day of the year."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Grab and Go"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## clmDayTLL\n",
"`clmDayTLL` calculates long-term daily means (daily climatology) from daily data"
"`clmDayTLL` calculates long-term daily means (daily climatology) from daily data."
]
},
{
Expand Down Expand Up @@ -131,12 +158,34 @@
"plt.ylabel(\"sea ice area\");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## clmMon2clmDay\n",
"`clmMon2clmDay` creates a daily climatology from a monthly climatology.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Grab and Go"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## clmMonTLL\n",
"`clmMonTLL` calculates long-term monthly means (monthly climatology) from monthly data"
"`clmMonTLL` calculates long-term monthly means (monthly climatology) from monthly data."
]
},
{
Expand Down Expand Up @@ -173,7 +222,7 @@
"metadata": {},
"source": [
"## month_to_season\n",
"`month_to_season` computes a user-specified three-month seasonal mean (DJF, JFM, FMA, MAM, AMJ, MJJ, JJA, JAS, ASO, SON, OND, NDJ)\n",
"`month_to_season` computes a user-specified three-month seasonal mean (DJF, JFM, FMA, MAM, AMJ, MJJ, JJA, JAS, ASO, SON, OND, NDJ).\n",
"\n",
"```{note}\n",
"You can do something similar with directly with Xarray as shown in [this example in the Xarray documentation](https://docs.xarray.dev/en/stable/examples/monthly-means.html#Calculating-Seasonal-Averages-from-Time-Series-of-Monthly-Means). However, it requires substantially more code and doesn't have as much flexibility with respect to how the seasons are defined.\n",
Expand Down Expand Up @@ -210,12 +259,92 @@
"plt.title(\"2010 seasonal mean\");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## month_to_season12\n",
"\n",
"`month_to_season12` computes three-month seasonal means (DJF, JFM, FMA, MAM, AMJ, MJJ, JJA, JAS, ASO, SON, OND, NDJ)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Grab and Go"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"import geocat.datafiles as gdf\n",
"from geocat.comp import month_to_season\n",
"\n",
"ds = xr.open_dataset(\n",
" gdf.get(\"applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc\")\n",
")\n",
"aice = ds.aice\n",
"\n",
"month_to_season12 = {}\n",
"for month in [\"DJF\", \"JFM\", \"FMA\", \"MAM\", \"AMJ\", \"MJJ\", \"JJA\", \"JAS\", \"ASO\", \"SON\", \"OND\", \"NDJ\"]:\n",
" mon_to_season = month_to_season(aice, month)\n",
" mon_to_season = mon_to_season.assign_attrs(long_name=\"sea ice area\")\n",
" month_to_season12[month] = mon_to_season\n",
"\n",
"month_to_season12"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## month_to_seasonN\n",
"\n",
"`month_to_seasonN` computes a user-specified list of three-month seasonal means (DJF, JFM, FMA, MAM, AMJ, MJJ, JJA, JAS, ASO, SON, OND, NDJ). "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Grab and Go"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"import geocat.datafiles as gdf\n",
"from geocat.comp import month_to_season\n",
"\n",
"ds = xr.open_dataset(\n",
" gdf.get(\"applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc\")\n",
")\n",
"aice = ds.aice\n",
"\n",
"month_to_season12 = {}\n",
"for month in [\"DJF\", \"MAM\", \"JJA\", \"SON\"]:\n",
" mon_to_season = month_to_season(aice, month)\n",
" mon_to_season = mon_to_season.assign_attrs(long_name=\"sea ice area\")\n",
" month_to_season12[month] = mon_to_season\n",
"\n",
"month_to_season12"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## rmMonAnnCycTLL\n",
"`rmMonAnnCycTLL` removes the annual cycle from monthly data"
"`rmMonAnnCycTLL` removes the annual cycle from monthly data."
]
},
{
Expand Down Expand Up @@ -247,12 +376,35 @@
"plt.ylabel(\"sea ice area\");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## smthClmDayTll\n",
"\n",
"`smthClmDayTll` calculates a smooth mean daily annual cycle for an array.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Grab and Go"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## stdMonTLL\n",
"`stdMonTLL` calculates standard deviations of monthly means"
"`stdMonTLL` calculates standard deviations of monthly means."
]
},
{
Expand Down Expand Up @@ -299,16 +451,11 @@
"- Project Pythia Foundations [Computations and Masks with Xarray tutorial](https://foundations.projectpythia.org/core/xarray/computation-masking.html)\n",
"- Xarray User Guide [section on time series data](https://docs.xarray.dev/en/stable/user-guide/time-series.html)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "geocat-applications",
"language": "python",
"name": "python3"
},
Expand All @@ -322,7 +469,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.12.5"
}
},
"nbformat": 4,
Expand Down
2 changes: 2 additions & 0 deletions ncl/ncl_index/ncl-index-table.csv
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ NCL Function,Description,Python Equivalent,Notes
`clmDayTLL <https://www.ncl.ucar.edu/Document/Functions/Contributed/clmDayTLL.shtml>`__,"Calculates long-term daily means (daily climatology) from daily data","``xarray.DataArray.groupby()``",`example notebook <../ncl_entries/climatology_functions.ipynb#clmdaytll>`__
`clmMonTLL <https://www.ncl.ucar.edu/Document/Functions/Contributed/clmMonTLL.shtml>`__,"Calculates long-term monthly means (monthly climatology) from monthly data","``xarray.DataArray.groupby()``",`example notebook <../ncl_entries/climatology_functions.ipynb#clmmontll>`__
`month_to_season <https://www.ncl.ucar.edu/Document/Functions/Contributed/month_to_season.shtml>`__,"Computes a user-specified three-month seasonal mean","``geocat.comp.month_to_season()``",`example notebook <../ncl_entries/climatology_functions.ipynb#month-to-season>`__
`month_to_season12 <https://www.ncl.ucar.edu/Document/Functions/Contributed/month_to_season12.shtml>`__,"Computes three-month seasonal means (DJF, JFM, FMA, MAM, AMJ, MJJ, JJA, JAS, ASO, SON, OND, NDJ).","``geocat.comp.month_to_season()``",`example notebook <../ncl_entries/climatology_functions.ipynb#month-to-season>`__
`month_to_seasonN <https://www.ncl.ucar.edu/Document/Functions/Contributed/month_to_seasonN.shtml>`__,"Computes a user-specified list of three-month seasonal means (DJF, JFM, FMA, MAM, AMJ, MJJ, JJA, JAS, ASO, SON, OND, NDJ).","``geocat.comp.month_to_season()``",`example notebook <../ncl_entries/climatology_functions.ipynb#month-to-season>`__
`rmMonAnnCycTLL <https://www.ncl.ucar.edu/Document/Functions/Contributed/rmMonAnnCycTLL.shtml>`__,"Removes the annual cycle from monthly data","``xarray.DataArray.groupby()``",`example notebook <../ncl_entries/climatology_functions.ipynb#rmmonanncyctll>`__
`stdMonTLL <https://www.ncl.ucar.edu/Document/Functions/Contributed/stdMonTLL.shtml>`__,"Calculates standard deviations of monthly means","``xarray.DataArray.groupby()``",`example notebook <../ncl_entries/climatology_functions.ipynb#stdmontll>`__
`abs <https://www.ncl.ucar.edu/Document/Functions/Built-in/abs.shtml>`__,"Returns the absolute value of numeric data","``abs()`` or ``numpy.abs()``",`example notebook <../ncl_entries/general_applied_math.ipynb#abs-fabs>`__
Expand Down