Skip to content

Instantly share code, notes, and snippets.

View daguiam's full-sized avatar

Diogo Aguiam daguiam

View GitHub Profile
import os
import re
def read_optical_profilometer_data(filename):
with open(filename, "r") as f:
line = f.readline()
# reading the resolutuon line
line = f.readline()
! ZPL macro for Zemax to initialize multiconfiguration setup for arrangements of angles x and y
! with the help from https://osphotonics.wordpress.com/2015/05/21/zemax-programming-language-3-11-multi-configuration/
FOR i, 1, 4, 1
DELETEMCO 1
NEXT
! delete all existing configurations
FOR i, 1, NCON(), 1
DELETECONFIG 1
import os
def walk_levels(inputpath, outputpath, levels=1):
if levels==0:
return
else:
if not os.path.isdir(outputpath):
os.mkdir(outputpath)
for dirpath in os.listdir(inputpath):
def parse_profilometer_xy_data(filename):
df_header = pd.read_csv(filename, sep='\s+',header=None, nrows=7 )
df_header = df_header.T
df_header.columns = df_header.iloc[0]
df_header = df_header.reindex(df_header.index.drop(0))
name = df_header.Data
x_resolution = df_header['X-Resolution'].astype('float').values
import asyncio
from bleak import BleakScanner
import matplotlib
import PySimpleGUI as sg
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import numpy as np
import matplotlib.pyplot as plt
from collections import deque
class CircularBuffer (deque):
""" Creates a circular buffer class which inherits the deque collection
and implements extract functions"""
def extract(self,n):
""" Extracts n items from the right """
return list([self.pop() for i in range(n)])
from collections import deque
class CircularBuffer (deque):
""" Creates a circular buffer class which inherits the deque collection
and implements extract functions"""
def extract(self,n):
""" Extracts n items from the right """
return list(reversed([self.pop() for i in range(n)]))
import struct
import zlib
import os
import math
def readarc(f, verbose=False):
# from https://stackoverflow.com/a/15860757/7996766
import time, sys
from IPython.display import clear_output
def update_progress(progress):
bar_length = 20
def remap(x, in_min, in_max, out_min, out_max):
""" Remaps X in the range [in_min, in_max] to the range [out_min, out_max]
Equal to the arduino map function."""
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min