Skip to content

Commit 640f75b

Browse files
authored
Merge pull request #168 from jbisits/fixpkgdeps
Fix dependencies + clean up `output_utils.jl`
2 parents 0da0eac + 69f9d36 commit 640f75b

File tree

3 files changed

+2
-191
lines changed

3 files changed

+2
-191
lines changed

Project.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
name = "TwoLayerDirectNumericalShenanigans"
22
uuid = "40aaee9f-3595-48be-b36c-f1067009652f"
33
authors = ["Josef Bisits <[email protected]>"]
4-
version = "0.6.0"
4+
version = "0.6.1"
55

66
[deps]
77
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
88
GibbsSeaWater = "9a22fb26-0b63-4589-b28e-8f9d0b5c3d05"
99
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
1010
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
11-
OceanRasterConversions = "07ff2621-03e0-4bfb-9812-e5d28c6dbff8"
1211
Oceananigans = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09"
1312
Oceanostics = "d0ccf422-c8fb-49b5-a76d-74acdde946ac"
1413
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
@@ -29,7 +28,6 @@ CairoMakie = "0.10"
2928
GibbsSeaWater = "0.1"
3029
JLD2 = "0.4"
3130
NCDatasets = "0.12, 0.13"
32-
OceanRasterConversions = "0.5"
3331
Oceananigans = "0.89"
3432
Oceanostics = "0.11, 0.12, 0.13"
3533
Reexport = "1.2"

src/TwoLayerDirectNumericalShenanigans.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module TwoLayerDirectNumericalShenanigans
22

3-
using Oceananigans, Printf, Reexport, JLD2, Rasters, NCDatasets, GibbsSeaWater
3+
using Oceananigans, Printf, Reexport, JLD2, NCDatasets, GibbsSeaWater
44
using Oceananigans: AbstractModel, Operators.ℑzᵃᵃᶜ
55
using Oceananigans: Models.seawater_density
66
using SeawaterPolynomials: BoussinesqEquationOfState
@@ -9,7 +9,6 @@ using SeawaterPolynomials.SecondOrderSeawaterPolynomials
99
import SeawaterPolynomials.ρ
1010
using SpecialFunctions: erf
1111
using Oceanostics: KineticEnergyDissipationRate
12-
using OceanRasterConversions: get_σₚ
1312
using CUDA: allowscalar, CuArray
1413
import Base: show, iterate
1514

src/output_utils.jl

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,3 @@
1-
"""
2-
function compute_density(S_timeseries::FieldTimeSeries, T_timeseries::FieldTimeSeries;
3-
reference_pressure = 0)
4-
Return a density `FieldTimeSeries` calculated from the salinity and temperature
5-
`FieldTimeSeries` DNS simulation output. The keyword argument `reference_pressure` can be
6-
passed to specify a reference pressure at which to compute the density variable.
7-
"""
8-
function compute_density(S_timeseries::FieldTimeSeries, T_timeseries::FieldTimeSeries;
9-
reference_pressure = 0)
10-
11-
ρ_ts = FieldTimeSeries{Center, Center, Center}(S_timeseries.grid, S_timeseries.times,
12-
indices = S_timeseries.indices,
13-
boundary_conditions =
14-
S_timeseries.boundary_conditions)
15-
16-
t = S_timeseries.times
17-
for i eachindex(t)
18-
Sᵢ, Θᵢ = S_timeseries[i], T_timeseries[i]
19-
ρ_ts[i] .= @at (Center, Center, Center) gsw_rho.(Sᵢ, Θᵢ, reference_pressure)
20-
end
21-
22-
return ρ_ts
23-
24-
end
25-
"""
26-
function compute_density!(filepath::String; reference_pressure = 0)
27-
Compute a density variable at `reference_pressure` and append it to saved output. **Note**
28-
this only needs to be done once! After that the group will exist and will not be able to be
29-
overwritten but a different group can be made by passing a different `density_string`.
30-
This allows calling `FieldTimeSeries` on the `density_variable`
31-
"""
32-
function compute_density!(filepath::AbstractString; density_string = "σ", reference_pressure = 0)
33-
34-
file_type = find_file_type(filepath)
35-
if isequal(file_type, ".nc")
36-
37-
@info "Lazily loading S and T into separate Rasters"
38-
S_rs = Raster(filepath, lazy = true, name = :S)
39-
T_rs = Raster(filepath, lazy = true, name = :T)
40-
time = lookup(S_rs, :Ti)
41-
42-
NCDataset(filepath, "a") do ds
43-
@info "Appending density variable to saved .nc file"
44-
defVar(ds, density_string, zeros(size(S_rs)), ("xC", "yC", "zC", "time"),
45-
attrib = Dict("units" => "kgm⁻³",
46-
"longname" => "Potential density",
47-
"comments" => "computed at reference pressues p = $reference_pressure"))
48-
@info "Computing density and saving to .nc file"
49-
for t eachindex(time)
50-
ds[density_string][:, :, :, t] = get_σₚ(S_rs[:, :, :, t], T_rs[:, :, :, t],
51-
reference_pressure)
52-
end
53-
end
54-
55-
elseif isequal(file_type, ".jld2")
56-
57-
file = jldopen(filepath, "a+")
58-
file_keys = keys(file["timeseries"]["S"])
59-
JLD2.Group(file, "timeseries/"*density_string)
60-
for (i, key) enumerate(file_keys)
61-
if i == 1
62-
for k keys(file["timeseries/S/"*key])
63-
file["timeseries/"*density_string*"/"*key*"/"*k] =
64-
file["timeseries/S/"*key*"/"*k]
65-
end
66-
file["timeseries/"*density_string*"/"*key*"/reference_pressure"] =
67-
reference_pressure
68-
else
69-
Sᵢ, Θᵢ = file["timeseries/S/"*key], file["timeseries/T/"*key]
70-
file["timeseries/"*density_string*"/"*key]= gsw_rho.(Sᵢ, Θᵢ, reference_pressure)
71-
end
72-
end
73-
74-
close(file)
75-
76-
end
77-
78-
return nothing
79-
80-
end
81-
"""
82-
function append_density!(; saved_simulations = readdir(SIMULATION_PATH, join = true))
83-
Append a density timeseries to the saved output from a `TwoLayerDNS` simulation. By default
84-
the function looks for saved data at the default filepath for saving `SIMULATION_PATH`.
85-
Pass another path as the keyword argument `saved_simulations` to look somewhere else.
86-
"""
87-
function append_density!(; saved_simulations = readdir(SIMULATION_PATH, join = true))
88-
89-
for simulation saved_simulations
90-
91-
file_type = find_file_type(simulation)
92-
93-
if isequal(file_type, ".jld2")
94-
open_sim = jldopen(simulation)
95-
if "σ" keys(open_sim["timeseries"])
96-
close(open_sim)
97-
compute_density!(simulation, density_string = "σ₀")
98-
else
99-
@info "A density timeseries already exists in $simulation."
100-
close(open_sim)
101-
end
102-
elseif isequal(file_type, ".nc")
103-
NCDataset(simulation, "a") do ds
104-
if "σ" keys(ds)
105-
compute_density!(simulation)
106-
else
107-
@info "A density timeseries already exists in $simulation."
108-
end
109-
end
110-
end
111-
end
112-
113-
return nothing
114-
115-
end
116-
117-
"Return the mean from a `FieldTimeSeries` that is `OnDisk()`."
118-
function field_ts_timemean(field_ts::FieldTimeSeries)
119-
120-
t = field_ts.times
121-
field_data = field_ts[1].data
122-
for i 2:length(t)
123-
field_data .+= field_ts[i].data
124-
end
125-
126-
return field_data ./ length(t)
127-
128-
end
1291
"""
1302
function predicted_maximum_density
1313
Compute the predicted maximum density of water that can form along the mixing line between
@@ -185,33 +57,6 @@ function predicted_maximum_density!(file::AbstractString; reference_pressure = 0
18557
end
18658
"Calculate the Kolmogorov length scale `η` from viscousity and average TKE dissapation."
18759
η(ν, ϵ) =^3 / ϵ)^(1/4)
188-
"""
189-
function minimum_η(ϵ::FieldTimeSeries; ν = 1e-6)
190-
Find the minimum `η`, i.e. the Kolmogorov length scale, from the `KineticEnergyDissaption`,
191-
`ϵ`, time series.
192-
"""
193-
function minimum_η::FieldTimeSeries; ν = 1e-6)
194-
195-
t = ϵ.times
196-
minimum_η_t = similar(t)
197-
for i eachindex(t)
198-
minimum_η_t[i] = minimum(η.(ν, ϵ[i].data))
199-
end
200-
201-
return minimum(minimum_η_t)
202-
203-
end
204-
function minimum_η::Raster; ν = 1e-6)
205-
206-
t = lookup(ϵ, :Ti)
207-
minimum_η_t = similar(t)
208-
for i eachindex(t)
209-
minimum_η_t[i] = minimum(η.(ν, ϵ.data[:, :, :, i]))
210-
end
211-
212-
return minimum(minimum_η_t)
213-
214-
end
21560
"""
21661
function kolmogorov_and_batchelor_scale!(file::AbstractString)
21762
Append the minimum Kolmogorov and Batchelor scales (in space and time) from a `TwoLayerDNS`
@@ -255,37 +100,6 @@ function kolmogorov_and_batchelor_scale!(file::AbstractString)
255100

256101
return nothing
257102

258-
end
259-
"""
260-
function batchelor_scale!
261-
Compute and append the minimum space-time Batchelor scale and append it to save output.
262-
"""
263-
function batchelor_scale!(file::AbstractString)
264-
265-
file_type = find_file_type(file)
266-
if isequal(file_type, ".nc")
267-
268-
NCDataset(file, "a") do ds
269-
Sc = ds.attrib["Sc"]
270-
find_num = findfirst(' ', ds.attrib["ν"]) - 1
271-
ν = parse(Float64, ds.attrib["ν"][1:find_num])
272-
η_min =^3 / maximum(ds["ϵ_maximum"][:]))
273-
ds.attrib["λ_B"] = η_min / sqrt(Sc) # minimum space and time Batchelor scale
274-
end
275-
276-
elseif isequal(file_type, ".jld2")
277-
278-
Sc = load(file, "Non_dimensional_numbers")["Sc"]
279-
η = FieldTimeSeries(file, "ϵ_maximum")
280-
min_η = minimum(η)
281-
jldopen(file, "a+") do f
282-
f["minimum_batchelor_scale"] = min_η / sqrt(Sc)
283-
end
284-
285-
end
286-
287-
return nothing
288-
289103
end
290104
"""
291105
function non_dimensional_numbers(simulation::Simulation, dns::TwoLayerDNS)

0 commit comments

Comments
 (0)