Skip to content

Commit

Permalink
need to test bilinear
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Oct 3, 2024
1 parent faf4a27 commit 4169d27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Interpolation/bilinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Z = rand(T, length(lon), length(lat), 2)
r = bilinear(lon, lat, Z, Lon, Lat; na_rm=true)
```
"""
function bilinear(x, y, z::AbstractArray{T,3}, xx, yy; na_rm=true,
function bilinear(x, y, z::AbstractArray{T,3}, xx, yy; na_rm=true,
parallel=true, progress=true) where {T<:Real}

nx = length(x)
ny = length(y)

Expand Down Expand Up @@ -76,7 +76,7 @@ function bilinear(x, y, z::AbstractArray{T,3}, xx, yy; na_rm=true,
z12 = z[I, J2, k]
z21 = z[I2, J, k]
z22 = z[I2, J2, k]

if na_rm
zmean = nanmean4(z11, z12, z21, z22) # mean
isnan(z11) && (z11 = z12)
Expand All @@ -89,8 +89,8 @@ function bilinear(x, y, z::AbstractArray{T,3}, xx, yy; na_rm=true,
isnan(z21) && (z21 = zmean)
isnan(z22) && (z22 = zmean)
end
@fastmath res[i, j, k] =

@fastmath res[i, j, k] =
z11 * (1 - _ex) * (1 - _ey) +
z12 * (1 - _ex) * _ey +
z21 * _ex * (1 - _ey) +
Expand All @@ -112,5 +112,15 @@ function bilinear(x, y, z::AbstractArray{T,3};
bilinear(x, y, z, xx, yy; na_rm)
end

function bilinear(ra::AbstractArray{T,3};
cellsize=1, na_rm=true, kw...) where {T<:Real}
(; time, name, bands) = ra
b = ra.b
x, y = ra.lon, ra.lat
lon, lat = bbox2dims(b; cellsize)
Z = bilinear(x, y, ra.A, lon, lat; na_rm)
rast(Z, b; time, name, bands, kw...)
end


export bilinear
4 changes: 4 additions & 0 deletions src/nc_write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ $(METHODLIST)
"""
function nc_write!(f::AbstractString, varname::AbstractString, val,
dims::Vector{<:Union{NcDim,AbstractString}}, attrib::Dict=Dict();
units=nothing, longname=nothing,
compress=1, kw...)

!isnothing(units) && (attrib["units"] = units)
!isnothing(longname) && (attrib["longname"] = longname)

mode = check_file(f) ? "a" : "c"
ds = nc_open(f, mode)
Expand Down

0 comments on commit 4169d27

Please sign in to comment.