Skip to content

Commit

Permalink
allow longitude range restriction in LatitudeCircles
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelforget committed Sep 14, 2024
1 parent 7ff90d0 commit 3006188
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,26 +331,45 @@ end
## LatitudeCircles function

"""
LatitudeCircles(LatValues,Γ::NamedTuple; format=:gridpath)
LatitudeCircles(LatValues,Γ::NamedTuple; format=:gridpath, range=(0.0,360.0))
Compute integration paths that follow latitude circles
Compute integration paths that follow latitude circles, within the specified longitude `range`.
"""
function LatitudeCircles(LatValues,Γ::NamedTuple; format=:gridpath)
function LatitudeCircles(LatValues,Γ::NamedTuple;
format=:gridpath, range=(0.0,360.0))
T=(format==:NamedTuple ? NamedTuple : gridpath)
LatitudeCircles=Array{T}(undef,length(LatValues))
for j=1:length(LatValues)
mskCint=1*.YC .>= LatValues[j])
mskC,mskW,mskS=edge_mask(mskCint)
LatitudeCircles[j]=
if format==:NamedTuple
(lat=LatValues[j],tabC=MskToTab(mskC),
tabW=MskToTab(mskW),tabS=MskToTab(mskS))
else
gridpath(name="Parallel $(LatValues[j])", grid=Γ,
C=MskToTab(mskC),W=MskToTab(mskW),S=MskToTab(mskS))
end
LatitudeCircles[j]=LatitudeCircle(LatValues[j],Γ;
format=format,range=range)
end
return LatitudeCircles
(length(LatValues)==1 ? LatitudeCircles[1] : LatitudeCircles)
end

function LatitudeCircle(lat,Γ::NamedTuple;
format=:gridpath, range=(0.0,360.0))
mskCint=1*.YC .>= lat)
mskC,mskW,mskS=edge_mask(mskCint)
restrict_longitudes!(mskC,Γ.XC,range=range)
restrict_longitudes!(mskS,Γ.XS,range=range)
restrict_longitudes!(mskW,Γ.XW,range=range)
LC=if format==:NamedTuple
(lat=LatValues[j],tabC=MskToTab(mskC),

Check warning on line 357 in src/Operations.jl

View check run for this annotation

Codecov / codecov/patch

src/Operations.jl#L357

Added line #L357 was not covered by tests
tabW=MskToTab(mskW),tabS=MskToTab(mskS))
else
gridpath(name="Parallel $lat", grid=Γ,
C=MskToTab(mskC),W=MskToTab(mskW),S=MskToTab(mskS))
end

end

is_in_lon_range(x,range)=(range[2].-range[1]>=360)||
(mod(x-range[1],360).<mod(range[2].-range[1],360))

function restrict_longitudes!(x::MeshArray,lon::MeshArray;range=(0.0,360.0))
for f in 1:x.grid.nFaces
x[f].=x[f].*is_in_lon_range.(lon[f],Ref(range))
end
end

function MskToTab(msk::MeshArray)
Expand Down

0 comments on commit 3006188

Please sign in to comment.