Skip to content

Commit a1b0180

Browse files
authored
Merge pull request #181 from seamanticscience/jml_llc270
add support for LLC270 grid
2 parents 0661c82 + 85cffc4 commit a1b0180

File tree

3 files changed

+110
-65
lines changed

3 files changed

+110
-65
lines changed

Artifacts.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ lazy = true
1414
sha256 = "90d5e4a07014e7958e4ec6d461fa78fa72d81d09589a8b951cd392dd74ecc7cb"
1515
url = "https://github.com/gaelforget/GRID_LL360/archive/v1.0.tar.gz"
1616

17+
[GRID_LLC270]
18+
#git-tree-sha1 = "7ccfbaa17e91bdbd2d585a9aea466469168b3bd5"
19+
git-tree-sha1 = "1bc43784dfbcb787cc4e8018ab61d5c3cdcd5ea3"
20+
lazy = true
21+
22+
[[GRID_LLC270.download]]
23+
sha256 = "c5b44a7afd463a480d370a8577edecf36a93ff099447c8052faf44c091096544"
24+
url = "https://zenodo.org/records/15352381/files/GRID_LLC270-1.0.0.tar.gz"
25+
1726
[GRID_LLC90]
1827
git-tree-sha1 = "0a62225e81fc22f37aefcf57465676c4cc934b11"
1928
lazy = true

src/Grids.jl

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
GRID_LLC90_hash = artifact_hash("GRID_LLC90", artifact_toml)
33
GRID_LLC90 = joinpath(artifact_path(GRID_LLC90_hash)*"/","GRID_LLC90-1.1/")
44
GRID_LLC90_download() = artifact"GRID_LLC90"
5+
GRID_LLC270_hash = artifact_hash("GRID_LLC270", artifact_toml)
6+
GRID_LLC270 = joinpath(artifact_path(GRID_LLC270_hash)*"/","GRID_LLC270-1.0.0/")
7+
GRID_LLC270_download() = artifact"GRID_LLC270"
58
GRID_LL360_hash = artifact_hash("GRID_LL360", artifact_toml)
69
GRID_LL360 = joinpath(artifact_path(GRID_LL360_hash)*"/","GRID_LL360-1.0/")
710
GRID_LL360_download() = artifact"GRID_LL360"
@@ -28,7 +31,7 @@ land_mask(Γ::NamedTuple)=land_mask(Γ.hFacC[:,1])
2831
## GridSpec function with category argument:
2932

3033
"""
31-
GridSpec(category="PeriodicDomain",path=tempname(); ID=:unknown)
34+
GridSpec(category="PeriodicDomain",path=tempname(); np=nothing, ID=:unknown)
3235
3336
- Select one of the pre-defined grids either by ID (keyword) or by category.
3437
- Return the corresponding `gcmgrid` specification, including the path where grid files can be accessed (`path`).
@@ -37,6 +40,7 @@ land_mask(Γ::NamedTuple)=land_mask(Γ.hFacC[:,1])
3740
3841
- `:LLC90`
3942
- `:CS32`
43+
- `:LLC270`
4044
- `:onedegree`
4145
- `:default`
4246
@@ -68,22 +72,46 @@ isa(g,gcmgrid)
6872
6973
# output
7074
75+
true
76+
```
77+
78+
3. by `category` and `path` with the `np` argument
79+
- `np` is the number of grid points in x or y for the `LatLonCap` and `CubeSphere` tiles.
80+
`np` defaults to 90 for `LatLonCap` and 32 for `CubeSphere`, and so must be included to access the LLC270 grid with the category argument.
81+
82+
Examples:
83+
84+
```jldoctest; output = false
85+
using MeshArrays
86+
g = GridSpec("LatLonCap",MeshArrays.GRID_LLC90,np=90)
87+
g = GridSpec("LatLonCap",MeshArrays.GRID_LLC270,np=270)
88+
g = GridSpec("CubeSphere",MeshArrays.GRID_CS32,np=32)
89+
isa(g,gcmgrid)
90+
91+
# output
92+
7193
true
7294
```
7395
"""
74-
function GridSpec(category="PeriodicDomain",path=tempname(); ID=:unknown)
96+
function GridSpec(category="PeriodicDomain", path=tempname(); np=nothing, ID=:unknown)
7597

