Skip to content

Commit

Permalink
Fix plotting tools (#490)
Browse files Browse the repository at this point in the history
* Fix matlab script

* Fix the gnuplot script

* Fix the Python script and other modifications

* Tweak the R script

* Correct printout messages

* Correct scientific notation

* Fix y-axis ticks

* Run all tests even if one fails
  • Loading branch information
rs028 committed Mar 31, 2023
1 parent 739879e commit 6650b8a
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 149 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
matrix:
os: [ubuntu-22.04, macos-11, macos-12]
fortran: [9, 10, 11]
fail-fast: false

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down
114 changes: 62 additions & 52 deletions tools/plot/plot-atchem2-numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# -----------------------------------------------------------------------------

## Plotting tool for the AtChem2 model output
## --> Python version [requires numpy & matplotlib]
## --> version for Python [requires numpy & matplotlib]
##
## Acknowledgements: M. Panagi
##
Expand All @@ -26,100 +26,110 @@
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

os.chdir(sys.argv[1])
print(os.getcwd())
if len(sys.argv) < 2:
print("[!] Please provide the model output directory as an argument.")
exit()
else:
output_dir = sys.argv[1]
os.chdir(output_dir)

with open('speciesConcentrations.output') as f:
var1 = f.readline().split()
with open('environmentVariables.output') as f:
var2 = f.readline().split()
with open('photolysisRates.output') as f:
var3 = f.readline().split()
with open('photolysisRatesParameters.output') as f:
var4 = f.readline().split()
var1 = np.genfromtxt('speciesConcentrations.output', max_rows=1, dtype=str)
df1 = np.genfromtxt('speciesConcentrations.output', skip_header=1)

df1 = np.loadtxt('speciesConcentrations.output', skiprows=1, unpack=True)
df2 = np.loadtxt('environmentVariables.output', skiprows=1, unpack=True)
df3 = np.loadtxt('photolysisRates.output', skiprows=1, unpack=True)
df4 = np.loadtxt('photolysisRatesParameters.output', skiprows=1, unpack=True)
var2 = np.genfromtxt('environmentVariables.output', max_rows=1, dtype=str)
df2 = np.genfromtxt('environmentVariables.output', skip_header=1)

nc1 = df1.shape[0]
nc2 = df2.shape[0]
nc3 = df3.shape[0]
nc4 = df4.shape[0]
var3 = np.genfromtxt('photolysisRates.output', max_rows=1, dtype=str)
df3 = np.genfromtxt('photolysisRates.output', skip_header=1)

var4 = np.genfromtxt('photolysisRatesParameters.output', max_rows=1, dtype=str)
df4 = np.genfromtxt('photolysisRatesParameters.output', skip_header=1)

nc1 = df1.shape[1]
nc2 = df2.shape[1]
nc3 = df3.shape[1]
nc4 = df4.shape[1]

## ---------------------------- ##

with PdfPages('atchem2_output.pdf') as pdf:

## speciesConcentrations.output
fig = plt.figure(figsize=(11,7))
j = 1
fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(11,7))
axs = axs.ravel()
j = 0
for i in range(1,nc1):
ax = fig.add_subplot(3,2,j)
ax.plot(df1[0], df1[i], linestyle='-', color='black')
ax = axs[j]
ax.plot(df1[:,0], df1[:,i], linestyle='-', color='black')
ax.set(title=var1[i], xlabel='seconds', ylabel='')
ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda x, _: '%.1e' % x))
plt.tight_layout()
plt.ticklabel_format(style='sci', axis='y', useMathText=True)
if j == 6:
if j == 8:
pdf.savefig(fig)
fig = plt.figure(figsize=(11,7))
j = 1
fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(11,7))
axs = axs.ravel()
j = 0
else:
j = j + 1
pdf.savefig(fig)

## environmentVariables.output
fig = plt.figure(figsize=(11,7))
j = 1
fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(11,7))
axs = axs.ravel()
j = 0
for i in range(1,nc2):
ax = fig.add_subplot(3,2,j)
ax.plot(df2[0], df2[i], linestyle='-', color='black')
ax = axs[j]
ax.plot(df2[:,0], df2[:,i], linestyle='-', color='black')
ax.set(title=var2[i], xlabel='seconds', ylabel='')
ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda x, _: '%.1e' % x))
plt.tight_layout()
plt.ticklabel_format(style='sci', axis='y', useMathText=True)
if j == 6:
if j == 8:
pdf.savefig(fig)
fig = plt.figure(figsize=(11,7))
j = 1
fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(11,7))
axs = axs.ravel()
j = 0
else:
j = j + 1
pdf.savefig(fig)

## photolysisRates.output
fig = plt.figure(figsize=(11,7))
j = 1
fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(11,7))
axs = axs.ravel()
j = 0
for i in range(1,nc3):
ax = fig.add_subplot(3,2,j)
ax.plot(df3[0], df3[i], linestyle='-', color='black')
ax = axs[j]
ax.plot(df3[:,0], df3[:,i], linestyle='-', color='black')
ax.set(title=var3[i], xlabel='seconds', ylabel='')
ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda x, _: '%.1e' % x))
plt.tight_layout()
plt.ticklabel_format(style='sci', axis='y', useMathText=True)
if j == 6:
if j == 8:
pdf.savefig(fig)
fig = plt.figure(figsize=(11,7))
j = 1
fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(11,7))
axs = axs.ravel()
j = 0
else:
j = j + 1
pdf.savefig(fig)

