ClimaAnalysis.SimDirType
SimDir(simulation_path::String)

Object that describes all the ClimaAtmos output found in the given simulation_path.

Base.getMethod
get(simdir::SimDir, short_name)

If only one reduction and period exist for short_name, return the corresponding OutputVar.

Base.getMethod
get(simdir::SimDir;
    short_name,
    reduction = nothing,
    period = nothing)

Return a OutputVar for the corresponding combination of short_name, reduction, and period (if it exists).

The variable is read only once and saved into the simdir.

Keyword arguments

When passing nothing to reduction and period, ClimaAnalysis will try to automatically deduce the value. An error will be thrown if this is not possible.

For instance, if the simulation has only one ta, you do not need to specify short_name, reduction, and period (short_name is enough). Similarly, if there is only one ta_average (ie, not multiple periods), short_name and reduction will be enough.

Base.isemptyMethod
isempty(simdir::SimDir)

Check if the given SimDir contains OutputVars.

ClimaAnalysis._reduce_overMethod
_reduce_over(reduction::F, dim::String, var::OutputVar)

Apply the given reduction over the given dimension.

reduction has to support the dims key. Additional arguments are passed to reduction.

The return type is an OutputVar with the same attributes, the new data, and the dimension dropped.

Example

Average over latitudes

import Statistics: mean
long = 0.:180. |> collect
lat = 0.:90. |> collect
data = reshape(1.:91*181., (181, 91))
dims = Dict(["lat" => lat, "long" => long])
var = OutputVar(dims, data)
_reduce_over(mean, "lat", var)
ClimaAnalysis._slice_generalMethod
_slice_general(var::OutputVar, val, dim_name)

Return a new OutputVar by selecting the available index closest to the given val for the given dimension

ClimaAnalysis.arecompatibleMethod
arecompatible(x::OutputVar, y::OutputVar)

Return whether two OutputVar are defined on the same physical space

This is accomplished by comparing dims and dim_attributes (the latter because they might contain information about the units).

We assume that:

  • dim2index and index2dim where correctly created and they reflect dims
  • data is also consistent with dims,

We also do not check units for data.

ClimaAnalysis.available_periodsMethod
available_periods(simdir::SimDir, short_name::String, reduction::String)

Return the periods associated to the given variable and reduction.

ClimaAnalysis.available_reductionsMethod
available_reductions(simdir::SimDir, short_name::String)

Return the reductions available for the given variable in the given simdir.

ClimaAnalysis.average_latMethod
average_lat(var::OutputVar)

Return a new OutputVar where the values on the latitudes are averaged arithmetically.

ClimaAnalysis.average_lonMethod
average_lon(var::OutputVar)

Return a new OutputVar where the values on the longitudes are averaged arithmetically.

ClimaAnalysis.average_timeMethod
average_time(var::OutputVar)

Return a new OutputVar where the values are averaged arithmetically in time.

ClimaAnalysis.average_xMethod
average_x(var::OutputVar)

Return a new OutputVar where the values along the x dimension are averaged arithmetically.

ClimaAnalysis.average_xyMethod
average_xy(var::OutputVar)

Return a new OutputVar where the values along both horizontal dimensions x and y are averaged arithmetically.

ClimaAnalysis.average_yMethod
average_y(var::OutputVar)

Return a new OutputVar where the values along the y dimension are averaged arithmetically.

ClimaAnalysis.center_longitude!Method
center_longitude!(var::OutputVar, lon::Real)

Shift the longitudes in var so that lon is the center one.

This is useful to center the global projection to the 180 meridian instead of the 0.

ClimaAnalysis.is_z_1DMethod
is_z_1D(var::OutputVar)

Return whether the given variable has an altitude dimension that is 1D.

When topography is present, the altitude dimension in the output variable is typically multidimensional. The dimensions are (X, Y, Z), where (X, Y) are the horizontal dimensions. In this case, dims["z"] is essentially a map that identifies the physical altitude of the given point.

ClimaAnalysis.long_nameMethod
long_name(var::OutputVar)

Return the long_name of the given var, if available.

If not available, return an empty string.

ClimaAnalysis.read_varMethod
read_var(path::String)

Read a variable in the given NetCDF file.

Example

simdir = SimDir("my_output")
read_var(simdir.variable_paths["hu"]["inst"])
ClimaAnalysis.short_nameMethod
short_name(var::OutputVar)

Return the short_name of the given var, if available.

If not available, return an empty string.

ClimaAnalysis.sliceMethod
slice(var::OutputVar, kwargs...)

Return a new OutputVar by slicing across dimensions as defined by the keyword arguments.

Example

slice(var, lat = 30, lon = 20, time = 100)
ClimaAnalysis.unitsMethod
units(var::OutputVar)

Return the units of the given var, if available.

If not available, return an empty string.

ClimaAnalysis.windowMethod
window(var::OutputVar, dim_name; left = nothing, right = nothing)

Return a new OutputVar by selecting the values of the given dimension that are between left and right.

If left and/or right are nothing, assume beginning (or end) of the array.

Example

window(var, 'lat', left = -50, right = 50)
ClimaAnalysis.@overload_binary_opMacro
overload_binary_op(op)

Add methods to overload the given binary operator for OutputVars and Reals.

Attributes that are not short_name, long_name, are discarded in the process.

ClimaAnalysis.Utils.kwargsMethod
kwargs(; kwargs...)

Convert keyword arguments in a dictionary that maps Symbols to values.

Useful to pass keyword arguments to different constructors in a function.

Examples

julia> kwargs(a = 1)
pairs(::NamedTuple) with 1 entry:
  :a => 1
ClimaAnalysis.Utils.match_nc_filenameMethod
match_nc_filename(filename::String)

Return short_name, period, reduction extracted from the filename, if matching the expected convention.

The convention is: shortname_(period)_reduction.nc, with period being optional.

Examples

julia> match_nc_filename("bob")
julia> match_nc_filename("ta_1d_average.nc")
("ta", "1d", "average")
julia> match_nc_filename("pfull_6.0min_max.nc")
("pfull", "6.0min", "max")
julia> match_nc_filename("hu_inst.nc")
("hu", nothing, "inst")
ClimaAnalysis.Utils.nearest_indexMethod
nearest_index(A::AbstractArray, val)

Return the index in A closest to the given val.

Examples

julia> A = [-1, 0, 1, 2, 3, 4, 5];

julia> nearest_index(A, 3)
5

julia> nearest_index(A, 0.1)
2
ClimaAnalysis.Utils.seconds_to_prettystrMethod
seconds_to_prettystr(seconds::Real)

Convert the given seconds into a string with rich time information.

One year is defined as having 365 days.

Examples

julia> seconds_to_prettystr(10)
"10s"

julia> seconds_to_prettystr(600)
"10m"

julia> seconds_to_prettystr(86400)
"1d"

julia> seconds_to_prettystr(864000)
"10d"

julia> seconds_to_prettystr(864010)
"10d 10s"

julia> seconds_to_prettystr(24 * 60 * 60 * 365 + 1)
"1y 1s"
ClimaAnalysis.Utils.squeezeMethod
squeeze(A :: AbstractArray; dims)

Return an array that has no dimensions with size 1.

When an iterable dims is passed, only try to squeeze the given dimensions.

Examples

julia> A = [[1 2] [3 4]];

julia> size(A)
(1, 4)

julia> A_squeezed = squeeze(A);

julia> size(A_squeezed)
(4,)

julia> A_not_squeezed = squeeze(A; dims = (2, ));

julia> size(A_not_squeezed)
(1, 4)