-
Notifications
You must be signed in to change notification settings - Fork 3
/
adv_timeseries_volume.py
67 lines (57 loc) · 2.39 KB
/
adv_timeseries_volume.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from numpy import *
from matplotlib.pyplot import *
# Plot timeseries of total sea ice volume for all the advection experiments.
# Before running this script, you must run timeseries_seaice for each
# experiment.
def adv_timeseries_volume ():
num_simulations = 6
# Number of output steps in the simulation (daily averages, 1 leap year)
num_days = 366
# Paths to simulation directories (in order of decreasing sea ice volume)
paths = ['/short/m68/kaa561/ROMS-CICE-MCT/tmproms/run/advection/c4_lowdif/', '/short/m68/kaa561/ROMS-CICE-MCT/tmproms/run/advection/a4_lowdif/', '/short/m68/kaa561/ROMS-CICE-MCT/tmproms/run/advection/u3_lowdif/', '/short/m68/kaa561/ROMS-CICE-MCT/tmproms/run/advection/c4_highdif/', '/short/m68/kaa561/ROMS-CICE-MCT/tmproms/run/advection/a4_highdif/', '/short/m68/kaa561/ROMS-CICE-MCT/tmproms/run/advection/u3limiters_lowdif/']
# Name of timeseries_seaice logfile in each directory
logfile = 'seaice.log'
# Abbreviations for each simulation to use in the legend
labels = ['C4_L', 'A4_L', 'U3_L','C4_H', 'A4_H', 'U3_LIM']
# Colours for plotting each simulation
colours = ['k', 'm', 'b', 'r', 'g', 'c']
# Set up array of volume timeseries for each simulation
volume = zeros([num_simulations, num_days])
# Read each logfile
for sim in range(num_simulations):
f = open(paths[sim] + logfile, 'r')
# Skip the time header
f.readline()
# Skip the time values
for line in f:
try:
tmp = float(line)
except(ValueError):
break
# Skip the sea ice area values
for line in f:
try:
tmp = float(line)
except(ValueError):
break
# Save the sea ice volume values
t = 0
for line in f:
volume[sim,t] = float(line)
t += 1
f.close()
# Set up time array
time = arange(num_days)
# Plot
fig, ax = subplots()
for sim in range(num_simulations):
ax.plot(time, volume[sim,:], label=labels[sim], linewidth=2, color=colours[sim])
title(r'Total sea ice volume', fontsize=18)
xlabel('days', fontsize=14)
ylabel(r'million km$^3$', fontsize=14)
grid(True)
ax.legend(loc='lower right')
fig.savefig('adv_timeseries_volume.png')
# Command-line interface
if __name__ == "__main__":
adv_timeseries_volume()