From af7fff4390c1cf8a0ae76b9eee85d84e6bfdf3fd Mon Sep 17 00:00:00 2001 From: gaelforget Date: Sat, 14 Sep 2024 19:33:13 -0400 Subject: [PATCH 1/4] increase codecov --- src/Operations.jl | 20 +++++++++----------- src/Types.jl | 4 +++- test/Project.toml | 1 + test/runtests.jl | 35 +++++++++++++++++++++++++++++++---- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/Operations.jl b/src/Operations.jl index 293a44a..ee48c6b 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -483,20 +483,18 @@ function UVtoUEVN(u::MeshArray,v::MeshArray,G::NamedTuple) return uC.*G.AngleCS-vC.*G.AngleSN, uC.*G.AngleSN+vC.*G.AngleCS end -function UVtoSpeed!(u::MeshArray,v::MeshArray,G::NamedTuple,dD) - (u,v)=exch_UV(u,v) +function UVtoSpeed!(uC::MeshArray,vC::MeshArray,G::NamedTuple,dD) + (u,v)=exch_UV(uC,vC) for iF=1:u.grid.nFaces - for i in 1:size(vC[iF],1) + for i in 1:size(vC[iF],1) for j in 1:size(vC[iF],2) - u0=nanmean(u[iF][i,j],u[iF][i+1,j]) - v0=nanmean(v[iF][i,j],v[iF][i,j+1]) - u1=u0*G.AngleCS[iF][i,j]-v0*G.AngleSN[iF][i,j] - v1=u0*G.AngleSN[iF][i,j]+v0*G.AngleCS[iF][i,j] - dD[iF][i,j]=sqrt(u1^2 + v1^2) - #uC[iF][i,j]=u0*G.AngleCS[iF][i,j]-v0*G.AngleSN[iF][i,j] - #vC[iF][i,j]=u0*G.AngleSN[iF][i,j]+v0*G.AngleCS[iF][i,j] - end + u0=nanmean(u[iF][i,j],u[iF][i+1,j]) + v0=nanmean(v[iF][i,j],v[iF][i,j+1]) + u1=u0*G.AngleCS[iF][i,j]-v0*G.AngleSN[iF][i,j] + v1=u0*G.AngleSN[iF][i,j]+v0*G.AngleCS[iF][i,j] + dD[iF][i,j]=sqrt(u1^2 + v1^2) end + end end end diff --git a/src/Types.jl b/src/Types.jl index a22f220..078cb46 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -97,7 +97,9 @@ MeshArray=gcmarray ## Methods that apply to all AbstractMeshArray types -import Base: maximum, minimum, sum, fill, fill! +import Base: maximum, minimum, extrema, sum, fill, fill! + +extrema(a::AbstractMeshArray) = [minimum(a) maximum(a)] function maximum(a::AbstractMeshArray) c=-Inf; diff --git a/test/Project.toml b/test/Project.toml index 3afa1d6..3907544 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -5,4 +5,5 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" Proj = "c94c279d-25a6-4763-9509-64d165bea63e" Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4" +Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index 4ed6af8..d3d4dbb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using Test, Documenter +using Test, Documenter, Suppressor using MeshArrays, DataDeps, CairoMakie, JLD2, Shapefile, Proj MeshArrays.GRID_LL360_download() @@ -60,6 +60,7 @@ end μ=land_mask(hFacC[:,1]) lons=[-68 -63]; lats=[-54 -66]; name="Drake Passage" + Trsct=Transect(name,lons,lats,Γ,segment=:long,format=:NamedTuple) Trsct=Transect(name,lons,lats,Γ) #Various vector operations @@ -71,6 +72,8 @@ end UVtoTransport(U,V,Γ) UVtoUEVN(U[:,1],V[:,1],Γ) curl(U[:,1],V[:,1], merge(Γ,(hFacW=hFacW,hFacS=hFacS,RAZ=RAZ,)) ) + dD=zeros(γ) + MeshArrays.UVtoSpeed!(U[:,1],V[:,1],Γ,dD) #Meridional transport integral uv=Dict("U"=>Tx,"V"=>Ty,"dimensions"=>["x","y"]) @@ -78,6 +81,17 @@ end T=Array{Float64,1}(undef,length(LC)) [T[i]=1e-6*ThroughFlow(uv,LC[i],Γ) for i=1:length(LC)] + x=zeros(γ) + fill!(x,1.0) + y=fill(-1.0,γ) + extrema(y) + @test minimum(y) Date: Sat, 14 Sep 2024 20:39:39 -0400 Subject: [PATCH 2/4] increase codecov --- src/Grids.jl | 2 +- src/Operations.jl | 6 +++--- test/runtests.jl | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Grids.jl b/src/Grids.jl index 8b57b3d..5fd6794 100644 --- a/src/Grids.jl +++ b/src/Grids.jl @@ -286,7 +286,7 @@ function GridLoad(γ=GridSpec(); ID=:default, option=:minimal) end [Γ[ii]=GridLoadVar(ii,gr) for ii in list_n] - option=="full"||option=="light" ? GridAddWS!(Γ) : nothing + op=="full"||op=="light" ? GridAddWS!(Γ) : nothing return Dict_to_NamedTuple(Γ) end diff --git a/src/Operations.jl b/src/Operations.jl index ee48c6b..7845b41 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -551,8 +551,8 @@ function calc_bolus(GM_PsiX,GM_PsiY, Γ) bolusU.f[:,k].=(GM_PsiX.f[:,k+1].-GM_PsiX.f[:,k])/Γ.DRF[k]; bolusV.f[:,k].=(GM_PsiY.f[:,k+1].-GM_PsiY.f[:,k])/Γ.DRF[k]; end; - bolusU.f[:, nr] .= 0. -GM_PsiX.f[:,nr]./Γ.DRF[nr]; - bolusV.f[:, nr] .= 0. -GM_PsiY.f[:,nr]./Γ.DRF[nr]; + bolusU.f[:, nr] .= 0*GM_PsiX.f[:,nr] .-GM_PsiX.f[:,nr]./Γ.DRF[nr]; + bolusV.f[:, nr] .= 0*GM_PsiY.f[:,nr] .-GM_PsiY.f[:,nr]./Γ.DRF[nr]; bolusU=bolusU.*mskW; bolusV=bolusV.*mskS; @@ -566,7 +566,7 @@ function calc_bolus(GM_PsiX,GM_PsiY, Γ) for k in 1:nr (tmpU,tmpV)=exch_UV(tmp_x[:, k],tmp_y[:, k]) for a=1:tmpU.grid.nFaces - (s1,s2)=size(tmpU.f[a]) + (s1,s2)=size(tmp_x.f[a]) tmpU1=view(tmpU.f[a],1:s1,1:s2) tmpU2=view(tmpU.f[a],2:s1+1,1:s2) tmpV1=view(tmpV.f[a],1:s1,1:s2) diff --git a/test/runtests.jl b/test/runtests.jl index d3d4dbb..f1312f6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -54,7 +54,7 @@ end γ=GridSpec("LatLonCap",MeshArrays.GRID_LLC90) Tx=γ.read(MeshArrays.GRID_LLC90*"TrspX.bin",MeshArray(γ,Float32)) Ty=γ.read(MeshArrays.GRID_LLC90*"TrspY.bin",MeshArray(γ,Float32)) - Γ=GridLoad(γ;option="light") + Γ=GridLoad(γ;option=:full) hFacC=GridLoadVar("hFacC",γ) μ=land_mask(hFacC[:,1]) @@ -91,6 +91,10 @@ end ones(γ) ones(y) zeros(y) + + GM_PsiX=read(randn(90,1170,50),Γ.hFacW) + GM_PsiY=read(randn(90,1170,50),Γ.hFacS) + bolusU, bolusV, bolusW=MeshArrays.calc_bolus(GM_PsiX,GM_PsiY, Γ) #See: OceanTransports/helper_functions.jl #u,v,uC,vC=rotate_uv(uv,Γ); From 60fefbef8bb76b8baba3420f2fd6e067c6142a8a Mon Sep 17 00:00:00 2001 From: gaelforget Date: Sat, 14 Sep 2024 23:22:08 -0400 Subject: [PATCH 3/4] increase codecov --- test/runtests.jl | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index f1312f6..74a5624 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ -using Test, Documenter, Suppressor -using MeshArrays, DataDeps, CairoMakie, JLD2, Shapefile, Proj +using Test, Documenter, Suppressor, MeshArrays, CairoMakie +import DataDeps, JLD2, Shapefile, GeoJSON, Proj MeshArrays.GRID_LL360_download() MeshArrays.GRID_LLC90_download() @@ -55,7 +55,8 @@ end Tx=γ.read(MeshArrays.GRID_LLC90*"TrspX.bin",MeshArray(γ,Float32)) Ty=γ.read(MeshArrays.GRID_LLC90*"TrspY.bin",MeshArray(γ,Float32)) Γ=GridLoad(γ;option=:full) - + plot(Γ.XC) + hFacC=GridLoadVar("hFacC",γ) μ=land_mask(hFacC[:,1]) @@ -80,6 +81,8 @@ end L=-85.0:5.0:85.0; LC=LatitudeCircles(L,Γ,format=:gridpath) T=Array{Float64,1}(undef,length(LC)) [T[i]=1e-6*ThroughFlow(uv,LC[i],Γ) for i=1:length(LC)] + plot(LC) + plot(LC[1]) x=zeros(γ) fill!(x,1.0) @@ -215,8 +218,10 @@ end proj=Proj.Transformation(MA_preset=2,lon0=lon0) Dint=reshape(Interpolate(D,λ.f,λ.i,λ.j,λ.w),size(λ.lon)) - fil=demo.download_polygons("ne_110m_admin_0_countries.shp") # fil=demo.download_polygons("countries.geojson") +# pol=MeshArrays.read_polygons(fil) + + fil=demo.download_polygons("ne_110m_admin_0_countries.shp") pol=MeshArrays.read_polygons(fil) f = Figure() @@ -228,6 +233,10 @@ end MeshArrays.grid_lines!(pr_ax;color=:lightgreen,linewidth=0.5) f + meta=(colorrange=(0.0,6000.0),cmap=:BrBG_10,ttl="Ocean Depth (m)",lon0=lon0) + data=(lon=λ.lon,lat=λ.lat,var=Dint,meta=meta) #,polygons=pol) + plot_examples(:projmap,data,lon0,proj) + end @testset "nanmath" begin @@ -243,6 +252,18 @@ end nanmean(NaN,NaN) end +@testset "plotting" begin + lon,lat,earth_img=demo.get_basemap() + plot_examples(:basemap,lon,lat,earth_img) + + pol_file=demo.download_polygons("ne_110m_admin_0_countries.shp") + pol=MeshArrays.read_polygons(pol_file) + + lon0=-160 + proj=Proj.Transformation(MA_preset=2,lon0=lon0) + plot_examples(:baseproj,proj,lon0,pol=pol) +end + @testset "doctests" begin doctest(MeshArrays; manual = false) end From acbf381af8018e6ec03a733dd1ee18379144b3dc Mon Sep 17 00:00:00 2001 From: gaelforget Date: Sat, 14 Sep 2024 23:31:30 -0400 Subject: [PATCH 4/4] add GeoJSON --- test/Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Project.toml b/test/Project.toml index 3907544..a4e7299 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -2,6 +2,7 @@ CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" DataDeps = "124859b0-ceae-595e-8997-d05f6a7a8dfe" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" Proj = "c94c279d-25a6-4763-9509-64d165bea63e" Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"