This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make signal starting point and length equal | |
signal_min = bss_spectra[0].axes_manager[-1].axis.min() # This is a float | |
signal_shortest_len = len(bss_spectra[0].axes_manager[-1].axis) # This is an int | |
# Get largest value of s | |
for s in mlls_objects: | |
if s.axes_manager[0].axis.min() > signal_min: | |
signal_min = s.axes_manager[0].axis.min() | |
# Crop all the spectra to start at the same energy index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------------------------------------------------------------------------- | |
ValueError Traceback (most recent call last) | |
<ipython-input-8-d6ad06492590> in <module>() | |
----> 1 bss_spectra[0].plot() | |
/Users/thomas/Dropbox/0_Git/GitHub Desktop/hyperspy/hyperspy/signal.py in plot(self, navigator, axes_manager, **kwargs) | |
2029 | |
2030 self._plot.plot(**kwargs) | |
-> 2031 self.events.data_changed.connect(self.update_plot, []) | |
2032 if self._plot.signal_plot: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [out,h] = read_bytes(fid, location, num_bytes, ttype, reverse_bytes, b8) | |
fseek(fid,location,'bof'); | |
h=fread(fid,num_bytes,ttype); | |
if reverse_bytes | |
% when data have been stored under Windows, the bytes are reversed | |
h=h(end:-1:1); | |
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [im,pp,p]=read_im_file(ff,ask_for_planes,load_accumulated) | |
% Read the binary im file produced by the NanoSIMS 50L machine, and output | |
% the raw images as well as the additional parameters characterizing the | |
% dataset. | |
% NOTE: I don't know why, but data in some binary files are stored as uint8 | |
% (e.g. from MPI Bremen), and in some others they are stored as ushort | |
% (e.g., IoW Warnemuende). It seems that this difference can be "detected" | |
% based on the value of the pixel_size in the Header_image structure. | |
% Therefore, the below coding relies on this to automatically find out how |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> s = hs.load(...) | |
>>> m = s.create_model() | |
... | |
>>> m.store() | |
>>> s.models() | |
└── a | |
├── components | |
│ ├── C_K | |
│ ├── O_K |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mybin(s, xbin=1, ybin=1, sbin=1): | |
"""Return spectrum s binned by factors xbin, ybin, sbin""" | |
if (xbin < 1) or (ybin < 1) or (sbin < 1): | |
raise ValueError("One of your binnings is smaller than 1. For signal axis to remain constant, leave as 1") | |
if all(n==1 for n in (xbin, ybin, sbin)): | |
print("Not binning because all binnings == 1") | |
return s # End Early | |
# Get signal channels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In model.py | |
from numpy.linalg import lstsq as linear_lstsq | |
(...) | |
elif fitter == "linear_lstsq": | |
signal_axis = self.axis.axis[np.where(self.channel_switches)] | |
component_data = np.array([component.function(signal_axis) for component in self]) | |
print(weights) | |
output = linear_lstsq(component_data.T, self.signal()[np.where(self.channel_switches)], **kwargs) | |
self.p0 = tuple([old*factor for old, factor in zip(self.p0, output[0])]) | |
self.fit_output = output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ROI_Rect(s, roi_XY=[], hide=False): | |
""" | |
Plots a hyperspy signal and draws an interactive ROI on it on the top left tenth of the image. | |
Can take a list of [x1, y1, x2, y2] to set a known intial ROI. | |
Returns a tuple of (roi, roi_signal). Use hide=True to not show the plot. | |
Please report bugs/improvements to [email protected] | |
""" | |
import hyperspy.api as hs | |
if s.axes_manager.navigation_dimension < 2: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> m = sc.create_model(auto_add_lines=False) | |
>>> samf = m.create_samfire() | |
[0:apply]: | |
---------------------------------------------------------------------------AttributeError Traceback (most recent call last)<string> in <module>() | |
/Users/thomas/Dropbox/0_Git/GitHub/hyperspy_aar/hyperspy/samfire_utils/samfire_pool.py in <lambda>(worker, m_dict) | |
148 self.rworker = ipp_Reference('worker') | |
149 direct_view.apply(lambda worker, m_dict: | |
--> 150 worker.create_model(m_dict, 'z'), self.rworker, | |
151 m_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> m = sc.create_model() | |
>>> m.components | |
# | Attribute Name | Component Name | Component Type | |
---- | ------------------- | ------------------- | ------------------- | |
0 | background_order_6 | background_order_6 | Polynomial | |
1 | Al_Ka | Al_Ka | Gaussian | |
2 | Al_Kb | Al_Kb | Gaussian | |
3 | C_Ka | C_Ka | Gaussian | |
4 | Ca_Ka | Ca_Ka | Gaussian | |
... |