Skip to content

Instantly share code, notes, and snippets.

View tomr-stargazer's full-sized avatar

Tom Rice tomr-stargazer

View GitHub Profile
@tomr-stargazer
tomr-stargazer / variable_precision_float.py
Last active December 24, 2015 01:29
Variable length float formatting in strings!
"""
This is useful if you need to output a float to a string to a given length
but don't know what that length is ahead of time.
Hence, you can use
>>> "%.*f" % (x, 3.1415)
instead of
>>> str(round(3.1415, x))
where `x` is the number of decimal places you need.
The main difference is that the former will pad the end with zeros
class BasicDendrogramViewer(object):
def __init__(self, dendrogram, galactic=False):
if galactic:
self.ax1_limits = [0.1, 0.5, 0.8, 0.4] # image
self.slice_slider_ax_limits = [0.05, 0.2, 0.25, 0.03]
self.vmin_slider_ax_limits = [0.05, 0.15, 0.25, 0.03]
self.vmax_slider_ax_limits = [0.05, 0.1, 0.25, 0.03]
self.ax2_limits = [0.4, 0.1, 0.5, 0.35] # dendrogram
else:
@tomr-stargazer
tomr-stargazer / Scatter for phase data
Created November 25, 2013 04:38
Demo of how to do cool colorful folded
import numpy as np
import matplotlib.pyplot as plt
# Let's make some "dummy" data -- a time coordinate "x" and corresponding data "y".
x = np.arange(500)
y = np.sin(x/20.) + x/250.
period= 20 * 2*np.pi
# And then fold it on the period.
{
"metadata": {
"name": "Astro501 Project. Tom Rice"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
{
"metadata": {
"name": "Response to swolk email"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@tomr-stargazer
tomr-stargazer / MAD.py
Last active August 29, 2015 13:59
MAD
import numpy as np
def mad(x):
"""
Calculates the median absolute deviation of an array.
See http://en.wikipedia.org/wiki/Median_absolute_deviation
Parameters
----------
@tomr-stargazer
tomr-stargazer / gist:da2d59204459b04faa88
Created June 17, 2014 22:48
python -m cProfile -s cumtime dendro_test.py > test_output.txt
Generating dendrogram using 307,278 of 5,296,671 pixels (5% of data)
[> ] 0%
[> ] 0%
[> ] 0%
[> ] 0%
[> ] 0%
[> ] 0%
[> ] 0%
[> ] 0%
@tomr-stargazer
tomr-stargazer / recenter_wcs_header.py
Last active August 29, 2015 14:04
recenter wcs header
def recenter_wcs_header(input_header, central_value=0):
"""
Sets the header CRVAL on zero if it's not already.
A quick-and-dirty implementation.
"""
new_header = input_header.copy()
@tomr-stargazer
tomr-stargazer / gist:50deda1f8fefff484773
Created August 5, 2014 05:31
Correlation coefficients
{
"metadata": {
"name": "",
"signature": "sha256:bdad813af58e34dc0582a258505db7bd92308dfcb54d7e5edcf2a1dc2e24cfd1"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"metadata": {
"name": "",
"signature": "sha256:101a92bab1e51ebbcfae72e79a03dc466e53ce36a04ab6fab03dd96b2e2f2770"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [