Skip to content

Instantly share code, notes, and snippets.

View jasonmhite's full-sized avatar

Jason Hite jasonmhite

View GitHub Profile
@jasonmhite
jasonmhite / src-my_project-pipelines-do_stuff-__init__.py
Created April 27, 2023 13:22
Convention for kedro pipelines; pretend dashes are / in the file names for folder structure
"""
This is the pipeline `do_stuff`
generated using kedro <blah>
"""
from .pipeline_do_stuff import create_pipeline
__all__ = ["create_pipeline"]
__version__ = "0.1"
@jasonmhite
jasonmhite / gmd.py
Last active November 19, 2019 18:25
Simple implementation for a Gaussian mixture distribution
import numpy as np
import scipy.stats as st
class GaussianMixture(object):
def __init__(self, mu, sigma, w):
self.mu = np.asarray(mu)
self.sigma = np.asarray(sigma)
self.w = np.asarray(w)
self.w /= self.w.sum()
@jasonmhite
jasonmhite / write_spe.py
Created July 18, 2019 14:25
A quick and dirty prototype for writing SPE files in becquerel
# Based off the implementation that is already in becquerel.parsers.SpeFile,
# but adapted to read *some* of the info from a Spectrum instance.
# I'm a little fuzzy on the details of the SPE format (e.g. what is the difference
# between $ENER_CAL and $MCA_CAL) but this produces files that load without
# issue in Sandia's InterSpec tool.
# This is a rough implementation as a prototype, it needs a lot of work.
def write_spe(
spec,
### Time ###
All of this needs to be done as root.
This assumes the GPS module is connected to the 4th channel of the
FT4232H. If it isn't, you need to edit the DEVICES variable below to
point to the correct one. The connections you need to make are:
GPS Pin <--> FT4232 Pin
----------------------------
@jasonmhite
jasonmhite / tm1638.py
Last active November 15, 2021 15:07
TM1638 example for FT232H
# See https://blog.3d-logic.com/2015/01/10/using-a-tm1638-based-board-with-arduino/
import atexit
from pyftdi.spi import SpiController
from time import sleep
SPI_FREQ = 10000
SPI_MODE = 0
# Initialize the controller
@jasonmhite
jasonmhite / bme280.py
Created August 20, 2018 17:04
BMP280 pyFTDI
import pyftdi as F
from pyftdi import i2c
from ctypes import c_short
from time import sleep
import atexit
### Some utility functions
@jasonmhite
jasonmhite / solid_angle.py
Last active January 12, 2018 19:06
Computation of the solid angle of an oriented right triangle in free space
##################################################################################
# Copyright (c) 2018, Jason M. Hite
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
from scipy.optimize import minimize
def least_squares(A, b, x0): # Least-squares solution for Ax=b, initial guess of x0
return minimize(
lambda x: np.linalg.norm(A.dot(x) - b),
x0,
)
def least_squares_tikhonov(A, b, alpha, x0): # Least squares for Ax=b with simple Tikhonov regularization
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.