Skip to content

Commit

Permalink
Merge pull request #154 from gaelforget/v0p3p16b
Browse files Browse the repository at this point in the history
V0p3p16b
  • Loading branch information
gaelforget committed Sep 22, 2024
2 parents 0f6a89f + 4866576 commit 07daf88
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 154 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MeshArrays"
uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683"
authors = ["gaelforget <gforget@mit.edu>"]
version = "0.3.15"
version = "0.3.16"

[deps]
CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31"
Expand Down
11 changes: 9 additions & 2 deletions docs/src/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ MeshArrays.gcmfaces
## 2. Grids And I/O

```@docs
simple_periodic_domain
GridSpec
GridLoad
GridLoadVar
```

More :

```
Grids_simple.periodic_domain
Grids_simple.UnitGrid
Grids_simple.GridLoad_lonlatdep
Grids_simple.GridLoad_lonlat
```

More :

```@docs
Expand All @@ -38,7 +46,6 @@ exchange
MeshArrays.read
MeshArrays.read!
MeshArrays.write
UnitGrid
```

## 3. Interpolation
Expand Down
2 changes: 1 addition & 1 deletion examples/Demos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ heatmap(Rini,title="raw noise",clims=(-0.5,0.5))
function demo2()

#Pre-requisite: either load predefined grid using `demo1` or call `GridOfOnes`
isdir(MeshArrays.GRID_LLC90) ? Γ=GridLoad(GridSpec("LatLonCap",MeshArrays.GRID_LLC90)) : (γ,Γ)=GridOfOnes("CubeSphere",6,100)
isdir(MeshArrays.GRID_LLC90) ? Γ=GridLoad(ID:LLC90) : (γ,Γ)=Grids_simple.GridOfOnes("CubeSphere",6,100)

(Rini,Rend,DXCsm,DYCsm)=demo2(Γ)
end
Expand Down
4 changes: 3 additions & 1 deletion ext/MeshArraysMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,9 @@ function basemap(lon,lat,basemap)
fig=with_theme(Figure,theme_light())
ax = Axis(fig[1, 1])
#im=image!(ax,lon[:,1],lat[1,:],0.5 .+0.5*Gray.(basemap))
im=image!(ax,lon[:,1],lat[1,:],basemap)
#im=image!(ax,lon[:,1],lat[1,:],basemap)
im=image!(ax,lon[1,1]..lon[end,1],lat[1,1]..lat[1,end],basemap)

hidedecorations!(ax)

#fig,ax,im
Expand Down
140 changes: 1 addition & 139 deletions src/Grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,111 +25,6 @@ end

land_mask::NamedTuple)=land_mask.hFacC[:,1])

"""
UnitGrid(γ::gcmgrid;option="minimal")
Generate a unit grid, where every grid spacing and area is 1, according to γ.
"""
function UnitGrid::gcmgrid;option="minimal")
nFaces=γ.nFaces
ioSize=.ioSize[1],γ.ioSize[2])

Γ=Dict()

pc=fill(0.5,2); pg=fill(0.0,2); pu=[0.,0.5]; pv=[0.5,0.];
if option=="full"
list_n=("XC","XG","YC","YG","RAC","RAW","RAS","RAZ","DXC","DXG","DYC","DYG","Depth","hFacC","hFacS","hFacW");
list_u=(u"m",u"m",u"m",u"m",u"m^2",u"m^2",u"m^2",u"m^2",u"m",u"m",u"m",u"m",u"m",1.0,1.0,1.0)
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])
elseif option=="light"
list_n=("XC","XG","YC","YG","RAC","DXC","DXG","DYC","DYG","Depth");
list_u=(u"m",u"m",u"m",u"m",u"m^2",u"m",u"m",u"m",u"m",u"m")
list_p=(pc,pg,pc,pg,pc,pu,pv,pv,pu,pc)
else
list_n=("XC","YC");
list_u=(u"°",u"°")
list_p=(pc,pc)
end

for ii=1:length(list_n);
tmp1=fill(1.,(ioSize[:]))
m=varmeta(list_u[ii],list_p[ii],missing,list_n[ii],list_n[ii]);
tmp1=γ.read(tmp1,MeshArray(γ,Float64;meta=m));
Γ[list_n[ii]]=tmp1
end

