Install
pip install py2ls
ips
listdir, basename, dirname, newfolder, finfo
e.g.,
fpath = "....../"
ips.listdir(fpath, kind='pdf', sort_by="size", ascending=0, output = 'df')
it filters the ‘.pdf’ files, and sort by the (file-size/name, length of name, create_time, mod_time, last_open_time …) it returns a DataFrame or BoxList (setting by ‘output’)
dir_data, dir_fig = newfolder(fpath, {'data', 'fig'})
finfo(fpath)
dir_lib(lib_of_interest)
list_func/func_list (same)
list functions in a package
fload, fsave, figsave
e.g.,
fload(fpath, kind=None, **kwargs)
load file (docx, pdf, image, md, json,csv,txt, html, yaml, xml, xlsx…) or save file.
figsave(dir_save, "fname.pdf", dpi=300)
pdf2img, img2pdf, docx2pdf
extract images from a PDF, or merge images into a pdf file
pdf2img(dir_pdf, dir_save=None, page=None, kind="png",verbose=True, **kws)
pdf2img(fpath, page=[None, None])
img2pdf(dir_img, kind="jpeg",page=None, dir_save=None, page_size="a4", dpi=300)
docx2pdf(dir_docx, dir_save)
paper_size
quickly get the size info
paper_size('a4')
paper_size('card')
str2num, num2str, str2list
str2num(“123.345 dollers”,2)
str2list("abcd")
list2str(['a','b','c','d'])
ssplit, sreplace
sreplace(text, dict_replace=None, robust=True)
ssplit(text, by="space", verbose=False, **kws)
text = "The most pronounced physiological changes in sleep occur in the brain.[10] The brain uses significantly less energy during sleep than it does when awake, especially during non-REM sleep. In areas with reduced activity, the brain restores its supply of adenosine triphosphate (ATP), the molecule used for short-term storage and transport of energy.[11] In quiet waking, the brain is responsible for 20% of the body's energy use, thus this reduction has a noticeable effect on overall energy consumption.[12]"
ssplit(text, by=["[10]", "[11]", "[12]"])
ssplit(text[:30], by="len", length=5)
ssplit(text, by="non_alphanumeric")
ssplit(text, by="sent")
ssplit(text, by="lowup")
sreplace(text, dict_replace=None, robust=True)
text= 'The most pronounced physiological changes in sleep occur in the brain.[10] '
'The brain uses significantly less energy during sleep than it does when '
'awake, especially during non-REM sleep. In areas with reduced activity, the '
'brain restores its supply of adenosine triphosphate (ATP), the molecule used '
'for short-term storage and transport of energy.[11] In quiet waking, the '
"brain is responsible for 20% of the body's energy use, thus this reduction "
'has a noticeable effect on overall energy consumption.[12]'
sreplace(text)
"The most pronounced physiological changes in sleep occur in the brain"
sreplace(text,{"sleep":"wakewake"})
"The most pronounced physiological changes in wakewake occur in the brain."
stats
FuncCmpt ( two groups cmp)
FuncCmpt(X1, X2, pmc='auto', pair='unpaired')
e.g.,
X1 = [19, 22, 16, 29, 24]
X2 = [20, 11, 17, 12, 22]
p, res = FumcCmpt(X1,X2, pmc='pmc', pair = 'unpair')
p,res = FuncCmpt(x1,x2, pmc='pmc',pair='pair')
FuncMultiCmpt ( multiple groups cmp)
FuncMultiCmpt(pmc='pmc', pair='unpair', data=None, dv=None, factor=None,
ss_type=2, detailed=True, effsize='np2',
correction='auto', between=None, within=None,
subject=None, group=None
)
df = pd.DataFrame({'score': [64, 66, 68, 75, 78, 94, 98, 79, 71, 80,
91, 92, 93, 90, 97, 94, 82, 88, 95, 96,
79, 78, 88, 94, 92, 85, 83, 85, 82, 81],
'group': np.repeat(['strat1', 'strat2', 'strat3'],repeats=10)})
res = FuncMultiCmpt(pmc='auto',pair='unpaired',data=df, dv='score', factor='group', group='group')
res["APA"]
FuncStars
FuncStars(ax,
pval=None,
Ylim=None,
Xlim=None,
symbol='*',
yscale=0.95,
x1=0,
x2=1,
alpha=0.05,
fontsize=14,
fontsize_note=6,
rotation=0,
fontname='Arial',
values_below=None,
linego=True,
linestyle='-',
linecolor='k',
linewidth=.8,
nsshow='off',
symbolcolor='k',
tailindicator=[0.06, 0.06],
report=None,
report_scale=-0.1,
report_loc=None)
plots
stdshade
stdshade(ax=None,*args, **kwargs)
add_colorbar
add_colorbar(im, width=None, pad=None, **kwargs)
get_color
get_color(n=1, cmap='auto')
get_color(12)
get_color(5, cmap="jet")
get_color(5,cmap="rainbow")
img appearance
imgsets
imgsets(
img,
sets=None,
show=True,
show_axis=False,
size=None,
dpi=100,
figsize=None,
auto=False,
filter_kws=None,
)
img = imgsets(
fpath,
sets={"rota": -5, "sharp": 10},
dpi=200,
)
figsave(dir_save, "test1_sharp.pdf")
img2 = imgsets(
fpath,
sets={"rota": -5, "crop": [100, 100, 300, 400], "sharp": 10},
dpi=200,
filter_kws={
"sharpen": 10,
},
)
figsave(dir_save, "test2_crop.pdf")
fload(dir_img)
imgsets(img, sets={"color": 1.5}, show=0)
imgsets(img, sets={"pad": (300, 300), "bgcolor": (73, 162, 127)}, show=0)
imgsets(
img,
sets={"contrast": 1.3, "color": 1.5, "pad": (300, 300)},
show=0,
filter_kws=dict(sh=1050, EDG=10, gaus=5),
)
imgsets(
img,
sets={"color": 10.5},
show=0,
filter_kws=dict(EDGE_ENHANCE=50, EDGE_NHANCEmore=50),
)
imgsets(
img,
sets=dict(contr=1.5, rm="default"),
show=0,
)
imgsets(
img,
sets=dict(contr=0, rm="default"),
show=0,
filter_kws=dict(sharp=1),
)
figsets
figsets(*args)
cm = 1 / 2.54
plt.figure(figsize=[8 * cm, 5 * cm])
for i in range(2, 4):
plt.plot(x, y * i, ls="-")
figsets(
plt.gca(),
{
"xlabel": f"time([{x[0]}:{x[-1]}])",
"ylabel": "Amplitude (signals)",
"xlim": [0, 600],
"xtick": np.arange(0, 620, 150),
"xlabel": "test xticklabel",
"sp": "go",
"box": ":",
"grid": "on",
"minorticks": "on",
"ticks": {"c": "k"},
},
)
figsets('style','paper')
cm = 1/2.54
fig, ax = plt.subplots(1, 1, figsize=(7*cm, 5*cm))
x = np.linspace(0, 2 * np.pi, 50) * 100
y = np.sin(x)
c=get_color(7)
for i in range(2,7):
plt.plot(x, y*i,c=c[i])
figsets(
ax,
{
"xlim": [0, 450],
"xlabel": "2222",
"yticks": np.arange(-5,5, 2),
"ylabel": "ylabelsssss",
"xtkbel": range(0, 800, 100),
"suptitle": "supertitle",
"rotation":45,
},
)