Skip to content

Commit 5c8c656

Browse files
authored
Merge branch 'master' into v0p5p5a
2 parents e801ed5 + 1194bdb commit 5c8c656

4 files changed

Lines changed: 74 additions & 31 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "MeshArrays"
22
uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683"
3-
version = "0.5.3"
3+
version = "0.5.4"
44
authors = ["gaelforget <gforget@mit.edu>"]
55

66
[deps]

examples/dev/NEMO_MeridionalTransports.jl

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,46 +78,79 @@ md"""## Overturning"""
7878
# ╔═╡ e4d1091d-9ae2-489b-b2fc-809e8e373079
7979
md"""## Methods"""
8080

81+
# ╔═╡ f789dcf4-a381-478f-9a5c-7676985ed754
82+
Pkg.status()
83+
8184
# ╔═╡ 5c314ad6-5e5c-40c1-b501-54d0917dad6e
82-
function read_vel_3d_array(month=1,Γ=[])
85+
function read_vel_3d_array(month=1,γ=missing; calc_uTvT=false)
8386
m=string(month)
8487
fil=joinpath(path_vo,"ORAS5_uo_2000-"*m*".nc")
8588
U=MeshArrays.NEMO_GRID.read_one(Dataset(fil)["vozocrtx"],:U,true)
8689
fil=joinpath(path_vo,"ORAS5_vo_2000-"*m*".nc")
8790
V=MeshArrays.NEMO_GRID.read_one(Dataset(fil)["vomecrty"],:V,true)
8891
fil=joinpath(path_vo,"ORAS5_thetao_2000-"*m*".nc")
8992
T=MeshArrays.NEMO_GRID.read_one(Dataset(fil)["votemper"],:T,true)
90-
(U=U,V=V,T=T)
93+
94+
if calc_uTvT
95+
TatU,TatV=MeshArrays.to_UV(read(T,γ)) #15s
96+
uT=(write(TatU).*U)
97+
vT=(write(TatV).*V)
98+
(U=U,V=V,T=T,uT=uT,vT=vT)
99+
else
100+
(U=U,V=V,T=T)
101+
end
102+
91103
end
92104

93105
# ╔═╡ 15d6085d-e2af-4285-9a30-b036c730ad83
94-
function read_vel_3d_nemoarray(month=1:12=[])
106+
function read_vel_3d_nemoarray(month=1:12=[]; option=1, verbose=false)
95107
U,V,T=(zeros(1440,1020,75),zeros(1440,1020,75),zeros(1440,1020,75))
96108
uT,vT=(zeros(1440,1020,75),zeros(1440,1020,75))
97109

110+
γ=(!haskey(Γ,:XC) ? missing : Γ.XC.grid)
98111
for m in month
99-
tmp=read_vel_3d_array(m,Γ)
100-
#
101-
tmp.U.=tmp.U.*write.hFacW)
102-
tmp.V.=tmp.V.*write.hFacS)
103-
#
104-
U.+=tmp.U./length(month)
105-
V.+=tmp.V./length(month)
106-
T.+=tmp.T./length(month)
107-
#
108-
TatU,TatV=MeshArrays.to_UV(read(tmp.T,γ))
109-
uT.+=(write(TatU).*tmp.U./length(month))
110-
vT.+=(write(TatV).*tmp.V./length(month))
112+
tmp=read_vel_3d_array(m,γ) #9s
113+
U.+=tmp.U
114+
V.+=tmp.V
115+
T.+=tmp.T
116+
#
117+
if option>1
118+
TatU,TatV=MeshArrays.to_UV(read(tmp.T,γ)) #15s
119+
uT.+=(write(TatU).*tmp.U)
120+
vT.+=(write(TatV).*tmp.V)
121+
end
111122
end
112-
(U=read(U,γ),V=read(V,γ),T=read(T,γ),uT=read(uT,γ),vT=read(vT,γ))
123+
hFacW=write.hFacW)
124+
hFacS=write.hFacS)
125+
126+
UU=read(U.*hFacW,γ)/length(month)
127+
VV=read(V.*hFacS,γ)/length(month)
128+
TT=read(T,γ)/length(month)
129+
if option>1
130+
UUT=read(uT.*hFacW,γ)/length(month)
131+
VVT=read(vT.*hFacS,γ)/length(month)
132+
(U=UU,V=VV,T=TT,uT=UUT,vT=VVT)
133+
else
134+
(U=UU,V=VV,T=TT)
135+
end
113136
end
114137

