Skip to content

Instantly share code, notes, and snippets.

import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
pg.mkQApp()
## Create window with two ImageView widgets
win = QtGui.QMainWindow()
win.resize(800,800)
win.setWindowTitle('pyqtgraph example: DataSlicing')
cw = QtGui.QWidget()
win.setCentralWidget(cw)
@campagnola
campagnola / style_pass_examples
Created March 18, 2014 19:48
Readable Python examples that fail PEP8
"""
pep8 violations:
E121,E123,E126,E201,E202,E203,E221,E222,E226,E227,E228,E231,E241,E251,
E302,E303,E401,E701,W291,W293,W391
Proposed style guidelines:
1. Is this code sufficiently readable?
2. Does the formatting cause extra effort for other people?
# -*- coding: utf8 -*-
"""
Constrained delaunay implementation based on
Domiter, V. and Žalik, B.
Sweep‐line algorithm for constrained Delaunay triangulation
(this implementation is not complete)
"""
@campagnola
campagnola / make_png.py
Last active August 19, 2022 04:13
Pure python PNG writer
import numpy as np
import zlib
import struct
def make_png(data):
"""
Convert numpy array to PNG byte array.
*data* must be (H, W, 4) with dtype=ubyte
"""
@campagnola
campagnola / hdf5.py
Created September 1, 2018 00:14
Reading HDF5 with python / ctypes
"""
Demonstrates basic interaction with HDF5 library using python / ctypes
"""
import ctypes
# load library (this would be platform-dependent)
hdf5 = ctypes.cdll.LoadLibrary('libhdf5.so')
# Define constants
@campagnola
campagnola / 60Hz_removal.ipynb
Created June 21, 2019 21:40
Very simple, artifact-free 60Hz hum removal (using scipy minimize)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@campagnola
campagnola / composable_data_modeling.py
Created October 31, 2019 20:13
Composable, inheritance-free data modeling in Python
"""
Goals:
- Extensible data modeling in python
- Does _not_ use inheritance as a mechanism for model extension
- Lightweight / simple infrastructure
- Data objects have reasonably nice user API
"""
class Model:
"""Base class providing infrastructure for composable data modeling
@campagnola
campagnola / python-data-acquisition-camera.py
Created February 8, 2020 23:48
python-data-acquisition imaging API
# extended from https://gist.github.com/HazenBabcock/8d1042f564dcaee60c3a3972f2d56999
class ImageData(object):
"""Contains information about one or more acquired frames.
"""
def __init__(self, data, meta):
self._data = data
self._meta = meta
@campagnola
campagnola / flu_vs_covid19.py
Created April 24, 2020 19:28
A week-by-week comparison of deaths caused by influenza and COVID-19 un the United States.
"""
A week-by-week comparison of deaths caused by influenza and COVID-19 un the United States.
CDC influenza / pneumonia data:
https://www.cdc.gov/flu/weekly/#S2
COVID19 data:
http://www.healthdata.org/covid/data-downloads
"""