Skip to content

Instantly share code, notes, and snippets.

View apetri's full-sized avatar

Andrea Petri apetri

View GitHub Profile
@apetri
apetri / customizeAndSend.py
Created July 16, 2017 13:01
Send an email to multiple recipients customizing the message body for each recipient
#!/usr/bin/env python
import sys,os
import smtplib
from email.mime.text import MIMEText
import getpass
import argparse
def sendMail(user,password,to,subject,text,mail_server="smtp.gmail.com",port=587):
@apetri
apetri / mergePDF.py
Created February 15, 2017 17:40
Merge multiple PDF documents in a single PDF document
#!/usr/bin/env python
import sys,argparse
import pyPdf
################################################################
###########Merge PDF files in a single document#################
#python mergePDF.py <file1.pdf> ... <fileN.pdf> -o <output.pdf>#
################################################################
@apetri
apetri / binomial.py
Created March 30, 2016 21:37
Python implementation of binomial coefficient calculation (n,k) modulo M with dynamic programming
from __future__ import division
import numpy as np
class Binomial(object):
def __init__(self,maxN=501,modulo=100003):
self._modulo = modulo
self._binomial = np.ones((maxN,)*2,dtype=np.int)*-1
#Initialize binomials with boundary conditions
@apetri
apetri / add_lens.py
Created December 15, 2015 19:16
Add the last lens for the raytracing
from lenstools.simulations import PotentialPlane
import numpy as np
import astropy.units as u
from astropy.cosmology import WMAP9
#Last non trivial snapshot
last_snapshot = 60
#Size of the plane (make it large enough to fit 3.5 degrees in angular size)
angle = 300*u.Mpc
@apetri
apetri / pyFindFunc.pl
Last active August 29, 2015 14:22
Reads python source code, finds all the function definitions and determines the required arguments for each of these
#!/usr/bin/env perl
use warnings;
use strict;
use 5.010;
##############################################################################################################################
#Read a text file and look for the lines that contain a python function definition: separate into function name and arguments#
##############################################################################################################################
@apetri
apetri / checkStage.py
Last active August 29, 2015 14:09
Useful python scripts to handle staging of large files from tape storage
#!/usr/bin/env python
import sys,os
#Get root path
if len(sys.argv)<2:
print("Usage: python {0} <root_path>".format(sys.argv[0]))
sys.exit(0)
root_path = sys.argv[1]
@apetri
apetri / notify.py
Last active August 29, 2015 14:09
Notify user via email when remote shell command has completed
#!/usr/bin/env python
import sys,os
import smtplib
from email.mime.text import MIMEText
import getpass
import argparse
def sendMail(user,password,to,subject,text,mail_server="smtp.gmail.com",port=587):
@apetri
apetri / noise.py
Created November 6, 2014 18:42
Generate noise time streams with an arbitrary power spectrum
from __future__ import division
import numpy as np
#FFT engines
from numpy.fft import rfftfreq,irfft
#Interpolation
from scipy import interpolate
#Units