Skip to content

Instantly share code, notes, and snippets.

View daguiam's full-sized avatar

Diogo Aguiam daguiam

View GitHub Profile
""" Calculate mean std of clipped array"""
import numpy as np
from scipy import interpolate
def calc_func_clipped(X, Y, func=np.mean, npoints=None, verbose=False):
""" Calculates func of Y values, where Y is clipped to the longest continuous
values of X to prevent aliasing
"""
# Size of each data vector
import numpy as np
def expand_time(time, shape, verbose=True):
if verbose:
print 'Old time shape:',time.shape,'new shape:',shape
output = np.tile(time, shape[1]).reshape(np.fliplr([shape])[0]).T
if verbose:
print 'output time shape:',output.shape
return output
@daguiam
daguiam / calc_sep_ra.py
Created November 9, 2017 16:06
Calculate sep_ra from rant,zant and sep_z, sep_r
rant = data['r'][0][0]
zant = data['z'][0][0]
sep_z = data['sep_z']
sep_r = data['sep_r']
sep_ra = np.linalg.norm(np.array([sep_r-rant,sep_z-zant]),axis=0)
%%%%%%%%%%%%%%%%%
% 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
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
#include <stdio.h>
typedef enum {
NORTH = 0,
EAST = 1,
SOUTH = 2,
WEST = 3
} directionValues;
@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
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)
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
def remove_extension(filename, separator="."):
return separator.join(filename.split(separator)[:-1])