Skip to content

Commit fc53bba

Browse files
committed
Add 2.0 dev version to try version switcher
1 parent 7fcbbab commit fc53bba

File tree

416 files changed

+136106
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

416 files changed

+136106
-0
lines changed

dev/.buildinfo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 60e0ddb440842457518e04499e7322f0
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7

dev/.nojekyll

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%matplotlib inline"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"\n# EELS curve fitting\n\nPerforms curve fitting to an EELS spectrum, plots the result and saves it as\npng file.\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [],
28+
"source": [
29+
"import hyperspy.api as hs\n\ns = hs.load(\"coreloss_spectrum.msa\", signal_type=\"EELS\")\nll = hs.load(\"lowloss_spectrum.msa\", signal_type=\"EELS\")\n\ns.add_elements((\"Mn\", \"O\"))\ns.set_microscope_parameters(\n beam_energy=300,\n convergence_angle=24.6,\n collection_angle=13.6\n )\n\nm = s.create_model(ll=ll)\nm.enable_fine_structure()\nm.multifit(kind=\"smart\")\nm.plot()"
30+
]
31+
}
32+
],
33+
"metadata": {
34+
"kernelspec": {
35+
"display_name": "Python 3",
36+
"language": "python",
37+
"name": "python3"
38+
},
39+
"language_info": {
40+
"codemirror_mode": {
41+
"name": "ipython",
42+
"version": 3
43+
},
44+
"file_extension": ".py",
45+
"mimetype": "text/x-python",
46+
"name": "python",
47+
"nbconvert_exporter": "python",
48+
"pygments_lexer": "ipython3",
49+
"version": "3.9.13"
50+
}
51+
},
52+
"nbformat": 4,
53+
"nbformat_minor": 0
54+
}
Binary file not shown.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
Creates a spectrum image and plots it
3+
=====================================
4+
5+
This example creates a spectrum image, i.e. navigation dimension 2 and
6+
signal dimension 1, and plots it
7+
"""
8+
9+
import numpy as np
10+
import hyperspy.api as hs
11+
import matplotlib.pyplot as plt
12+
13+
# Create a spectrum image with random data
14+
s = hs.signals.Signal1D(np.random.random((64, 64, 1024)))
15+
16+
# Define the axis properties
17+
s.axes_manager.signal_axes[0].name = 'Energy'
18+
s.axes_manager.signal_axes[0].units = 'eV'
19+
s.axes_manager.signal_axes[0].scale = 0.3
20+
s.axes_manager.signal_axes[0].offset = 100
21+
22+
s.axes_manager.navigation_axes[0].name = 'X'
23+
s.axes_manager.navigation_axes[0].units = 'nm'
24+
s.axes_manager.navigation_axes[0].scale = 0.1
25+
s.axes_manager.navigation_axes[0].offset = 100
26+
27+
s.axes_manager.navigation_axes[1].name = 'Y'
28+
s.axes_manager.navigation_axes[1].units = 'nm'
29+
s.axes_manager.navigation_axes[1].scale = 0.1
30+
s.axes_manager.navigation_axes[1].offset = 100
31+
32+
# Give a title
33+
s.metadata.General.title = 'Random spectrum image'
34+
35+
# Plot it
36+
s.plot()
37+
38+
plt.show() # No necessary when running in the HyperSpy's IPython profile
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
Simple simulation (2 Gaussians)
3+
===============================
4+
5+
Creates a 2D hyperspectrum consisting of two Gaussians and plots it.
6+
7+
This example can serve as starting point to test other functionalities on the
8+
simulated hyperspectrum.
9+
10+
"""
11+
import numpy as np
12+
import hyperspy.api as hs
13+
import matplotlib.pyplot as plt
14+
15+
16+
# Create an empty spectrum
17+
s = hs.signals.Signal1D(np.zeros((32, 32, 1024)))
18+
19+
# Generate some simple data: two Gaussians with random centers and area
20+
21+
# First we create a model
22+
m = s.create_model()
23+
24+
# Define the first gaussian
25+
gs1 = hs.model.components1D.Gaussian()
26+
# Add it to the model
27+
m.append(gs1)
28+
29+
# Set the parameters
30+
gs1.sigma.value = 10
31+
# Make the center vary in the -5,5 range around 128
32+
gs1.centre.map['values'][:] = 256 + (np.random.random((32, 32)) - 0.5) * 10
33+
gs1.centre.map['is_set'][:] = True
34+
35+
# Make the area vary between 0 and 10000
36+
gs1.A.map['values'][:] = 10000 * np.random.random((32, 32))
37+
gs1.A.map['is_set'][:] = True
38+
39+
# Second gaussian
40+
gs2 = hs.model.components1D.Gaussian()
41+
# Add it to the model
42+
m.append(gs2)
43+
44+
# Set the parameters
45+
gs2.sigma.value = 20
46+
47+
# Make the center vary in the -10,10 range around 768
48+
gs2.centre.map['values'][:] = 768 + (np.random.random((32, 32)) - 0.5) * 20
49+
gs2.centre.map['is_set'][:] = True
50+
51+
# Make the area vary between 0 and 20000
52+
gs2.A.map['values'][:] = 20000 * np.random.random((32, 32))
53+
gs2.A.map['is_set'][:] = True
54+
55+
# Create the dataset
56+
s_model = m.as_signal()
57+
58+
# Add noise
59+
s_model.set_signal_origin("simulation")
60+
s_model.add_poissonian_noise()
61+
62+
# Plot the result
63+
s_model.plot()
64+
65+
plt.show()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Simple arctan fit
3+
=================
4+
5+
Fit an arctan function.
6+
7+
"""
8+
9+
import numpy as np
10+
import hyperspy.api as hs
11+
12+
# Generate the data and make the spectrum
13+
data = np.arctan(np.arange(-500, 500))
14+
s = hs.signals.Signal1D(data)
15+
s.axes_manager[0].offset = -500
16+
s.axes_manager[0].units = ""
17+
s.axes_manager[0].name = "x"
18+
s.metadata.General.title = "Simple arctan fit"
19+
s.set_signal_origin("simulation")
20+
21+
s.add_gaussian_noise(0.1)
22+
23+
# Make the arctan component for use in the model
24+
arctan_component = hs.model.components1D.Arctan()
25+
26+
# Create the model and add the arctan component
27+
m = s.create_model()
28+
m.append(arctan_component)
29+
30+
# Fit the arctan component to the spectrum
31+
m.fit()
32+
33+
# Print the result of the fit
34+
m.print_current_values()
35+
36+
# Plot the spectrum and the model fitting
37+
m.plot()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Creates a 4D image and plots it
3+
===============================
4+
5+
This example creates a 4D dataset, i.e. 2 navigation dimension and
6+
2 signal dimension and plots it
7+
"""
8+
9+
import numpy as np
10+
import hyperspy.api as hs
11+
12+
# Create a 2D image stack with random data
13+
im = hs.signals.Signal2D(np.random.random((16, 16, 32, 32)))
14+
15+
# Define the axis properties
16+
im.axes_manager.signal_axes[0].name = ''
17+
im.axes_manager.signal_axes[0].units = '1/nm'
18+
im.axes_manager.signal_axes[0].scale = 0.1
19+
im.axes_manager.signal_axes[0].offset = 0
20+
21+
im.axes_manager.signal_axes[1].name = ''
22+
im.axes_manager.signal_axes[1].units = '1/nm'
23+
im.axes_manager.signal_axes[1].scale = 0.1
24+
im.axes_manager.signal_axes[1].offset = 0
25+
26+
im.axes_manager.navigation_axes[0].name = 'X'
27+
im.axes_manager.navigation_axes[0].units = 'nm'
28+
im.axes_manager.navigation_axes[0].scale = 0.3
29+
im.axes_manager.navigation_axes[0].offset = 100
30+
31+
im.axes_manager.navigation_axes[1].name = 'Y'
32+
im.axes_manager.navigation_axes[1].units = 'nm'
33+
im.axes_manager.navigation_axes[1].scale = 0.3
34+
im.axes_manager.navigation_axes[1].offset = 100
35+
36+
# Give a title
37+
im.metadata.General.title = 'Random 2D image stack'
38+
39+
im.plot()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%matplotlib inline"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"\n# Creates a line spectrum\n\nThis example creates a line spectrum and plots it\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [],
28+
"source": [
29+
"import numpy as np\nimport hyperspy.api as hs\n\n# Create a line spectrum with random data\ns = hs.signals.Signal1D(np.random.random((100, 1024)))\n\n# Define the axis properties\ns.axes_manager.signal_axes[0].name = 'Energy'\ns.axes_manager.signal_axes[0].units = 'eV'\ns.axes_manager.signal_axes[0].scale = 0.3\ns.axes_manager.signal_axes[0].offset = 100\n\ns.axes_manager.navigation_axes[0].name = 'time'\ns.axes_manager.navigation_axes[0].units = 'fs'\ns.axes_manager.navigation_axes[0].scale = 0.3\ns.axes_manager.navigation_axes[0].offset = 100\n\n# Give a title\ns.metadata.General.title = 'Random line spectrum'\n\n# Plot it\ns.plot()"
30+
]
31+
}
32+
],
33+
"metadata": {
34+
"kernelspec": {
35+
"display_name": "Python 3",
36+
"language": "python",
37+
"name": "python3"
38+
},
39+
"language_info": {
40+
"codemirror_mode": {
41+
"name": "ipython",
42+
"version": 3
43+
},
44+
"file_extension": ".py",
45+
"mimetype": "text/x-python",
46+
"name": "python",
47+
"nbconvert_exporter": "python",
48+
"pygments_lexer": "ipython3",
49+
"version": "3.9.13"
50+
}
51+
},
52+
"nbformat": 4,
53+
"nbformat_minor": 0
54+
}
Binary file not shown.

0 commit comments

Comments
 (0)