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/26af8a1f3a4bb642517abe0417f4a49c147c3c1e05d2477b121390be6fac413d.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/af36c38ec6f166afb94b6765d5da780ee437142a5484d9b6ada931de4d87b21c.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/b76886032e3d60535940099e6b547d6f52f58a20de3ab5b5927938e93b76a4ef.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/067a1b9d6ee6ea3b7c5000ed3faf3d0564cc1d056cfe5328b484234c4fd197ce.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/d57e74447d8fb42d58b8c8db43bd051a5a005e46964357882be8a369ec0bd392.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/3d3c742564ce308ced60889fc780418636c0b4ebfaec73684299fb708c0b1958.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/0492b6fa938bc68e1908eb543576cd85fabee2612fc8e5abeb5fa5b92921d1e8.png

Python Resources#