Skip to content

Instantly share code, notes, and snippets.

View granttremblay's full-sized avatar
🌳

Grant Tremblay granttremblay

🌳
View GitHub Profile
@granttremblay
granttremblay / cmap_discretize.py
Created July 2, 2022 21:10
Make a discrete colormap from a continuous colormap
def cmap_discretize(cmap, N):
"""Return a discrete colormap from the continuous colormap cmap.
cmap: colormap instance, eg. cm.jet.
N: number of colors.
"""
if type(cmap) == str:
cmap = get_cmap(cmap)
colors_i = np.concatenate((np.linspace(0, 1., N), (0.,0.,0.,0.)))
colors_rgba = cmap(colors_i)
#!/usr/bin/env python
import numpy as np
from astropy import units as u
from astropy import constants as const
@u.quantity_input # input validation decorator
def photon_ring_angular_size(mass: u.Msun, dist: u.pc):
def calc_time_to_next_comm(start=None, debug_prints=False):
'''
Queries the Kadi event database for the next several (scheduled) comm passes.
Calculates the duration between now (in UTC) and the next comm pass.
If that duration is negative (i.e. that comm already happened), it searches
the list of passes for the first positive time delta, i.e. the first comm pass in the future.
Returns a string in reporting the time to the next comm pass.
'''
import os
import shutil
import glob
filelist = glob.glob('*.png')
for image in filelist:
stringarray = image.split('_')
namearray = stringarray[-1].split('---')[-1].split('.')[0].split('-')
@granttremblay
granttremblay / elise.py
Created January 22, 2020 03:20
Make Elise's Excel Spreadsheets
#!/usr/bin/env python3
'''
A script for my cutie by her boy
'''
import numpy as np
import pandas as pd
import xlrd
@granttremblay
granttremblay / paranal_colormaps.py
Last active December 12, 2019 04:33
Paranal Colormaps (**NOT PERCEPTUALLY UNIFORM!! ***)
import json
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.cm import register_cmap
cdict_sunset = {'red': [[0.0, 0.10980392156862745, 0.10980392156862745], [0.09090909090909091, 0.14901960784313725, 0.14901960784313725], [0.18181818181818182, 0.17254901960784313, 0.17254901960784313], [0.2727272727272727, 0.22745098039215686, 0.22745098039215686], [0.36363636363636365, 0.2549019607843137, 0.2549019607843137], [0.45454545454545453, 0.2901960784313726, 0.2901960784313726], [0.5454545454545454, 0.38823529411764707, 0.38823529411764707], [0.6363636363636364, 0.5333333333333333, 0.5333333333333333], [0.7272727272727273, 0.7058823529411765, 0.7058823529411765], [0.8181818181818182, 0.8392156862745098, 0.8392156862745098], [0.9090909090909091, 0.9764705882352941, 0.9764705882352941], [1.0, 1.0, 1.0]], 'green': [[0.0, 0.09803921568627451, 0.09803921568627451], [0.09090909090909091, 0.1411764705882353, 0.1411764705882353], [0.18181818181818182, 0.16470588235294117, 0.16470588235294117], [0.272
@granttremblay
granttremblay / download_astro2020_whitepapers.py
Last active March 13, 2019 01:52
Download all Astro2020 Whitepaper PDFs
#!/usr/bin/env/python
import requests
from astropy.io import ascii
table = ascii.read('all_astro2020_whitepapers.csv')
numbers = table['Response ID']
people = table['Last Name:Principal Author']
urls = table['1:Upload File']
@granttremblay
granttremblay / stack_tables.py
Last active May 23, 2018 17:44
Stack Mainak's FITS tables quickly & flexibly
#!/usr/bin/env python
import glob
import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
from astropy.table import Table, vstack
def make_stars(kintable, fovimage, redshift, name, snthresh=100, velocity_thresh=None, project_by_median=True, project_by_redshift=False, cropbox=None, zoom=False, zoombox=None, wcs=True, nancolor='white', colorbar_scalefactor=0.047, vel_vmin=-500, vel_vmax=500, disp_vmin=0, disp_vmax=300, save=True, file_save_directory="./"):
table = fits.getdata(kintable)
#hdr = fits.getheader(fovimage)
x = table['x_cor']
y = table['y_cor']
# Get the 2D dimensions into which you'll paint this data
fovdata = fits.getdata(fovimage)
def fusemusealma(muse_moment_fits, alma_moment_fits):
'''
Open MUSE and ALMA HDUs, pick up their WCSs,
drop needless ALMA WCS axes, reproject
ALMA to MUSE, then output new HDUs.
'''
museHDU = fits.open(get_pkg_data_filename(muse_moment_fits))
almaHDU = fits.open(get_pkg_data_filename(alma_moment_fits))