Skip to content

Instantly share code, notes, and snippets.

@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 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 / 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.
"""
to store:
$ python manual_grid_val_test.py 1
to compare
$ python manual_grid_val_test.py 0
"""
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;
'''
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

draft_yt_notes.py

A script for initially drafting release notes for yt.

Most of the code is from @neutrinoceros, with some minor updates from @chrishavlin.

It's designed to run with uv. To run directly off of this gist, use the url you get when vewing the raw draft_yt_release_notes.py and supply --help to see the command line options:

uv run https://gist.githubusercontent.com/chrishavlin/248adea4296abb7bcdbaac952f304cf0/raw/fc3443b281fea40f195c563aeddbc722fac4408a/draft_yt_release_notes.py --help 
@chrishavlin
chrishavlin / vbrc_katz_with_partitioning.m
Created October 20, 2025 18:51
using equilibrium partitioning to calculate water concentration to use with the SoLiquidus function from the VBRc
addpath(getenv('vbrdir'))
vbr_init
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% equilibrium partitioning
%
% solidii are in terms of volatile concentration in the
% fluid phase. Can use equilibrium partitioning to estimate
%
% mass conservation: