Skip to content

Instantly share code, notes, and snippets.

View kartheikiyer's full-sized avatar

Kartheik Iyer kartheikiyer

View GitHub Profile
@kartheikiyer
kartheikiyer / find_npeaks.py
Created October 24, 2018 20:11
short function to find the number of major episodes of star formation in a galaxy's SFH
import numpy as np
import matplotlib.pyplot as plt
def find_nep(sfh_input, timeax, fname, vb = False):
# code to find the number of major episodes of star formation comprisinga galaxy's SFH
#
# inputs:
# sfh_input - 1D numpy array of star formation rates at various times
# timeax - 1D numpy array of the times at which the SFRs are recorded
@kartheikiyer
kartheikiyer / sample_from_pdf.py
Created April 22, 2020 02:07
Simple way to sample from a PDF (not tested for all failure modes)
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(font_scale=1.8)
sns.set_style('white')
# generate some suitably weird random data
pdfsize = 1000000
@kartheikiyer
kartheikiyer / CANDELS_pairs.py
Created October 22, 2020 16:16
Calculating close pairs in the CANDELS fields
# -------------------------------------------------------
# Script to find close pairs in the CANDELS catalog
# By: Kartheik Iyer [Oct 22, 2020]
# -------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
from astropy.cosmology import FlatLambdaCDM
cosmo = FlatLambdaCDM(H0=70, Om0=0.3)
from astropy import units as u
@kartheikiyer
kartheikiyer / making_poster_ready_plots.py
Created August 6, 2021 16:27
Quick matplotlib settings for posters and print
#-------------------------------------------------------------------------------
import matplotlib.pyplot as plt
import matplotlib
# set font and figure sizes here - change these according to your preference
ticksize = 18
labelsize = 24
legendsize = 18
matplotlib.rc('xtick', labelsize=ticksize)
matplotlib.rc('ytick', labelsize=ticksize)
@kartheikiyer
kartheikiyer / prism_disp.py
Created May 4, 2023 15:18
PRISM dispersion for JWST
# get the dispersion function from:
# https://jwst-docs.stsci.edu/jwst-near-infrared-spectrograph/nirspec-instrumentation/nirspec-dispersers-and-filters
# and put it in the _data_path folder
from astropy.table import Table
from sedpy.smoothing import smoothspec
_data_path = 'disp_curves/'
grating = 'prism'
disp = Table.read(f'{_data_path}jwst_nirspec_{grating}_disp.fits')
@kartheikiyer
kartheikiyer / mult_sample.py
Created May 17, 2023 18:55
Sample from multidimensional posteriors
import scipy.stats
# given an SedFit() object from dense basis, this code allows you to sample from the z-M* posterior
# and can be adapted to more general cases as needed
def sample_from_2d_dist(atlas, sedfit, nsamples, zbins = np.linspace(0, 3, 201), massbins = np.linspace(6,12,201)):
zbin_centers = zbins[0:-1] + np.mean(np.diff(zbins))/2
massbin_centers = massbins[0:-1] + np.mean(np.diff(massbins))/2
hist = np.histogram2d(atlas['mstar']+np.log10(sedfit.norm_fac),
atlas['zval'].ravel(),
@kartheikiyer
kartheikiyer / db_setup.md
Created May 12, 2024 17:50
Getting dense_basis set up on a cluster (currently for rusty)
  1. Create a new environment
module load python
module load jupyter-kernels
module load fi-utils
VENVDIR=/mnt/home/kiyer/jhive/
python -m venv --system-site-packages $VENVDIR/jhive_env
source $VENVDIR/jhive_env/bin/activate
  1. Clone the FSPS repository
@kartheikiyer
kartheikiyer / make_smooth_plot.py
Created May 14, 2024 21:29
showing overall trends in a messy camels prediction plot
#-----------------------
def make_smooth_plot(truevals, predvals, lb, ub, nbins = 10, force_bw = True, bw = 0.3):
xgrid = np.linspace(lb, ub, nbins)
if force_bw == True:
xbw = (ub-lb) * bw
else:
xbw = np.mean(np.diff(xgrid))
@kartheikiyer
kartheikiyer / arxiv_cat:astro-ph.HE_daily_digest.md
Last active September 26, 2024 13:14
cat:astro-ph.HE daily digest

2024-09-26 09:14:44:

Headline: From Stellar Explosions to Quantum Black Holes: Unraveling the Mysteries of the Cosmos

Recent advancements in astrophysics and cosmology have unveiled exciting insights into the universe, ranging from the dynamics of supernovae to the enigmatic behavior of black holes. This column highlights several groundbreaking studies that push the boundaries of our understanding.

Neutrino Transport and Supernova Dynamics A significant leap in modeling core-collapse supernovae has been achieved by Santos-Pérez et al. (2024), who introduced a minimally implicit Runge-Kutta method for the numerical integration of neutrino transport equations. This innovative approach addresses the computational challenges posed by stiff equations in optically thick environments, enhancing the accuracy and efficiency of simulations. By applying this method to realistic supernova models, the authors provide a clearer picture of neutrino interactions with matter, w

@kartheikiyer
kartheikiyer / arxiv_cat:astro-ph.IM_daily_digest.md
Last active September 26, 2024 13:17
cat:astro-ph.IM daily digest

2024-09-26 09:17:04:

Headline: From Machine Learning to Gravitational Waves: A New Era in Astrophysics Unfolds

Recent advancements in astrophysics and cosmology are reshaping our understanding of the universe, driven by innovative methodologies and cutting-edge technology. This month, a series of papers highlight significant breakthroughs in areas ranging from the discovery of ultracool dwarfs to the detection of gravitational waves, showcasing the power of machine learning and experimental techniques in modern astronomy.

Machine Learning and Stellar Discoveries: Unveiling Ultracool Dwarfs and Exoplanets
In a groundbreaking study, Brooks et al. (2024) have harnessed the power of machine learning to identify 118 new ultracool dwarf candidates using the SMDET tool, significantly enhancing the efficiency of data analysis from the Wide-field Infrared Survey Explorer (WISE). This advancement builds on previous efforts that relied on manual classification, allowing