Skip to content

Commit

Permalink
Merge pull request #20 from gaelforget/v0p1p9d
Browse files Browse the repository at this point in the history
V0p1p9d
  • Loading branch information
gaelforget authored Jul 9, 2021
2 parents 58160a5 + 5fa962e commit ec83957
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
21 changes: 12 additions & 9 deletions examples/MITgcm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ using ClimateModels, MITgcmTools, MeshArrays, Plots, Suppressor

MC=MITgcm_config(configuration="global_with_exf")

# The `setup` function links input files to the `run/` folder (see below) including model parameters that are then accessed via `MC.inputs`.
# The `setup` function links input files to the `run/` folder (see below).

setup(MC)

# Model parameters can then be accessed via `MC.inputs`.

MC.inputs

# ## Build `mitgcmuv`
Expand All @@ -27,25 +30,25 @@ MC.inputs
# If `mitcmuv` is not found at this stage then it is assumed that the chosen model configuration still needs to be compiled (once, via the `build` function).
# This might take a lot longer than a normal model run due to the one-time cost of compiling the model.

try
filexe=joinpath(MITgcm_path[1],"verification",MC.configuration,"build","mitgcmuv")
if isa(MITgcm_path,Array) #MITgcmTools > v0.1.22
build(MC,"--allow-skip")
catch e #MITgcmTools before v0.1.22
filexe=joinpath(MITgcm_path,"verification",MC.configuration,"build","mitgcmuv")
@suppress !isfile(filexe) ? build(MC) : nothing
else
build(MC)
end

# ## Run Model
#
# The main model computation takes place via the `launch` function. This will output files in the `rundir` folder, incl. the MITgcm standard `output.txt` file.
# The main model computation takes place via the `launch` function.

launch(MC)

@suppress launch(MC)
# MITgcm will output files in the `run/` folder incl. the standard `output.txt` file.

rundir=joinpath(MC.folder,string(MC.ID),"run")
fileout=joinpath(rundir,"output.txt")
readlines(fileout)

# ## Monitor Model
# ## Model Monitor
#
# Often, the term _monitor_ in climate modeling denotes a statement / counter printed to standard model output (text file) at regular intervals to monitor the model's integration through time. In the example below, we use global mean temperature which is reported every time step as `dynstat_theta_mean` in the MITgcm `output.txt` file.

Expand Down
28 changes: 1 addition & 27 deletions src/ClimateModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,6 @@ export cmip

include("interface.jl")
include("access.jl")

init_git_log = git_log_init #alias to old name
export init_git_log #temporary fix, until MITgcmTools.jl revised

"""
RandomWalker(x::AbstractModelConfig)
Random Walk in 2D over `NS` steps (100 by default). Returns the results to as an array and
saves them to a `.csv` file ("RandomWalker.csv" by default) inside the run directory
`joinpath(x.folder,string(x.ID)`, if `setup` method has been invoked to create it.
"""
function RandomWalker(x::AbstractModelConfig)
#model run
haskey(x.inputs,"NS") ? NS=x.inputs["NS"] : NS=100
m=zeros(NS,2)
[m[i,j]=m[i-1,j]+rand((-1,1)) for j in 1:2, i in 2:NS]

#output to file
haskey(x.inputs,"filename") ? fil=x.inputs["filename"] : fil="RandomWalker.csv"
if isdir(joinpath(x.folder,string(x.ID)))
df = DataFrame(x = m[:,1], y = m[:,2])
fil=joinpath(x.folder,string(x.ID),"RandomWalker.csv")
CSV.write(fil, df)
end

return m
end
include("toy_models.jl")

end
24 changes: 24 additions & 0 deletions src/toy_models.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

"""
RandomWalker(x::AbstractModelConfig)
Random Walk in 2D over `NS` steps (100 by default). Returns the results to as an array and
saves them to a `.csv` file ("RandomWalker.csv" by default) inside the run directory
`joinpath(x.folder,string(x.ID)`, if `setup` method has been invoked to create it.
"""
function RandomWalker(x::AbstractModelConfig)
#model run
haskey(x.inputs,"NS") ? NS=x.inputs["NS"] : NS=100
m=zeros(NS,2)
[m[i,j]=m[i-1,j]+rand((-1,1)) for j in 1:2, i in 2:NS]

#output to file
haskey(x.inputs,"filename") ? fil=x.inputs["filename"] : fil="RandomWalker.csv"
if isdir(joinpath(x.folder,string(x.ID)))
df = DataFrame(x = m[:,1], y = m[:,2])
fil=joinpath(x.folder,string(x.ID),"RandomWalker.csv")
CSV.write(fil, df)
end

return m
end

0 comments on commit ec83957

Please sign in to comment.