Skip to content

Instantly share code, notes, and snippets.

@michael-petersen
michael-petersen / outcoef.py
Created May 5, 2020 20:36
Bare minimum coefficient reader -- just an interface to pull in outcoefs directly to python.
'''
outcoef.py
(broken out of exptool)
tools to read coefficient files and do rudimentary manipulation.
MSP 30 April 2020
'''
Principal Components and Data comparison.
@michael-petersen
michael-petersen / Alegendre_test.cpp
Last active November 24, 2023 20:43
Practice implementation of Holmes & Featherstone (2002) associated Legendre function calculation, as compared to Bonnet's recursion relation.
// C++ program to calculate test breakdown of Legendre polynomials
// clang++ -I/opt/local/include/eigen3 -o legendre legendre_test.cpp
#include <iostream>
#include <cmath>
#include <Eigen/Eigen>
#define MINEPS 1.0e-10
###################################################################
# a 1-d Monte Carlo example
###################################################################
import numpy as np
import matplotlib.pyplot as plt
# first, set up the gaussian we want to approximate
gaussmean = 0.0
gaussdisp = 0.3
import numpy as np
import matplotlib.pyplot as plt
def read_outlog(filename):
"""definition to read EXP 'OUTLOG'-style files
One large dictionary is returned, with sub-dictionaries.
Each component is returned as a sub-dictionary, with positions,
velocities, and energy conservation.
An additional sub-dictionary, with global quantities, is also included.
@michael-petersen
michael-petersen / read_orbtrace.py
Last active July 19, 2023 10:52
Code to read EXP-specific 'ORBTRACE' files.
import numpy as np
import matplotlib.pyplot as plt
def read_orbtrace(filename):
"""definition to read EXP 'ORBTRACE'-style files
One large dictionary is returned, with sub-dictionaries.
Each orbit is returned as a sub-dictionary, with positions,
velocities, and accelerations.
"""
@michael-petersen
michael-petersen / makemodel.py
Last active December 18, 2024 11:35
Code to make EXP-compatible spherical model files
import numpy as np
from simple_density_functions import *
def makemodel(func,M,funcargs,rvals = 10.**np.linspace(-2.,4.,2000),pfile='',plabel = '',verbose=True):
"""make an EXP-compatible spherical basis function table
inputs
-------------
func : (function) the callable functional form of the density
@michael-petersen
michael-petersen / density_binner.py
Last active May 20, 2022 19:01
A basic particle density binning technique in Python.
import numpy as np
def return_density(logr,weights=1.,rangevals=[-2, 6],bins=500,d2=False):
"""return_density
simple binned density using logarithmically spaced bins
inputs
---------
logr : (array) log radii of particles to bin
@michael-petersen
michael-petersen / GenerateSphereSurface.py
Last active August 10, 2022 00:42
How would a oblate ellipsoid of points look if projected on a sphere? How does the inclusion of spherical harmonic deformations affect originally spherical equipotential surfaces?
import numpy as np
def gen_sphere_surface(npoints):
"""generate a sphere of stars, evenly spaced on the surface of a sphere"""
npoint = 0
points = np.zeros([npoints,3])
a = 4*np.pi/npoints
d = np.sqrt(a)
Mtheta = np.floor(np.pi/d).astype('int')
dtheta = np.pi/Mtheta
@michael-petersen
michael-petersen / launch_all_lmaxnmax.sh
Last active May 11, 2024 09:53
PBS script to run EXP on infinity, including a template YAML file, and a driver file.
#!/bin/sh
# we want to create a grid of simulations, from
# lmax \in [2,4,6,8,12,16,24,32,64]
# nmax \in [2,4,8,16,24,32,48,64,128]
# for an ensemble of 10 simulations, e.g.
# run in run1a run1b run1c run1d run1e run1f run1g run1h run1i run1j
for run in run2a run2b run2c run2d run2e run2f