Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argparse and json support #15

Merged
merged 1 commit into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
!docs/src/assets/*.png
*.nc
*.png
*.json
*.in

# System-specific files and directories generated by the BinaryProvider and BinDeps packages
# They contain absolute paths specific to the host computer, and so should not be committed
Expand Down
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ authors = ["Charles Kawczynski <[email protected]>"]
version = "0.1.0"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
ArtifactWrappers = "a14bc488-3040-4b00-9dc1-f6467924858a"
Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LambertW = "984bce1d-4616-540c-a9ee-88d1112d94c9"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ An extended eddy-diffusivity mass-flux scheme for unified representation of
subgrid-scale turbulence and convection. Journal of Advances in Modeling Earth Systems, 2018.
(see [Tan et al., 2018](https://agupubs.onlinelibrary.wiley.com/doi/abs/10.1002/2017MS001162)).

The code is written in Julia, and was translated from [SCAMPy](https://github.com/CliMA/SCAMPy) on 7/13/2021.
The code is written in Julia, and was translated from [SCAMPy](https://github.com/CliMA/SCAMPy) for the commit 496dad0c2438235684823511cacbf5761d6a237c.

Code Contributors:
Colleen Kaul (PNNL) --initial/primary developer,
Expand Down Expand Up @@ -50,7 +50,7 @@ pkg> instantiate
$ cd TurbulenceConvection.jl
```

Note that, we will soon support running TurbulenceConvection.jl in the same way that SCAMPy used to. For now, run one of the cases:
TurbulenceConvection.jl can be run in the same way that SCAMPy used to, given one of the following cases:

- Bomex
- life_cycle_Tan2018
Expand All @@ -63,10 +63,13 @@ Note that, we will soon support running TurbulenceConvection.jl in the same way
- GABLS
- SP

with
with, for example:

```
julia --project integration_tests/Soares.jl
julia --project integration_tests/utils/generate_namelist.jl Soares
julia --project integration_tests/utils/generate_paramlist.jl Soares
julia --project integration_tests/utils/main.jl Soares

```
or, interactively, with
```julia-repl
Expand Down
5 changes: 1 addition & 4 deletions integration_tests/ARM_SGP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
include(joinpath("utils", "compute_mse.jl"))
using .Cases
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

best_mse = OrderedDict()
best_mse["qt_mean"] = 6.7939652328911526e+00
best_mse["updraft_area"] = 2.6728907094911216e+02
Expand Down
5 changes: 1 addition & 4 deletions integration_tests/Bomex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
include(joinpath("utils", "compute_mse.jl"))
using .Cases
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

best_mse = OrderedDict()
best_mse["qt_mean"] = 8.3714605287379840e-02
best_mse["updraft_area"] = 7.0261471608838769e+02
Expand Down
5 changes: 1 addition & 4 deletions integration_tests/DYCOMS_RF01.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
include(joinpath("utils", "compute_mse.jl"))
using .Cases
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

best_mse = OrderedDict()
best_mse["qt_mean"] = 3.8001673126194867e-02
best_mse["ql_mean"] = 8.4578478184878048e+00
Expand Down
6 changes: 2 additions & 4 deletions integration_tests/DryBubble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
using .Cases
include(joinpath("utils", "compute_mse.jl"))
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

@testset "DryBubble" begin
println("Running DryBubble...")
namelist = NameList.DryBubble(default_namelist("DryBubble"))
Expand Down
5 changes: 1 addition & 4 deletions integration_tests/GABLS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
include(joinpath("utils", "compute_mse.jl"))
using .Cases
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

best_mse = OrderedDict()

best_mse["updraft_thetal"] = 5.0418613105717345e+00
Expand Down
6 changes: 2 additions & 4 deletions integration_tests/GATE_III.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
using .Cases
include(joinpath("utils", "compute_mse.jl"))
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

@testset "GATE_III" begin
println("Running GATE_III...")
namelist = NameList.GATE_III(default_namelist("GATE_III"))
Expand Down
5 changes: 1 addition & 4 deletions integration_tests/Nieuwstadt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
include(joinpath("utils", "compute_mse.jl"))
using .Cases
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

best_mse = OrderedDict()
best_mse["qt_mean"] = 1.1424341230332884e-01
best_mse["updraft_area"] = 1.1765062251021085e+02
Expand Down
5 changes: 1 addition & 4 deletions integration_tests/Rico.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
include(joinpath("utils", "compute_mse.jl"))
using .Cases
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

best_mse = OrderedDict()
best_mse["qt_mean"] = 4.0432375728696790e-01
best_mse["updraft_area"] = 1.8875614747005029e+03
Expand Down
6 changes: 2 additions & 4 deletions integration_tests/SP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
using .Cases
include(joinpath("utils", "compute_mse.jl"))
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

@testset "SP" begin
println("Running SP...")
namelist = NameList.SP(default_namelist("SP"))
Expand Down
5 changes: 1 addition & 4 deletions integration_tests/Soares.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
include(joinpath("utils", "compute_mse.jl"))
using .Cases
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

best_mse = OrderedDict()
best_mse["qt_mean"] = 2.5654529603089010e-01
best_mse["updraft_area"] = 7.7772077592145229e+02
Expand Down
5 changes: 1 addition & 4 deletions integration_tests/TRMM_LBA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
include(joinpath("utils", "compute_mse.jl"))
using .Cases
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

best_mse = OrderedDict()
best_mse["qt_mean"] = 3.0653862333906230e+00
best_mse["updraft_area"] = 2.7495023710812657e+04
Expand Down
6 changes: 2 additions & 4 deletions integration_tests/life_cycle_Tan2018.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import TurbulenceConvection
using TurbulenceConvection
using Test

include(joinpath("utils", "Cases.jl"))
include(joinpath("utils", "main.jl"))
include(joinpath("utils", "generate_paramlist.jl"))
include(joinpath("utils", "generate_namelist.jl"))
using .Cases
include(joinpath("utils", "compute_mse.jl"))
using .NameList
using .ParamList

include(joinpath("utils", "main.jl"))

@testset "life_cycle_Tan2018" begin
println("Running life_cycle_Tan2018...")
namelist = NameList.life_cycle_Tan2018(default_namelist("life_cycle_Tan2018"))
Expand Down
62 changes: 42 additions & 20 deletions integration_tests/utils/generate_namelist.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
module NameList

#Adapated from PyCLES: https://github.com/pressel/pycles

using ArgParse
import JSON

export default_namelist
function default_namelist(case_name)

function parse_commandline()
s = ArgParseSettings(;description="Namelist Generator")

@add_arg_table! s begin
"case_name"
help = "The case name"
arg_type = String
required = true
end

return parse_args(s)
end

function default_namelist(::Nothing)
args = parse_commandline()
case_name = args["case_name"]
return default_namelist(case_name)
end

function default_namelist(case_name::String)

namelist_defaults = Dict()
namelist_defaults["grid"] = Dict()
namelist_defaults["grid"]["dims"] = 1
Expand Down Expand Up @@ -71,9 +97,10 @@ function default_namelist(case_name)
elseif case_name == "DryBubble"
namelist = DryBubble(namelist_defaults)
else
error("Not a valid case name")
error("Not a valid case name in namelist")
end
# write_file(namelist)
write_file(namelist)
return namelist
end


Expand Down Expand Up @@ -273,27 +300,22 @@ function DryBubble(namelist_defaults)
return namelist
end

# function write_file(namelist)
function write_file(namelist)

# try
# type(namelist["meta"]["simname"])
# catch
# print("Casename not specified in namelist dictionary!")
# print("FatalError")
# exit()
# end
@assert haskey(namelist, "meta")
@assert haskey(namelist["meta"], "simname")

# namelist["meta"]["uuid"] = str(uuid.uuid4())
namelist["meta"]["uuid"] = basename(tempname())

# fh = open(namelist["meta"]["simname"] + ".in", "w")
# #pprint.pprint(namelist)
# json.dump(namelist, fh, sort_keys=true, indent=4)
# fh.close()
open(namelist["meta"]["simname"]*".in", "w") do io
JSON.print(io, namelist, 4)
end

# return
# end
return
end

# if __name__ == "__main__"
# main()
if abspath(PROGRAM_FILE) == @__FILE__
default_namelist(nothing)
end

end
Loading