Skip to content

Commit 33cc1a2

Browse files
authored
Merge pull request #152 from gaelforget/v0p3p15a
V0p3p15a
2 parents 29a6194 + 032d10e commit 33cc1a2

10 files changed

+118
-54
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MeshArrays"
22
uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683"
33
authors = ["gaelforget <[email protected]>"]
4-
version = "0.3.14"
4+
version = "0.3.15"
55

66
[deps]
77
CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31"

docs/src/API.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ AbstractMeshArray
99
MeshArrays.gcmarray
1010
gcmgrid
1111
varmeta
12+
gridpath
13+
gridmask
1214
```
1315

1416
More :
@@ -21,7 +23,6 @@ MeshArrays.gcmfaces
2123
## 2. Grids And I/O
2224

2325
```@docs
24-
UnitGrid
2526
simple_periodic_domain
2627
GridSpec
2728
GridLoad
@@ -37,6 +38,7 @@ exchange
3738
MeshArrays.read
3839
MeshArrays.read!
3940
MeshArrays.write
41+
UnitGrid
4042
```
4143

4244
## 3. Interpolation
@@ -62,11 +64,19 @@ UVtoTransport
6264
UVtoUEVN
6365
```
6466

65-
## 5. Other
67+
## 5. Integration
68+
69+
```@docs
70+
Integration.loops
71+
```
72+
73+
## 6. Other
6674

6775
```@docs
6876
LatitudeCircles
6977
Transect
78+
demo.ocean_basins
79+
demo.extended_basin
7080
isosurface
71-
MA_datadep
81+
MeshArrays.mydatadep
7282
```

ext/MeshArraysDataDepsExt.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
module MeshArraysDataDepsExt
33

44
using DataDeps, MeshArrays
5-
import MeshArrays: MA_datadep
5+
import MeshArrays: mydatadep
66

77

88
__init__() = begin
@@ -23,7 +23,7 @@ module MeshArraysDataDepsExt
2323

2424

2525
"""
26-
MA_datadep(nam="countries_shp1")
26+
mydatadep(nam="countries_shp1")
2727
2828
Download data dependency with predefined name; currently :
2929
@@ -34,7 +34,7 @@ module MeshArraysDataDepsExt
3434
"interp_halfdeg"
3535
```
3636
"""
37-
MA_datadep(nam="countries_shp1") = begin
37+
mydatadep(nam="countries_shp1") = begin
3838
withenv("DATADEPS_ALWAYS_ACCEPT"=>true) do
3939
if nam=="countries_shp1"
4040
datadep"countries_shp1"

src/Grids.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ end
231231
- option :
232232
- (default) option=:minimal means that only grid cell center positions (XC, YC) are loaded.
233233
- option=:full provides a complete set of 2D grid variables.
234-
- option=:full provides a complete set of 2D & 3d grid variables.
234+
- option=:full provides a complete set of 2D & 3D grid variables.
235235
236236
Based on the MITgcm naming convention, grid variables are:
237237

src/Integration.jl

+41-36
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import MeshArrays: demo, MeshArray, gridmask
88

99
##
1010

11-
example(;option=:hv,regions=:dlat_10,depths=[(0,7000)]) = begin
11+
example(;option=:loops,regions=:dlat_10,depths=[(0,7000)]) = begin
1212
g=GridSpec(ID=:LLC90); Γ=GridLoad(g)
1313
G=(hFacC=GridLoadVar("hFacC",g),RF=GridLoadVar("RF",g),
1414
RC=GridLoadVar("RC",g),RAC=GridLoadVar("RAC",g),
1515
DRF=GridLoadVar("DRF",g))
1616
G=merge(Γ,G)
1717

18-
M=define_boxes(option=option, regions=regions, grid=G, depths=depths)
18+
M=define_sums(option=option, regions=regions, grid=G, depths=depths)
1919

2020
diags=joinpath(pwd(),"diags")
2121
files=glob("state_3d_set1*.data",diags)
@@ -89,11 +89,11 @@ layer_mask(dF,d0,d1)=begin
8989
end
9090

