py2ls 0.1.8.1__py3-none-any.whl → 0.1.8.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
py2ls/ips.py CHANGED
@@ -44,7 +44,8 @@ from fuzzywuzzy import fuzz, process
44
44
  from langdetect import detect
45
45
  from duckduckgo_search import DDGS
46
46
 
47
- from py2ls import netfinder
47
+ from . import netfinder
48
+ from .plot import get_color
48
49
 
49
50
  try:
50
51
  get_ipython().run_line_magic("load_ext", "autoreload")
@@ -2340,11 +2341,7 @@ def imgsets(img, **kwargs):
2340
2341
  "BOX_BLUR",
2341
2342
  "MEDIAN_FILTER",
2342
2343
  ]
2343
- print(
2344
- "sets: a dict,'sharp:1.2','color','contrast:'auto' or 1.2','bright', 'crop: x_upperleft,y_upperleft, x_lowerright, y_lowerright','rotation','resize','rem or background'"
2345
- )
2346
- print(f"usage: filter_kws 'dict' below:")
2347
- pp([str(i).lower() for i in supported_filters])
2344
+ print('usage: imgsets(dir_img, contrast="auto", rm=True, color=2.2)')
2348
2345
  print("\nlog:\n")
2349
2346
 
2350
2347
  def confirm_rembg_models(model_name):
@@ -2460,9 +2457,8 @@ def imgsets(img, **kwargs):
2460
2457
  img_update = ImageOps.contain(img_update, size=value)
2461
2458
  elif "fit" in k.lower():
2462
2459
  if isinstance(value, dict):
2463
- if filter_kws:
2464
- for filter_name, filter_value in filter_kws.items():
2465
- img_update = apply_filter(img_update, filter_name, filter_value)
2460
+ for filter_name, filter_value in value.items():
2461
+ img_update = apply_filter(img_update, filter_name, filter_value)
2466
2462
  else:
2467
2463
  img_update = ImageOps.fit(img_update, size=value)
2468
2464
  elif "pad" in k.lower():
@@ -2533,7 +2529,15 @@ def imgsets(img, **kwargs):
2533
2529
  else:
2534
2530
  plt.figure(figsize=figsize, dpi=dpi)
2535
2531
  plt.imshow(img_update)
2536
- plt.axis("on") if show_axis else plt.axis("off")
2532
+ if show_axis:
2533
+ plt.axis("on") # Turn on axis
2534
+ plt.minorticks_on()
2535
+ plt.grid(
2536
+ which="both", linestyle="--", linewidth=0.5, color="gray", alpha=0.7
2537
+ )
2538
+
2539
+ else:
2540
+ plt.axis("off") # Turn off axis
2537
2541
  return img_update
2538
2542
 
2539
2543
 
@@ -2632,66 +2636,6 @@ def dir_lib(lib_oi):
2632
2636
  # example usage:
2633
2637
  # dir_lib("seaborn")
2634
2638
 
