This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def magnitude(vector): | |
return np.sqrt(np.dot(np.array(vector),np.array(vector))) | |
def norm(vector): | |
return np.array(vector)/magnitude(np.array(vector)) | |
def lineRayIntersectionPoint(rayOrigin, rayDirection, point1, point2): | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tables import * | |
# Isolated the copying logic | |
def append_column(table, group, name, column): | |
"""Returns a copy of `table` with an empty `column` appended named `name`.""" | |
description = table.description._v_colObjects.copy() | |
description[name] = column | |
copy = Table(group, table.name+"_copy", description) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn.preprocessing import MultiLabelBinarizer | |
# Feature-list data frame | |
df = pd.DataFrame(columns = ["features"], index=['Item 1', 'Item 2']) | |
df['features'] = [["A", "B"], ["C", "D"]] | |
# Use scikits-learn to create feature matrix and feature names | |
mlb = MultiLabelBinarizer() | |
feature_column_name = 'features' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def non_linear_parameters_95_percent_confidence_interval(fvec, jac): | |
"""Returns the 95% confidence interval on parameters from | |
non-linear fit results.""" | |
# residual sum of squares | |
rss = np.sum(fvec**2) | |
# number of data points and parameters | |
n, p = jac.shape | |
# the statistical degrees of freedom | |
nmp = n - p | |
# mean residual error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://apple.stackexchange.com/questions/6707/how-to-stop-os-x-from-writing-spotlight-and-trash-files-to-memory-cards-and-usb | |
mdutil -i off /Volumes/yourUSBstick | |
cd /Volumes/yourUSBstick | |
rm -rf .{,_.}{fseventsd,Spotlight-V*,Trashes} | |
mkdir .fseventsd | |
touch .fseventsd/no_log .metadata_never_index .Trashes | |
cd - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, psutil, subprocess | |
# Usage: | |
# This script MUST be run from the root of the | |
# teraview-test-robot directory for example using, | |
# python run_test_robot_cmd.py | |
def make_test_robot_process(): | |
"""Creates the test robot process.""" | |
REL_TEST_ROBOT_EXE = "bin\\Debug\\test-robot.exe" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_frequency_information(self): | |
"""NB kUseNewFFTMethod = True for MATLAB algorithm.""" | |
reference = self.measurement.reference | |
if len(reference) > 1: | |
dt = self.measurement.optical_delay_spacing | |
t_offset = self.measurement.optical_delay_offset | |
f_max = 1./(2*dt) | |
if kUseNewFFTMethod: | |
freq = np.linspace(0.0, f_max, len(reference) + 1) | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_reference_signal_with_experimental_reference_method_with_extended_FFT( | |
signal, | |
reference, | |
optical_delay_spacing, | |
ref_calibration=None): | |
"""Removes reference signal using extended FFT method.""" | |
# transform reference signal to frequency domain | |
t_points = reference.shape[0] | |
ref_spec = np.fft.rfft(reference, reference.shape[0]*2) | |
signal_spec = np.fft.rfft(signal, signal.shape[0]*2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tree_editor.py -- Example of a tree editor | |
from traits.api \ | |
import HasTraits, Str, Regex, List, Instance, Any, Property | |
from traitsui.api \ | |
import TreeEditor, TreeNode, View, Item, VSplit, \ | |
HGroup, Handler, Group, ModelView | |
from traitsui.menu \ | |
import Menu, Action, Separator | |
from traitsui.wx.tree_editor \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import time | |
now = datetime.datetime.now() | |
now_iso = now.isoformat() | |
def parse_iso8601_badly(iso_str): | |
date_str, time_str = iso_str.split('T') | |
d = dict() | |
d.update(zip(['hour', 'minute', 'second'], |