@@ -130,27 +130,39 @@ function simple_periodic_domain(np::Integer,nq=missing)
130
130
return UnitGrid (γ)
131
131
end
132
132
133
- # # GridSpec function with default GridName argument:
133
+ # # GridSpec function with category argument:
134
134
135
- GridSpec () = GridSpec (" PeriodicDomain" ," ./" )
135
+ """
136
+ GridSpec(category="PeriodicDomain",path=tempname(); ID=:unknown)
136
137
137
- # # GridSpec function with GridName argument:
138
+ - Select one of the pre-defined grids either by ID (keyword) or by category.
139
+ - Return the corresponding `gcmgrid` specification, including the path where grid files can be accessed (`path`).
138
140
139
- """
140
- GridSpec(GridName,GridParentDir="./")
141
+ 1. selection by `ID`
141
142
142
- Select one of the pre-defined grids (by `GridName`) and return
143
- the corresponding `gcmgrid` -- a global grid specification
144
- which contains the grid files location (`GridParentDir`).
145
-
143
+ - `:LLC90`
144
+ - `:CS32`
145
+ - `:onedegree`
146
+ - `:default`
147
+
148
+ Example:
149
+
150
+ ```
151
+ using MeshArrays
152
+ g = GridSpec(ID=:LLC90)
153
+ ```
154
+
155
+ note : the path to these fully supported grids are handled internally in `MeshArrays.jl`.
146
156
147
- Possible choices for `GridName`:
157
+ 2. by `category` and `path`
148
158
149
159
- `"PeriodicDomain"`
150
160
- `"PeriodicChannel"`
151
161
- `"CubeSphere"`
152
162
- `"LatLonCap"``
153
163
164
+ Examples:
165
+
154
166
```jldoctest; output = false
155
167
using MeshArrays
156
168
g = GridSpec()
@@ -164,51 +176,62 @@ isa(g,gcmgrid)
164
176
true
165
177
```
166
178
"""
167
- function GridSpec (GridName,GridParentDir = " ./ " )
179
+ function GridSpec (category = " PeriodicDomain " ,path = tempname (); ID = :unknown )
168
180
169
- grDir= GridParentDir
170
- if GridName== " LatLonCap"
181
+ if category== " LatLonCap"
171
182
nFaces= 5
172
183
grTopo= " LatLonCap"
173
184
ioSize= [90 1170 ]
174
185
facesSize= [(90 , 270 ), (90 , 270 ), (90 , 90 ), (270 , 90 ), (270 , 90 )]
175
186
ioPrec= Float64
176
- elseif GridName == " CubeSphere"
187
+ elseif category == " CubeSphere"
177
188
nFaces= 6
178
189
grTopo= " CubeSphere"
179
190
ioSize= [32 192 ]
180
191
facesSize= [(32 , 32 ), (32 , 32 ), (32 , 32 ), (32 , 32 ), (32 , 32 ), (32 , 32 )]
181
192
ioPrec= Float32
182
- elseif GridName == " PeriodicChannel"
193
+ elseif category == " PeriodicChannel"
183
194
nFaces= 1
184
195
grTopo= " PeriodicChannel"
185
196
ioSize= [360 160 ]
186
197
facesSize= [(360 , 160 )]
187
198
ioPrec= Float32
188
- elseif GridName == " PeriodicDomain"
199
+ elseif category == " PeriodicDomain"
189
200
nFaces= 4
190
201
grTopo= " PeriodicDomain"
191
202
ioSize= [80 42 ]
192
203
facesSize= [(40 , 21 ), (40 , 21 ), (40 , 21 ), (40 , 21 )]
193
204
ioPrec= Float32
194
205
else
195
- error (" unknown GridName case" )
206
+ error (" unknown category case" )
196
207
end
197
208
198
- return gcmgrid (grDir,grTopo,nFaces,facesSize, ioSize, ioPrec, read, write)
209
+ if ID== :unknown
210
+ gcmgrid (path,grTopo,nFaces,facesSize, ioSize, ioPrec, read, write)
211
+ elseif ID== :LLC90
212
+ GridSpec (" LatLonCap" ,MeshArrays. GRID_LLC90)
213
+ elseif ID== :CS32
214
+ GridSpec (" CubeSphere" ,MeshArrays. GRID_CS32)
215
+ elseif ID== :onedegree
216
+ GridSpec (" PeriodicChannel" ,MeshArrays. GRID_LL360)
217
+ elseif ID== :default
218
+ GridSpec ()
219
+ else
220
+ error (" unknwown grid" )
221
+ end
199
222
200
223
end
201
224
202
225
# # GridLoad function
203
226
204
227
"""
205
- GridLoad(γ::gcmgrid; option=" minimal" )
228
+ GridLoad(γ=GridSpec(); ID=:default, option=: minimal)
206
229
207
- Return a `NamedTuple` of grid variables read from files located in `γ.path` (see `?GridSpec`).
208
-
209
- By default, option=" minimal" means that only grid cell center positions (XC, YC) are loaded.
210
-
211
- The "full" option provides a complete set of grid variables.
230
+ - Return a `NamedTuple` of grid variables read from files located in `γ.path` (see `?GridSpec`).
231
+ - option :
232
+ - ( default) option=: minimal means that only grid cell center positions (XC, YC) are loaded.
233
+ - option=:full provides a complete set of 2D grid variables.
234
+ - option=:full provides a complete set of 2D & 3d grid variables.
212
235
213
236
Based on the MITgcm naming convention, grid variables are:
214
237
@@ -222,11 +245,7 @@ https://mitgcm.readthedocs.io/en/latest/algorithm/algorithm.html#spatial-discret
222
245
223
246
```jldoctest; output = false
224
247
using MeshArrays
225
-
226
- γ = GridSpec("CubeSphere",MeshArrays.GRID_CS32)
227
- #γ = GridSpec("LatLonCap",MeshArrays.GRID_LLC90)
228
- #γ = GridSpec("PeriodicChannel",MeshArrays.GRID_LL360)
229
-
248
+ γ = GridSpec(ID=:LLC90)
230
249
Γ = GridLoad(γ;option="full")
231
250
232
251
isa(Γ.XC,MeshArray)
@@ -236,33 +255,38 @@ isa(Γ.XC,MeshArray)
236
255
true
237
256
```
238
257
"""
239
- function GridLoad (γ:: gcmgrid ;option= " minimal" )
258
+ function GridLoad (γ= GridSpec (); ID= :default , option= :minimal )
259
+
260
+ gr = (ID!= = :default ? GridSpec (ID= ID) : γ)
240
261
241
- γ . path== GRID_CS32 ? GRID_CS32_download () : nothing
242
- γ . path== GRID_LL360 ? GRID_LL360_download () : nothing
243
- γ . path== GRID_LLC90 ? GRID_LLC90_download () : nothing
262
+ gr . path== GRID_CS32 ? GRID_CS32_download () : nothing
263
+ gr . path== GRID_LL360 ? GRID_LL360_download () : nothing
264
+ gr . path== GRID_LLC90 ? GRID_LLC90_download () : nothing
244
265
245
266
Γ= Dict ()
246
267
247
- if option== " full"
248
- list_n= (" XC" ," XG" ," YC" ," YG" ," RAC" ," RAW" ," RAS" ," RAZ" ," DXC" ," DXG" ," DYC" ," DYG" ," Depth" );
249
- if (! isempty (filter (x -> occursin (" AngleCS" ,x), readdir (γ. path))))
268
+ op= string (option)
269
+ if op== " full"
270
+ list_n= (" XC" ," XG" ," YC" ," YG" ," RAC" ," RAW" ," RAS" ," RAZ" ," DXC" ," DXG" ," DYC" ," DYG" ," Depth" )
271
+ if (! isempty (filter (x -> occursin (" AngleCS" ,x), readdir (gr. path))))
250
272
list_n= (list_n... ," AngleCS" ," AngleSN" );
251
273
end
252
274
list_n= (list_n... ," DRC" ," DRF" ," RC" ," RF" )
253
- list_n= (list_n... ," hFacC" ," hFacS" ," hFacW" );
254
- elseif option == " light"
255
- list_n= (" XC" ," XG" ," YC" ," YG" ," RAC" ," DXC" ," DXG" ," DYC" ," DYG" ," Depth" );
256
- if (! isempty (filter (x -> occursin (" AngleCS" ,x), readdir (γ . path))))
257
- list_n= (list_n... ," AngleCS" ," AngleSN" );
275
+ list_n= (list_n... ," hFacC" ," hFacS" ," hFacW" )
276
+ elseif op == " light"
277
+ list_n= (" XC" ," XG" ," YC" ," YG" ," RAC" ," DXC" ," DXG" ," DYC" ," DYG" ," Depth" )
278
+ if (! isempty (filter (x -> occursin (" AngleCS" ,x), readdir (gr . path))))
279
+ list_n= (list_n... ," AngleCS" ," AngleSN" )
258
280
end
259
281
list_n= (list_n... ," DRC" ," DRF" ," RC" ," RF" )
282
+ elseif op== " minimal" || op== " minimum"
283
+ list_n= (" XC" ," YC" )
260
284
else
261
- list_n = ( " XC " , " YC " );
285
+ error ( " unknown option " )
262
286
end
263
287
264
- [Γ[ii]= GridLoadVar (ii,γ ) for ii in list_n]
265
- option== " full" ? GridAddWS! (Γ) : nothing
288
+ [Γ[ii]= GridLoadVar (ii,gr ) for ii in list_n]
289
+ option== " full" || option == " light " ? GridAddWS! (Γ) : nothing
266
290
return Dict_to_NamedTuple (Γ)
267
291
end
268
292
0 commit comments