Skip to content

Commit 3006188

Browse files
committed
allow longitude range restriction in LatitudeCircles
1 parent 7ff90d0 commit 3006188

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

Diff for: src/Operations.jl

+33-14
Original file line numberDiff line numberDiff line change
@@ -331,26 +331,45 @@ end
331331
## LatitudeCircles function
332332

333333
"""
334-
LatitudeCircles(LatValues,Γ::NamedTuple; format=:gridpath)
334+
LatitudeCircles(LatValues,Γ::NamedTuple; format=:gridpath, range=(0.0,360.0))
335335
336-
Compute integration paths that follow latitude circles
336+
Compute integration paths that follow latitude circles, within the specified longitude `range`.
337337
"""
338-
function LatitudeCircles(LatValues,Γ::NamedTuple; format=:gridpath)
338+
function LatitudeCircles(LatValues,Γ::NamedTuple;
339+
format=:gridpath, range=(0.0,360.0))
339340
T=(format==:NamedTuple ? NamedTuple : gridpath)
340341
LatitudeCircles=Array{T}(undef,length(LatValues))
341342
for j=1:length(LatValues)
342-
mskCint=1*.YC .>= LatValues[j])
343-
mskC,mskW,mskS=edge_mask(mskCint)
344-
LatitudeCircles[j]=
345-
if format==:NamedTuple
346-
(lat=LatValues[j],tabC=MskToTab(mskC),
347-
tabW=MskToTab(mskW),tabS=MskToTab(mskS))
348-
else
349-
gridpath(name="Parallel $(LatValues[j])", grid=Γ,
350-
C=MskToTab(mskC),W=MskToTab(mskW),S=MskToTab(mskS))
351-
end
343+
LatitudeCircles[j]=LatitudeCircle(LatValues[j],Γ;
344+
format=format,range=range)
352345
end
353-
return LatitudeCircles
346+
(length(LatValues)==1 ? LatitudeCircles[1] : LatitudeCircles)
347+
end
348+
349+
function LatitudeCircle(lat,Γ::NamedTuple;
350+
format=:gridpath, range=(0.0,360.0))
351+
mskCint=1*.YC .>= lat)
352+
mskC,mskW,mskS=edge_mask(mskCint)
353+
restrict_longitudes!(mskC,Γ.XC,range=range)
354+
restrict_longitudes!(mskS,Γ.XS,range=range)
355+
restrict_longitudes!(mskW,Γ.XW,range=range)
356+
LC=if format==:NamedTuple
357+
(lat=LatValues[j],tabC=MskToTab(mskC),
358+
tabW=MskToTab(mskW),tabS=MskToTab(mskS))
359+
else
360+
gridpath(name="Parallel $lat", grid=Γ,
361+
C=MskToTab(mskC),W=MskToTab(mskW),S=MskToTab(mskS))
362+
end
363+
364+
end
365+
366+
is_in_lon_range(x,range)=(range[2].-range[1]>=360)||
367+
(mod(x-range[1],360).<mod(range[2].-range[1],360))
368+
369+
function restrict_longitudes!(x::MeshArray,lon::MeshArray;range=(0.0,360.0))
370+
for f in 1:x.grid.nFaces
371+
x[f].=x[f].*is_in_lon_range.(lon[f],Ref(range))
372+
end
354373
end
355374

356375
function MskToTab(msk::MeshArray)

0 commit comments

Comments
 (0)