Skip to content

Commit ef001ee

Browse files
author
Bryan Lawrence
committed
test runner
1 parent df6b5bb commit ef001ee

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed

bnl/bnl_timeseries.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Simple code to get hemispheric mean of the lowest level of air temperature from
2+
# float UM_m01s30i204_vn1106(time, air_pressure_3, latitude_1, longitude_1) ;
3+
# UM_m01s30i204_vn1106:long_name = "TEMPERATURE ON P LEV/UV GRID" ;" ;
4+
# UM_m01s30i204_vn1106:units = "K" ;
5+
# UM_m01s30i204_vn1106:cell_methods = "time: point" ;
6+
# with
7+
# time = 40 ;
8+
# latitude_1 = 1921 ;
9+
# latitude = 1920 ;
10+
# longitude_1 = 2560 ;
11+
# air_pressure_3 = 11 ;
12+
13+
# This variable is held in an 18 GB file on S3 storage
14+
15+
from activestorage.active import Active
16+
import numpy as np
17+
from time import time
18+
19+
S3_BUCKET = "bnl"
20+
S3_URL = "https://uor-aces-o.s3-ext.jc.rl.ac.uk"
21+
ACTIVE_URL = "https://192.171.169.248:8080"
22+
23+
def timeseries(location='uni', blocks_MB=1, version=2, threads=100):
24+
25+
invoke = time()
26+
storage_options = {
27+
'key': "f2d55c6dcfc7618b2c34e00b58df3cef",
28+
'secret': "$/'#M{0{/4rVhp%n^(XeX$q@y#&(NM3W1->~N.Q6VP.5[@bLpi='nt]AfH)>78pT",
29+
'client_kwargs': {'endpoint_url': f"{S3_URL}"},
30+
'default_fill_cache':False,
31+
'default_cache_type':"readahead",
32+
'default_block_size': blocks_MB * 2**20
33+
}
34+
35+
filename = 'ch330a.pc19790301-def.nc'
36+
uri = S3_BUCKET + '/' + filename
37+
var = "UM_m01s30i204_vn1106"
38+
39+
active = Active(uri, var, storage_type="s3", max_threads=threads,
40+
storage_options=storage_options,
41+
active_storage_url=ACTIVE_URL)
42+
43+
# set active to use the remote reductionist.
44+
# (we intend to change the invocation method
45+
# to something more obvious and transparent.)
46+
active._version = version
47+
48+
# and set the operation, again, the API will change
49+
active._method = "mean"
50+
51+
# get hemispheric mean timeseries:
52+
# (this would be more elegant in cf-python)
53+
ts = []
54+
md = []
55+
for i in range(40):
56+
ts.append(active[i,0,0:960,:][0])
57+
# get some performance diagnostics from pyactive
58+
print(active.metric_data)
59+
if i == 0:
60+
nct = active.metric_data['load nc time']
61+
md.append(active.metric_data['reduction time (s)'])
62+
63+
result = np.array(ts)
64+
print(result)
65+
complete = time()
66+
method = {1:'Local',2:'Active'}[version]
67+
titlestring = f"{location}:{method} (T{threads},BS{blocks_MB}): {nct:.3}s,{sum(md):.4}s,{complete-invoke:.4}s"
68+
print('Summary: ',titlestring)

bnl/bnl_timeseries_plot.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from pathlib import Path
2+
import numpy as np
3+
from matplotlib import pyplot as plt
4+
import os
5+
6+
7+
plt.rcParams["figure.figsize"] = (8,12)
8+
9+
data = {'timeseries1':'Hm1, Active: 5 MB Blks',
10+
'timeseries2':'Hm1, Active: 1 MB Blks',
11+
'timeseries2v1':'Hm1, Local: 1 MB Blks',
12+
'timeseries2-uor-t1-a':'Uni, Active: T1, 1 MB Blks',
13+
'timeseries2-uor-t1-b':'Uni, Active: T1, 1 MB Blks',
14+
'timeseries2-uor-t1-c':'Uni, Active: T1, 1 MB Blks',
15+
'timeseries2-uor-t100-a':'Uni, Active: T100, 1 MB Blks',
16+
'timeseries2-uor-t100-b':'Uni, Active: T100, 1 MB Blks',
17+
'timeseries1-uor-t100-a':'Uni, Local: T100, 1 MB Blks',
18+
'timeseries1-uor-t100-b':'Uni, Local: T100, 1 MB Blks',
19+
'timeseries2v1-uor-t1':'Uni, Local: T1, 1 MB Blks',
20+
'timeseries1-uor-t1':'Uni, Active: T1, 5 MB Blks',
21+
}
22+
tt = []
23+
24+
mypath = Path(__file__).parent
25+
26+
logfiles = mypath.glob('timeseries3-H*.log')
27+
28+
#for d,t in data.items():
29+
30+
for ff in logfiles:
31+
32+
#fname1 = mypath/f'{d}.log'
33+
#fname2 = mypath/f'{d}.metrics.txt'
34+
#os.system(f'grep -a "dataset shape" {fname1} > {fname2}')
35+
#with open(fname2,'r') as f:
36+
with open(ff,'r') as f:
37+
lines = f.readlines()
38+
dicts = [eval(l) for l in lines if l.startswith('{') ]
39+
nct = dicts[0]['load nc time']
40+
rt = [v['reduction time (s)'] for v in dicts]
41+
summary = lines[-1][9:]
42+
overall_time = float(summary.split(',')[-1][:-2])
43+
tt.append((overall_time, rt, summary))
44+
#os.system(f'rm {fname2}')
45+
46+
tts = sorted(tt)
47+
curve = {k:v for i,v,k in tts}
48+
49+
for k in curve.keys():
50+
51+
if 'Local' in k:
52+
ls = 'dashed'
53+
else:
54+
ls = 'solid'
55+
56+
plt.plot(curve[k], label=k, linestyle=ls)
57+
58+
59+
plt.legend(bbox_to_anchor=(0.7, -0.1), fontsize=8)
60+
plt.title('Comparison of reduction parameters')
61+
plt.ylabel('Time to reduce each timestep (s)')
62+
plt.tight_layout()
63+
plt.savefig('home.png')
64+
plt.show()
65+
66+
67+

bnl/bnl_timeseries_runner.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from bnl_timeseries import timeseries
2+
import sys
3+
4+
location = 'Hm1'
5+
blocks = [1,5]
6+
version = [1,2]
7+
threads = [1,100]
8+
iterations = ['a','b','c']
9+
10+
for b in blocks:
11+
for v in version:
12+
for t in threads:
13+
for i in iterations:
14+
with open(f'timeseries3-{location}-{b}-{v}-{t}-{i}.log','w') as sys.stdout:
15+
timeseries(location, b, v, t)

0 commit comments

Comments
 (0)