Skip to content

Instantly share code, notes, and snippets.

@DanHickstein
Created April 11, 2019 14:16
Show Gist options
  • Save DanHickstein/68da7ba0c155e0550993e29f392575be to your computer and use it in GitHub Desktop.
Save DanHickstein/68da7ba0c155e0550993e29f392575be to your computer and use it in GitHub Desktop.
comb comparison
import abel
from abel.tools.analytical import PiecewisePolynomial
from itertools import chain
import matplotlib.pyplot as plt
import numpy as np
hw = 1 # peak half-width
step = 10 # center-to-center distance between peaks
n = 10 # number of peaks
rmax = int(n * step)
def peak(i):
c = i * step
if i:
return [(c - hw, c, [1, 1], c, hw),
(c, c + hw, [1, -1], c, hw)]
else:
return [(c, c + hw, [1, -1], c, hw)]
comb = PiecewisePolynomial(rmax + 1, rmax,
chain(*[peak(i) for i in range(1, n)]),
symmetric=False)
np.random.seed(0)
func = comb.abel + np.random.random(comb.abel.size)*1
transforms = [
("basex" , abel.basex.basex_transform , '#880000'),
("direct" , abel.direct.direct_transform , '#EE0000'),
("hansenlaw" , abel.hansenlaw.hansenlaw_transform , '#CCAA00'),
("onion_bordas" , abel.onion_bordas.onion_bordas_transform, '#00AA00'),
("onion_peeling", abel.dasch.onion_peeling_transform , '#00CCFF'),
("three_point" , abel.dasch.three_point_transform , '#0000FF'),
("two_point" , abel.dasch.two_point_transform , '#CC00FF'),
# ("linbasex" , abel.linbasex.linbasex_transform , '#BBBBBB'),
]
ntrans = len(transforms) # number of transforms
fig, axs = plt.subplots(ntrans, 1, figsize=(3.37,7.3), sharex=True, sharey=True)
for num, (ax, (label, transFunc, color)) in enumerate(zip(axs.ravel(), transforms)):
print(label)
ax.plot(comb.r, comb.func, lw=1, label='actual'.format(hw))
recd = transFunc(func)
ax.plot(comb.r, recd, lw=1, label=label)
for ax in axs:
ax.legend(fontsize=8, loc='upper right')
ax.set_xlim(0,40)
axs[-1].set_xlabel('r (pixel)')
fig.tight_layout(pad=0)
plt.savefig('comb.png', dpi=300)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment