Advanced functionality

This page lists functionality that is currently in ClimateBase.jl but will be ported over to ClimateTools.jl once ClimateTools.jl has been properly updated to latest ClimateBase.jl.

Vertical Interpolation

We offer 3 functions for vertical interpolation. Extrapolation results in missing values by default, but can also be linear (extrapolation_bc = Line()). Check the Interpolations.jl package for more information: https://juliamath.github.io/Interpolations.jl/latest/ For additional extrapolation boundary conditions: https://juliamath.github.io/Interpolations.jl/latest/extrapolation/

using ClimateBase
D = ClimArray([1.0:11.0 2.0:12.0 3.0:2.0:23.0], (Hei(0.0:2000.0:20000.0), Ti(1:3)))
pressure_levels = [950, 850, 650, 350, 250, 150] .* 100.0
D_pre = interpolate_height2pressure(D, pressure_levels)
D_back = interpolate_pressure2height(D_pre, Vector(dims(D,Hei).val),extrapolation_bc=Line())
ClimArray with dimensions: 
  Ti Sampled{Int64} 1:3 ForwardOrdered Regular Points,
  Hei Sampled{Float64} Float64[0.0, 2000.0, …, 18000.0, 20000.0] ForwardOrdered Irregular Points
and data: 3×11 Matrix{Float64}
 1.0198   2.0185   3.01562  4.01133   5.00703  …   9.02901  10.0325  11.0359
 2.0198   3.0185   4.01562  5.01133   6.00703     10.029    11.0325  12.0359
 3.03961  5.03701  7.03124  9.02265  11.0141      19.058    21.0649  23.0718
ClimateBase.interpolation2pressureFunction
interpolation2pressure(A::ClimArray, P::ClimArray, plevels::Vector; kwargs...) → B

Interpolate A, which has some arbitrary height dimension (height, model levels, etc.), into a new B::ClimArray where the vertical dimension is pressure. P is another ClimArray, that has the pressure values in Pascal, and otherwise same spatiotemporal structure as A. The plevels variable denotes which pressure levels B should have.

The keword vertical_dim = Hei() denotes which dimension of A denotes "height". The keyword extrapolation_bc = Line() configures extrapolation. It is linear by default, but can be any value such as extrapolation_bc = NaN. For other extrapolation methods use the Interpolations.jl package.

Keyword descending = true specifies whether pressure is ordered descendingly or ascendingly along the vertical dimension.

source
ClimateBase.interpolate_height2pressureFunction
interpolate_height2pressure(A::ClimArray, pressure_levels::Vector; extrapolation_bc=NaN )

Return a ClimArray where the vertical coordinate is pressure. Pressure levels are calculated with the height2pressure function, based on hydrostatic equilibrium, and then interpolated to the given levels.

A: ClimArray with height above ground [m] as height coordinate. pressure_levels: Vector which contains the pressure levels in Pascal that A should be interpolated on. extrapolation_bc: Extrapolation is set to NaN by default, but can be any value or linear extrapolation with extrapolation_bc = Line(). For other extrapolation methods use the Interpolations package.

source
ClimateBase.interpolate_pressure2heightFunction
interpolate_pressure2height(A::ClimArray,heights::Vector; extrapolation_bc=NaN)

Return a ClimArray where the vertical coordinate is height above ground. Height above ground is calculated with the pressure2height function, based on hydrostatic equilibrium, and then interpolated to the given heights.

A: ClimArray with pressure [Pa] as height coordinate. heights: Vector which contains the heights that A should be interpolated on in meters above ground. extrapolation_bc: Extrapolation is set to NaN by default, but can be any value or linear extrapolation with extrapolation_bc = Line(). For other extrapolation methods use the Interpolations package.

source

Quantile/value space

ClimateBase.quantile_spaceFunction
quantile_space(A, B; n = 50) → Aq, Bq, q

Express the array B into the quantile space of A. B, A must have the same indices.

The array B is binned according to the quantile values of the elements of A. n bins are created in total and the bin edges p are returned. The i-th bin contains data whose A-quantile values are ∈ [q[i], q[i+1]). The indices of these A values are used to group B.

In each bin, the binned values of A, B are averaged, resulting in Aq, Bq.

The amount of datapoints per quantile is by definition length(A)/n.

source
ClimateBase.value_spaceFunction
value_space(A, B; Arange) → Bmeans, bin_indices

Express the array B into the value space of A. B, A must have the same indices. This means that A is binned according to the given Arange, and the same indices that binned A are also used to bin B. The i-th bin contains data whose A values ∈ [Arange[i], Arange[i+1]). In each bin, the binned values of B are averaged, resulting in Bmeans.

Elements of A that are not ∈ Arange are skipped. The returned bin_indices are the indices in each bin (hence, the weights for the means are just length.(bin_indices))

By default Arange = range(minimum(A), nextfloat(maximum(A)); length = 100).

source
value_space(A, B, C; Arange, Brange) → Cmeans, bin_indices

Express the array C into the joint value space of A, B. A, B, C must have the same indices.

A 2D histogram is created based on the given ranges, the and elements of C are binned according to the values of A, B. Then, the elements are averaged, which returns a matrix Cmeans, defined over the joint space S = Arange × Brange. bin_indices is also a matrix (with vector elements). Cmeans is NaN for bins without any elements.

source

Climate quantities

Functions that calculate climate-related quantities.

ClimateBase.insolationFunction
insolation(t, ϕ; kwargs...)

Calculate daily averaged insolation in W/m² at given time and latitude t, φ. φ is given in degrees, and t in days (real number or date).

Keywords:

Ya = DAYS_IN_ORBIT # = 365.26 # days
t_VE = 76.0 # days of vernal equinox
S_0 = 1362.0 # W/m^2
γ=23.44
ϖ=282.95
e=0.017 # eccentricity
source

Timeseries Analysis

ClimateBase.sinusoidal_continuationFunction
sinusoidal_continuation(T::ClimArray, fs = [1, 2]; Tmin = -Inf, Tmax = Inf)

Fill-in the missing values of spatiotemporal field T, by fitting sinusoidals to the non-missing values, and then using the fitted sinusoidals for the missing values.

Frequencies are given per year (frequency 2 means 1/2 of a year).

Tmin, Tmax limits are used to clamp the result into this range (no clamping in the default case).

source
ClimateBase.seasonal_decompositionFunction
seasonal_decomposition(A::ClimArray, fs = [1, 2]) → seasonal, residual

Decompose A into a seasonal and residual components, where the seasonal contains the periodic parts of A, with frequencies given in fs, and residual contains what's left.

fs is measured in 1/year. This function works even for non-equispaced time axis (e.g. monthly averages) and uses LPVSpectral.jl and SignalDecomposition.jl.

source