Skip to content

Instantly share code, notes, and snippets.

@jj-github-jj
jj-github-jj / labview call.py
Last active February 13, 2022 16:05
labview run active x
# !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))
@jj-github-jj
jj-github-jj / jupyter environment modules.py
Last active December 28, 2021 02:48
jupyter environment copy installed modules to another system
!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
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)
@jj-github-jj
jj-github-jj / EXPORT IPYNB OUTPUT AS HTML.PY
Created December 26, 2021 16:43
EXPORT IPYNB OUTPUTS ONLY AS HTML
# output html without code only outputs. Use in ipynb file
#
#!pip install ipynbname
try :
import ipynbname #utility to get current notebook name and path
except:
!pip install ipynbname
import ipynbname #utility to get current notebook name and path
nb_fname_full= ipynbname.name()+'.ipynb'
!jupyter nbconvert "{nb_fname_full}" --no-input --to html
def shelve_multiple(list_of_objects=[],fname=''):
""" not providing filename, uses default current notebook name but slow ipynbname function
shelve files are fname.shelf.dir,.data, and .bak(?)
copy these files with ipynb files to save restore objects without re-running
"""
import ipynbname
if fname =='':
fname=ipynbname.name() #use note book name but way too slow so best to pass filename
@jj-github-jj
jj-github-jj / jupyter environment
Last active September 11, 2022 23:08
environment utility snippets
#force reload of specific module without restarting kernel. Useful for debug
import importlib
importlib.reload(<module name>)
# get path of python exe jupyter lab is using
!python --version
!jupyter kernelspec list
!jupyter --version
!{sys.executable} -m pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple jjutil
@jj-github-jj
jj-github-jj / holoviews_snippets.py
Last active January 25, 2022 13:46
holoviews examples
#https://notebook.community/redlegjed/cheatsheets/holoviews_cheatsheet
#bokeh figure from holoview
bf=hv.render(p) #bf is bokeh figure object
bf
def formatter(value):
return str(value) + ' days'
curve.relabel('Tick formatters').opts(xformatter=formatter, yformatter='$%.2f', width=500)
@jj-github-jj
jj-github-jj / interpolate
Created February 12, 2022 18:22
interpolate function for one line interpolation
def y_interpolate (xnew,x,y):
from scipy.interpolate import interp1d
y_interpolate_function = interp1d(x, y)
return (y_interpolate_function(xnew))
# importing packages
# IF errors replace line 30 in cipher.py as follows
# var_regex = re.compile(r"^\$*\w+\W")
import sys
import os
ytpath=r'https://www.youtube.com/watch?v=2SCOYFkvXWQ'
!{sys.executable} -m pip install pytube
import pytube
from pytube import YouTube
@jj-github-jj
jj-github-jj / quanitiphy usage
Last active September 3, 2022 04:49
basic quantiphy usage
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
from quantiphy import Quantity
a=Quantity('30MHz')
print (a) # 30 MHz
a.as_tuple()[0]
a.render() # '30 MHz'
float(a) # 30000000.0