Skip to content

Instantly share code, notes, and snippets.

Henry Roe henryroe

Block or report user

Report or block henryroe

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@henryroe
henryroe / grepfits
Last active Jul 26, 2016
grepfits: Command line script for summarizing selected keywords from headers of one or more FITS files
View grepfits
#!/usr/bin/env python
# This script is released under an "MIT License"; see https://opensource.org/licenses/MIT
# The MIT License (MIT)
# Copyright (c) 2016 Henry Roe (hroe@hroe.me)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
@henryroe
henryroe / lessfits
Created Jul 26, 2016
lessfits: Command line script for paging through a FITS file's headers
View lessfits
#!/bin/bash
# This script is released under an "MIT License"; see https://opensource.org/licenses/MIT
# The MIT License (MIT)
# Copyright (c) 2016 Henry Roe (hroe@hroe.me)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
@henryroe
henryroe / Save mail attachments with pre-pended YYYY-MM-DD_.kmmacros
Created Feb 16, 2015
Keyboard Maestro macro to take Mail.app attachments, pre-pend YYYY-MM-DD_..., and save to user-selected dir
View Save mail attachments with pre-pended YYYY-MM-DD_.kmmacros
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>Activate</key>
<string>Normal</string>
<key>IsActive</key>
<true/>
<key>Macros</key>
@henryroe
henryroe / prepend_and_save.scpt
Created Feb 14, 2015
Save mail attachments after pre-pending YYYY-MM-DD_
View prepend_and_save.scpt
set outputPath to choose folder
tell application "Mail"
set curMessage to selection
set listAttachments to mail attachment of item 1 of curMessage
set curMessageDate to date received of item 1 of curMessage
set dateStr to (rich text -4 thru -1 of ("0000" & (year of curMessageDate))) & "-" & ¬
(rich text -2 thru -1 of ("00" & ((month of curMessageDate) as integer))) & "-" & ¬
(rich text -2 thru -1 of ("00" & (day of curMessageDate)))
repeat with a from 1 to length of listAttachments
@henryroe
henryroe / bad_idea.py
Created Oct 3, 2014
Example of why you shouldn't use a mutable as a default parameter in python
View bad_idea.py
class BadIdea():
def __init__(self, history=[]):
self.history = history
def get_history(self):
return self.history
def append_history(self, input):
self.history.append(input)
@henryroe
henryroe / talk2subprocess_traitsui.py
Created Aug 25, 2014
Demo of launching a traitsui GUI in a separate thread and communicating with it via stdin and stdout
View talk2subprocess_traitsui.py
import time
import os
import sys
import pickle
import numpy as np
import subprocess
from threading import Thread
from traits.api import HasTraits, String, Instance, Bool, on_trait_change, Long
from traitsui.api import View, Item, Handler
import psutil
@henryroe
henryroe / traitsui_matplotlib_playground.py
Last active Aug 29, 2015
The demo of traitsui, matplotlib, including a pop-up menu, I wish I'd found.
View traitsui_matplotlib_playground.py
import wx
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.image import AxesImage
from matplotlib.axes import Axes
from matplotlib.widgets import AxesWidget
import matplotlib.pyplot as plt
@henryroe
henryroe / plot_nsf_ast_grant_totals.py
Created Jun 20, 2014
Plot NSF AST funding data for total funding of grants
View plot_nsf_ast_grant_totals.py
max_award = 1e6 # above this amount just bin in to top bin
years_per_bin = 1.0
award_bin_size = 50000
start_year = np.array([a.year + (a.month - 1)/12. for a in awards['StartDate']])
year_bins = np.arange(np.floor(start_year.min()), np.ceil(start_year.max())+1, years_per_bin)
awarded = np.array(awards['AwardedAmountToDate'])
awarded_mean_per_bin = np.zeros(year_bins.size - 1)
awarded_median_per_bin = np.zeros(year_bins.size - 1)
year_per_bin = np.zeros(year_bins.size - 1)
for i in np.arange(year_bins.size - 1):
@henryroe
henryroe / plot_nsf_ast_grants_per_year.py
Created Jun 20, 2014
Plot NSF AST funding data for per-year funding of grants
View plot_nsf_ast_grants_per_year.py
max_award_per_year = 3e5 # above this amount just bin in to top bin
years_per_bin = 1.0
award_bin_size = 10000
start_year = np.array([a.year + (a.month - 1)/12. for a in awards['StartDate']])
year_bins = np.arange(np.floor(start_year.min()), np.ceil(start_year.max())+1, years_per_bin)
awarded_per_year = np.array(awards['AwardedAmountToDate']/awards['DurationYears'])
awarded_per_year_mean_per_bin = np.zeros(year_bins.size - 1)
awarded_per_year_median_per_bin = np.zeros(year_bins.size - 1)
year_per_bin = np.zeros(year_bins.size - 1)
for i in np.arange(year_bins.size - 1):
@henryroe
henryroe / import_nsf_ast_csv.py
Created Jun 20, 2014
Import NSF AST funding data in CSV format
View import_nsf_ast_csv.py
import pandas
import numpy as np
awards = pandas.read_csv("awards_dump_2014-06-20.csv",
parse_dates=['StartDate', 'LastAmendmentDate', 'ExpirationDate',
'AwardedAmountToDate'],
converters={'AwardedAmountToDate': lambda x:
float(x.replace('$', '').replace(',', ''))},
dtype={'AwardedAmountToDate':np.float64})
awards['DurationYears'] = ((awards['ExpirationDate'] - awards['StartDate']) /
(365.25 * np.timedelta64(1, 'D')))
You can’t perform that action at this time.