Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit 8eb21889 authored by ulrich_y's avatar ulrich_y
Browse files

14: Generic combineplot function in re #17

parent e4ed02c8
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,8 @@ import matplotlib.pyplot as plt ...@@ -3,7 +3,8 @@ import matplotlib.pyplot as plt
from vegas import importvegas from vegas import importvegas
from errortools import mergenumbers, plusnumbers, dividenumbers, timesnumbers,\ from errortools import mergenumbers, plusnumbers, dividenumbers, timesnumbers,\
mergeplots, addplots, combineNplots, scaleplot, \ mergeplots, addplots, divideplots, scaleplot, \
combineplots, combineNplots, \
integratehistogram, mergebins integratehistogram, mergebins
from loader import importreg, pattern, setup, sigma, \ from loader import importreg, pattern, setup, sigma, \
mergeset, mergeseeds, mergefks, \ mergeset, mergeseeds, mergefks, \
......
...@@ -82,7 +82,7 @@ def mergeplots(ps, returnchi=False): ...@@ -82,7 +82,7 @@ def mergeplots(ps, returnchi=False):
return out return out
def addplots(a, b, sa=1., sb=1.): def combineplots(a, b, yfunc, efunc):
# There must be a better way of doing this # There must be a better way of doing this
maskA = [False]*len(a) maskA = [False]*len(a)
maskB = [False]*len(b) maskB = [False]*len(b)
...@@ -93,12 +93,27 @@ def addplots(a, b, sa=1., sb=1.): ...@@ -93,12 +93,27 @@ def addplots(a, b, sa=1., sb=1.):
maskB[ib] = True maskB[ib] = True
x = a[maskA, 0] x = a[maskA, 0]
y = sa*a[maskA, 1] + sb*b[maskB, 1] y = yfunc(a[maskA, 1], b[maskB, 1])
e = np.sqrt(sa**2 * a[maskA, 2]**2 + sb**2 * b[maskB, 2]**2) e = efunc(a[maskA, 1], a[maskA, 2], b[maskB, 1], b[maskB, 2])
return np.column_stack((x, y, e)) return np.column_stack((x, y, e))
def addplots(a, b, sa=1., sb=1.):
return combineplots(
a, b,
lambda y1, y2: y1 + y2,
lambda y1, e1, y2, e2: np.sqrt(e1**2 + e2**2)
)
def divideplots(a, b):
return combineplots(
a, b,
lambda y1, y2: y1 / y2,
lambda y1, e1, y2, e2: np.sqrt(e2**2 * y1**2 / y2**4 + e1**2 / y2**2)
)
def combineNplots(func, plots): def combineNplots(func, plots):
accum = plots[0] accum = plots[0]
for plot in plots[1:]: for plot in plots[1:]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment