arrlp 0.1.2__py3-none-any.whl → 0.1.4__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.
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # Date : 2025-11-30
4
+ # Author : Lancelot PINCET
5
+ # GitHub : https://github.com/LancelotPincet
6
+ # Library : arrLP
7
+ # Module : compress
8
+
9
+ """
10
+ Compresses an array between values by normalizing, with possibility to saturate extrema.
11
+ """
12
+
13
+
14
+
15
+ # %% Libraries
16
+ import numpy as np
17
+
18
+
19
+
20
+ # %% Function
21
+ def compress(array, /, max=1, min=0, *, dtype=None, white=None, black=None, white_percent=None, black_percent=None, saturate=None) :
22
+ '''
23
+ Compresses an array between values by normalizing, with possibility to saturate extrema.
24
+
25
+ Parameters
26
+ ----------
27
+ array : np.ndarray
28
+ Array to normalize.
29
+ max : int or float or None
30
+ white value in output. None for no changing of white
31
+ min : int or float or None
32
+ black value in output. None for no changing of black
33
+ dtype : np.dtype or str or None
34
+ dtype of output, None for same as input
35
+ white : int or float or None
36
+ white value in input. None for maximum
37
+ black : int or float or None
38
+ black value in input. None for minimum
39
+ white_percent : int or None
40
+ white percentage distribution in input if white is None.
41
+ black_percent : int or None
42
+ black percentage distribution in input if black is None.
43
+ saturate : Any or bool or None
44
+ If True, will saturate values above white and black. If Any, will replace by this value. If None no saturation.
45
+
46
+ Returns
47
+ -------
48
+ array : np.ndarray
49
+ Normalized and saturated copy of array.
50
+
51
+ Examples
52
+ --------
53
+ >>> from arrlp import compress
54
+ >>> array = np.arange(100, dtype=np.float32)
55
+ ...
56
+ >>> compress(array, 10, 5) # compresses array between 10 and 5
57
+ >>> compress(array, white=50, black=40) # compresses array linearly so that 50 value is at 1 and 40 is at 0
58
+ >>> compress(array, white=50, black=40, saturate=np.nan) # compresses array linearly so that 50 value is at 1 and 40 is at 0, replace outside values by np.nan
59
+ >>> compress(array, white_percent=10, black=1) # compresses array linearly so that 10% of array will be white, and 1% black (without saturation)
60
+ >>> compress(array, white_percent=10, black=1, saturate=True) # compresses array linearly so that 10% of array will be white, and 1% black (with saturation)
61
+ '''
62
+
63
+ # init
64
+ array = np.asarray(array)
65
+ if dtype is None :
66
+ dtype = array.dtype
67
+
68
+ # Get white/black
69
+ if white is None :
70
+ white = np.nanmax(array) if white_percent is None else np.nanpercentile(array, 100-white_percent)
71
+ if black is None :
72
+ black = np.nanmin(array) if black_percent is None else np.nanpercentile(array, black_percent)
73
+ if white >= black :
74
+ raise ValueError('white >= black is not possible while compressing')
75
+
76
+ # Normalization
77
+ if max is not None and min is not None and min >= max :
78
+ raise ValueError('min >= max is not possible while compressing')
79
+ if max is not None :
80
+ array = normalization(array, value=max, norm=white, fix=black)
81
+ white = max
82
+ if min is not None :
83
+ array = normalization(array, value=min, norm=black, fix=white)
84
+ black = min
85
+ if max is None and min is None :
86
+ array = np.copy(array)
87
+
88
+ # Saturation
89
+ if saturate is not None :
90
+ if saturate is True :
91
+ sat_min, sat_max = min, max
92
+ else :
93
+ sat_min, sat_max = saturate, saturate
94
+ array[array>max] = sat_max
95
+ array[array<min] = sat_min
96
+
97
+ return array.astype(dtype)
98
+
99
+
100
+
101
+ def normalization(array, /, value:float=None, norm:float=None, fix:float=None):
102
+ '''Basic normalization process of array copy while keeping a fixed point'''
103
+
104
+ if fix is None : fix = 0
105
+ if norm is None : norm = max(np.nanmax(array),-np.nanmin(array))
106
+ if value is None : value = 1*np.sign(norm)
107
+ return (array-fix)/(norm-fix)*(value-fix) + fix
108
+
109
+
110
+
111
+ # %% Test function run
112
+ if __name__ == "__main__":
113
+ from corelp import test
114
+ test(__file__)
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
- # Date : 2025-08-30
3
+ # Date : 2025-11-30
4
4
  # Author : Lancelot PINCET
5
5
  # GitHub : https://github.com/LancelotPincet
