From 7cc4346e756af4cbb3bfb955f460a8892143f356 Mon Sep 17 00:00:00 2001 From: gaelforget Date: Sun, 15 Aug 2021 22:26:44 -0400 Subject: [PATCH 1/3] add time to varmeta (missing by default) --- Project.toml | 1 + src/Grids.jl | 16 ++++++++-------- src/Types.jl | 14 ++++++++------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Project.toml b/Project.toml index b5f8bc1e..66c7e621 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ version = "0.2.19" [deps] CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31" +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" diff --git a/src/Grids.jl b/src/Grids.jl index c5aef2fc..229b5b94 100644 --- a/src/Grids.jl +++ b/src/Grids.jl @@ -35,7 +35,7 @@ function simple_periodic_domain(np::Integer,nq=missing) list_p=(pc,pg,pc,pg,pc,pu,pv,pg,pu,pv,pv,pu,pc,fill(0.5,3),[0.,0.5,0.5],[0.5,0.,0.5]) for ii=1:length(list_n); tmp1=fill(1.,np,nq*nFaces); - m=varmeta(list_u[ii],list_p[ii],list_n[ii],list_n[ii]); + m=varmeta(list_u[ii],list_p[ii],missing,list_n[ii],list_n[ii]); tmp1=γ.read(tmp1,MeshArray(γ,Float64;meta=m)); tmp2=Symbol(list_n[ii]); @eval (($tmp2) = ($tmp1)) @@ -164,7 +164,7 @@ function GridLoad(γ::gcmgrid) end for ii=1:length(list_n) - m=varmeta(list_u[ii],list_p[ii],list_n[ii],list_n[ii]) + m=varmeta(list_u[ii],list_p[ii],missing,list_n[ii],list_n[ii]) tmp1=γ.read(joinpath(γ.path,list_n[ii]*".data"),MeshArray(γ,γ.ioPrec;meta=m)) tmp2=Symbol(list_n[ii]) @eval (($tmp2) = ($tmp1)) @@ -196,7 +196,7 @@ function GridLoad(γ::gcmgrid) list_p=(fill(0.5,3),[0.,0.5,0.5],[0.5,0.,0.5]) n3=length(Γ["RC"]) for ii=1:length(list_n) - m=varmeta(list_u[ii],list_p[ii],list_n[ii],list_n[ii]); + m=varmeta(list_u[ii],list_p[ii],missing,list_n[ii],list_n[ii]); tmp1=γ.read(joinpath(γ.path,list_n[ii]*".data"),MeshArray(γ,γ.ioPrec,n3;meta=m)) tmp2=Symbol(list_n[ii]) @eval (($tmp2) = ($tmp1)) @@ -247,7 +247,7 @@ function GridOfOnes(grTp,nF,nP) list_p=(pc,pg,pc,pg,pc,pu,pv,pg,pu,pv,pv,pu,pc,fill(0.5,3),[0.,0.5,0.5],[0.5,0.,0.5]) for ii=1:length(list_n); - tmp1=fill(1.,nP,nP*nF); m=varmeta(list_u[ii],list_p[ii],list_n[ii],list_n[ii]); + tmp1=fill(1.,nP,nP*nF); m=varmeta(list_u[ii],list_p[ii],missing,list_n[ii],list_n[ii]); tmp1=γ.read(tmp1,MeshArray(γ,Float64;meta=m)); tmp2=Symbol(list_n[ii]); @eval (($tmp2) = ($tmp1)) @@ -343,10 +343,10 @@ function GridAddWS!(Γ::Dict) uX=XC.meta.unit uY=YC.meta.unit - XW=MeshArrays.gcmarray(XC.grid,eltype(XC);meta=varmeta(uX,[0.,0.5],"XW","XW")) - YW=MeshArrays.gcmarray(XC.grid,eltype(XC);meta=varmeta(uY,[0.,0.5],"YW","YW")) - XS=MeshArrays.gcmarray(XC.grid,eltype(XC);meta=varmeta(uX,[0.5,0.],"XS","XS")) - YS=MeshArrays.gcmarray(XC.grid,eltype(XC);meta=varmeta(uY,[0.5,0.],"YS","YS")) + XW=MeshArrays.gcmarray(XC.grid,eltype(XC);meta=varmeta(uX,[0.,0.5],missing,"XW","XW")) + YW=MeshArrays.gcmarray(XC.grid,eltype(XC);meta=varmeta(uY,[0.,0.5],missing,"YW","YW")) + XS=MeshArrays.gcmarray(XC.grid,eltype(XC);meta=varmeta(uX,[0.5,0.],missing,"XS","XS")) + YS=MeshArrays.gcmarray(XC.grid,eltype(XC);meta=varmeta(uY,[0.5,0.],missing,"YS","YS")) for ff=1:nFaces tmp1=XC[ff][1:end-2,2:end-1] diff --git a/src/Types.jl b/src/Types.jl index 56d0a61e..99b3db44 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -1,5 +1,5 @@ -using Unitful +using Unitful, Dates """ AbstractMeshArray{T, N} @@ -36,28 +36,30 @@ end varmeta varmeta data structure. By default, `unit` is `1.0` (non-dimensional), `position` -is `fill(0.5,3)` (cell center), and `name` / `long_name` is unknown. +is `fill(0.5,3)` (cell center), time is missing, and `name` / `long_name` is unknown. Available constructors: ``` -varmeta(unit::Union{Unitful.AbstractQuantity,Number},position::Array{Float64,1}, - name::String,long_name::String) +varmeta(unit::Union{Unitful.Units,Number,Missing},position::Array{Float64,1}, + time::Union{DateTime,Missing,Array{DateTime,1}},name::String,long_name::String) ``` And: -```defaultmeta = varmeta(1.0,fill(0.5,3),"unknown","unknown")``` +```defaultmeta = varmeta(missing,fill(0.5,3),missing,"unknown","unknown")``` """ struct varmeta unit::Union{Unitful.Units,Number,Missing} position::Array{Float64,1} + time::Union{DateTime,Missing,Array{DateTime,1}} name::String long_name::String + #time? format? end -defaultmeta = varmeta(missing,fill(0.5,3),"unknown","unknown") +defaultmeta = varmeta(missing,fill(0.5,3),missing,"unknown","unknown") ## concrete types and MeshArray alias: From 91ef214397da58a9abb2067bec21260f0b14d495 Mon Sep 17 00:00:00 2001 From: gaelforget Date: Sun, 15 Aug 2021 22:28:35 -0400 Subject: [PATCH 2/3] add constructor that just receives an array --- src/Type_gcmarray.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Type_gcmarray.jl b/src/Type_gcmarray.jl index cc294fe7..83bcc7ff 100644 --- a/src/Type_gcmarray.jl +++ b/src/Type_gcmarray.jl @@ -19,6 +19,8 @@ gcmarray(grid::gcmgrid) gcmarray(grid::gcmgrid,::Type{T}) gcmarray(grid::gcmgrid,::Type{T},n3::Int) gcmarray(grid::gcmgrid,::Type{T},n3::Int,n4::Int) + +gcmarray(A::Array{T,N};meta::varmeta=defaultmeta) ``` """ struct gcmarray{T, N, AT} <: AbstractMeshArray{T, N} @@ -30,6 +32,21 @@ struct gcmarray{T, N, AT} <: AbstractMeshArray{T, N} version::String end +function gcmarray(A::Array{T,N}; + meta::varmeta=defaultmeta) where {T, N} + s=size(A)[1:2] + fs=Array{NTuple{2, Int},1}(undef,1) + fs[1]=s + ios=[s[1] s[2]] + γ=gcmgrid("","PeriodicDomain",1, fs, ios, T, read, write) + if N==2 + B=γ.read(A,gcmarray(γ,T;meta=meta)); + else + B=γ.read(A,gcmarray(γ,T,size(A)[3];meta=meta)); + end + B +end + function gcmarray(grid::gcmgrid,f::OuterArray{InnerArray{T,2},N}; meta::varmeta=defaultmeta) where {T, N} gcmarray{T,N,InnerArray{T,2}}(grid,meta,f,grid.fSize,collect(1:grid.nFaces),thisversion) From 84d426f7c98a0cefae6f3b61597618b621f90252 Mon Sep 17 00:00:00 2001 From: gaelforget Date: Tue, 17 Aug 2021 11:15:16 -0400 Subject: [PATCH 3/3] updates (workflow, ci) --- .github/workflows/ci.yml | 69 ++++++++++++++++++++++++++++++++++++++++ Project.toml | 2 +- README.md | 2 +- 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..9b11d1e2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,69 @@ +name: CI +on: + pull_request: + branches: + - master + push: + branches: + - master + tags: '*' +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + version: + - '1.6' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'. + - '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia. + - 'nightly' + os: + - ubuntu-latest + - macOS-latest + - windows-latest + arch: + - x64 + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: actions/cache@v1 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v1 + with: + file: lcov.info + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: '1' + - run: | + julia --project=docs -e ' + using Pkg + Pkg.develop(PackageSpec(path=pwd())) + Pkg.instantiate()' + - run: julia --project=docs docs/make.jl + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} + GKSwstype: "100" # https://discourse.julialang.org/t/generation-of-documentation-fails-qt-qpa-xcb-could-not-connect-to-display/60988 + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v1 + diff --git a/Project.toml b/Project.toml index 66c7e621..d040712a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MeshArrays" uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683" authors = ["gaelforget "] -version = "0.2.19" +version = "0.2.20" [deps] CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31" diff --git a/README.md b/README.md index 376c89aa..c2221566 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # MeshArrays.jl -[![Travis Build Status](https://travis-ci.org/juliaclimate/MeshArrays.jl.svg?branch=master)](https://travis-ci.org/juliaclimate/MeshArrays.jl) +[![CI](https://github.com/juliaclimate/MeshArrays.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/juliaclimate/MeshArrays.jl/actions/workflows/ci.yml) [![](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliaclimate.github.io/MeshArrays.jl/stable) [![](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliaclimate.github.io/MeshArrays.jl/dev) [![codecov](https://codecov.io/gh/juliaclimate/MeshArrays.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/juliaclimate/MeshArrays.jl)