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
from pymatgen.ext.matproj import MPRester | |
from pymatgen.analysis.phase_diagram import PhaseDiagram, Element, Composition | |
from pymatgen.apps.battery.conversion_battery import ConversionElectrode | |
from collections import defaultdict | |
mpr = MPRester() | |
ents = mpr.get_entries_in_chemsys("Fe-Li-O") | |
pd = PhaseDiagram(ents) | |
def get_conversion_electrodes(pd: PhaseDiagram, working_ion_symbol: str): | |
"""Compute all of the conversion electrodes for a given phase diagram.""" | |
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
from skimage import data | |
from skimage.color import rgb2gray | |
img = data.astronaut() | |
img = rgb2gray(img) | |
a,b,c,d = 90,112,190,220 # crop around the eye | |
fig, (ax1, ax2, ax3) = plt.subplots(1,3, figsize=(20,20)) | |
ax1.axis("off") |
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
from matplotlib import pyplot as plt | |
def func1(X): | |
return np.sin(6 * X) | |
x_coarse = np.linspace(0, np.pi, 10, endpoint=False) | |
x_fine = np.linspace(0, np.pi, 100, endpoint=False) | |
y_coarse = func1(x_coarse) | |
y_fine = interpolate_fourier(y_coarse, [100,]) |
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
import numpy as np | |
import numpy.typing as npt | |
def pad_arr(arr_in: npt.NDArray, shape: list[int]) -> npt.NDArray: | |
"""Pad a function on a hypercube. | |
Parameters | |
---------- | |
arr_in: | |
Data to be padded with zeros |
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
from jobflow.settings import JobflowSettings | |
settings = JobflowSettings() | |
store = jstore.docs_store |
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 update_metadata(flow, metadata_updates: dict): | |
for job in flow.jobs: | |
if isinstance(job, Flow): | |
update_metadata(job, metadata_updates) | |
else: | |
job.metadata.update(metadata_updates) |
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
import stackprinter | |
stackprinter.set_excepthook(style='darkbg2') # for jupyter notebooks try style='lightbg' |
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
from collections import defaultdict | |
import random | |
insert_idx = defaultdict(set) | |
ll = range(6) | |
for n in range(1, 7): | |
for i in range(20): | |
sites = random.sample(ll, n) | |
insert_idx[n].add(frozenset(sites)) |
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
# requires maggma>= 0.19 | |
# Works the same way for MongoStore | |
# For MongoClient just change host to localhost(127.0.0.1) and port to the one from local bind address | |
from maggma.stores.advanced_stores import MongograntStore | |
from sshtunnel import open_tunnel | |
ms = MongograntStore("ro:mongodb03/db_name", 'collection') | |
# Start the ssh_tunnel | |
server = open_tunnel( | |
("dtn03.nersc.gov", 22), |
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
from itertools import product | |
def get_filtered_pos(arr, func): | |
""" | |
Take any ndarray and return the position | |
""" | |
d_ranges = [range(_) for _ in arr.shape] | |
for j in product(*d_ranges): | |
if func(arr[j]): | |
yield j, arr[j] |