Skip to content

Commit f57acfc

Browse files
author
Peter Bräuer
committed
Write MCM/GECKO-A parameters to md file
In generate_wiki.jl, new function write_params to write new MCM/GECKO-A photolysis parameters to a md file from a markdown. New support function format_float to return a formatted string with for a float and its errors. New function lnew to l at 350DU from the new l parameters. New file src/data/params_header.md with header for the md output file. In function generate_wiki in TUVtools.jl, renaming kwarg collength to more concise name MCMcollength. Introducing kwargs parinput and paroutput for the parameters.csv file from MCMphotolysis (https://github.com/wacl-york/MCMphotolysis.git) and the output file name. Calling function write_params from function generate_wiki.
1 parent 7809348 commit f57acfc

File tree

5 files changed

+100
-8
lines changed

5 files changed

+100
-8
lines changed

src/TUVtools.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,13 @@ end
8686
Generate markdown files from templates specified kwarg `wikitemplates`, where
8787
reactions numbers from TUV in `tuvdir` and in MCM/GECKO-A are listed for every
8888
reaction listed at the beginning of each template line and written to files specified
89-
by kwarg `wikioutput`. The table `collength` can be specifief with a kwarg, for nicer
89+
by kwarg `wikioutput`. The table `MCMcollength` can be specifief with a kwarg, for nicer
9090
md file formatting. The `MCMversion` needs to be specified for every wiki template.
9191
"""
9292
function generate_wiki(tuvdir::String; wikitemplates::Union{String, Vector{String}}="",
93-
wikioutput::Union{String, Vector{String}}="WIKI.md", collength::Union{Int64,Vector{Int64}}=10,
94-
MCMversion::Union{Int64,Vector{Int64}}=4)
93+
wikioutput::Union{String, Vector{String}}="WIKI.md", MCMcollength::Union{Int64,Vector{Int64}}=10,
94+
MCMversion::Union{Int64,Vector{Int64}}=4, parinput::String="",
95+
paroutput::String="../MCM-Photolysis-Parameters.md")
9596
# Save current directory
9697
currdir = pwd()
9798
# Find files related to photolysis mechanism
@@ -100,7 +101,8 @@ function generate_wiki(tuvdir::String; wikitemplates::Union{String, Vector{Strin
100101
rxnlist = generate_rxns(rxnfiles, callfiles)
101102

102103
# Auto-generate inc files for TUV_DSMACC
103-
write_wiki(rxnlist, tuvdir, wikitemplates, wikioutput, collength, MCMversion, currdir)
104+
write_wiki(rxnlist, tuvdir, wikitemplates, wikioutput, MCMcollength, MCMversion, currdir)
105+
write_params(parinput, paroutput, currdir)
104106
# Go back to original directory
105107
cd(currdir)
106108
end #function generate_wiki

src/data/WIKItemplate_MCMv3.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ OIO -> I + O2
111111
## Additional explanations
112112

113113
<sup>(1)</sup> J(56): NOA photolyses to CH<sub>3</sub>COCH<sub>2</sub>O<sup>•</sup>
114-
and NO<sub>2</sub> as only products in the MCMv3.3.1 with a quantum yield of 0.9.
115-
In the MCMv3.2 an additional channel J(57) is assumed leading to
116-
CH<sub>3</sub>CO<sup>•</sup>, HCHO, and NO<sub>2</sub> with a branching of 0.75:0.25 between J(56) and J(57), respectively.
114+
and NO<sub>2</sub> as only products in the MCMv3.3.1 with a quantum yield of 0.9.
115+
In the MCMv3.2 an additional channel J(57) is assumed leading to
116+
CH<sub>3</sub>CO<sup>•</sup>, HCHO, and NO<sub>2</sub> with a branching of
117+
0.75:0.25 between J(56) and J(57), respectively.

src/data/params_header.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MCM photolysis parameterisations
2+
3+
The table below lists improved MCM/GECKO-A photolysis parameterisations,
4+
which include a dependence on the overlying ozone column.
5+
At 350DU they are identical the original MCM photolysis parameterisation:
6+
7+
j(χ) = l·cosᵐ(χ)·exp(-n·sec(χ))
8+
9+
where j is in s<sup>-1</sup>. For other ozone columns `l` is redefined to:
10+
11+
l([O3]) = l_a0 + l_b0·exp(l_b1/[O3]) + l_c0·exp(l_c1/[O3])
12+
13+
where l, l<sub>a0</sub>, l<sub>b0</sub>, l<sub>c0</sub> are in
14+
s<sup>-1</sup> and l<sub>b1</sub>, l<sub>c1</sub> are in DU.
15+
16+
Download the parameters as [formatted text file](github.com/pb866) or
17+
[csv file](github.com/pb866).
18+
19+
20+
MCM/GECKO-A | TUV | l<sub>a0</sub> | l<sub>b0</sub> | l<sub>b1</sub> | l<sub>c0</sub> | l<sub>c1</sub> | l(350DU) | m | n | TUV label
21+
-----------:|----:|:-----------------------------:|:-----------------------------:|:--------------:|:-----------------------------:|:--------------:|:----------------------:|:-----------:|:-----------:|:---------

src/generate_wiki.jl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,72 @@ function init_wikifiles(ifile, ofile, len, DB, currdir)
6969
[push!(db, database[i-2]) for i in DB]
7070

7171
return ifile, ofile, collength, db
72+
end #function init_wikifiles
73+
74+
75+
"""
76+
write_params(ifile, ofile, pwd)
77+
78+
From `ifile` `parameters.csv` from repository
79+
[MCMphotolysis](https://github.com/wacl-york/MCMphotolysis.git)
80+
write a table of the MCM/GECKO-A photolysis parameters to a markdown file `ofile`.
81+
Use `pwd` to determine absolute paths of the files.
82+
"""
83+
function write_params(ifile, ofile, pwd)
84+
# Skip routine, if no template is provided
85+
if ifile == "" return end
86+
# Determine absolute paths of I/O files
87+
if !isabspath(ifile) ifile = joinpath(pwd, ifile) end
88+
if !isabspath(ofile) ofile = joinpath(pwd, ofile) end
89+
# Read header of md file
90+
header = readfile(joinpath(@__DIR__, "data/params_header.md"))
91+
92+
# Open output file
93+
open(ofile,"w") do f
94+
# print header
95+
[println(f, line) for line in header]
96+
# Read parameter file from MCMphotolysis
97+
param = read_data(ifile, sep = ";", header = 1)
98+
# Loop over reactions
99+
for i = 1:length(param[1])
100+
# Retrieve and format l parameters and errors
101+
la0 = format_float(param[1][i], param[8][i])
102+
lb0 = format_float(param[2][i], param[9][i])
103+
lb1 = @sprintf("%8.2f±%.2f", param[3][i], param[10][i])
104+
lc0 = format_float(param[4][i], param[11][i])
105+
lc1 = @sprintf("%8.2f±%.2f", param[5][i], param[12][i])
106+
# Calculate orignal l parameter at 350 DU and order of magnitude
107+
l = lnew(350., param[i,1:5])
108+
o = Int(floor(log10(abs(l))))
109+
lp = l/10.0^o
110+
# Print reaction to md file
111+
@printf(f, "%10s | %3d |%30s |%30s |%s|%30s |",
112+
rpad(param[end-2][i],8), param[end-1][i], la0, lb0, rpad(lb1,16), lc0)
113+
@printf(f, "%s| %6.3f·10<sup>%d</sup> |%6.3f±%.3f |%6.3f±%.3f | %s\n",
114+
rpad(lc1,16),lp, o,
115+
param[6][i], param[13][i], param[7][i], param[14][i], param[end][i])
116+
end # loop over reactiojns
117+
# Inform about number of reactions on screen
118+
println("MCM/GECKO-A parameters for $(length(param[1])) reactions ",
119+
"written to $(basename(ofile)).")
120+
end # close file
121+
end #function write_params
122+
123+
124+
"""
125+
format_float(n::AbstractFloat, m::AbstractFloat)
126+
127+
Derive the order of magnitude for float `n` and return `String` in the form
128+
`"(X.XXX±Y.YYY)·10<sup>Z</sup>"`, where `X` and `Y` are n and m reduced by the
129+
order of magnitude of `n` and `Z` is the order of magnitude.
130+
"""
131+
function format_float(n::AbstractFloat, m::AbstractFloat)
132+
o = Int(floor(log10(abs(n))))
133+
@sprintf("(%.3f±%.3f)·10<sup>%d</sup>",n/10.0^o, m/10.0^o, o)
72134
end
135+
136+
137+
"""
138+
lnew(O3,p) / s^-1 = p[1] + p[2]·exp(-O3/p[3]) + p[4]·exp(-O3/p[5])
139+
"""
140+
lnew(O3,p) = (p[1]+p[2]*exp.(-O3/p[3])+p[4]*exp.(-O3/p[5]))[1]

src/setrxns.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,4 @@ function write_incfiles(rxnlist, tuvdir)
273273
println(f, " END SELECT")
274274
end # close file
275275
end # loop over files
276-
end #function write_incfiles
276+
end

0 commit comments

Comments
 (0)