@@ -8,14 +8,14 @@ import MeshArrays: demo, MeshArray, gridmask
8
8
9
9
# #
10
10
11
- example (;option= :hv ,regions= :dlat_10 ,depths= [(0 ,7000 )]) = begin
11
+ example (;option= :loops ,regions= :dlat_10 ,depths= [(0 ,7000 )]) = begin
12
12
g= GridSpec (ID= :LLC90 ); Γ= GridLoad (g)
13
13
G= (hFacC= GridLoadVar (" hFacC" ,g),RF= GridLoadVar (" RF" ,g),
14
14
RC= GridLoadVar (" RC" ,g),RAC= GridLoadVar (" RAC" ,g),
15
15
DRF= GridLoadVar (" DRF" ,g))
16
16
G= merge (Γ,G)
17
17
18
- M= define_boxes (option= option, regions= regions, grid= G, depths= depths)
18
+ M= define_sums (option= option, regions= regions, grid= G, depths= depths)
19
19
20
20
diags= joinpath (pwd ()," diags" )
21
21
files= glob (" state_3d_set1*.data" ,diags)
@@ -89,11 +89,11 @@ layer_mask(dF,d0,d1)=begin
89
89
end
90
90
91
91
"""
92
- define_boxes (;option=:hv, grid::NamedTuple, regions=:basins, depths=[(0,7000)])
92
+ define_sums (;option=:loops, grid::NamedTuple, regions=:basins, depths=[(0,7000)])
93
93
94
94
Define regional integration function for each basin and depth range.
95
95
"""
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 )])
97
97
dep= (isa (depths,Tuple) ? [depths] : depths)
98
98
nd= length (dep)
99
99
rgns= define_regions (option= regions,grid= grid)
@@ -118,7 +118,7 @@ function define_boxes(;option=:hv, grid::NamedTuple, regions=:basins, depths=[(0
118
118
tmp2d
119
119
end
120
120
121
- if option== :full
121
+ if option== :streamlined_loop
122
122
# ocn_surf=[sum(xymsk(b)*(grid.hFacC[:,1].>0)*grid.RAC) for b in 1:nb]
123
123
BX= (name= String[],volsum= Function[],volume= Float64[],
124
124
ocn_surf= Float64[],tmp2d= tmp2d,tmp3d= tmp3d)
@@ -153,9 +153,9 @@ function define_boxes(;option=:hv, grid::NamedTuple, regions=:basins, depths=[(0
153
153
push! (BXv. vint,f)
154
154
end
155
155
156
- if option== :hv
156
+ if option== :loops
157
157
gridmask (rgns. map,BXh. name,depths,BXh. hsum,BXv. vint,tmp2d,tmp3d)
158
- elseif option== :full
158
+ elseif option== :streamlined_loop
159
159
gridmask (rgns. map,BX. name,depths,BX. volsum,[],tmp2d,tmp3d)
160
160
else
161
161
error (" unknown option" )
@@ -165,17 +165,18 @@ end
165
165
# nonan(x)=[(isnan(y) ? 0.0 : y) for y in x]
166
166
167
167
"""
168
- loop(boxes::NamedTuple ; files=String[], var=:THETA, rd=read)
168
+ loops(mask::gridmask ; files=String[], var=:THETA, rd=read)
169
169
170
170
```
171
171
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)
176
176
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)
179
180
```
180
181
181
182
and to save results:
@@ -188,55 +189,59 @@ jldsave(output_path; depths=M.depths, integral=H, volume=vol, name=M.names)
188
189
where vol is calculated as follows:
189
190
190
191
```
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]
194
195
```
195
196
196
197
or
197
198
198
199
```
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]
202
203
```
203
204
"""
204
- function loop_3d (boxes :: gridmask ; files= String[], var= :THETA , rd= read)
205
+ function loops (mask :: gridmask ; files= String[], var= :THETA , rd= read)
205
206
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)
208
210
@sync @distributed for t in 1 : nt
209
211
mod (t,10 )== 0 ? println (t) : nothing
210
212
F= files[t]
211
213
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
214
219
GC. gc ()
215
220
end
216
221
BA
217
222
end
218
223
219
- # #
224
+ """
225
+ streamlined_loop(mask::gridmask; files=String[], var=:THETA, rd=read)
220
226
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)
222
230
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)
226
233
@sync @distributed for t in 1 : nt
227
234
mod (t,10 )== 0 ? println (t) : nothing
228
235
F= files[t]
229
236
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]
236
239
GC. gc ()
237
240
end
238
241
BA
239
242
end
240
243
244
+ # #
245
+
241
246
end
242
247
0 commit comments