Skip to content

Instantly share code, notes, and snippets.

View marcocamma's full-sized avatar

marco cammarata marcocamma

View GitHub Profile
@marcocamma
marcocamma / mpl_to_plotly.py
Last active March 14, 2023 21:29
Exporting matplotlib figure as interactive plotly figure
# tested with plotly 5.13.1, matplotlib 3.5.3
from matplotlib import pyplot as plt
import plotly.tools as tls
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
plt.plot([1,2,3])
fig=plt.gcf()
fig_plotly=tls.mpl_to_plotly(fig)
fig_plotly.write_html("my_image.html")
@marcocamma
marcocamma / frequency_filter
Last active March 16, 2022 13:50
Simple functions around scipy.signal.butter
def digital_filter(x,y,f=1000,order=10,kind="lowpass"):
dt = x[1]-x[0]
fs = 1/dt
sos = signal.butter(order, f, kind, fs=fs, output='sos')
return signal.sosfiltfilt(sos,y)
def lowpass(x,y,f=1000,order=10):
return digital_filter(x,y,f=f,order=order,kind="lowpass")
def highpass(x,y,f=1000,order=10,add_average=True):
@marcocamma
marcocamma / simple_diffract.py
Last active June 17, 2020 12:33
Simple Diffraction by slits using XRT
import matplotlib as mpl
mpl.use('Agg')
import argparse
import numpy as np
from matplotlib import pyplot as plt
import xrt.backends.raycing as raycing
import xrt.backends.raycing.sources as rsource
import xrt.backends.raycing.screens as rscreens
import xrt.backends.raycing.oes as roes
import xrt.backends.raycing.apertures as rslits
@marcocamma
marcocamma / auto_args.py
Last active April 30, 2017 00:14 — forked from judy2k/auto_args.py
Save constructor arguments on self without writing self.x = x etc...
from inspect import signature
def auto_args(f):
sig = signature(f) # Get a signature object for the target:
def replacement(self, *args, **kwargs):
# Parse the provided arguments using the target's signature:
bound_args = sig.bind(self, *args, **kwargs)
# add defaults otherwise defaults are unbonund, thus not in the list
bound_args.apply_defaults();
# Save away the arguments on `self`:
@marcocamma
marcocamma / h5py_links.py
Created November 4, 2016 10:03
Script demonstrating the problems of figuring out if a group is a link or not with h5py
@marcocamma
marcocamma / dropletize_comparison.py
Last active September 30, 2016 20:42
comparison of dropletizing algorithms
import numpy as np
import time
import matplotlib.pyplot as plt
g_fname = "beams_f16.npy"
_colors = ["#a6611a","#dfc27d","#80cdc1","#018571"]; # from colorbrewer2.prg
def maskEdges(img,edge=5,makeCopy=True):
if edge is None or edge == 0: return img