for i in 1:nFaces
(np,nq)=γ.fSize[i]
Γ["XC"][i]=vec(0.5:1.0:np-0.5)*ones(1,nq)
option=="full" ? Γ["XG"][i]=vec(0.0:1.0:np-1.0)*ones(1,nq) : nothing
Γ["YC"][i]=ones(np,1)*transpose(vec(0.5:1.0:nq-0.5))
option=="full" ? Γ["YG"][i]=ones(np,1)*transpose(vec(0.0:1.0:nq-1.0)) : nothing
end

Γ=Dict_to_NamedTuple(Γ)

return Γ

end

"""
UnitGrid(ioSize, tileSize; option="minimal")
Generate a unit grid, where every grid spacing and area is 1, according to `ioSize, tileSize`.
Since `ioSize, tileSize` defines a one to one mapping from global to tiled array, here we use
`read_tiles, write_tiles` instead of the default `read, write`. And we overwrite local `XC,YC`
etc accordingly with global `XC,YC` etc .
"""
function UnitGrid(ioSize::NTuple{2, Int},tileSize::NTuple{2, Int}; option="minimal")

nF=div(prod(ioSize),prod(tileSize))
fSize=fill(tileSize,nF)

γ=gcmgrid("","PeriodicDomain",nF,fSize, ioSize, Float32,
MeshArrays.read_tiles, MeshArrays.write_tiles)
Γ=UnitGrid(γ;option=option)

Γ.XC[:]=γ.read([i-0.5 for i in 1:ioSize[1], j in 1:ioSize[2]],γ)
Γ.YC[:]=γ.read([j-0.5 for i in 1:ioSize[1], j in 1:ioSize[2]],γ)
if option=="full"
Γ.XG[:]=γ.read([i-1.0 for i in 1:ioSize[1], j in 1:ioSize[2]],γ)
Γ.YG[:]=γ.read([j-1.0 for i in 1:ioSize[1], j in 1:ioSize[2]],γ)
end

return Γ,γ
end

"""
simple_periodic_domain(np::Integer,nq=missing)
Set up a simple periodic domain of size np x nq
```jldoctest; output = false
using MeshArrays
np=16 #domain size is np x np
Γ=simple_periodic_domain(np)
isa(Γ.XC,MeshArray)
# output
true
```
"""
function simple_periodic_domain(np::Integer,nq=missing)
ismissing(nq) ? nq=np : nothing

nFaces=1
ioSize=[np nq]
facesSize=Array{NTuple{2, Int},1}(undef,nFaces)
facesSize[:].=[(np,nq)]
ioPrec=Float32
γ=gcmgrid("","PeriodicDomain",1,facesSize, ioSize, ioPrec, read, write)

return UnitGrid(γ)
end

## GridSpec function with category argument:

"""
Expand Down Expand Up @@ -356,40 +251,7 @@ function GridLoadVar(nam::String,γ::gcmgrid)
end
end

"""
GridOfOnes(grTp,nF,nP;option="minimal")
Define all-ones grid variables instead of using `GridSpec` & `GridLoad`. E.g.
```
γ,Γ=GridOfOnes("CubeSphere",6,20);
```
"""
function GridOfOnes(grTp,nF,nP;option="minimal")

grDir=""
grTopo=grTp
nFaces=nF
if grTopo=="LatLonCap"
ioSize=[nP nP*nF]
elseif grTopo=="CubeSphere"
ioSize=[nP nP*nF]
elseif grTopo=="PeriodicChannel"
ioSize=[nP nP]
elseif grTopo=="PeriodicDomain"
nFsqrt=Int(sqrt(nF))
ioSize=[nP*nFsqrt nP*nFsqrt]
else
error("unknown configuration (grTopo)")
end
facesSize=Array{NTuple{2, Int},1}(undef,nFaces)
facesSize[:].=[(nP,nP)]
ioPrec=Float32

γ=gcmgrid(grDir,grTopo,nFaces,facesSize, ioSize, ioPrec, read, write)

return γ, UnitGrid(γ;option=option)
end
##

"""
Tiles(γ::gcmgrid,ni::Int,nj::Int)
Expand Down
Loading

0 comments on commit 07daf88

Please sign in to comment.