ClimaAnalysis.Sim.SimDir
— TypeSimDir(simulation_path::String)
Object that describes all the ClimaAtmos
output found in the given simulation_path
.
Base.get
— Methodget(simdir::SimDir, short_name)
If only one reduction and period exist for short_name
, return the corresponding OutputVar
.
Base.get
— Methodget(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.isempty
— Methodisempty(simdir::SimDir)
Check if the given SimDir contains OutputVars.
ClimaAnalysis.Sim.available_periods
— Methodavailable_periods(simdir::SimDir, short_name::String, reduction::String)
Return the periods associated to the given variable and reduction.
ClimaAnalysis.Sim.available_reductions
— Methodavailable_reductions(simdir::SimDir, short_name::String)
Return the reductions available for the given variable in the given simdir
.
ClimaAnalysis.Sim.available_vars
— Methodavailable_vars(simdir::SimDir)
Return the short names of the variables found in the given simdir
.
ClimaAnalysis.Utils.kwargs
— Methodkwargs(; kwargs...)
Convert keyword arguments in a dictionary that maps Symbol
s 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_filename
— Methodmatch_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_index
— Methodnearest_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_prettystr
— Methodseconds_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.squeeze
— Methodsqueeze(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 dim
ensions.
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)
ClimaAnalysis.Var.OutputVar
— TypeRepresenting an output variable
ClimaAnalysis.Var._reduce_over
— Method_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.Var._slice_general
— Method_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.Var.altitude_name
— Methodaltitude_name(var::OutputVar)
Return the name of the altitude
dimension in var
.
ClimaAnalysis.Var.altitudes
— Methodaltitudes(var::OutputVar)
Return the altitude
dimension in var
.
ClimaAnalysis.Var.arecompatible
— Methodarecompatible(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
andindex2dim
where correctly created and they reflectdims
data
is also consistent withdims
,
We also do not check units for data
.
ClimaAnalysis.Var.average_lat
— Methodaverage_lat(var::OutputVar; weighted = false)
Return a new OutputVar where the values on the latitudes are averaged arithmetically.
When weighted
is true
, weight the average over cos(lat)
.
ClimaAnalysis.Var.average_lon
— Methodaverage_lon(var::OutputVar)
Return a new OutputVar where the values on the longitudes are averaged arithmetically.
ClimaAnalysis.Var.average_time
— Methodaverage_time(var::OutputVar)
Return a new OutputVar where the values are averaged arithmetically in time.
ClimaAnalysis.Var.average_x
— Methodaverage_x(var::OutputVar)
Return a new OutputVar where the values along the x
dimension are averaged arithmetically.
ClimaAnalysis.Var.average_xy
— Methodaverage_xy(var::OutputVar)
Return a new OutputVar where the values along both horizontal dimensions x
and y
are averaged arithmetically.
ClimaAnalysis.Var.average_y
— Methodaverage_y(var::OutputVar)
Return a new OutputVar where the values along the y
dimension are averaged arithmetically.
ClimaAnalysis.Var.center_longitude!
— Methodcenter_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.Var.date_name
— Methoddate_name(var::OutputVar)
Return the name of the date
dimension in var
.
ClimaAnalysis.Var.dates
— Methoddates(var::OutputVar)
Return the date
dimension in var
.
ClimaAnalysis.Var.find_dim_name
— Methodfind_dim_name(dim_names::Iterable, allowed_names::Iterable)
Find the first occurrence of a name in allowed_names
in dim_names
.
Example
julia> ClimaAnalysis.Var.find_dim_name(["z", "lat", "lon"], ["lon", "long"])
"lon"
ClimaAnalysis.Var.is_z_1D
— Methodis_z_1D(var::OutputVar)
Return whether the given var
iable 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.Var.latitude_name
— Methodlatitude_name(var::OutputVar)
Return the name of the latitude
dimension in var
.
ClimaAnalysis.Var.latitudes
— Methodlatitudes(var::OutputVar)
Return the latitude
dimension in var
.
ClimaAnalysis.Var.long_name
— Methodlong_name(var::OutputVar)
Return the long_name
of the given var
, if available.
If not available, return an empty string.
ClimaAnalysis.Var.longitude_name
— Methodlongitude_name(var::OutputVar)
Return the name of the longitude
dimension in var
.
ClimaAnalysis.Var.longitudes
— Methodlongitudes(var::OutputVar)
Return the longitude
dimension in var
.
ClimaAnalysis.Var.read_var
— Methodread_var(path::String)
Read a variable in the given NetCDF file.
Example
simdir = SimDir("my_output")
read_var(simdir.variable_paths["hu"]["inst"])
ClimaAnalysis.Var.short_name
— Methodshort_name(var::OutputVar)
Return the short_name
of the given var
, if available.
If not available, return an empty string.
ClimaAnalysis.Var.slice
— Methodslice(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.Var.time_name
— Methodtime_name(var::OutputVar)
Return the name of the time
dimension in var
.
ClimaAnalysis.Var.times
— Methodtimes(var::OutputVar)
Return the time
dimension in var
.
ClimaAnalysis.Var.units
— Methodunits(var::OutputVar)
Return the units
of the given var
, if available.
If not available, return an empty string.
ClimaAnalysis.Var.weighted_average_lat
— Methodweighted_average_lat(var::OutputVar)
Return a new OutputVar where the values on the latitudes are averaged arithmetically with weights of cos(lat)
.
ClimaAnalysis.Var.window
— Methodwindow(var::OutputVar, dim_name; left = nothing, right = nothing)
Return a new OutputVar by selecting the values of the given dim
ension 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.Var.@overload_binary_op
— Macrooverload_binary_op(op)
Add methods to overload the given binary op
erator for OutputVars
and Real
s.
Attributes that are not short_name
, long_name
, are discarded in the process.