auswertung fuer tem done

This commit is contained in:
hiro98 2020-01-26 13:27:14 +01:00
parent a07decf99f
commit 84823fde4e
7 changed files with 411 additions and 15 deletions

File diff suppressed because one or more lines are too long

View file

@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 102,
"execution_count": 4,
"metadata": {
"autoscroll": false,
"collapsed": false,
@ -41,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count": 109,
"execution_count": 5,
"metadata": {
"autoscroll": false,
"collapsed": false,
@ -111,7 +111,24 @@
},
{
"cell_type": "code",
"execution_count": 293,
"execution_count": 8,
"metadata": {
"autoscroll": false,
"collapsed": false,
"ein.hycell": false,
"ein.tags": "worksheet-0",
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"source": [
"hypothesis = evaluate_hypothesis(analyzed)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"autoscroll": false,
"collapsed": false,
@ -135,8 +152,80 @@
}
],
"source": [
"print(generate_hypethsesis_table(*evaluate_hypothesis(analyzed)))"
"print(generate_hypethsesis_table(*hypothesis))"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"autoscroll": false,
"collapsed": false,
"ein.hycell": false,
"ein.tags": "worksheet-0",
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"data": {
"text/plain": [
"(0.4131417242218807, 0.009111543899908446, 0.007970106548602144)"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = determine_lattice_constant(hypothesis)\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"autoscroll": false,
"collapsed": false,
"ein.hycell": false,
"ein.tags": "worksheet-0",
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"data": {
"text/plain": [
"(0.413, 0.009, 0.008)"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scientific_round(*a)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"autoscroll": false,
"collapsed": false,
"ein.hycell": false,
"ein.tags": "worksheet-0",
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"source": []
}
],
"metadata": {
@ -155,7 +244,7 @@
"metadata": null,
"name": "python3"
},
"name": "Untitled.ipynb"
"name": "hrtem.ipynb"
},
"nbformat": 4,
"nbformat_minor": 2

View file

@ -42,6 +42,9 @@ def load_profiles(path):
def scientific_round(val, *err):
"""Scientifically rounds the values to the given errors."""
val, err = np.asarray(val), np.asarray(err)
if len(err.shape) == 1:
err = np.array([err])
err = err.T
err = err.T
if err.size == 1 and val.size > 1:
@ -74,7 +77,7 @@ def scientific_round(val, *err):
return rounded, rounded_err
else:
prec = prec[0]
return smart_round(val, prec), smart_round(err, prec)[0]
return smart_round(val, prec), *smart_round(err, prec)[0]
###############################################################################
# Plot Porn #
@ -131,25 +134,55 @@ def save_fig(fig, title, folder='unsorted', size=(5, 4)):
\end{figure}
''')
def plot_profile(profile, **pyplot_args):
def plot_profile_common(profile, **pyplot_args):
x, amp = profile.T
fig, ax = set_up_plot()
ax.step(x, amp, label='Intensität', **pyplot_args)
ax.set_xlim([x[0], x[-1]])
ax.set_ylabel('relative Intensit\"a')
ax.set_xlabel('x [nm]')
ax.legend()
return fig, ax
def analyze_profile(profile, limits=(0, -1), save=None):
def plot_profile(profile, **pyplot_args):
fig, ax = plot_profile_common(profile, **pyplot_args)
ax.set_xlabel('x [nm]')
return fig, ax
def plot_diffr_profile(profile, **pyplot_args):
fig, ax = plot_profile_common(profile, **pyplot_args)
ax.set_xlabel('x [1/nm]')
return fig, ax
def analyze_diffr_profile(profile, limits, save=None, **peak_args):
x, amp = profile.T
fig, ax = plot_diffr_profile(profile)
peaks, peak_info = find_peaks(amp[limits[0]:limits[1]], width=0, **peak_args)
peaks += limits[0]
ax.plot(x[peaks], amp[peaks], "x", label='Peaks')
ax.axvspan(x[limits[0]], x[limits[1]], color='gray', zorder=-1, alpha=.2,
label='Auswertungsbereich')
ax.legend()
candidates = 1/x[peaks]
d_candidates = candidates**2*(x[1]-x[0])
sigma_candidates = candidates**2*peak_info['widths']*(x[1]-x[0])
return candidates, d_candidates, sigma_candidates
def analyze_profile(profile, limits=(0, -1), save=None, **peak_args):
x, amp = profile.T
fig, ax = plot_profile(profile)
peaks, _ = find_peaks(amp[limits[0]:limits[1]])
peaks, _ = find_peaks(amp[limits[0]:limits[1]], **peak_args)
peaks += limits[0]
ax.plot(x[peaks], amp[peaks], "x", label='Peaks')
@ -182,10 +215,25 @@ def evaluate_hypothesis(analyzed, maximum=10, gold=.4078):
def generate_hypethsesis_table(squared, analyzed, residues):
out = ''
for square, value, residue in zip(squared, analyzed, residues):
#value = scientific_round(*value)
val, err = scientific_round(value[0], [value[1]], [value[2]])
value = np.array(scientific_round(*value))
out += rf'\(\sqrt{{{square}}}\) & {val} & ' \
+ ' & '.join(err.astype(str)) + f' & {residue:.3f} \\\\\n'
out += rf'\(\sqrt{{{square}}}\) & ' \
+ ' & '.join(value.astype(str)) + f' & {residue:.3f} \\\\\n'
return out
def determine_lattice_constant(hypothesis):
"""
Calculate the weighted mean and standard deviation by using the
combined deviation as weights.
The systemic deviation is calculated by error propagation.
"""
a_s = hypothesis[1][:,0]
syst_err = hypothesis[1][:,1] + hypothesis[1][:,2]
weights = 1/syst_err**2
a = np.average(a_s, weights=weights)
d_a = np.sqrt(1/np.sum(weights))
sigma_a = np.sqrt(np.average((a_s-a)**2, weights=weights))
return a, d_a, sigma_a