Skip to content

Instantly share code, notes, and snippets.

View awade's full-sized avatar

Andrew Wade awade

  • The Australian National University
  • Canberra, Australia
View GitHub Profile
@awade
awade / randomUnitVectors.m
Created May 26, 2021 06:56
Some Matlab code for generating random normal vectors uniformly distributed in angle
%% First a method using quaternions
qtn = randrot(1000,1);
pts = rotatepoint(qtn, [1 0 0]);
figure()
scatter3(pts(:,1), pts(:,2), pts(:,3))
axis equal
@awade
awade / RG58_loss.m
Created March 12, 2021 04:30
Matlab helper function for interpolating loss of coaxial RG58 cable as function of frequency per unit length.
function dBLossPerM = RG58_loss(f)
% Function for estimate RG58 coaxial cable loss as a function of frequency
% per meter. Data is drawn from https://www.w4rp.com/ref/coax.html and is
% not varified with real lab measurments. Take it with a
% grain of salt.
%
% Output interpolates from the spaced data points. This is for estimating
% only.
%
% Author: Andrew Wade
@awade
awade / rms2.m
Last active May 10, 2021 01:20
Matlab function for computing the rms integrating from high frequency to low frequency. Has additional option to clip the integration to some frequency upper bound.
function [x_clipped, rms] = rms2(x, y, varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% find the rms value of y(x)
% y(f) could be a spectral density
% or y(t) could be a time series
%
% optional var sets the cutoff of x to compute
% from. This will shorten the output vector
@awade
awade / cask-upgrade.sh
Created September 16, 2019 22:55
This is a bash script for updating casks pre-"brew cask upgrade" cmd. It catches all version mismatches missed by official cask upgrade methods by doing it manually.
#!/bin/bash
# USE AT YOUR OWN RISK.
# This is a bash script for checking brew cask versions and reinstalling if
# there is a version mismatch. Obviously this may revert casks that have self
# updating to previous version, but then it is as easy as simply updating the
# repo with the cask-repair command. This way the community gets the updates
# too.
@awade
awade / PDH_shotNoise.py
Created September 11, 2019 08:20
Python function for computing PDH shot noise limit
def S_f_SN(Pcar, Finesse, Lcav, lambd=1064.0e-9):
'''
Compute PDH shot noise
'''
_h = 6.62607004e-34 # [J.s] Plank's constant
_c = 2.99792458e8 # [m/s] Speed of light
return np.sqrt(_h * _c**3) / 8 / (Finesse * Lcav * np.sqrt(lambd * Pcar))
@awade
awade / ZurichPythonAccess.ipynb
Created May 17, 2019 01:28
Minimum working example of how to access Zurich HF2LI instrument via python API
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@awade
awade / numpyfloatRandRound.py
Created January 24, 2019 21:23
Simple implementation of python code (using numpy) for rounding numbers using probabilistic rounding on the last digit. Should be able to handle pos and neg values but not arrays.
def truncFloat(x,dp):
'''Truncates a numpy float to given decimal places (dp)'''
return np.trunc(x * 10 ** dp) / 10 ** dp
def probRound(x, dp):
'''Rounds float to given decimal places (dp), with
last digit round done on a probablistic basis.'''
xTrunc = truncFloat(x, dp) # Truncate to dp figures
xrem = x - xTrunc # find remainder of truncation
@awade
awade / rms.py
Created December 5, 2018 03:44
Python function for computing rms integral from high frequency to low frequency
import numpy as np
'''
Find the rms value of y(x). Here y(f) could be a spectral density or y(t) could be a time series
usage:
rms_of_y = rms(X,Y);
'''
@awade
awade / HostUp.py
Created September 19, 2018 21:08
Simple python function to check if host is up using ping, allows setting of waittime
def HostUp(hostname, waittime=1000):
'''Function returns True if host IP returns a ping, else False'''
assert isinstance(hostname, str), \
"IP/hostname must be provided as a string."
if os.system("ping -c 1 -W " + str(waittime) + " " +
hostname + " > /dev/null 2>&1") is 0:
HOST_UP = True
else:
HOST_UP = False
return HOST_UP
@awade
awade / roombaroo.sh
Created August 8, 2018 17:08
Minimalist bash script for cleaning downloads folder on a mac. Logs which were files deleted. Configured for deleting files older than 7 days. Call from crontab to automate. Use at own risk.
#!/bin/bash
#
# Cleans a mac computer directory when called from crontab
#
#Author: Andrew Wade
#Date: 20170125
#Last modified: yyyymmdd
TIMESTAMP=$(date +"%Y%m%d-%H%M%S")