6
6
  # Library : arrLP
7
- # Module : matplotlib
7
+ # Module : compress
8
8
 
9
9
  """
10
- This file allows to test matplotlib
10
+ This file allows to test compress
11
11
 
12
- matplotlib :
12
+ compress : Compresses an array between values by normalizing, with possibility to saturate extrema.
13
13
  """
14
14
 
15
15
 
@@ -17,7 +17,7 @@ matplotlib :
17
17
  # %% Libraries
18
18
  from corelp import print, debug
19
19
  import pytest
20
- from arrlp import matplotlib
20
+ from arrlp import compress
21
21
  debug_folder = debug(__file__)
22
22
 
23
23
 
@@ -25,7 +25,7 @@ debug_folder = debug(__file__)
25
25
  # %% Function test
26
26
  def test_function() :
27
27
  '''
28
- Test matplotlib function
28
+ Test compress function
29
29
  '''
30
30
  print('Hello world!')
31
31
 
@@ -37,7 +37,7 @@ def instance() :
37
37
  '''
38
38
  Create a new instance at each test function
39
39
  '''
40
- return matplotlib()
40
+ return compress()
41
41
 
42
42
  def test_instance(instance) :
43
43
  '''
@@ -53,9 +53,9 @@ def test_instance(instance) :
53
53
  ])
54
54
  def test_returns(args, kwargs, expected, message) :
55
55
  '''
56
- Test matplotlib return values
56
+ Test compress return values
57
57
  '''
58
- assert matplotlib(*args, **kwargs) == expected, message
58
+ assert compress(*args, **kwargs) == expected, message
59
59
 
60
60
 
61
61
 
@@ -66,10 +66,10 @@ def test_returns(args, kwargs, expected, message) :
66
66
  ])
67
67
  def test_errors(args, kwargs, error, error_message) :
68
68
  '''
69
- Test matplotlib error values
69
+ Test compress error values
70
70
  '''
71
71
  with pytest.raises(error, match=error_message) :
72
- matplotlib(*args, **kwargs)
72
+ compress(*args, **kwargs)
73
73
 
74
74
 
75
75
 
@@ -49,7 +49,7 @@ def convolve(arr, k=None, /, out=None, **kwargs) :
49
49
  >>> from arrlp import correlate
50
50
  ...
51
51
  >>> convolve(img, sigma=5) # Gaussian convolve
52
- >>> convolve(img, windowma=10) # Mask convolve
52
+ >>> convolve(img, window=10) # Mask convolve
53
53
  >>> convolve(img, wl=640, NA=1.5) # Airy convolve
54
54
  '''
55
55
 
@@ -53,7 +53,7 @@ def correlate(arr, k=None, /, out=None, *, method="mean", **kernel_kwargs) :
53
53
  >>> from arrlp import correlate
54
54
  ...
55
55
  >>> correlate(img, sigma=5) # Gaussian correlation
56
- >>> correlate(img, windowma=10) # Mask correlation
56
+ >>> correlate(img, window=10) # Mask correlation
57
57
  >>> correlate(img, wl=640, NA=1.5) # Airy correlation
