Skip to content

Instantly share code, notes, and snippets.

@astrofrog
astrofrog / python-montage demo
Created August 21, 2010 06:12
python-montage demo
Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import montage
>>> montage.mArchiveList('2MASS', 'K', 'm31', 0.5, 0.5, 'm31_list.tbl')
count : 18
stat : OK
>>> montage.mMakeHdr('m31_list.tbl', 'header.hdr', north_aligned=True)
count : 18
lat4 : 41.744136
# The purpose of this script is to automatically install APLpy and all
# the dependencies (except numpy and matplotlib), either using the latest
# stable versions of packages, or the latest unstable versions from svn or
# git repositories.
import os
import getopt
import sys
import tempfile
import urllib
@astrofrog
astrofrog / data.fits.gz
Created November 11, 2010 17:26
fun with astronomical dendrograms (test code)
@astrofrog
astrofrog / extract_kurucz.py
Created November 20, 2010 02:20
Script to convert Kurucz ODFNEW model packages to HDF5
import io
import numpy as np
import atpy
def chunk(string, n):
return [string[i*n:i*n+n] for i in range(len(string) / n)]
# Open file
@astrofrog
astrofrog / wordcount.py
Created November 21, 2010 02:36
Word count stats
# Pipe text into this to get a word count list in decreasing order, e.g.:
#
# $ detex ms.tex | python wordcount.py
# model:9
# star:8
# formation:7
# YSOs:7
# ...
import sys
@astrofrog
astrofrog / orion_to_hdf5.py
Created November 21, 2010 03:09
Experimental script to extract Orion AMR output
import numpy as np
import h5py
def parse_multi_tuple(string):
string = string.replace(' ', '')
string = string.replace(')(', '), (')
return eval(string)
@astrofrog
astrofrog / find_doi.py
Created November 22, 2010 13:50
Recursively find all PDF files in a folder that contain DOIs and display them
import os
import glob
import sys
def extract_doi(filename):
f = open(filename,'rb')
text = f.read()
f.close()
start = text.find('URI(')
if start > 0:
from mendeley_client import MendeleyClient
mendeley = MendeleyClient(..., ...) # Fill out API keys here
try:
mendeley.load_keys()
except IOError:
mendeley.get_required_keys()
mendeley.save_keys()
import cloud
cloud.setkey('...','...')
def square(x):
return x*x
jid = cloud.call(square,3)
cloud.result(jid)
@astrofrog
astrofrog / find_duplicate_folders.py
Created December 27, 2010 09:36
Recursively find folders with same size and checksum (still experimental)
import sys
import os
from hashlib import md5
def dir_size(directory):
"Find the total size of a directory"
folder_size = 0
for (path, dirs, files) in os.walk(directory):
for filename in files: