Skip to content

Commit

Permalink
Merge pull request #4 from pdijksta/restructure_code
Browse files Browse the repository at this point in the history
Restructure coder
  • Loading branch information
pdijksta authored Oct 5, 2017
2 parents d546d65 + b615fea commit ccb8c97
Show file tree
Hide file tree
Showing 16 changed files with 295 additions and 439 deletions.
27 changes: 12 additions & 15 deletions 002b_special_instrumented_cells_details.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from __future__ import division
import cPickle as pickle
import sys
import time
import re
import argparse
import cPickle as pickle

import numpy as np
import matplotlib.pyplot as plt

import sys
sys.path.append('../')



if '..' not in sys.path:
sys.path.append('..')

import LHCMeasurementTools.TimberManager as tm
import LHCMeasurementTools.mystyle as ms
Expand Down Expand Up @@ -253,10 +251,9 @@
arc_hist_dict = lhc_hist_dict['arcs']

# Plots
figs = []

title = 'Special instrumented cells for fill %i' % filln
fig = ms.figure(title, figs)
fig = ms.figure(title)
fig.subplots_adjust(left=.1, right=.75, hspace=.38, wspace=.45)
sp = None

Expand Down Expand Up @@ -311,7 +308,7 @@ def round_to(arr, precision):
bins = np.arange(round_to(arc_hist_total.min(),binwidth)-binwidth, round_to(arc_hist_total.max(),binwidth)+binwidth*3/2, binwidth)

if separate_fig_for_hist:
fig = ms.figure('Special cells in histogram of heatloads', figs)
fig = ms.figure('Special cells in histogram of heatloads')
sp = plt.subplot(2,2,1)
else:
sp = plt.subplot(2,2,4)
Expand All @@ -334,7 +331,7 @@ def round_to(arr, precision):
sp_ctr = ctr % 4 + 1
if sp_ctr == 1:
title = 'Fill %i: Heat loads at %.1f hours' % (filln, avg_time_hrs)
fig = ms.figure(title, figs)
fig = ms.figure(title)
sp = plt.subplot(2,2,sp_ctr)
sp.hist(arc_hist_total, bins=bins, alpha=0.5, color='blue', weights=1./len(arc_hist_total)*np.ones_like(arc_hist_total))
sp.hist(data, bins=bins, color='green', alpha=0.5, weights=1./len(data)*np.ones_like(data))
Expand Down Expand Up @@ -377,7 +374,7 @@ def round_to(arr, precision):


# Compare dipoles to quads
fig_dev = ms.figure('Compare devices', figs)
fig_dev = ms.figure('Compare devices')
fig_dev.subplots_adjust(left=.06, right=.84, top=.93, hspace=.38, wspace=.46)

# Logged data
Expand Down Expand Up @@ -461,7 +458,7 @@ def round_to(arr, precision):
for cell_ctr, cell in enumerate(cells):
sp_ctr = cell_ctr % 3 + 1
if sp_ctr == 1:
fig = ms.figure('HL dict' + title, figs)
fig = ms.figure('HL dict' + title)
fig.subplots_adjust(left=.06, right=.84, top=.93, hspace=.38, wspace=.42)
sp = plt.subplot(3,1,sp_ctr, sharex=sp)
sp.set_xlabel('Fill number')
Expand Down Expand Up @@ -522,7 +519,7 @@ def round_to(arr, precision):

re_var = re.compile('^\w{4}_\w?(\d\d[RL]\d_TT\d{3})\.POSST$')
title = 'Fill %i temperature sensors' % filln
fig = ms.figure(title, figs)
fig = ms.figure(title)
fig.subplots_adjust(left=.06, right=.84, top=.93, hspace=.38, wspace=.42)
for cell_ctr, cell in enumerate(cells):
acell = alternate_notation[cell]
Expand Down Expand Up @@ -557,7 +554,7 @@ def round_to(arr, precision):
# Separate hl for b1, b2
if args.separate:
title = 'Fill %i separate beam screens' % filln
fig = ms.figure(title, figs)
fig = ms.figure(title)
fig.subplots_adjust(left=.06, right=.84, top=.93, hspace=.38, wspace=.42)

qbs_special = cqs.compute_qbs_special(special_atd, separate=True)
Expand Down Expand Up @@ -585,7 +582,7 @@ def round_to(arr, precision):
ms.comb_legend(sp,sp2,bbox_to_anchor=(1.3,1), fontsize=myfontsz)

if args.contributions:
fig = ms.figure('Heat load contributions', figs)
fig = ms.figure('Heat load contributions')
fig.subplots_adjust(right=0.75, wspace=0.45, hspace=0.4)
sp = None

Expand Down
12 changes: 9 additions & 3 deletions 004_compare_qbs_versions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import division
import os
import re
import argparse

import matplotlib.pyplot as plt

import h5_storage
Expand All @@ -10,12 +12,16 @@

import LHCMeasurementTools.mystyle as ms

parser = argparse.ArgumentParser()
parser.add_argument('filln', type=int)
parser.add_argument('--include-current', action='store_true', help='Recompute using the current code')
args = parser.parse_args()

plt.close('all')
ms.mystyle()

filln = 5219
show_current = False
filln = args.filln
show_current = args.include_current

re_dir = re.compile('recalculated_qbs_(nodP_)?v(\d+)')
dirs = filter(re_dir.match, os.listdir(h5_storage.recalc_dir))
Expand All @@ -38,7 +44,7 @@
sps.append(sp)

for ctr, (dir_, nodp, version) in enumerate(dir_dp_version):
use_dP = nodp == None
use_dP = (nodp == None)
if use_dP:
label = 'V%s with dP' % version
else:
Expand Down
107 changes: 0 additions & 107 deletions 007_compare_to_older_version.py

This file was deleted.

1 change: 1 addition & 0 deletions 008_play_with_compute_qbs_LHC.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## Find out more about computation internals: What happens for different Reynold's numbers.
import numpy as np
import matplotlib.pyplot as plt
#import sys
Expand Down
14 changes: 6 additions & 8 deletions 009_investigate_gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@
import LHCMeasurementTools.mystyle as ms
#import LHCMeasurementTools.savefig as sf

parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser('For a typical fill, show values that are important to the computation, and how often they occur during a typical computation of a typical fill. Both at high energy and for the full duration.')
parser.add_argument('--calc', help='Calculate instead of loading from pickle.', action='store_true')
parser.add_argument('--savefig', help='Save in file.')
parser.add_argument('--savefig', help='Save in files.')
parser.add_argument('--noshow', help='Do not call plt.show', action='store_true')
parser.add_argument('--onlyarcs', help='Only show arc_cells', action='store_true')
parser.add_argument('--onlyinterp', help='Only show interp values', action='store_true')
args = parser.parse_args()

recompute = args.calc
only_interp = args.onlyinterp
figs = []


ms.mystyle()

plt.close('all')

filln = 5219
Expand All @@ -51,7 +48,7 @@
for i in xrange(hlc.Ncell):
gamma[j,i] = interp_P_T_gamma(P3[j,i], T3[j,i])

fig = ms.figure('Interpolated Data', figs)
fig = ms.figure('Interpolated Data')

interps = (interp_P_T_hPT, interp_P_T_DPT, interp_P_T_mu, interp_P_T_gamma)
titles = ('Enthalpy', 'Density', 'Viscosity', 'Heat capacity ratio')
Expand Down Expand Up @@ -179,7 +176,7 @@
affix = '(computed)'
sp_ctr = ctr % 4 +1
if cc == 1 and sp_ctr == 1:
fig = ms.figure(plot_title, figs)
fig = ms.figure(plot_title)
fig.subplots_adjust(right=0.75, )
fig_ctr += 1
if cc == 1:
Expand Down Expand Up @@ -210,7 +207,8 @@
sp.legend(loc=0)

if args.savefig:
for fig in figs:
for num in plt.get_fignums():
fig = plt.figure(num)
fig.savefig(os.path.expanduser(args.savefig) + '_%i.png' % fig.number)

if not args.noshow:
Expand Down
11 changes: 6 additions & 5 deletions 011_test_aligned_to_dict.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## Test if two methods in compute_QBS_special work.
import numpy as np
import qbs_fill as qf
import compute_QBS_special as cqs

filln = 5219

def compare_dicts_recursively(dd1, dd2):
equal = True
for key, value1 in dd1.iteritems():
value2 = dd2[key]
if type(value1) is np.ndarray:
Expand All @@ -18,18 +18,19 @@ def compare_dicts_recursively(dd1, dd2):
else:
equal = value1 == value2
if not equal:
break
return equal
return False
return True

qbs_dict = qf.special_qbs_fill(5219)

qbs_ob = cqs.dict_to_aligned(qbs_dict)
qbs_ob = cqs.dict_to_aligned_separate(qbs_dict)

qbs_dict_2 = cqs.aligned_to_dict(qbs_ob)
qbs_dict_2 = cqs.aligned_to_dict_separate(qbs_ob)
print(compare_dicts_recursively(qbs_dict_2, qbs_dict))


qbs_dict_2['timestamps'] = np.copy(qbs_dict['timestamps'])
qbs_dict_2['timestamps'][0] = 0

print(compare_dicts_recursively(qbs_dict_2, qbs_dict))

Loading

0 comments on commit ccb8c97

Please sign in to comment.