7698
if category=="LatLonCap"
7799
nFaces=5
78100
grTopo="LatLonCap"
79-
ioSize=[90 1170]
80-
facesSize=[(90, 270), (90, 270), (90, 90), (270, 90), (270, 90)]
81-
ioPrec=Float64
101+
np === nothing ? np=90 : np
102+
ioSize=[np np*13]
103+
facesSize=[(np, np*3), (np, np*3), (np, np), (np*3, np), (np*3, np)]
104+
if np==270
105+
ioPrec=Float32
106+
else
107+
ioPrec=Float64
108+
end
82109
elseif category=="CubeSphere"
83110
nFaces=6
84111
grTopo="CubeSphere"
85-
ioSize=[32 192]
86-
facesSize=[(32, 32), (32, 32), (32, 32), (32, 32), (32, 32), (32, 32)]
112+
np === nothing ? np=32 : np
113+
ioSize=[np np*nFaces]
114+
facesSize=[(np, np), (np, np), (np, np), (np, np), (np, np), (np, np)]
87115
ioPrec=Float32
88116
elseif category=="PeriodicChannel"
89117
nFaces=1
@@ -102,13 +130,18 @@ else
102130
end
103131

104132
if ID==:unknown
105-
gcmgrid(path,grTopo,nFaces,facesSize, ioSize, ioPrec, read, write)
133+
gcmgrid(path, grTopo, nFaces, facesSize, ioSize, ioPrec, read, write)
106134
elseif ID==:LLC90
107-
GridSpec("LatLonCap",MeshArrays.GRID_LLC90)
135+
np = 90
136+
GridSpec("LatLonCap", MeshArrays.GRID_LLC90, np=np)
137+
elseif ID==:LLC270
138+
np = 270
139+
GridSpec("LatLonCap", MeshArrays.GRID_LLC270, np=np)
108140
elseif ID==:CS32
109-
GridSpec("CubeSphere",MeshArrays.GRID_CS32)
141+
np = 32
142+
GridSpec("CubeSphere", MeshArrays.GRID_CS32, np=np)
110143
elseif ID==:onedegree
111-
GridSpec("PeriodicChannel",MeshArrays.GRID_LL360)
144+
GridSpec("PeriodicChannel", MeshArrays.GRID_LL360)
112145
elseif ID==:default
113146
GridSpec()
114147
else
@@ -156,6 +189,7 @@ function GridLoad(γ=GridSpec(); ID=:default, option=:minimal)
156189

157190
gr.path==GRID_CS32 ? GRID_CS32_download() : nothing
158191
gr.path==GRID_LL360 ? GRID_LL360_download() : nothing
192+
gr.path==GRID_LLC270 ? GRID_LLC270_download() : nothing
159193
gr.path==GRID_LLC90 ? GRID_LLC90_download() : nothing
160194

161195
Γ=Dict()

test/runtests.jl

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import DataDeps, JLD2, Shapefile, GeoJSON, Proj
33

44
MeshArrays.GRID_LL360_download()
55
MeshArrays.GRID_LLC90_download()
6+
MeshArrays.GRID_LLC270_download()
67
MeshArrays.GRID_CS32_download()
78

89
p=dirname(pathof(MeshArrays))
@@ -36,7 +37,7 @@ include(joinpath(p,"../examples/Demos.jl"))
3637
end
3738

3839
@testset "Vertical Dimension:" begin
39-
γ=GridSpec("PeriodicChannel",MeshArrays.GRID_LL360)
40+
γ=GridSpec(ID=:onedegree)
4041
Γ=GridLoad(γ;option="full")
4142
θ=Float64.(Γ.hFacC)
4243
nk=length.RC)
@@ -168,59 +169,60 @@ end
168169
end
169170

170171
@testset "gcmfaces type:" begin
171-
γ=GridSpec(ID=:CS32)
172-
173-
MeshArrays.gcmfaces(γ)
174-
MeshArrays.gcmfaces(γ,Float32)
175-
tmp=MeshArrays.gcmfaces(γ,Float32,3)
176-
tmp[3,1,2]=1.0
177-
view(tmp,:,1,1:2)
178-
MeshArrays.gcmfaces(γ,tmp.f)
179-
MeshArrays.fsize(tmp)
180-
MeshArrays.fsize(tmp,2)
181-
MeshArrays.fsize(tmp.f)
182-
MeshArrays.fsize(tmp.f,2)
183-
size(tmp)
184-
size(tmp,3)
185-
tmp1=similar(tmp)
186-
2 .*tmp1
187-
findall(tmp.>0)
188-
MeshArrays.nFacesEtc(tmp)
189-
@suppress show(tmp)
190-
191-
x=tmp[1:10,1,1:2]; y=x[2]; x[3]=1.0
192-
view(x,1:3,:,1)
193-
MeshArrays.gcmsubset(γ,x.f,x.fSize,x.aSize,x.i,x.iSize)
194-
MeshArrays.fsize(x.f)
195-
MeshArrays.fsize(x.f,2)
196-
size(x)
197-
size(x,3)
198-
199-
MeshArrays.fijind(tmp,10)
200-
MeshArrays.fsize(tmp)
201-
@test isa(tmp,MeshArrays.gcmfaces)
202-
203-
tmp=MeshArray(γ)
204-
tmp1=findall(tmp.>0)
205-
tmp[tmp1]
206-
tmp[tmp1].=1.0
207-
size(tmp1)
208-
tmp1[2]
209-
view(tmp1,:)
210-
@suppress show(tmp1)
211-
similar(tmp1)
212-
#tmp[tmp1]
213-
214-
@suppress show(tmp)
215-
MeshArrays.getindexetc(tmp,2)
216-
MeshArray(γ,tmp.f,meta=tmp.meta)
217-
MeshArray(γ,meta=tmp.meta)
218-
MeshArray(γ,Float32,3,4)
219-
MeshArray(γ,Float32,tmp.fSize,tmp.fIndex,2,3)
220-
221-
tmp1=MeshArray(γ,Float32,3)
222-
MeshArray(γ,tmp1.f,meta=tmp1.meta)
223-
MeshArrays.getindexetc(tmp1,2,1)
172+
for ID in (:default, :CS32, :LLC270)
173+
γ=GridSpec(ID=ID)
174+
MeshArrays.gcmfaces(γ)
175+
MeshArrays.gcmfaces(γ,Float32)
176+
tmp=MeshArrays.gcmfaces(γ,Float32,3)
177+
tmp[3,1,2]=1.0
178+
view(tmp,:,1,1:2)
179+
MeshArrays.gcmfaces(γ,tmp.f)
180+
MeshArrays.fsize(tmp)
181+
MeshArrays.fsize(tmp,2)
182+
MeshArrays.fsize(tmp.f)
183+
MeshArrays.fsize(tmp.f,2)
184+
size(tmp)
185+
size(tmp,3)
186+
tmp1=similar(tmp)
187+
2 .*tmp1
188+
findall(tmp.>0)
189+
MeshArrays.nFacesEtc(tmp)
190+
@suppress show(tmp)
191+
192+
x=tmp[1:10,1,1:2]; y=x[2]; x[3]=1.0
193+
view(x,1:3,:,1)
194+
MeshArrays.gcmsubset(γ,x.f,x.fSize,x.aSize,x.i,x.iSize)
195+
MeshArrays.fsize(x.f)
196+
MeshArrays.fsize(x.f,2)
197+
size(x)
198+
size(x,3)
199+
200+
MeshArrays.fijind(tmp,10)
201+
MeshArrays.fsize(tmp)
202+
@test isa(tmp,MeshArrays.gcmfaces)
203+
204+
tmp=MeshArray(γ)
205+
tmp1=findall(tmp.>0)
206+
tmp[tmp1]
207+
tmp[tmp1].=1.0
208+
size(tmp1)
209+
tmp1[2]
210+
view(tmp1,:)
211+
@suppress show(tmp1)
212+
similar(tmp1)
213+
#tmp[tmp1]
214+
215+
@suppress show(tmp)
216+
MeshArrays.getindexetc(tmp,2)
217+
MeshArray(γ,tmp.f,meta=tmp.meta)
218+
MeshArray(γ,meta=tmp.meta)
219+
MeshArray(γ,Float32,3,4)
220+
MeshArray(γ,Float32,tmp.fSize,tmp.fIndex,2,3)
221+
222+
tmp1=MeshArray(γ,Float32,3)
223+
MeshArray(γ,tmp1.f,meta=tmp1.meta)
224+
MeshArrays.getindexetc(tmp1,2,1)
225+
end
224226
end
225227

226228
@testset "UnitGrid:" begin

0 commit comments

Comments
 (0)