Climatology#

Overview#

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

Functions#

calcDayAnom*#

calcDayAnomTLL calculates daily anomalies from a daily data climatology.

Grab and Go#

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

ds = xr.open_dataset(gcd.get("applications_files/inputs/CMIP6_sea_ice_daily_subset.nc"))

DayTLL = ds.aice_d.groupby("time.dayofyear")
clmDayTLL = DayTLL.mean("time")
calcDayAnomTLL = DayTLL - clmDayTLL

calcDayAnomTLL[0, :, :].assign_attrs(long_name="sea ice anomaly").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/471d9490fdc8ecca8d8d3532b5cd036e18fc8439ac5209e928c5c8ac66a8ffe0.png
from geocat.comp import climate_anomaly
import geocat.datafiles as gcd

ds = xr.open_dataset(gcd.get("applications_files/inputs/CMIP6_sea_ice_daily_subset.nc"))

calcDayAnomTLL = climate_anomaly(ds.aice_d, "day")

calcMonAnom*#

calcMonAnomTLL, calcMonAnomTLLL, calcMonAnomLLT, and calcMonAnomLLLT calculate monthly anomalies by subtracting the long-term mean from each point.

Grab and Go#

import xarray as xr
import geocat.datafiles as gcd

ds = xr.open_dataset(
    gcd.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)

MonTLL = ds.aice.groupby("time.month")
clmMonTLL = MonTLL.mean("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/c2bedecc37915ca23d7e99d21cb017d87f47dfbc499d008ae5100a75220bdbe2.png
from geocat.comp import climate_anomaly
import geocat.datafiles as gcd

ds = xr.open_dataset(
    gcd.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)

calcMonAnomTLL = climate_anomaly(ds.aice, "month")

clmDay*#

clmDayTLL and clmDayTLLL calculate long-term daily means (daily climatology) from daily data.

Grab and Go#

import xarray as xr
import geocat.datafiles as gcd

ds = xr.open_dataset(gcd.get("applications_files/inputs/CMIP6_sea_ice_daily_subset.nc"))

clmDayTLL = ds.aice_d.groupby("time.dayofyear").mean("time")

clmDayTLL[:, 10, 10].plot()
plt.title("daily climatology")
plt.xlabel("day of year")
plt.ylabel("sea ice area");
../../_images/772b6a6a149e5d89be8908edd5aa2679f3963f7222eca2e58c28162a102df498.png
from geocat.comp import climatology_average
import geocat.datafiles as gcd

ds = xr.open_dataset(gcd.get("applications_files/inputs/CMIP6_sea_ice_daily_subset.nc"))

clmDayTLL = climatology_average(ds.aice_d, "day")

clmMon*#

clmMonTLL, clmMonTLLL, clmMonLLT, and clmMonLLLT calculate long-term monthly means (monthly climatology) from monthly data.

Grab and Go#

import xarray as xr
import geocat.datafiles as gcd

ds = xr.open_dataset(
    gcd.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)

clmMonTLL = ds.aice.groupby("time.month").mean("time")

clmMonTLL[:, 10, 10].plot()
plt.title("monthly climatology")
plt.xlabel("month of year")
plt.ylabel("sea ice area");
../../_images/41163c249108dae4d49621c7218a91ce4ccdd37efca7ac074bd6e77da07128fa.png
from geocat.comp import climatology_average
import geocat.datafiles as gcd

ds = xr.open_dataset(
    gcd.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)

clmMonTLL = climatology_average(ds.aice, "month")

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 directly with Xarray as shown here in the Xarray documentation. However, it requires more code.

Grab and Go#

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

ds = xr.open_dataset(
    gcd.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)

mon_to_season = month_to_season(ds.aice, "ASO").assign_attrs(long_name="sea ice area")

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

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

rmMonAnnCyc*#

rmMonAnnCycTLL, rmMonAnnCycLLT, and rmMonAnnCycLLLT remove the annual cycle from monthly data.

Grab and Go#

import xarray as xr
import geocat.datafiles as gcd

ds = xr.open_dataset(
    gcd.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)

MonTLL = ds.aice.groupby("time.month")
clmMonTLL = MonTLL.mean("time")
rmMonAnnCycTLL = MonTLL - clmMonTLL

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

stdMon*#

stdMonTLL, stdMonTLLL, stdMonLLT, and stdMonLLLT calculate standard deviations of monthly means.

Grab and Go#

import xarray as xr
import geocat.datafiles as gcd

ds = xr.open_dataset(
    gcd.get("applications_files/inputs/CMIP6_sea_ice_monthly_subset.nc")
)

stdMonTLL = ds.aice.groupby("time.month").std(ddof=1)

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

Python Resources#