Skip to content

Instantly share code, notes, and snippets.

View daguiam's full-sized avatar

Diogo Aguiam daguiam

View GitHub Profile
def clip_remainder(x, clip):
if isinstance(clip, tuple):
print("is tuple")
assert len(clip) == 2, "Clip should be (min, max)"
clipmin,clipmax = clip
else:
clipmin = -clip
clipmax = clip
clipptp = np.ptp([clipmin, clipmax])
from scipy import interpolate
import numpy as np
# x_resolution = 0.38
# y_resolution = 0.38
# z = matrix_data
# xsize,ysize = z.shape
# x = np.arange(0,xsize+extra,1)*x_resolution
# y = np.arange(0,ysize+extra,1)*y_resolution
def interpolate_scandata_2d(x,y,z, fast_axis=0, min_signal_size=500, points=100, filter_positive=False, center_to_peak=False, normalize=False):
if fast_axis == 0:
vector = x
else:
vector = y
# consider only the positive direction of the x values
if filter_positive:
def remove_extension(filename, separator="."):
return separator.join(filename.split(separator)[:-1])
def convert_array_to_levels(array, levels, limits=[-np.pi,np.pi], output_limits=None, verbose=False):
"""Dgitizes the given array to within the number of levels provided
Parameters
----------
array : input array of values
levels : number of levels to consider
limits : the input data limits to consider for the interval calculation
output_limits : if given, multiplies the digitized input to the output range
import numpy as np
from PIL import Image
def save_array_as_image(array, filename):
"""Saves a 2D numpy array to an image"""
image = Image.fromarray(array)
image.save(filename)
array = np.random.random((512,512))*255
array = np.uint8(array)
@daguiam
daguiam / renaming_files_sequence.py
Created August 1, 2018 08:46
Renaming files with a sequence number format (001, 002, etc)
# Reducing sample names of QN61 by 1 value to match QN62, QN63 and the DieMap
root_dir = os.path.abspath(path_string)
files = os.listdir(root_dir)
prefix = ".csv"
files = [file for file in files if prefix in file]
for file in files:
number = int(file[1:4])-1
# print("%03d"%number)
newfile = "S%03d.csv"%number
#include <stdio.h>
typedef enum {
NORTH = 0,
EAST = 1,
SOUTH = 2,
WEST = 3
} directionValues;
import numpy as np
from mpl_toolkits.mplot3d import axes3d
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib.colors as colors
%%%%%%%%%%%%%%%%%
% This is altacv.cls (v1.1.3, 30 April 2017) written by
% LianTze Lim ([email protected]).
%
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX