Skip to content

Instantly share code, notes, and snippets.

"""
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.
@chrishavlin
chrishavlin / IRIS_data_xr_to_yt.py
Created July 28, 2022 20:22
function for loading IRIS data into yt from xarray
import xarray as xr
import yt
import os
import numpy as np
import cartopy.feature as cfeature
import cartopy.crs as ccrs
ddir = os.path.join(yt.config.ytcfg.get('yt','test_data_dir'), 'sample_nc')
# running mypy on this file fails:
# error: Only concrete class can be given where "Type[Student]" is expected
import abc
import functools
# https://docs.python.org/3/library/functools.html#functools.total_ordering
@functools.total_ordering
class Student(abc.ABC):
def __init__(self, firstname: str, lastname: str):
self.firstname = firstname