Skip to content

Instantly share code, notes, and snippets.

'''
this takes the backup file from the Fast Notepad android app and saves every
note as an individual file. loses info on folder hierarchy, it probably is
buggy and may need tweaking but it was sufficient for my purposes...
Requirements:
python 3+
To use:
1. edit the fname, output_dir and output_format vars below
function manual_lau_holtzman_fig2()
% recreate fig 2 of lau and holtzman 2019 grl
% https://doi.org/10.1029/2019GL083529
beta = 1e-4
alf = 1/3
Mu_in = 60*1e9;
eta_ss = 1.8922e+21;
tau_M = eta_ss / Mu_in;
"""
to store:
$ python manual_grid_val_test.py 1
to compare
$ python manual_grid_val_test.py 0
"""
@chrishavlin
chrishavlin / streamlines_on_volume_rendering.py
Created November 6, 2023 17:36
adding streamlines to a volume rendering in yt
import yt
from yt.units import Mpc
from yt.visualization.api import Streamlines
from yt.visualization.volume_rendering.api import LineSource
import numpy as np
# streamline alpha value: determines opacity of LineSource
# objects. A bit of trial and error to pick a good value
# so that both the volume rendering and the lines show up.
# this value works for the transfer function used below.
import numpy as np
import yt.utilities.linear_interpolators as lin
from yt.testing import fake_random_ds
import time
import matplotlib.pyplot as plt
times_3d_eval = []
times_3d_init = []
Nvals_3d = 2 ** np.arange(3, 9)
for n in Nvals_3d:
@chrishavlin
chrishavlin / yt_off_axis_proj_varying_center_fixed_depth.py
Created October 19, 2023 15:05
yt_off_axis_proj_varying_center_fixed_depth.py
import yt
ds = yt.load_sample("gizmo_64") # 3ish GB download
center = ds.domain_center.to('Mpc').d
z_hat_original = ds.arr([0.3, 0.3, 0.3], 'kpc')
y_hat_original = ds.arr([1., 0., 0.], 'kpc')
for x_loc in list(range(2,19,1)):
c = ((x_loc, center[1], center[2]), 'Mpc')
import sys
import numpy as np
import yt
import yt_idv
# yt reminder: phi is the polar angle (0 to 2pi)
# theta is the angle from north (0 to pi)
diff --git a/yt/_typing.py b/yt/_typing.py
index 0062c63dd..15fcd8a6f 100644
--- a/yt/_typing.py
+++ b/yt/_typing.py
@@ -1,4 +1,4 @@
-from typing import List, Optional, Tuple, Union
+from typing import Any, Callable, Dict, List, Optional, Tuple, Union
import unyt as un
from numpy import ndarray
@chrishavlin
chrishavlin / rio_with_jpeg.ipynb
Created November 10, 2022 17:40
using rasterio to load a jpeg and reproject in memory
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.