Skip to content

Instantly share code, notes, and snippets.

@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 / 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.
"""
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.
###################################################################
# 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
@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
Principal Components and Data comparison.
@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
'''