## photolysisRatesParameters.output
fig = plt.figure(figsize=(11,7))
j = 1
fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(11,7))
axs = axs.ravel()
j = 0
for i in range(1,nc4):
ax = fig.add_subplot(3,2,j)
ax.plot(df4[0], df4[i], linestyle='-', color='black')
ax = axs[j]
ax.plot(df4[:,0], df4[:,i], linestyle='-', color='black')
ax.set(title=var4[i], xlabel='seconds', ylabel='')
ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda x, _: '%.1e' % x))
plt.tight_layout()
plt.ticklabel_format(style='sci', axis='y', useMathText=True)
if j == 6:
if j == 8:
pdf.savefig(fig)
fig = plt.figure(figsize=(11,7))
j = 1
fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(11,7))
axs = axs.ravel()
j = 0
else:
j = j + 1
pdf.savefig(fig)

## ---------------------------- ##

print("\n===> atchem2_output.pdf created in directory:", sys.argv[1], "\n\n")
print("\n==> atchem2_output.pdf created in directory:", output_dir, "\n")
63 changes: 34 additions & 29 deletions tools/plot/plot-atchem2.gp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@
# -----------------------------------------------------------------------------

## Plotting tool for the AtChem2 model output
## --> gnuplot version
## --> version for gnuplot
##
## ARGUMENT:
## - directory with the model output
##
## USAGE:
## gnuplot -c ./tools/plot/plot-atchem2.gp ./model/output/
## ---------------------------------------------- ##
cd ARG1
pwd
if (ARGC < 1) {
print "[!] Please provide the model output directory as an argument."
exit
} else {
output_dir = ARGV[1]
cd output_dir
}

df1 = 'speciesConcentrations.output'
df2 = 'environmentVariables.output'
Expand All @@ -33,18 +38,18 @@ stats df4 skip 1 noout; nc4 = STATS_columns

## ---------------------------- ##

set terminal pdf size 11,7
set terminal pdfcairo size 11,7
set output 'atchem2_output.pdf'

## speciesConcentrations.output
set multiplot layout 3,2
set multiplot layout 3,3
set format y '%.1e'
j = 1
do for [i=2:nc1] {
plot df1 using 1:i with lines title '' lt rgb 'black'
set title ''; set xlabel 'seconds'; set ylabel ''
if (j == 6) {
unset multiplot
set multiplot layout 3,2
plot df1 using 1:i with lines title columnheader(i) lt rgb 'black'
set xlabel 'seconds'; set ylabel ''
if (j == 9) {
unset multiplot; set multiplot layout 3,3
j = 1
} else {
j = j + 1
Expand All @@ -53,14 +58,14 @@ do for [i=2:nc1] {
unset multiplot

## environmentVariables.output
set multiplot layout 3,2
set multiplot layout 3,3
set format y '%.1e'
j = 1
do for [i=2:nc2] {
plot df2 using 1:i with lines title '' lt rgb 'black'
set title ''; set xlabel 'seconds'; set ylabel ''
if (j == 6) {
unset multiplot
set multiplot layout 3,2
plot df2 using 1:i with lines title columnheader(i) lt rgb 'black'
set xlabel 'seconds'; set ylabel ''
if (j == 9) {
unset multiplot; set multiplot layout 3,3
j = 1
} else {
j = j + 1
Expand All @@ -69,14 +74,14 @@ do for [i=2:nc2] {
unset multiplot

## photolysisRates.output
set multiplot layout 3,2
set multiplot layout 3,3
set format y '%.1e'
j = 1
do for [i=2:nc3] {
plot df3 using 1:i with lines title '' lt rgb 'black'
set title ''; set xlabel 'seconds'; set ylabel ''
if (j == 6) {
unset multiplot
set multiplot layout 3,2
plot df3 using 1:i with lines title columnheader(i) lt rgb 'black'
set xlabel 'seconds'; set ylabel ''
if (j == 9) {
unset multiplot; set multiplot layout 3,3
j = 1
} else {
j = j + 1
Expand All @@ -85,14 +90,14 @@ do for [i=2:nc3] {
unset multiplot

## photolysisRatesParameters.output
set multiplot layout 3,2
set multiplot layout 3,3
set format y '%.1e'
j = 1
do for [i=2:nc4] {
plot df4 using 1:i with lines title '' lt rgb 'black'
set title ''; set xlabel 'seconds'; set ylabel ''
if (j == 6) {
unset multiplot
set multiplot layout 3,2
plot df4 using 1:i with lines title columnheader(i) lt rgb 'black'
set xlabel 'seconds'; set ylabel ''
if (j == 9) {
unset multiplot; set multiplot layout 3,3
j = 1
} else {
j = j + 1
Expand All @@ -102,4 +107,4 @@ unset multiplot

## ---------------------------- ##

print "\n===> atchem2_output.pdf created in directory: ", ARG1, "\n\n"
print "\n==> atchem2_output.pdf created in directory: ", output_dir, "\n"
Loading

0 comments on commit 6650b8a

Please sign in to comment.