This file contains hidden or 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
| # Script should be applied to a single Velox emd file, where the file contains a single DCFI dataset | |
| # that has been applied to the detector signal that one wishes to apply to the other detector signals | |
| # A good example is using DCFI on a DF image, and then applying this correction to HAADF, BF and ABF. | |
| import hyperspy.api as hs | |
| import json | |
| import h5py | |
| import numpy as np | |
| def get_nonDCFI_signals(list_of_signals): |
This file contains hidden or 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
| [[language]] | |
| name = "python" | |
| scope = "source.python" | |
| injection-regex = "python" | |
| file-types = ["py","pyi","py3","pyw",".pythonstartup",".pythonrc"] | |
| shebangs = ["python"] | |
| roots = [".", "pyproject.toml", "pyrightconfig.json"] | |
| comment-token = "#" | |
| language-servers = ["pyright", "ruff"] | |
| indent = { tab-width = 4, unit = " " } |
This file contains hidden or 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
| ''' | |
| Python script to load any format supported by hyperspy directly into GMS | |
| Must be copied and pasted into Gatan DigitalMicrograph (aka Gatan Microscopy Suite) version 3.4+ | |
| Call by `load_img(filepath)` at the bottom of the script. Can not be called outside of GMS. | |
| Does not automatically convert the data type to EELS or EDS | |
| Written by Thomas Aarholt, see https://gist.github.com/thomasaarholt/fccf06d56ff84cf76345b44dae30871e for newer versions | |
| Feedback and forks are very welcome. | |
| MUST: First import of hyperspy (or scipy) must NOT be run with "Execute on background thread" checked. One | |
| can then swap to background thread and rerun. | |
| v. 0.3: Added delete statements to ensure python objects don't stay in memory. |
This file contains hidden or 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
| %matplotlib widget | |
| import hyperspy.api as hs | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| ll_sum = hs.load('ll_sum.hspy') | |
| s_sum = hs.load('s_sum.hspy') | |
| s_sum.metadata.Acquisition_instrument.TEM.beam_energy=200 | |
| s_sum.metadata.Acquisition_instrument.TEM.convergence_angle=22.5 | |
| s_sum.metadata.Acquisition_instrument.TEM.Detector.EELS.collection_angle=37.9 |
This file contains hidden or 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
| import numpy as np | |
| import matplotlib | |
| import matplotlib.pyplot as plt | |
| Arc = matplotlib.patches.Arc | |
| def halfangle(a, b): | |
| "Gets the middle angle between a and b, when increasing from a to b" | |
| if b < a: | |
| b += 360 | |
| return (a + b)/2 % 360 |
This file contains hidden or 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
| import numpy as np | |
| from scipy import signal | |
| def gaussian_kernel(n, std, normalised=False): | |
| ''' | |
| Generates a n x n matrix with a centered gaussian | |
| of standard deviation std centered on it. If normalised, | |
| its volume equals 1.''' | |
| gaussian1D = signal.gaussian(n, std) | |
| gaussian2D = np.outer(gaussian1D, gaussian1D) |
This file contains hidden or 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
| # Use the pymc master branch | |
| from collections.abc import Callable | |
| from typing import Literal | |
| from numpy._typing import ArrayLike | |
| import pymc as pm | |
| from numpy import ndarray | |
| from pymc.distributions.shape_utils import ( | |
| Dims, | |
| Shape, |
This file contains hidden or 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
| # print stashes that exist for the currently switched-to branch | |
| GREEN='\033[0;32m' | |
| NC='\033[0m' # No Color | |
| branch=$(git rev-parse --abbrev-ref HEAD) | |
| stashes=`git stash list | grep "WIP on $branch"` | |
| if [ "$stashes" ] | |
| then | |
| echo "${GREEN}You have the following stashes for this branch:" | |
| echo "${stashes}${NC}" |
This file contains hidden or 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
| import sys | |
| from time import time | |
| N_repeats = 100 | |
| def func(foo: list[int]): | |
| return [x for x in foo if x % 2 == 0] |
This file contains hidden or 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 Velox, choose a dataset and select all elements in the periodic table (This is a little tedious) | |
| # From the Velox Menu, go "EDS" -> "Export Quantification Details..." | |
| # This exports two files, one called "... Lines" and one called "... Composition". We want the former. | |
| import pandas as pd | |
| df = pd.read_csv(r"exported_eds_quant-Lines.csv") | |
| DF = df.iloc[1:] # There was a single blank line in my dataset, so I get rid of it | |
| DF.loc[:,'K-factor'] = DF['K-factor'].astype(float) # String to float on the k-factors | |
| # Two functions that we map across the dataset to split the header into separate elements and line | |
| def splitelement(entry): |
NewerOlder