py2ls 0.1.8.5__py3-none-any.whl → 0.1.8.7__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
@@ -924,13 +924,14 @@ def pdf2img(dir_pdf, dir_save=None, page=None, kind="png", verbose=True, **kws):
924
924
  page = [page]
925
925
  if page is None:
926
926
  page = [pdfinfo_from_path(dir_pdf)["Pages"]]
927
- if len(page) == 1 and page != pdfinfo_from_path(dir_pdf)["Pages"]:
927
+ if len(page) == 1 and page != [pdfinfo_from_path(dir_pdf)["Pages"]]:
928
928
  page = [page[0], page[0]]
929
929
  else:
930
930
  page = [1, page[0]]
931
- pages = convert_from_path(dir_pdf, first_page=page[0], last_page=page[1], **kws)
931
+ print(page)
932
+ pages = convert_from_path(dir_pdf, first_page=page[0], last_page=page[-1], **kws)
932
933
  if dir_save is None:
933
- dir_save = newfolder(dirname(dir_pdf), basename(dir_pdf).split(".")[0] + "_img")
934
+ dir_save = mkdir(dirname(dir_pdf), basename(dir_pdf).split(".")[0] + "_img")
934
935
  for i, page in enumerate(pages):
935
936
  if verbose:
936
937
  print(f"processing page: {i+1}")
py2ls/plot.py CHANGED
@@ -333,18 +333,39 @@ def catplot(data, *args, **kwargs):
333
333
  for i in df[x].unique().tolist():
334
334
  for j in df[hue].unique().tolist():
335
335
  xticklabels.append(i + "-" + j)
336
+ x_len = len(df[x].unique().tolist())
337
+ hue_len = len(df[hue].unique().tolist())
338
+ xticks = generate_xticks_with_gap(x_len, hue_len)
339
+ default_x_width = 0.85
336
340
  else:
337
341
  for i in df[x].unique().tolist():
338
342
  xticklabels.append(i)
339
- ylabel = y
340
- xlabe = x
341
-
342
- kw_figsets = {
343
- "ylabel": y,
344
- "xlabel": x,
345
- "xticklabels": xticklabels,
346
- **kw_figsets,
347
- }
343
+ xticks = np.arange(1, len(xticklabels) + 1)
344
+ default_x_width = 0.5
345
+ # when the xticklabels are too long, rotate the labels a bit
346
+
347
+ xangle = 30 if max([len(i) for i in xticklabels]) > 5 else 0
348
+ if kw_figsets is not None:
349
+ kw_figsets = {
350
+ "ylabel": y,
351
+ "xlabel": x,
352
+ "xticks": xticks,
353
+ "xticklabels": xticklabels,
354
+ "xangle": xangle,
355
+ **kw_figsets,
356
+ }
357
+ else:
358
+ kw_figsets = {
359
+ "ylabel": y,
360
+ "xlabel": x,
361
+ "xticks": xticks,
362
+ "xticklabels": xticklabels,
363
+ "xangle": xangle,
364
+ }
365
+ else:
366
+ xticks = np.arange(1, data.shape[1] + 1)
367
+ default_x_width = 0.5
368
+ xangle = 0
348
369
 
349
370
  # full_order
350
371
  opt = kwargs.get("opt", {})
@@ -375,7 +396,7 @@ def catplot(data, *args, **kwargs):
375
396
 
376
397
  opt.setdefault("loc", {})
377
398
  opt["loc"].setdefault("go", 0)
378
- opt["loc"].setdefault("xloc", np.arange(1, data.shape[1] + 1))
399
+ opt["loc"].setdefault("xloc", xticks)
379
400
 
380
401
  # export setting
381
402
  opt.setdefault("export", {})
@@ -394,7 +415,7 @@ def catplot(data, *args, **kwargs):
394
415
  opt["b"].setdefault("EdgeAlpha", 1)
395
416
  opt["b"].setdefault("LineStyle", "-")
396
417
  opt["b"].setdefault("LineWidth", 0.8)
397
- opt["b"].setdefault("x_width", 0.5)
418
+ opt["b"].setdefault("x_width", default_x_width)
398
419
  opt["b"].setdefault("ShowBaseLine", "off")
399
420
  opt["b"].setdefault("hatch", None)
400
421
 
@@ -1433,30 +1454,49 @@ def padcat(*args, fill_value=np.nan, axis=1, order="row"):
1433
1454
  The value to use for padding the shorter lists (default is np.nan).
1434
1455
  axis : int, optional
1435
1456
  The axis along which to concatenate (0 for rows, 1 for columns, default is 1).
1457
+ order : str, optional
1458
+ The order for flattening when required: "row" or "column" (default is "row").
1436
1459
 
1437
1460
  Returns:
1438
1461
  np.ndarray
1439
1462
  A 2D array with the input arrays concatenated along the specified axis,
1440
1463
  padded with fill_value where necessary.
1441
1464
  """
1442
- # Convert all inputs to 1D NumPy arrays
1465
+ # Set the order for processing
1443
1466
  if "ro" in order.lower():
1444
- order = "C" # in row
1467
+ order = "C" # row-major order
1445
1468
  else:
1446
- order = "F" # column
1447
- arrays = [np.asarray(arg).flatten(order=order) for arg in args]
1469
+ order = "F" # column-major order
1470
+
1471
+ # Process input arrays based on their dimensions
1472
+ processed_arrays = []
1473
+ for arg in args:
1474
+ arr = np.asarray(arg)
1475
+ if arr.ndim == 1:
1476
+ processed_arrays.append(arr) # Keep 1D arrays as is
1477
+ elif arr.ndim == 2:
1478
+ if axis == 0:
1479
+ # If concatenating along rows, split 2D arrays into 1D arrays row-wise
1480
+ processed_arrays.extend(arr)
1481
+ elif axis == 1:
1482
+ # If concatenating along columns, split 2D arrays into 1D arrays column-wise
1483
+ processed_arrays.extend(arr.T)
1484
+ else:
1485
+ raise ValueError("axis must be 0 or 1")
1486
+ else:
1487
+ raise ValueError("Input arrays must be 1D or 2D")
1448
1488
 
1449
1489
  if axis == 0:
1450
1490
  # Concatenate along rows
1451
- max_len = max(arr.size for arr in arrays)
1452
- result = np.full((len(arrays), max_len), fill_value)
1453
- for i, arr in enumerate(arrays):
1491
+ max_len = max(arr.size for arr in processed_arrays)
1492
+ result = np.full((len(processed_arrays), max_len), fill_value)
1493
+ for i, arr in enumerate(processed_arrays):
1454
1494
  result[i, : arr.size] = arr
1455
1495
  elif axis == 1:
1456
1496
  # Concatenate along columns
1457
- max_len = max(arr.size for arr in arrays)
1458
- result = np.full((max_len, len(arrays)), fill_value)
1459
- for i, arr in enumerate(arrays):
1497
+ max_len = max(arr.size for arr in processed_arrays)
1498
+ result = np.full((max_len, len(processed_arrays)), fill_value)
1499
+ for i, arr in enumerate(processed_arrays):
1460
1500
  result[: arr.size, i] = arr
1461
1501
  else:
1462
1502
  raise ValueError("axis must be 0 or 1")
@@ -1464,6 +1504,17 @@ def padcat(*args, fill_value=np.nan, axis=1, order="row"):
1464
1504
  return result
1465
1505
 
1466
1506
 
1507
+ # # Example usage:
1508
+ # a = [1, np.nan]
1509
+ # b = [1, 3, 4, np.nan, 2, np.nan]
1510
+ # c = [1, 2, 3, 4, 5, 6, 7, 8, 10]
1511
+ # d = padcat(a, b)
1512
+ # result1 = padcat(d, c)
1513
+ # result2 = padcat(a, b, c)
1514
+ # print("Result of padcat(d, c):\n", result1)
1515
+ # print("Result of padcat(a, b, c):\n", result2)
1516
+
1517
+
1467
1518
  def sort_rows_move_nan(arr):
1468
1519
  # Handle edge cases where all values are NaN
1469
1520
  if np.all(np.isnan(arr)):
@@ -1490,20 +1541,50 @@ def sort_rows_move_nan(arr):
1490
1541
  return clean_arr_
1491
1542
 
1492
1543
 
1493
- def df2array(data: pd.DataFrame, x, y, hue=None):
1544
+ def df2array(data: pd.DataFrame, x, y, hue=None, sort=False):
1494
1545
  if hue is None:
1495
1546
  a = []
1496
- cat_x = data[x].unique().tolist()
1547
+ if sort:
1548
+ np.sort(data[x].unique().tolist()).tolist()
1549
+ else:
1550
+ cat_x = data[x].unique().tolist()
1497
1551
  for i, x_ in enumerate(cat_x):
1498
1552
  new_ = data.loc[data[x] == x_, y].to_list()
1499
- a = padcat(a, new_, axis=0)
1500
- return sort_rows_move_nan(a.reshape(2**i, -1))
1553
+ a = padcat(a, new_, axis=0).T
1554
+ return sort_rows_move_nan(a)
1501
1555
  else:
1502
1556
  a = []
1503
- cat_x = data[x].unique().tolist()
1504
- cat_hue = data[hue].unique().tolist()
1557
+ if sort:
1558
+ cat_x = np.sort(data[x].unique().tolist()).tolist()
1559
+ cat_hue = np.sort(data[hue].unique().tolist()).tolist()
1560
+ else:
1561
+ cat_x = data[x].unique().tolist()
1562
+ cat_hue = data[hue].unique().tolist()
1505
1563
  for i, x_ in enumerate(cat_x):
1506
1564
  for j, hue_ in enumerate(cat_hue):
1507
1565
  new_ = data.loc[(data[x] == x_) & (data[hue] == hue_), y].to_list()
1508
1566
  a = padcat(a, new_, axis=0)
1509
- return sort_rows_move_nan(a.reshape(2 ** ((i + 1) * (j + 1)), -1))
1567
+ return sort_rows_move_nan(a)
1568
+
1569
+
1570
+ def generate_xticks_with_gap(x_len, hue_len):
1571
+ """
1572
+ Generate a concatenated array based on x_len and hue_len,
1573
+ and return only the positive numbers.
1574
+
1575
+ Parameters:
1576
+ - x_len: int, number of segments to generate
1577
+ - hue_len: int, length of each hue
1578
+
1579
+ Returns:
1580
+ - numpy array: Concatenated array containing only positive numbers
1581
+ """
1582
+
1583
+ arrays = [
1584
+ np.arange(1, hue_len + 1) + hue_len * (x_len - i) + (x_len - i)
1585
+ for i in range(max(x_len, hue_len), 0, -1) # i iterates from 3 to 1
1586
+ ]
1587
+ concatenated_array = np.concatenate(arrays)
1588
+ positive_array = concatenated_array[concatenated_array > 0]
1589
+
1590
+ return positive_array
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2ls
3
- Version: 0.1.8.5
3
+ Version: 0.1.8.7
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=mBFTARM6Pvj5EaVRR05CXCBlyNcbX2JfMQWBjnxONjI,100773
137
+ py2ls/ips.py,sha256=6eNvNwaCDj2jyjter7VPL9oEGB2jS4ge9mSgiIrvZfo,100788
138
138
  py2ls/netfinder.py,sha256=OMStrwMAASf1ajlyEfseoaEygo7G5WKBAFRE0LY15Lw,49477
139
- py2ls/plot.py,sha256=odZsLi4jG_WLULurpdGnWEyLC_RD_Yz2_EW-DqhJu98,54285
139
+ py2ls/plot.py,sha256=a0-U-NE31dEhiD-aBNWRIL81sBKfCIqeJeaefu-FpVE,57128
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.5.dist-info/METADATA,sha256=E0XmdaV6guqdnsCWF2XHqfkPHxrltAgElzNII6oWq8g,20017
146
- py2ls-0.1.8.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
147
- py2ls-0.1.8.5.dist-info/RECORD,,
145
+ py2ls-0.1.8.7.dist-info/METADATA,sha256=yBv9UvJ5xZzrjdmCzBxhOuqIU3jAK1_StxP3ofxNtoE,20017
146
+ py2ls-0.1.8.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
147
+ py2ls-0.1.8.7.dist-info/RECORD,,