115138
# ╔═╡ dd1f651a-f665-4bb2-a0cc-0cc047227d8c
116139
begin
117-
uvt_mean=read_vel_3d_nemoarray(1:12,Γ)
140+
uvt_mean=read_vel_3d_nemoarray(1:12,option=2)
118141
(Utr,Vtr)=UVtoTransport(uvt_mean.U,uvt_mean.V,Γ)
119142
end
120143

144+
# ╔═╡ 4542e819-f76b-4188-a365-d978c9b9d038
145+
begin
146+
# uvt=read_vel_3d_nemoarray(1:1,Γ);
147+
TatU,TatV=MeshArrays.to_UV(uvt_mean.T);
148+
[heatmap(TatU[:,1]);heatmap(TatV[:,71])]
149+
end
150+
151+
# ╔═╡ 60149351-6da6-4bdb-a61b-4692ca86313a
152+
uvt_mean
153+
121154
# ╔═╡ f0723ff8-477e-4aec-b756-001d0669ffb6
122155
begin
123156
mask=ones.XC.grid)
@@ -171,7 +204,7 @@ function read_uTvT(path,Γ,month=1)
171204
uT=MeshArrays.NEMO_GRID.read_one(Dataset(fil)["uT"],:U,false)
172205
fil=joinpath(path,"ORAS5_vT_1993-"*m*".nc")
173206
vT=MeshArrays.NEMO_GRID.read_one(Dataset(fil)["vT"],:V,false)
174-
(uT,vT)
207+
(read(uT,γ),read(vT,γ))
175208
end
176209

