Climatology#

Overview#

The NCL climatology functions listed below can be replicated using xarray and/or geocat.comp

calcDayAnomTLL#

calcDayAnomTLL calculates daily anomalies from a daily data climatology

Grab and Go#

import xarray as xr
import geocat.datafiles as gdf
from matplotlib import pyplot as plt

ds = xr.open_dataset(gdf.get("applications_files/inputs/CMIP6_sea_ice_daily_subset.nc"))
aice = ds.aice_d
DayTLL = aice.groupby(aice.time.dt.dayofyear)
clmDayTLL = DayTLL.mean(dim="time")
calcDayAnomTLL = DayTLL - clmDayTLL

calcDayAnomTLL = calcDayAnomTLL.assign_attrs(long_name="sea ice anomaly")

calcDayAnomTLL[0, :, :].plot();
Downloading file 'applications_files/inputs/CMIP6_sea_ice_daily_subset.nc' from 'https://github.com/NCAR/GeoCAT-datafiles/raw/main/applications_files/inputs/CMIP6_sea_ice_daily_subset.nc' to '/home/runner/.cache/geocat'.
../../_images/c19e8d888a3c759ef7907a6effa44387b309272c7d073663132f55a41ddc6aa3.png

calcMonAnomTLL#

calcMonAnomTLL calculates monthly anomalies by subtracting the long-term mean from each point

Grab and Go#

import xarray as xr
import geocat.datafiles as gdf

ds = xr.open_dataset(
    gdf.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)
aice = ds.aice
MonTLL = aice.groupby(aice.time.dt.month)
clmMonTLL = MonTLL.mean(dim="time")
calcMonAnomTLL = MonTLL - clmMonTLL

calcMonAnomTLL = calcMonAnomTLL.assign_attrs(long_name="sea ice anomaly")

calcMonAnomTLL[0, :, :].plot();
Downloading file 'applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc' from 'https://github.com/NCAR/GeoCAT-datafiles/raw/main/applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc' to '/home/runner/.cache/geocat'.
../../_images/63dfc16a22cbcc2fd2b23b5eff5fc19df11d6321bf6097c0487c068fb4b638de.png

clmDayTLL#

clmDayTLL calculates long-term daily means (daily climatology) from daily data

Grab and Go#

import xarray as xr
import geocat.datafiles as gdf

ds = xr.open_dataset(gdf.get("applications_files/inputs/CMIP6_sea_ice_daily_subset.nc"))
aice = ds.aice_d
DayTLL = aice.groupby(aice.time.dt.dayofyear)
clmDayTLL = DayTLL.mean(dim="time")

clmDayTLL[:, 10, 10].plot()
plt.title("daily climatology")
plt.xlabel("day of year")
plt.ylabel("sea ice area");
../../_images/f9f448bbe729b99319fa1bb916d1c5ac3d84e141dfd0cf0ccc804c103f626afb.png

clmMonTLL#

clmMonTLL calculates long-term monthly means (monthly climatology) from monthly data

Grab and Go#

import xarray as xr
import geocat.datafiles as gdf

ds = xr.open_dataset(
    gdf.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)
aice = ds.aice
MonTLL = aice.groupby(aice.time.dt.month)
clmMonTLL = MonTLL.mean(dim="time")

clmMonTLL[:, 10, 10].plot()
plt.title("monthly climatology")
plt.xlabel("month of year")
plt.ylabel("sea ice area");
../../_images/33e4815f7d753796c88653c47a626bcf3a9faaea7b02b370a7eac4e56ce9733d.png

month_to_season#

month_to_season computes a user-specified three-month seasonal mean (DJF, JFM, FMA, MAM, AMJ, MJJ, JJA, JAS, ASO, SON, OND, NDJ)

Note

You can do something similar with directly with Xarray as shown in this example in the Xarray documentation. However, it requires substantially more code and doesn’t have as much flexibility with respect to how the seasons are defined.

Grab and Go#

import xarray as xr
import geocat.datafiles as gdf
from geocat.comp import month_to_season

ds = xr.open_dataset(
    gdf.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)
aice = ds.aice
mon_to_season = month_to_season(aice, "ASO")

mon_to_season = mon_to_season.assign_attrs(long_name="sea ice area")

mon_to_season[0, :, :].plot()

plt.title("2010 seasonal mean");
../../_images/72a50b2308445361e1cd3e6e17155ecbf3889db3909bbdb4914163168d6ea5e0.png

rmMonAnnCycTLL#

rmMonAnnCycTLL removes the annual cycle from monthly data

Grab and Go#

import xarray as xr
import geocat.datafiles as gdf

ds = xr.open_dataset(
    gdf.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)
aice = ds.aice
MonTLL = aice.groupby(aice.time.dt.month)
clmMonTLL = MonTLL.mean(dim="time")
rmMonAnnCycTLL = MonTLL - clmMonTLL

rmMonAnnCycTLL[:, 10, 10].plot()
plt.title("annual cycle removed")
plt.ylabel("sea ice area");
../../_images/43dbf9f6cd571c978954d1ff2424ed99c2fb93f0873c7dcc13783bd38c4d716a.png

stdMonTLL#

stdMonTLL calculates standard deviations of monthly means

Grab and Go#

import xarray as xr
import geocat.datafiles as gdf

ds = xr.open_dataset(
    gdf.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)
aice = ds.aice
MonTLL = aice.groupby(aice.time.dt.month)
stdMonTLL = MonTLL.std(ddof=1)

stdMonTLL[0, :, :].plot();
../../_images/a51ca3905d9bf6acf75b6a2b85f2e203958e1b90c1d76999b6e00b79e5836c05.png

Python Resources#