Utilities
Useful utilities for TMI.
TMI.nearestneighbormask — Function
function nearestneighbormask
Make a 3D tracer field that is 1 at location
of nearest neighbor, 0 elsewhereArguments
loc: location in a 3-tuple (lon,lat,depth)γ: TMI.grid
Output
δ: nearest neighbor mask 3D field
TMI.nearestneighbor — Function
function nearestneighbor(loc,γ)
return the Cartesian index and linear index
of the nearest N neighborsArguments
loc: 3-tuple of lon,lat,depth locationγ: TMI.grid
Output
Inn: Cartesian indices of nearest neighbor
#- Rnn: linear indices of nearest neighbor, Removed from code
Base.zeros — Function
function zeros(γ::Grid,name=:none,longname="unknown",units="unknown")::Field
initialize tracer field on TMI grid
using a Field struct and constructorArguments
γ::TMI.Grid
Output
d::Field, 3d tracer field with NaN on dry points
function zeros(dim::Int64,dimval::Int64,γ::Grid,name::Symbol,longname::String,units::String)::BoundaryCondition
Initialize boundary condition with zeroesArguments
dim:dimvalγ::Gridname::Symbollongname::Stringunits::String
Output
b::BoundaryCondition
function zeros(wet,ltype=Float64)
initialize tracer field on TMI grid
This version will give an arrayArguments
wet::BitArray mask of ocean pointsltype:: optional type argument, default=Float64
Output
d:: 3d tracer field with NaN on dry points
Base.ones — Function
function ones(dim::Int64,dimval::Int64,γ::Grid)::BoundaryCondition
Initialize boundary condition with onesfunction ones(γ::Grid,name=:none,longname="unknown",units="unknown")::Field
initialize tracer field of ones on TMI grid
using a Field struct and constructorArguments
γ::TMI.Grid
Output
d::Field, 3d tracer field with NaN on dry points
TMI.tracerinit — Function
function tracerinit(wet,vec,I)
initialize tracer field on TMI grid
perhaps better to have a tracer struct and constructorArguments
wet:: BitArray mask of ocean pointsvec:: vector of values at wet pointsI:: Cartesian Index for vector
Output
field:: 3d tracer field with NaN on dry points
LinearAlgebra.dot — Function
`function *(c::Field,d::Field)::Field`
Field by field multiplication is element-by-element.TMI.unvec! — Function
function unvec!(u,uvec)
Undo the operations by vec(u)
Needs to update u because attributes of
u need to be known at runtime.TMI.synthetic_observations — Function
function synthetic_observations(TMIversion,variable)
Synthetic observations that are a contaminated version of real observations
This version: gridded observationsArguments
TMIversion::String: version of TMI water-mass/circulation modelvariable::String: variable name to use as template
Output
y: contaminated observations on 3D gridW⁻: appropriate weighting (inverse covariance) matrix for these observations,θtrue: real observations, 3D field
function synthetic_observations(TMIversion,variable,locs)
Synthetic observations that are a contaminated version of real observations
This version: observations with random (uniform) spatial samplingArguments
TMIversion::String: version of TMI water-mass/circulation modelvariable::String: variable name to use as templateN: number of observations
Output
y: contaminated observations on 3D gridW⁻: appropriate weighting (inverse covariance) matrix for these observations,ytrue: uncontaminated observations, 3D fieldlocs: 3-tuples of locations for observationswis: weighted indices for interpolation to locs sites
TMI.observe — Function
function observe
Take a observation at location given by weights wisfunction observe(c,loc,γ)
Extend the TMI.observe method to use locations rather than weighted interpolations.TMI.gobserve — Function
function gobserve(gy::Vector{T},c::Field{T},wis,γ) where T <: Real
ADJOINT Take a observation at location given by weights wis
Arguments not symmetric with `observe` due to splat operatorTMI.location_obs — Function
function location_obs(field, locs, γ)TMI.costfunction_gridded_obs — Function
function costfunction_gridded_obs(uvec::Vector{T},Alu,b::BoundaryCondition{T},y::Field{T},Wⁱ::Diagonal{T, Vector{T}},γ::Grid) where T <: Real
squared model-data misfit for gridded data
controls are a vector input for Optim.jlArguments
J: cost function of sum of squared misfitsgJ: derivative of cost function wrt to controlsu: controls, field formatAlu: LU decomposition of water-mass matrixb: boundary conditionsy: observations on gridWⁱ: inverse of W weighting matrix for observationsγ: grid
TMI.costfunction_gridded_obs! — Function
function costfunction_gridded_obs!(J,guvec,uvec::Vector{T},Alu,b₀::Union{BoundaryCondition{T},NamedTuple{<:Any, NTuple{N1,BoundaryCondition{T}}}},u₀::Union{BoundaryCondition{T},NamedTuple{<:Any, NTuple{N2,BoundaryCondition{T}}}},y::Field{T},Wⁱ::Diagonal{T, Vector{T}},γ::Grid) where {N1, N2, T <: Real}TMI.costfunction_point_obs — Function
function costfunction_point_obs(uvec::Vector{T},Alu,b₀::BoundaryCondition{T},u₀::BoundaryCondition{T},y::Vector{T},Wⁱ::Diagonal{T, Vector{T}},wis,locs,Q⁻,γ::Grid;q=nothing,r=1.0) where T <: Real
Squared model-data misfit for pointwise data.
Controls are a vector input for Optim.jl.
Core numerics handled by `costfunction_point_obs`.Arguments
uvec: controls, vector formatAlu: LU decomposition of water-mass matrixb: boundary conditiony: pointwise observationsWⁱ: inverse of W weighting matrix for observationswis: weights for interpolation (data sampling, E)locs: data locations (lon,lat,depth)Q⁻: weights for control vectorγ: grid
Optional
q::Field: interior sourcer::Number: scalar factor for source
Output
J: cost function of sum of squared misfitsgJ: derivative of cost function wrt to controls
TMI.costfunction_point_obs! — Function
function costfunction_point_obs!(J,guvec,uvec::Vector{T},Alu,b₀::BoundaryCondition{T},u₀::BoundaryCondition{T},y::Vector{T},Wⁱ::Diagonal{T, Vector{T}},wis,locs,Q⁻,γ::Grid) where T <: Real
squared model-data misfit for pointwise data
controls are a vector input for Optim.jl
Issue #1: couldn't figure out how to nest with costfunction_obs!Arguments
J: cost function of sum of squared misfitsguvec: derivative of cost function wrt to controlsuvec: controls, vector formatAlu: LU decomposition of water-mass matrixb: boundary conditiony: pointwise observationsWⁱ: inverse of W weighting matrix for observationswis: weights for interpolation (data sampling, E)locs: data locations (lon,lat,depth)Q⁻: weights for control vectorγ: grid
TMI.steadyinversion — Function
function steadyinversion(Alu,b;q=nothing,r=1.0)
invert for a steady-state tracer distributionArguments
Alu: LU decomposition of water-mass matrixb: boundary condition, assumed to be surface boundary conditionγ::Grid
Optional Arguments
q: interior sources/sinks of phosphater: stochiometric ratio of tracer:phosphate
Output
c::Field, steady-state tracer distribution
TMI.gsteadyinversion — Function
function gsteadyinversion(gc,Alu,b;q=nothing,r=1.0)
ADJOINT invert for a steady-state tracer distributionArguments
Alu: LU decomposition of water-mass matrixb: BoundaryConditionγ::Grid
Optional Arguments
q: interior sources/sinks of phosphater: stochiometric ratio of tracer:phosphate
Output
c::Field, steady-state tracer distribution
TMI.wetlocation — Function
function wetlocation(γ)
Get (lon,lat,depth) tuples of wet locations.
Allow a location to be wet if at least one out of 8 nearby gridpoints is wet.
Certainly "wet" gridpoints could be defined more strictly.Arguments
γ: TMI.grid
Output
loc: lon,lat,depth
TMI.iswet — Function
function iswet(loc, γ, neighbors)
Get (lon,lat,depth) tuples of wet locations.
Allow a location to be wet if at least one out of 8 nearby gridpoints is wet.
Certainly "wet" gridpoints could be defined more strictly.Arguments
loc: lon,lat,depthγneighbors
Output
- Boolean (true for ocean point)