177210
# ╔═╡ 887cdf28-25fd-4aa9-873c-14d15a0e2c28
@@ -183,7 +216,7 @@ begin
183216
vT_m=zeros.XC)
184217
for m in 1:12
185218
_uT,_vT=read_uTvT("data/NEMO_sample/monthly/",Γ,m)
186-
uT_m.+=read(_uT/12,γ); vT_m.+=read(_vT/12,γ);
219+
uT_m.+=_uT/12; vT_m.+=_vT/12;
187220
end
188221
UV=Dict("U"=>Γ.DYG*uT_m,"V"=>Γ.DXG*vT_m,"dimensions"=>["x","y"])
189222
MOHT_GF=1e-15*4e6*[ThroughFlow(UV,lc,Γ) for lc in LC]
@@ -211,6 +244,7 @@ end
211244
PLUTO_PROJECT_TOML_CONTENTS = """
212245
[deps]
213246
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
247+
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
214248
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
215249
MeshArrays = "cb8c808f-1acf-59a3-9d2b-6e38d009f683"
216250
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
@@ -2055,11 +2089,13 @@ version = "4.1.0+0"
20552089
# ╟─a62f4e07-4877-48ec-8ecc-4b5bd4c4b3c0
20562090
# ╟─887cdf28-25fd-4aa9-873c-14d15a0e2c28
20572091
# ╟─d0bcb388-503e-4729-a1e5-3c033a71b60e
2092+
# ╠═cf6c5965-4b50-4370-a428-f4feb3f19396
20582093
# ╠═4542e819-f76b-4188-a365-d978c9b9d038
20592094
# ╠═dd1f651a-f665-4bb2-a0cc-0cc047227d8c
20602095
# ╟─689989e4-5865-4034-8c56-731caff35334
20612096
# ╟─cb328ede-795e-43d6-8a73-ca7b61ea652b
20622097
# ╟─aebc7ac0-b7b9-4a73-a015-44bc64530d9e
2098+
# ╠═60149351-6da6-4bdb-a61b-4692ca86313a
20632099
# ╟─06a1e780-9d69-4fc5-8b67-c105813999e0
20642100
# ╟─b53e4149-cb41-4bac-bb55-b8b2e8c202b6
20652101
# ╠═b329f537-50ca-4f1c-8986-4216af5719af

src/Operations.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,21 @@ function to_UV_3d(inFLD::AbstractMeshArray)
9191
TatU,TatV
9292
end
9393

94-
function to_UV_3d!(inFLD::AbstractMeshArray,TatU::AbstractMeshArray,TatV::AbstractMeshArray)
95-
tmpU=similar(inFLD[:,1])
96-
tmpV=similar(inFLD[:,1])
97-
for k in 1:size(inFLD)[2]
94+
function to_UV_3d!(inFLD::AbstractMeshArray,
95+
TatU::AbstractMeshArray,TatV::AbstractMeshArray;
96+
verbose=false)
97+
tmpU=similar(inFLD[:,1])
98+
tmpV=similar(inFLD[:,1])
99+
verbose ? println(size(inFLD)[2]) : nothing
100+
for k in 1:size(inFLD)[2]
101+
verbose ? println(k) : nothing
98102
exFLD=exchange(inFLD[:,k])
99103
to_UV_2d!(exFLD,tmpU,tmpV)
100-
TatU.f[:,k].=tmpU.f
101-
TatV.f[:,k].=tmpV.f
102-
end
104+
for i in 1:size(inFLD)[1]
105+
TatU[i,k].=tmpU[i]
106+
TatV[i,k].=tmpV[i]
107+
end
108+
end
103109
end
104110

105111
function to_UV_2d(inFLD::AbstractMeshArray)

src/grids/NEMO.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ function convert_one_grid_variable(grid_data,df_line;
109109
read_one(grid_data[nam_in],loc,is_3d)
110110
end
111111

112-
nomissing64(x) = [(ismissing(a) ? 0 : Float64(a)) for a in x]
113-
nomissing64(x::UnitRange) = Float64.(x)
112+
nomissing64(x::Array) = nomissing64.(x)
113+
nomissing64(x::UnitRange) = nomissing64.(x)
114+
nomissing64(a) = (ismissing(a) ? 0 : Float64(a))
114115
nonan64(x) = [(isnan(a) ? 0 : Float64(a)) for a in x]
115116

116117
function read_one(fld,loc,is_3d)
@@ -245,7 +246,7 @@ function add_one_dim_variables!(grid,grid_data; verbose=false)
245246

246247
fac=(in(nam_out,[:RC,:RF]) ? -1 : 1)
247248
verbose ? println(typeof(grid_data[nam_in])) : nothing
248-
tmp=fac*nomissing64.(grid_data[nam_in][:])
249+
tmp=fac*nomissing64(grid_data[nam_in][:])
249250
merge!(grid,Dict(nam_out=>tmp))
250251
end
251252
end
@@ -258,7 +259,7 @@ function overwrite_hFac!(Γ,ds; verbose=false)
258259
e3t=read_one(ds["e3t_0_field"],:T,true)
259260
e3u=read_one(ds["e3u_0_field"],:U,true)
260261
e3v=read_one(ds["e3v_0_field"],:V,true)
261-
#why is e3t_0_field ~ 2xDRF at last point?
262+
#why is e3t_0_field ~ 2xDRF at last point?
262263
#and this seems necessary to compute correct top-bottom transports
263264
# e3t[:,:,end-1].=e3t[:,:,end-1]./2
264265
# e3u[:,:,end-1].=e3u[:,:,end-1]./2

0 commit comments

Comments
 (0)