9191
"""
92-
define_boxes(;option=:hv,grid::NamedTuple, regions=:basins, depths=[(0,7000)])
92+
define_sums(;option=:loops, grid::NamedTuple, regions=:basins, depths=[(0,7000)])
9393
9494
Define regional integration function for each basin and depth range.
9595
"""
96-
function define_boxes(;option=:hv, grid::NamedTuple, regions=:basins, depths=[(0,7000)])
96+
function define_sums(;option=:loops, grid::NamedTuple, regions=:basins, depths=[(0,7000)])
9797
dep=(isa(depths,Tuple) ? [depths] : depths)
9898
nd=length(dep)
9999
rgns=define_regions(option=regions,grid=grid)
@@ -118,7 +118,7 @@ function define_boxes(;option=:hv, grid::NamedTuple, regions=:basins, depths=[(0
118118
tmp2d
119119
end
120120

121-
if option==:full
121+
if option==:streamlined_loop
122122
#ocn_surf=[sum(xymsk(b)*(grid.hFacC[:,1].>0)*grid.RAC) for b in 1:nb]
123123
BX=(name=String[],volsum=Function[],volume=Float64[],
124124
ocn_surf=Float64[],tmp2d=tmp2d,tmp3d=tmp3d)
@@ -153,9 +153,9 @@ function define_boxes(;option=:hv, grid::NamedTuple, regions=:basins, depths=[(0
153153
push!(BXv.vint,f)
154154
end
155155

156-
if option==:hv
156+
if option==:loops
157157
gridmask(rgns.map,BXh.name,depths,BXh.hsum,BXv.vint,tmp2d,tmp3d)
158-
elseif option==:full
158+
elseif option==:streamlined_loop
159159
gridmask(rgns.map,BX.name,depths,BX.volsum,[],tmp2d,tmp3d)
160160
else
161161
error("unknown option")
@@ -165,17 +165,18 @@ end
165165
#nonan(x)=[(isnan(y) ? 0.0 : y) for y in x]
166166

167167
"""
168-
loop(boxes::NamedTuple; files=String[], var=:THETA, rd=read)
168+
loops(mask::gridmask; files=String[], var=:THETA, rd=read)
169169
170170
```
171171
begin
172-
@everywhere using MeshArrays, MITgcm
173-
@everywhere rd(F,var,tmp)=read(read_mdsio(F,var),tmp)
174-
@everywhere G,M,files=Integration.example(option=:hv)
175-
#,regions=(30,10),depths=Integration.DEPTHS)
172+
@everywhere using MeshArrays, MITgcm
173+
@everywhere rd(F,var,tim,tmp)=read(read_mdsio(F,var),tmp)
174+
@everywhere G,M,files=Integration.example()
175+
#,regions=(30,10),depths=Integration.DEPTHS)
176176
end;
177-
#H_3d=Integration.loop_3d(M,files=files,rd=rd)
178-
H_hv=Integration.loop_hv(M,files=files,rd=rd)
177+
178+
H=Integration.loops(M,files=files,rd=rd)
179+
# Hbis=Integration.streamlined_loop(M,files=files,rd=rd)
179180
```
180181
181182
and to save results:
@@ -188,55 +189,59 @@ jldsave(output_path; depths=M.depths, integral=H, volume=vol, name=M.names)
188189
where vol is calculated as follows:
189190
190191
```
191-
#option=:other
192-
allones=1.0 .+0*G.hFacC
193-
vol=[b(allones) for b in M.h_sum]
192+
#option=:loops
193+
M.tmp2d.=M.v_int[1](allones)
194+
vol=[b(M.tmp2d) for b in M.h_sum]
194195
```
195196
196197
or
197198
198199
```
199-
#option=:hv
200-
M.tmp2d.=M.v_int[1](allones)
201-
vol=[b(M.tmp2d) for b in M.h_sum]
200+
#option=:streamlined_loop
201+
allones=1.0 .+0*G.hFacC
202+
vol=[b(allones) for b in M.h_sum]
202203
```
203204
"""
204-
function loop_3d(boxes::gridmask; files=String[], var=:THETA, rd=read)
205+
function loops(mask::gridmask; files=String[], var=:THETA, rd=read)
205206
nt=length(files)
206-
nb=length(boxes.names)
207-
BA=SharedArray{Float64}(nb,nt)
207+
nh=length(mask.names)
208+
nv=length(mask.depths)
209+
BA=SharedArray{Float64}(nh,nv,nt)
208210
@sync @distributed for t in 1:nt
209211
mod(t,10)==0 ? println(t) : nothing
210212
F=files[t]
211213
ext=split(F,".")[end]
212-
boxes.tmp3d.=rd(F,var,boxes.tmp3d)
213-
BA[:,t]=[b(boxes.tmp3d) for b in boxes.h_sum]
214+
mask.tmp3d.=rd(F,var,t,mask.tmp3d)
215+
for layer in 1:nv
216+
mask.tmp2d.=mask.v_int[layer](mask.tmp3d)
217+
BA[:,layer,t]=[b(mask.tmp2d) for b in mask.h_sum]
218+
end
214219
GC.gc()
215220
end
216221
BA
217222
end
218223

219-
##
224+
"""
225+
streamlined_loop(mask::gridmask; files=String[], var=:THETA, rd=read)
220226
221-
function loop_hv(boxes::gridmask; files=String[], var=:THETA, rd=read)
227+
Alternate approach to loops, where loops are streamlined in a single dimension.
228+
"""
229+
function streamlined_loop(mask::gridmask; files=String[], var=:THETA, rd=read)
222230
nt=length(files)
223-
nh=length(boxes.names)
224-
nv=length(boxes.depths)
225-
BA=SharedArray{Float64}(nh,nv,nt)
231+
nb=length(mask.names)
232+
BA=SharedArray{Float64}(nb,nt)
226233
@sync @distributed for t in 1:nt
227234
mod(t,10)==0 ? println(t) : nothing
228235
F=files[t]
229236
ext=split(F,".")[end]
230-
boxes.tmp3d.=rd(F,var,boxes.tmp3d)
231-
for layer in 1:nv
232-
boxes.tmp2d.=boxes.v_int[layer](boxes.tmp3d)
233-
BA[:,layer,t]=[b(boxes.tmp2d) for b in boxes.h_sum]
234-
#dH0[i]=nansum(write(dT*(G.b_i.==i)))
235-
end
237+
mask.tmp3d.=rd(F,var,mask.tmp3d)
238+
BA[:,t]=[b(mask.tmp3d) for b in mask.h_sum]
236239
GC.gc()
237240
end
238241
BA
239242
end
240243

244+
##
245+
241246
end
242247

src/Interpolation.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function interpolation_setup(;Γ=NamedTuple(),
247247
lat=[j for i=-179.:2.0:179., j=-89.:2.0:89.])
248248

249249
if isempty(Γ)
250-
fil=joinpath(MeshArrays.MA_datadep("interp_halfdeg"),"interp_coeffs_halfdeg.jld2")
250+
fil=joinpath(MeshArrays.mydatadep("interp_halfdeg"),"interp_coeffs_halfdeg.jld2")
251251
else
252252
(f,i,j,w)=InterpolationFactors(Γ,vec(lon),vec(lat))
253253
fil=tempname()*"_interp_coeffs.jld2"

src/MeshArrays.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export StereographicProjection, isosurface
5050
#export location_is_out, NeighborTileIndices_dpdo, NeighborTileIndices_cs, RelocationFunctions_cs
5151
#export update_location_cs!, update_location_llc!, update_location_dpdo!
5252

53-
function MA_datadep end
53+
function mydatadep end
54+
55+
MA_datadep=mydatadep
5456
export MA_datadep
5557

5658
function plot_examples end; export plot_examples

src/Types.jl

+5
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ end
256256
gridmask
257257
258258
gridmask data structure.
259+
260+
```
261+
G,M,files=Integration.example()
262+
M
263+
```
259264
"""
260265
Base.@kwdef struct gridmask
261266
map::MeshArray

src/demo.jl

+47-6
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,62 @@ module demo
110110
"""
111111
ocean_basins()
112112
113-
Map of ocean basins on ECCO grid.
113+
Mask of ocean basins on ECCO grid (LLC90).
114114
115115
```
116116
basins=demo.ocean_basins()
117+
AtlExt=extended_basin(basins,:Atl)
117118
```
118119
"""
119120
function ocean_basins()
120-
γ=GridSpec("LatLonCap",GRID_LLC90)
121+
γ=GridSpec(ID=:LLC90)
121122
fil_basin=joinpath(GRID_LLC90,"v4_basin.bin")
122-
basins=(map=read(fil_basin,MeshArray(γ,Float32)),
123+
basins=(mask=read(fil_basin,MeshArray(γ,Float32)),
123124
name=["Pacific","Atlantic","indian","Arctic","Bering Sea","South China Sea","Gulf of Mexico",
124125
"Okhotsk Sea","Hudson Bay","Mediterranean Sea","Java Sea","North Sea","Japan Sea",
125126
"Timor Sea","East China Sea","Red Sea","Gulf","Baffin Bay","GIN Seas","Barents Sea"])
126127
end
127128

129+
130+
list_Atl=["Atlantic","Gulf of Mexico","Hudson Bay","Mediterranean Sea","North Sea","Baffin Bay","GIN Seas"]
131+
list_Pac=["Pacific","Bering Sea","Okhotsk Sea","Japan Sea","East China Sea"]
132+
list_Ind=["indian","South China Sea","Java Sea","Timor Sea","Red Sea","Gulf"]
133+
list_Arc=["Arctic","Barents Sea"]
134+
135+
"""
136+
extended_basin(basins,ID=:Atl)
137+
138+
Consolidate basins mask to include marginal seas.
139+
140+
note : has only be tested on the ECCO grid (LLC90).
141+
142+
```
143+
basins=demo.ocean_basins()
144+
AtlExt=extended_basin(basins,:Atl)
145+
```
146+
"""
147+
function extended_basin(basins,ID=:Atl)
148+
list_basins=if ID==:Pac
149+
list_Pac
150+
elseif ID==:Atl
151+
list_Atl
152+
elseif ID==:Ind
153+
list_Ind
154+
elseif ID==:Arc
155+
list_Arc
156+
else
157+
error("unknown basin")
158+
end
159+
160+
mask=0*basins.mask
161+
for i in list_basins
162+
println(i)
163+
jj=findall(basins.name.==i)[1]
164+
mask.=mask+1.0*(basins.mask.==jj)
165+
end
166+
mask
167+
end
168+
128169
"""
129170
download_polygons(ID::String)
130171
@@ -135,9 +176,9 @@ module demo
135176
"""
136177
function download_polygons(ID::String)
137178
if ID=="ne_110m_admin_0_countries.shp"
138-
joinpath(MeshArrays.MA_datadep("countries_shp1"),"ne_110m_admin_0_countries.shp")
179+
joinpath(MeshArrays.mydatadep("countries_shp1"),"ne_110m_admin_0_countries.shp")
139180
elseif ID=="countries.geojson"
140-
joinpath(MeshArrays.MA_datadep("countries_geojson1"),"countries.geojson")
181+
joinpath(MeshArrays.mydatadep("countries_geojson1"),"countries.geojson")
141182
else
142183
error("unknown data dependency")
143184
end
@@ -153,7 +194,7 @@ module demo
153194
lat=[j for i=-0.05:dx:359.95, j=-89.95:dx:89.95];
154195
lon=[i for i=-0.05:dx:359.95, j=-89.95:dx:89.95];
155196

156-
earth_jpg=joinpath(MeshArrays.MA_datadep("basemap_jpg1"),
197+
earth_jpg=joinpath(MeshArrays.mydatadep("basemap_jpg1"),
157198
"Blue_Marble_Next_Generation_%2B_topography_%2B_bathymetry.jpg")
158199

159200
earth_img=read_JLD2(earth_jpg)

test/runtests.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end
5050
end
5151

5252
@testset "Regional Integration:" begin
53-
G,M,files=Integration.example(option=:hv)
53+
G,M,files=Integration.example()
5454

5555
allones=1.0 .+0*G.hFacC
5656
vol0=sum(G.RAC*G.DRF*G.hFacC)
@@ -59,7 +59,7 @@ end
5959
vol=[b(M.tmp2d) for b in M.h_sum]
6060
@test isapprox(sum(vol),vol0)
6161

62-
G,M,files=Integration.example(option=:full)
62+
G,M,files=Integration.example(option=:streamlined_loop)
6363
vol=[b(allones) for b in M.h_sum]
6464
@test isapprox(sum(vol),vol0)
6565

@@ -230,6 +230,7 @@ end
230230
λ=interpolation_setup()
231231

232232
basins=demo.ocean_basins()
233+
AtlExt=demo.extended_basin(basins,:Atl)
233234
sections,path_sec=demo.ocean_sections(Γ)
234235
my_section=demo.one_section(Γ,[127 127],[-25 -68])
235236

0 commit comments

Comments
 (0)