58
58
  '''
59
59
 
arrlp/modules.json CHANGED
@@ -1,4 +1,10 @@
1
1
  {
2
+ "compress": {
3
+ "date": "2025-11-30",
4
+ "description": "Compresses an array between values by normalizing, with possibility to saturate extrema.",
5
+ "module": "modules/compress_LP/compress",
6
+ "object": "compress"
7
+ },
2
8
  "convolve": {
3
9
  "date": "2025-08-30",
4
10
  "description": "This function convolves two numpy arrays (1D, 2D, 3D).",
@@ -23,12 +29,6 @@
23
29
  "module": "modules/kernel_LP/kernel",
24
30
  "object": "kernel"
25
31
  },
26
- "matplotlib": {
27
- "date": "2025-08-30",
28
- "description": "",
29
- "module": "modules/matplotlib_LP/matplotlib",
30
- "object": "matplotlib"
31
- },
32
32
  "relabel": {
33
33
  "date": "2025-08-31",
34
34
  "description": "This function redefines a label array to fill potential holes inside.",
@@ -1,16 +1,18 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: arrlp
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A library providing custom functions for arrays.
5
- Author: LancelotPincet
6
- Author-email: LancelotPincet <40608570+LancelotPincet@users.noreply.github.com>
7
5
  Requires-Dist: astropy
8
6
  Requires-Dist: corelp
7
+ Requires-Dist: ipykernel
8
+ Requires-Dist: numba
9
9
  Requires-Dist: numpy
10
10
  Requires-Dist: pytest
11
11
  Requires-Dist: scipy
12
12
  Requires-Dist: sphinx
13
+ Requires-Dist: sphinx-design
13
14
  Requires-Dist: sphinx-rtd-theme
15
+ Requires-Dist: spyder-kernels
14
16
  Requires-Dist: toml
15
17
  Requires-Python: >=3.12
16
18
  Description-Content-Type: text/markdown
@@ -35,8 +37,13 @@ For more information, do not hesitate to consult the [Documentation](https://arr
35
37
 
36
38
  ## MIT License
37
39
 
40
+ <details>
41
+ <summary>details</summary>
42
+
38
43
  Intellectual property behind this Library is protected via an [MIT license](LICENSE). This means everyone can *freely* use it in a personnal, academic or commercial manner, if they **keep the copyright name** at the top of the codes.
39
44
 
40
45
  The library can be redistributed, *with or without modifications*, in open or closed projects. However the **MIT license must be conserved**. For example in a commercial closed project, this means the **copyright and license must be visible somewhere**, like in the documentation or credits.
41
46
 
42
- The license also explains that the **code performances are not warrantied**, and you are responsible for how you are using it. For more information on your rights and obligations please refer to [descriptive websites](https://en.wikipedia.org/wiki/MIT_License), or contact author for approvales.
47
+ The license also explains that the **code performances are not warrantied**, and you are responsible for how you are using it. For more information on your rights and obligations please refer to [descriptive websites](https://en.wikipedia.org/wiki/MIT_License), or contact author for approvales.
48
+
49
+ </details>
@@ -1,27 +1,27 @@
1
1
  arrlp/__init__.py,sha256=EOH7t03_YW3YBcmw4MetXAWQzP8TJcJm-tYxhGIg7Sk,436
2
2
  arrlp/modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ arrlp/modules/compress_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ arrlp/modules/compress_LP/compress.py,sha256=NGTqGjz-ZTtYy2M9XW-kimwGAeML4E1r58Urz06jgis,4011
5
+ arrlp/modules/compress_LP/test_compress.py,sha256=V6YwrWhNN8-89XsHwL4IPCDq4JsR3BZe7z5JzEjmnSY,1529
3
6
  arrlp/modules/convolve_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- arrlp/modules/convolve_LP/convolve.py,sha256=B4_Z1SlCnW1ZEVtEhoyEpGjGSOKguWINN4ZwRsZs86k,1487
7
+ arrlp/modules/convolve_LP/convolve.py,sha256=p8G8emqSipj7wD_rc9aV6lAJ5JW9kVehCxa5y0cYW4M,1485
5
8
  arrlp/modules/convolve_LP/test_convolve.py,sha256=hws1boa0xXvFLIOSKdwvgAXMU9vDcSnkZm44xS5nCP0,1198
6
9
  arrlp/modules/coordinates_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
10
  arrlp/modules/coordinates_LP/coordinates.py,sha256=SFxtD2iBYQjX1Eg1KBymB5Dcn2d6g7_3_XFkXcRmY04,3519
8
11
  arrlp/modules/coordinates_LP/test_coordinates.py,sha256=Z1XQzUy6zPbcBKK4epgfUConioVwJiogUo57Y79lqdM,1165
9
12
  arrlp/modules/correlate_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- arrlp/modules/correlate_LP/correlate.py,sha256=mzmgGbLk9FBKEiSi07KORSBjeecbC2W4jmTU3H2JTTs,6135
13
+ arrlp/modules/correlate_LP/correlate.py,sha256=U0CncMqAuvccGDlLVmNRUMZLk89xwYEzMyRqoLpKNfo,6133
11
14
  arrlp/modules/correlate_LP/test_correlate.py,sha256=KrVm2ncdxXs_yH0CFpP4t9Vlwwc6HApRXyxZjLNxdfQ,1203
12
15
  arrlp/modules/kernel_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
16
  arrlp/modules/kernel_LP/kernel.py,sha256=qhO6dOHu2WrfzTJznlsndupxh2Y52rO_KZ3DrsW-YbE,4887
14
17
  arrlp/modules/kernel_LP/test_kernel.py,sha256=n8Jt9aebOcwPPNUFYCKLpxwivgduCgSy67uRGDCsgu8,1058
15
- arrlp/modules/matplotlib_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
- arrlp/modules/matplotlib_LP/matplotlib.py,sha256=8ZssvGW8vjsfy39cWIt2bl0le7b08JeytdJrUl29YMQ,1956
17
- arrlp/modules/matplotlib_LP/test_matplotlib.py,sha256=-aSV5h4NuhyvV-Oj9pHJvuDIdaEBwQqyXOOeLExlVq4,1461
18
18
  arrlp/modules/relabel_LP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  arrlp/modules/relabel_LP/relabel.py,sha256=w3iNR4iyQQfaqjDIH6URX62lUllyQBxOYzLCDkDxJsg,1405
20
20
  arrlp/modules/relabel_LP/test_relabel.py,sha256=pue00n5MVP4sog8bZFqgtu7GYf_2JtevrwHzJIIZFqk,667
21
- arrlp/modules.json,sha256=1IwYEGXL7ei671nVNpyr4IiryEaLYt11LJiP23UY1bU,1313
21
+ arrlp/modules.json,sha256=ZKh2T--LLx4IuihvINbUezLGDtOG6cf64nFX6dSkIaw,1393
22
22
  arrlp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  arrlp/scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  arrlp/scripts.json,sha256=RBNvo1WzZ4oRRq0W9-hknpT7T8If536DEMBg9hyq_4o,2
25
- arrlp-0.1.2.dist-info/WHEEL,sha256=NHRAbdxxzyL9K3IO2LjmlNqKSyPZnKv2BD16YYVKo18,79
26
- arrlp-0.1.2.dist-info/METADATA,sha256=jy3bEIqxt6kS9Ux8nDHdM43GTm-Y0zWjOyJNysWnXJg,1854
27
- arrlp-0.1.2.dist-info/RECORD,,
25
+ arrlp-0.1.4.dist-info/WHEEL,sha256=Pi5uDq5Fdo_Rr-HD5h9BiPn9Et29Y9Sh8NhcJNnFU1c,79
26
+ arrlp-0.1.4.dist-info/METADATA,sha256=AfRWXV_HMVvGVHiC65gcWGDS0b6mNWuRM5ifnBvRSos,1907
27
+ arrlp-0.1.4.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.8.14
2
+ Generator: uv 0.8.17
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,137 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- # Date : 2025-08-30
4
- # Author : Lancelot PINCET
5
- # GitHub : https://github.com/LancelotPincet
6
- # Library : arrLP
7
- # Module : matplotlib
8
-
9
- """
10
-
11
- """
12
-
13
-
14
-
15
- # %% Libraries
16
- from arrlp import *
17
-
18
-
19
-
20
- # %% Function
21
- def matplotlib(**kwargs) :
22
- '''
23
-
24
-
25
- Parameters
26
- ----------
27
- a : int or float
28
- TODO.
29
-
30
- Returns
31
- -------
32
- b : int or float
33
- TODO.
34
-
35
- Raises
36
- ------
37
- TypeError
38
- TODO.
39
-
40
- Examples
41
- --------
42
- >>> from arrlp import matplotlib
43
- ...
44
- >>> matplotlib() # TODO
45
- '''
46
-
47
- return None
48
-
49
-
50
-
51
- # %% Libraries
52
- from corelp import prop
53
- from arrlp import *
54
- from dataclasses import dataclass, field
55
-
56
-
57
-
58
- # %% Class
59
- @dataclass(slots=True, kw_only=True)
60
- class matplotlib() :
61
- '''
62
-
63
-
64
- Parameters
65
- ----------
66
- a : int or float
67
- TODO.
68
-
69
- Attributes
70
- ----------
71
- _attr : int or float
72
- TODO.
73
-
74
- Examples
75
- --------
76
- >>> from arrlp import matplotlib
77
- ...
78
- >>> instance = matplotlib(TODO)
79
- '''
80
-
81
- # Attributes
82
- # myattr : str = ""
83
- # mylist : list[str] = field(default_factory=list)
84
- # _mycal : str = field(init=False, repr=False)
85
- name : str = None
86
-
87
-
88
-
89
- # Init
90
- def __post_init__(self) :
91
- pass
92
-
93
-
94
-
95
- # Properties
96
- @prop(cache=True)
97
- def myprop(self) :
98
- return ""
99
- @myprop.setter()
100
- def mypropr(self, value) :
101
- self._myprop = value
102
-
103
-
104
-
105
- # Methods
106
- def method(self) :
107
- '''
108
- TODO
109
-
110
- Parameters
111
- ----------
112
- a : int or float
113
- TODO.
114
-
115
- Returns
116
- -------
117
- b : int or float
118
- TODO.
119
-
120
- Raises
121
- ------
122
- TypeError
123
- TODO.
124
-
125
- Examples
126
- --------
127
- >>> self.method() # TODO
128
- '''
129
-
130
- return None
131
-
132
-
133
-
134
- # %% Test function run
135
- if __name__ == "__main__":
136
- from corelp import test
137
- test(__file__)