2635
-
2636
- # set up the colorlist, give the number, or the colormap's name
2637
- def get_color(n=1, cmap="auto", by="start"):
2638
- # Extract the colormap as a list
2639
- def cmap2hex(cmap_name):
2640
- cmap_ = matplotlib.pyplot.get_cmap(cmap_name)
2641
- colors = [cmap_(i) for i in range(cmap_.N)]
2642
- return [matplotlib.colors.rgb2hex(color) for color in colors]
2643
- # usage: clist = cmap2hex("viridis")
2644
-
2645
- # cycle times, total number is n (defaultn=10)
2646
- def cycle2list(colorlist, n=10):
2647
- cycler_ = cycler(tmp=colorlist)
2648
- clist = []
2649
- for i, c_ in zip(range(n), cycler_()):
2650
- clist.append(c_["tmp"])
2651
- if i > n:
2652
- break
2653
- return clist
2654
-
2655
- def hue2rgb(hex_colors):
2656
- def hex_to_rgb(hex_color):
2657
- """Converts a hexadecimal color code to RGB values."""
2658
- if hex_colors.startswith("#"):
2659
- hex_color = hex_color.lstrip("#")
2660
- return tuple(int(hex_color[i : i + 2], 16) / 255.0 for i in (0, 2, 4))
2661
-
2662
- if isinstance(hex_colors, str):
2663
- return hex_to_rgb(hex_colors)
2664
- elif isinstance(hex_colors, (list)):
2665
- """Converts a list of hexadecimal color codes to a list of RGB values."""
2666
- rgb_values = [hex_to_rgb(hex_color) for hex_color in hex_colors]
2667
- return rgb_values
2668
-
2669
- if "aut" in cmap:
2670
- colorlist = [
2671
- "#474747",
2672
- "#FF2C00",
2673
- "#0C5DA5",
2674
- "#845B97",
2675
- "#58BBCC",
2676
- "#FF9500",
2677
- "#D57DBE",
2678
- ]
2679
- else:
2680
- colorlist = cmap2hex(cmap)
2681
- if "st" in by.lower() or "be" in by.lower():
2682
- # cycle it
2683
- clist = cycle2list(colorlist, n=n)
2684
- if "l" in by.lower() or "p" in by.lower():
2685
- clist = []
2686
- [
2687
- clist.append(colorlist[i])
2688
- for i in [int(i) for i in np.linspace(0, len(colorlist) - 1, n)]
2689
- ]
2690
-
2691
- return clist # a color list
2692
- # example usage: clist = get_color(4,cmap="auto", by="start") # get_color(4, cmap="hot", by="linspace")
2693
-
2694
-
2695
2639
  """
2696
2640
  # n = 7
2697
2641
  # clist = get_color(n, cmap="auto", how="linspace") # get_color(100)
py2ls/plot.py CHANGED
@@ -978,9 +978,13 @@ def figsets(*args, **kwargs):
978
978
  from cycler import cycler
979
979
 
980
980
 
981
- # set up the colorlist, give the number, or the colormap's name
982
- def get_color(n=1, cmap="auto", by="start", alpha=1.0):
983
- # Extract the colormap as a list
981
+ def get_color(
982
+ n: int = 1,
983
+ cmap: str = "auto",
984
+ by: str = "start",
985
+ alpha: float = 1.0,
986
+ output: str = "hue",
987
+ ):
984
988
  def cmap2hex(cmap_name):
985
989
  cmap_ = matplotlib.pyplot.get_cmap(cmap_name)
986
990
  colors = [cmap_(i) for i in range(cmap_.N)]
@@ -1013,6 +1017,22 @@ def get_color(n=1, cmap="auto", by="start", alpha=1.0):
1013
1017
  rgba_values = [hex_to_rgba(hex_color, alpha) for hex_color in hex_colors]
1014
1018
  return rgba_values
1015
1019
 
1020
+ def rgba2hue(rgba_color):
1021
+ if len(rgba_color) == 3:
1022
+ r, g, b = rgba_color
1023
+ a = 1
1024
+ else:
1025
+ r, g, b, a = rgba_color
1026
+ # Convert each component to a scale of 0-255
1027
+ r = int(r * 255)
1028
+ g = int(g * 255)
1029
+ b = int(b * 255)
1030
+ a = int(a * 255)
1031
+ if a < 255:
1032
+ return "#{:02X}{:02X}{:02X}{:02X}".format(r, g, b, a)
1033
+ else:
1034
+ return "#{:02X}{:02X}{:02X}".format(r, g, b)
1035
+
1016
1036
  # Determine color list based on cmap parameter
1017
1037
  if "aut" in cmap:
1018
1038
  colorlist = [
@@ -1037,13 +1057,17 @@ def get_color(n=1, cmap="auto", by="start", alpha=1.0):
1037
1057
  for i in [int(i) for i in np.linspace(0, len(colorlist) - 1, n)]
1038
1058
  ]
1039
1059
 
1040
- # Convert colors to RGBA format with the specified alpha
1041
- clist_with_alpha = hue2rgb(clist, alpha)
1042
-
1043
- return clist_with_alpha
1060
+ if "rgb" in output.lower():
1061
+ return hue2rgb(clist, alpha)
1062
+ elif "h" in output.lower():
1063
+ hue_list = []
1064
+ [hue_list.append(rgba2hue(i)) for i in hue2rgb(clist, alpha)]
1065
+ return hue_list
1066
+ else:
1067
+ raise ValueError("Invalid output type. Choose 'rgb' or 'hue'.")
1044
1068
 
1045
1069
  # # Example usage
1046
- # colors = get_color(n=5, cmap="viridis", by="linear", alpha=0.5)
1070
+ # colors = get_color(n=5, cmap="viridis", by="linear", alpha=0.5,output='rgb')
1047
1071
  # print(colors)
1048
1072
 
1049
1073
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2ls
3
- Version: 0.1.8.1
3
+ Version: 0.1.8.3
4
4
  Summary: py(thon)2(too)ls
5
5
  Author: Jianfeng
6
6
  Author-email: Jianfeng.Liu0413@gmail.com
@@ -134,14 +134,14 @@ py2ls/db2ls.py,sha256=MMfFX47aIPIyu7fU9aPvX9lbPRPYOpJ_VXwlnWk-8qo,13615
134
134
  py2ls/doc.py,sha256=xN3g1OWfoaGUhikbJ0NqbN5eKy1VZVvWwRlhHMgyVEc,4243
135
135
  py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,2325
136
136
  py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
137
- py2ls/ips.py,sha256=w3FfvnCnsl92XHm3sxzGpr2LhUZ7zUNgvrS9WSaquYo,102629
137
+ py2ls/ips.py,sha256=nGGA9Xqa5MzU5X7aE7Mfkk0qrnOkn3DGYulKuh-Ew48,100571
138
138
  py2ls/netfinder.py,sha256=MY_0TQY_zaRBZ6wfR4RxNCGrU93HFmDVDRRy1EXl75o,47566
139
- py2ls/plot.py,sha256=Y9tmGlIN4jjVKRtPpRDz067yq0DlR9KYv5TJ7s3jZwc,49812
139
+ py2ls/plot.py,sha256=WIAUDd4cRjFTX_Y_SWwsSw9_gIQF_Ye6R_-MvhB9G1k,50437
140
140
  py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
141
141
  py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso68,52145
142
142
  py2ls/stats.py,sha256=Wd9yCKQ_61QD29WMEgMuEcreFxF91NmlPW65iWT2B5w,39041
143
143
  py2ls/translator.py,sha256=bc5FB-wqC4TtQz9gyCP1mE38HqNRJ_pmuRIgKnAlMzM,30581
144
144
  py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
145
- py2ls-0.1.8.1.dist-info/METADATA,sha256=aG7rHa3yELrjuHiV338xDPIxbCEgCssNxY8CepQTSOw,20017
146
- py2ls-0.1.8.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
147
- py2ls-0.1.8.1.dist-info/RECORD,,
145
+ py2ls-0.1.8.3.dist-info/METADATA,sha256=-paqLVPq6PniDxsUdZ0UVwJQIry2DrS958ohish7h2o,20017
146
+ py2ls-0.1.8.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
147
+ py2ls-0.1.8.3.dist-info/RECORD,,