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 my_float(s): | |
""" bug in python cant convert -12,345.0 to float so use this workaround | |
""" | |
return (float(s.replace(",",""))) | |
#show large nubmers with commas pandas dataframe | |
# column is string column name | |
df[column] = df.apply(lambda x: "{:,}".format(x[column]), axis=1) | |
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
!jupyter --data-dir | |
#!pip install datamodel-code-generator | |
!pip install pandasgui | |
!pip install quantiphy | |
!pip install plotly.express | |
!pip install scikit-rf | |
!pip install nptdms | |
!pip install cufflinks |
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
# !pip install pywin32 | |
import win32com | |
labview = win32com.client.Dispatch("Labview.Application") | |
VI = labview.getvireference(vi_path) | |
print(f'Name: {VI.Name}') | |
VI.setcontrolvalue(control_name,f) # this works to set float values | |
s=(VI.getcontrolvalue(ind_name)) |
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
from dataclasses import dataclass, is_dataclass | |
def nested_dataclass(*args, **kwargs): | |
def wrapper(cls): | |
cls = dataclass(cls, **kwargs) | |
original_init = cls.__init__ | |
def __init__(self, *args, **kwargs): | |
for name, value in kwargs.items(): | |
field_type = cls.__annotations__.get(name, None) | |
if is_dataclass(field_type) and isinstance(value, dict): |
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 ntuples_list(list_of_names): | |
""" | |
""" | |
list_of_names_dict = {x:x for x in list_of_names} | |
Varnames = namedtuple('Varnames', list_of_names) | |
return Varnames(**list_of_names_dict) | |
def change_to_valid_column_names(df3): | |
df3.columns=[(re.sub("[/' ()-+]","_",x)) for x in df3.columns.to_list()] #replace invalid char with _ |
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
# convert data frame strings to numeric where possible and drop rows with non numeric content | |
df23=df23.apply(pd.to_numeric, errors='ignore') # converts to numbers when possible for all columns | |
df23 | |
c=df23.columns.to_list() | |
data_columns=[c[x] for x in range(1,6)] | |
# Eliminate invalid data from dataframe (see Example below for more context) | |
num_df = (df23.drop(data_columns, axis=1) | |
.join(df23[data_columns].apply(pd.to_numeric, errors='coerce'))) #numeric dataframe |
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 find_nearest(array, value): | |
array = np.asarray(array) | |
idx = (np.abs(array - value)).argmin() | |
return idx,array[idx] #return in x,y format x is index, y is value | |
[print (i,v/1e9) for i,v in enumerate(x)] #print index and value of elements in list | |
def avg_dB(dB): |
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
# speed up figures with lots of data | |
pip install plotly-resampler | |
from plotly_resampler import register_plotly_resampler, unregister_plotly_resampler | |
register_plotly_resampler(mode="auto", default_n_shown_samples=1000) | |
import plotly.io as pio | |
pio.renderers.default = "notebook" # patch for exporting to html in vscode for plotly interactive plots |
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
tdms_file=TdmsFile.read(fpath) | |
for name, value in tdms_file.properties.items(): | |
print("{0}: {1}".format(name, value)) | |
print ("------ Groups --------") | |
all_groups = tdms_file.groups() | |
for group in all_groups: | |
print ("Group Name:",group.name) | |
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
# for key,value in x.iteritems(): | |
# new_key = key.replace(" ","_") | |
# del x[key] # Deleting Previous Key | |
# x[new_key] = value # Adding Modified key | |
# for key,value in x.iteritems(): | |
# new_key = key.replace(" ","_") | |
# del x[key] # Deleting Previous Key | |
# x[new_key] = value # Adding Modified key |