This file contains 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
set root=C:\Users\user\Anaconda3 | |
call %root%\Scripts\activate.bat %root% | |
call activate py37 | |
call cd "C:\Users\TNiederhauser\Dropbox (Medic)\MedicData\Floor Scale" | |
call jupyter lab |
This file contains 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 | |
import pendulum | |
def create_data_directory( | |
data_kind, # 'VolCal' | |
data_source_id, | |
timezone, | |
parent_directory | |
): |
This file contains 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
# See https://stackoverflow.com/questions/7894856/line-contains-null-byte-in-csv-reader-python | |
with open(path_to_csv_file) as f: | |
reader = csv.reader((x.replace('\0', '') for x in f), delimiter=',') # Handle null values | |
while True: | |
try: | |
line = next(reader) | |
except StopIteration: | |
break | |
print(line) # process lines |
This file contains 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 create_logger(log_file_path, display_level, file_level): | |
""" | |
Logs to file as well as to display. | |
See https://www.dataquest.io/blog/advanced-jupyter-notebooks-tutorial/ | |
Args: | |
log_file_path (str): | |
display_level (int): logging.INFO for example | |
file_level (int): logging.INFO for example |
This file contains 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 get_ranges_in_between_ranges(df, start_name, stop_name): | |
""" | |
Get range boundaries in between range boundaries arranged to be strictly increasing. | |
For example if we had three range boundaries where the range start and stop values | |
are found in two separate columns in a dataframe, | |
start, stop | |
----------- | |
0, 5 | |
7, 8 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
# Sometimes timeseries need to be concatenated and then sorted so that the time vector is monotonic. | |
# ---- Monotonic in x, but not strictly increasing | |
# ******************************************************************************** | |
x1 = np.array([1, 2, 3, 4, 4]) # Not all of the values are unique | |
y1 = np.array([10, 20, 30, 42, 40]) | |
x2 = np.array([1.5, 2.5, 3.5, 4.5]) | |
y2 = np.array([15, 25, 35, 45]) | |
x_ = np.concatenate((x1, x2)) |
This file contains 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 find_index_of_first_nonzero_occurrence(array): | |
""" | |
Find the index of the first non-zero occurrence in a numpy array. | |
This is essentially a wrapper around np.flatnonzero(). If there are | |
no non-zero values None is returned. | |
array (numpy array): Should be 1d array and all elements should be numeric | |
""" |
This file contains 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 matplotlib.pyplot as plt | |
from matplotlib import gridspec | |
import mplcursors | |
annotations0 = ['cat', 'dog', 'hare'] | |
x = [1, 2, 3] | |
y = [0, 2.5, 3] | |
fontsize=20 |
This file contains 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 fnmatch | |
pattern = "aaa_*" # Special characters '*' and '?' | |
list_of_all_files = ['aaa_1.json', 'a.json', 'b.json'] | |
for filename in list_of_all_files: | |
if fnmatch.fnmatch(filename, pattern): | |
print(filename) |