Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update variable names and default #153

Merged
merged 2 commits into from
Sep 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions src/Integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,32 @@
(700,800),(800,1000),(1000,1200),(1200,1400),(1400,1700),(1700,2000),
(2000,2500),(2500,3000),(3000,4000),(4000,5000),(5000,7000)]

lon180(x)=Float64(x>180.0 ? x-360.0 : x)

"""
define_regions(;option=:basins,grid::NamedTuple)
define_regions(;option=:global,grid::NamedTuple)

Define regional integration mask (one value period region).
"""
function define_regions(;option=:basins,grid::NamedTuple)
function define_regions(;option=:global,grid::NamedTuple)
if option==:basins
demo.ocean_basins()
elseif option==:global
mask=1.0*(grid.hFacC[:,1].>0)
(map=mask,name=["Global"])
(mask=mask,name=["Global"])

Check warning on line 44 in src/Integration.jl

View check run for this annotation

Codecov / codecov/patch

src/Integration.jl#L44

Added line #L44 was not covered by tests
elseif option==:dlat_10
mask=1.0*(grid.hFacC[:,1].>0)
la=grid.YC
lats=[-90 ; -75:10:75 ; 90]
nl=length(lats)-1
name=[Symbol("lat_$(lats[l])_to_$(lats[l+1])") for l in 1:nl]
[mask[findall((mask.>0)*(la.>=lats[l])*(la.<lats[l+1]))].=l for l in 1:nl]
(map=mask,name=name)
(mask=mask,name=name)
elseif isa(option,Tuple)
dlo=option[1]; dla=option[2]
mask=1.0*(grid.hFacC[:,1].>0)

lo=grid.XC
lo=lon180.(grid.XC)
lons=collect(-180:dlo:180)
nlo=length(lons)-1
la=grid.YC
Expand All @@ -72,7 +74,7 @@
end
end
end
(map=mask,name=name)
(mask=mask,name=name)
else
error("unknown option")
end
Expand All @@ -89,19 +91,19 @@
end

"""
define_sums(;option=:loops, grid::NamedTuple, regions=:basins, depths=[(0,7000)])
define_sums(;option=:loops, grid::NamedTuple, regions=:global, depths=[(0,7000)])

Define regional integration function for each basin and depth range.
"""
function define_sums(;option=:loops, grid::NamedTuple, regions=:basins, depths=[(0,7000)])
function define_sums(;option=:loops, grid::NamedTuple, regions=:global, depths=[(0,7000)])
dep=(isa(depths,Tuple) ? [depths] : depths)
nd=length(dep)
rgns=define_regions(option=regions,grid=grid)
nb=length(rgns.name)
allones=1.0 .+0*grid.hFacC
nr=length(grid.RC)

xymsk(b) = 1.0*(rgns.map.==b)
xymsk(b) = 1.0*(rgns.mask.==b)
func_h(X,b)=sum(xymsk(b)*X)
tmp2d=MeshArray(grid.XC.grid,Float32)

Expand Down Expand Up @@ -154,9 +156,9 @@
end

if option==:loops
gridmask(rgns.map,BXh.name,depths,BXh.hsum,BXv.vint,tmp2d,tmp3d)
gridmask(rgns.mask,BXh.name,depths,BXh.hsum,BXv.vint,tmp2d,tmp3d)
elseif option==:streamlined_loop
gridmask(rgns.map,BX.name,depths,BX.volsum,[],tmp2d,tmp3d)
gridmask(rgns.mask,BX.name,depths,BX.volsum,[],tmp2d,tmp3d)
else
error("unknown option")
end
Expand Down Expand Up @@ -243,5 +245,15 @@

##

volumes(M::gridmask,G::NamedTuple)=begin
allones=1.0 .+0*G.hFacC
vol=zeros(length(M.names),length(M.depths))
for j in 1:length(M.depths)
M.tmp2d.=M.v_int[j](allones)
vol[:,j]=[b(M.tmp2d) for b in M.h_sum]
end
vol

Check warning on line 255 in src/Integration.jl

View check run for this annotation

Codecov / codecov/patch

src/Integration.jl#L248-L255

Added lines #L248 - L255 were not covered by tests
end

end

Loading