Skip to content

Commit

Permalink
basin mask tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ggebbie committed Mar 18, 2024
1 parent 36b1b64 commit 5802cff
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
38 changes: 28 additions & 10 deletions src/ECCOtour.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ export vars2sigma1, sigma1grid
export landmask, land2nan!
export cons_offset!
export RegularpolesParameters, regularpoles

export grid_attributes, times_ecco
export wet_mask, basin_mask

include("HannFilter.jl")
include("MatrixFilter.jl")
include("SeasonalCycle.jl")
include("basins.jl")

struct RegularpolesParameters{T<:Real,I<:Integer,NT<: NamedTuple}
λC::StepRangeLen
Expand All @@ -58,8 +60,6 @@ struct RegularpolesParameters{T<:Real,I<:Integer,NT<: NamedTuple}
λantarc::NT
end

include("basins.jl")

"""
function sigma2grid()
Standard chosen from the time-averaged Pacific Ocean Density Configuration.
Expand Down Expand Up @@ -959,15 +959,15 @@ end
assuming using ECCOv4r4
"""
function timestamp_monthly_v4r4(t)
tstart = 1992 + 1/24
tend = 2018
tecco = range(tstart,step=1/12,stop=2018)
tecco = times_ecco()
year = Int(floor(tecco[t]))
month = ((t-1)%12)+1
println("year ",year," month ",month)
return year,month
end

times_ecco() = range(1992 + 1/24,step=1/12,stop=2018)

notnanorzero(z) = !iszero(z) && !isnan(z)

"""
Expand Down Expand Up @@ -1203,7 +1203,7 @@ end
- `linearinterp::Logical`: optional keyword argument, do linear interpolation?, default = false
- `eos::String`: optional key argument for equation of state, default = "JMD95"
"""
function mdsio2sigma1(pathin::String,pathout::String,fileroots::Vector{String},γ,pstdz,sig1grid;splorder=3,linearinterp=false,eos="JMD95",writefiles=writefiles)
function mdsio2sigma1(pathin::String,pathout::String,fileroots::Vector{String},γ,pstdz,sig1grid;splorder=3,linearinterp=false,eos="JMD95",writefiles=true)
# Read All Variables And Puts Them Into "Vars" Dictionary

# ideally would be more generic and Float64 would be covered.
Expand Down Expand Up @@ -1384,9 +1384,12 @@ function regularpoles(var,γ,params)
# remove contamination from land
# this is a problem for masks
# going to make the code slow with deepcopy but don't want mutation
varnative = deepcopy(var)
varnative = MeshArrays.mask(var,NaN,0.0)

# older options
#varnative = deepcopy(var)
#varnative = var
land2nan!(varnative,γ)
#land2nan!(varnative,γ)

#pre-allocate output
varregpoles = fill(NaNT,(params.nx,params.ny))
Expand All @@ -1405,7 +1408,9 @@ end
"""
function land2nan!(msk,γ)
Replace surface land points with NaN
Replace surface land points with NaN
Deprecate this function: slower than MeshArrays.mask
"""
function land2nan!(msk,γ)
land = landmask(γ)
Expand Down Expand Up @@ -2265,4 +2270,17 @@ function exch_UV_cs3D(fldU::MeshArrays.gcmarray{T, 2, Matrix{T}},

end

grid_attributes() = (
lon = Dict("longname" => "Longitude", "units" => "degrees east"),
lat = Dict("longname" => "Latitude", "units" => "degrees north"),
depth = Dict("longname" => "Depth", "units" => "m")
)

function wet_mask(Γ)
μ =Γ.hFacC[:,1]
μ[findall.>0.0)].=1.0
μ[findall.==0.0)].=NaN
return μ
end

end #module
5 changes: 3 additions & 2 deletions src/basins.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function basin_mask(basin_name::String,γ)
pth = MeshArrays.GRID_LLC90
Γ = GridLoad(γ;option="full")
basins=read(joinpath(pth,"v4_basin.bin"),MeshArray(γ,Float32))
basin_list=ECCOonPoseidon.basinlist()
basin_list=basinlist()
basinID=findall(basin_list.==basin_name)[1]
basinmask=similar(basins)
for ff in 1:5
Expand Down Expand Up @@ -79,7 +79,8 @@ end
"""
function land2zero!(msk,γ)
move to ECCOtour.jl
# see tests for different masking from MeshArrays
that could replace this function
"""
function land2zero!(msk,γ)
land = landmask(γ)
Expand Down
14 changes: 6 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Base: replace_in_print_matrix
using Revise
using Test
using ECCOtour
Expand All @@ -10,7 +9,7 @@ using NetCDF
#using GoogleDrive

@testset "ECCOtour.jl" begin

pth = MeshArrays.GRID_LLC90
γ = GridSpec("LatLonCap",pth)
Γ = GridLoad(γ;option="full")
Expand All @@ -29,6 +28,10 @@ using NetCDF

!ispath(datadir()) && mkdir(datadir())

@testset "basin mask" begin
include("test_basinmask.jl")
end

cd(srcdir())
# workaround: use a shell script
#run(`sh $srcdir/download_google_drive.sh`)
Expand Down Expand Up @@ -127,11 +130,7 @@ using NetCDF
filesuffix = "suffix.nc"
pathout = pathin
filelog = srcdir("available_diagnostics.log")
gridatts = (
lon = Dict("longname" => "Longitude", "units" => "degrees east"),
lat = Dict("longname" => "Latitude", "units" => "degrees north"),
depth = Dict("longname" => "Depth", "units" => "m")
)
gridatts = grid_attributes()

@time writeregularpoles(varsregpoles,
γ,
Expand Down Expand Up @@ -207,7 +206,6 @@ using NetCDF

end


@testset "MeshArrays" begin
######################################
# Test the statistics for MeshArrays.
Expand Down

0 comments on commit 5802cff

Please sign in to comment.