kbasic 0.3.19__tar.gz → 0.3.21__tar.gz
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.
- {kbasic-0.3.19 → kbasic-0.3.21}/PKG-INFO +1 -1
- {kbasic-0.3.19 → kbasic-0.3.21}/pyproject.toml +1 -1
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/array.py +33 -6
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/audio/lib/Caroline Rose - year of the slug - 01 everything in its right place.wav +1 -1
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/parsing/basic.py +4 -1
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/shell.py +3 -3
- {kbasic-0.3.19 → kbasic-0.3.21}/README.md +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/Tex.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/__init__.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/audio/__init__.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/audio/lib/success.mp3 +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/audio/sound.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/bar.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/environment/Keyan.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/environment/__init__.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/environment/anvil.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/environment/defaultPC.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/parsing/__init__.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/parsing/logging.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/parsing/parser.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/parsing/toml.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/parsing/utils.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/strings.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/typing.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/user_input.py +0 -0
- {kbasic-0.3.19 → kbasic-0.3.21}/src/kbasic/vectors.py +0 -0
|
@@ -26,6 +26,8 @@ def tile(arr: ArrayLike) -> NDArray:
|
|
|
26
26
|
"""
|
|
27
27
|
x = array(arr)
|
|
28
28
|
return r_[c_[x, x, x], c_[x, x, x], c_[x, x, x]]
|
|
29
|
+
|
|
30
|
+
|
|
29
31
|
def where_closest(arr:ArrayLike, value: Number) -> int | tuple[int]:
|
|
30
32
|
"""find the index where arr is closest to the value of x
|
|
31
33
|
|
|
@@ -39,6 +41,8 @@ def where_closest(arr:ArrayLike, value: Number) -> int | tuple[int]:
|
|
|
39
41
|
arr = array(arr)
|
|
40
42
|
indices = unravel_index(argmin(absolute(arr-value)), arr.shape)
|
|
41
43
|
return indices if len(indices)>1 else indices[0]
|
|
44
|
+
|
|
45
|
+
|
|
42
46
|
def where_between(arr:ArrayLike, low: Number, high: Number) -> NDArray:
|
|
43
47
|
"""Find the range of indicies where arr is between low and high
|
|
44
48
|
|
|
@@ -52,10 +56,21 @@ def where_between(arr:ArrayLike, low: Number, high: Number) -> NDArray:
|
|
|
52
56
|
"""
|
|
53
57
|
arr = array(arr)
|
|
54
58
|
return where((arr>=low)&(arr<=high))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def is_between(value: Number, low: Number, high: Number) -> bool:
|
|
62
|
+
"""return whether value is in between low and high (inclusive)."""
|
|
63
|
+
return (value>=low) & (value<=high)
|
|
64
|
+
|
|
65
|
+
def std_err(x: ArrayLike):
|
|
66
|
+
"""standard error of the mean"""
|
|
67
|
+
return nanstd(x) / sqrt(len(x))
|
|
68
|
+
|
|
55
69
|
def bin_this(
|
|
56
|
-
x: ArrayLike, y: ArrayLike,
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
x: ArrayLike, y: ArrayLike,
|
|
71
|
+
bins: int | ArrayLike = 50,
|
|
72
|
+
y_func: Callable = nanmean,
|
|
73
|
+
e_func: Callable = std_err
|
|
59
74
|
) -> tuple[NDArray]:
|
|
60
75
|
"""a function to rebin x, y data and calculate errors.
|
|
61
76
|
|
|
@@ -71,16 +86,18 @@ def bin_this(
|
|
|
71
86
|
bin_errors (NDArray): standard error of the mean for each bin
|
|
72
87
|
"""
|
|
73
88
|
x, y = array(x), array(y)
|
|
74
|
-
xbins = linspace(nanmin(x),nanmax(x),
|
|
89
|
+
xbins = linspace(nanmin(x),nanmax(x),bins) if type(bins)==int else bins
|
|
75
90
|
Y,error = list(),list()
|
|
76
91
|
for i,low_edge in enumerate(xbins[:-1]):
|
|
77
92
|
high_edge = xbins[i+1]
|
|
78
93
|
mask = (low_edge<x)&(x<high_edge)
|
|
79
94
|
yin = y[mask]
|
|
80
|
-
Y.append(
|
|
81
|
-
error.append(
|
|
95
|
+
Y.append(y_func(yin))
|
|
96
|
+
error.append(e_func(yin))
|
|
82
97
|
x_binned, y_binned, bin_errors = array(xbins)[:-1],array(Y),array(error)
|
|
83
98
|
return x_binned, y_binned, bin_errors
|
|
99
|
+
|
|
100
|
+
|
|
84
101
|
def nan_clip(*args: tuple[ArrayLike]) -> tuple[ArrayLike]:
|
|
85
102
|
"""
|
|
86
103
|
take a series of arrays and only return the indicies where ALL members are not nan
|
|
@@ -88,6 +105,8 @@ def nan_clip(*args: tuple[ArrayLike]) -> tuple[ArrayLike]:
|
|
|
88
105
|
mask = ~any([isnan(a) for a in args], axis=0)
|
|
89
106
|
nanless_args = tuple([array(a)[mask] for a in args])
|
|
90
107
|
return nanless_args
|
|
108
|
+
|
|
109
|
+
|
|
91
110
|
def only_finite(*args: tuple[ArrayLike]) -> tuple[ArrayLike]:
|
|
92
111
|
"""
|
|
93
112
|
take a series of arrays and only return the indicies where ALL members are finite
|
|
@@ -95,6 +114,8 @@ def only_finite(*args: tuple[ArrayLike]) -> tuple[ArrayLike]:
|
|
|
95
114
|
mask = all([isfinite(a) for a in args], axis=0)
|
|
96
115
|
nanless_args = tuple([array(a)[mask] for a in args])
|
|
97
116
|
return nanless_args
|
|
117
|
+
|
|
118
|
+
|
|
98
119
|
def interpolate2d(
|
|
99
120
|
data: ArrayLike, factor: int,
|
|
100
121
|
method: str = 'linear',
|
|
@@ -120,9 +141,13 @@ def interpolate2d(
|
|
|
120
141
|
data_repeat[-1,-1] = data[-1,-1]
|
|
121
142
|
new_grid = mgrid[:Nx:1/factor, :Ny:1/factor].T
|
|
122
143
|
return RegularGridInterpolator(grid, data_repeat, method=method)(new_grid).T
|
|
144
|
+
|
|
145
|
+
|
|
123
146
|
def kspec(image: ArrayLike) -> NDArray:
|
|
124
147
|
"""take 2d fft and center k=0 at the center point"""
|
|
125
148
|
return absolute(fftshift(fft2(image) / (1. * image.shape[0] * image.shape[1])))**2
|
|
149
|
+
|
|
150
|
+
|
|
126
151
|
def kspec1d(
|
|
127
152
|
image: ArrayLike,
|
|
128
153
|
bins: int = 100,
|
|
@@ -152,6 +177,8 @@ def kspec1d(
|
|
|
152
177
|
kerr = array([nanstd(in_bin:=k[where((kgrid[i] < kmag) & (kmag < kgrid[i+1]))])/sqrt(len(in_bin)) for i in range(len(kgrid)-1)])
|
|
153
178
|
if not return_bin_edges: return kx, ks, kerr
|
|
154
179
|
return kgrid, kx, ks, kerr
|
|
180
|
+
|
|
181
|
+
|
|
155
182
|
def kspec3d(
|
|
156
183
|
cube: ArrayLike,
|
|
157
184
|
parallel_axis: int = 0
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
|
-
name: kbasic-0.3.
|
|
2
|
+
name: kbasic-0.3.21/src/kbasic/audio/lib/Caroline Rose - year of the slug - 01 everything in its right place.wav
|
|
3
3
|
size: 39844960 bytes
|
|
4
4
|
sha256: 4cdd2c0f7e886a48b3d524c14a3e24de7e8cb924874980cd5179f3d589153a04
|
|
@@ -26,6 +26,7 @@ unreadable_file_types: list[str] = ['.gz', '.tar', '.zip']
|
|
|
26
26
|
# >-|===|> Classes <|===|-<
|
|
27
27
|
# !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
|
|
28
28
|
class File:
|
|
29
|
+
__match_args__=("path",)
|
|
29
30
|
def __init__(
|
|
30
31
|
self, path: str | Self,
|
|
31
32
|
master: Optional[Self] = None, verbose: bool = False
|
|
@@ -71,6 +72,7 @@ class File:
|
|
|
71
72
|
if other==0: return self
|
|
72
73
|
return self.__add__(other)
|
|
73
74
|
def __fspath__(self) -> str: return self.path
|
|
75
|
+
def __gt__(self, other) -> bool: return self.path > other.path
|
|
74
76
|
@property
|
|
75
77
|
def exists(self) -> bool:
|
|
76
78
|
"""_summary_
|
|
@@ -158,6 +160,7 @@ class File:
|
|
|
158
160
|
system(f"touch {self.path}")
|
|
159
161
|
|
|
160
162
|
class Folder:
|
|
163
|
+
__match_args__=("path",)
|
|
161
164
|
def __init__(
|
|
162
165
|
self, path: str|Self,
|
|
163
166
|
master: Optional[Self] = None
|
|
@@ -211,7 +214,7 @@ class Folder:
|
|
|
211
214
|
return exists(self.path)
|
|
212
215
|
def glob(self, pattern: str, recursive=True):
|
|
213
216
|
"""summary"""
|
|
214
|
-
return glob(self
|
|
217
|
+
return glob(self / pattern, recursive=recursive)
|
|
215
218
|
@property
|
|
216
219
|
def children(self) -> list:
|
|
217
220
|
"""summary"""
|
|
@@ -49,13 +49,13 @@ def system(cmd: str) -> str | list[str]:
|
|
|
49
49
|
"""
|
|
50
50
|
command = cmd.split(' ') if type(cmd)==str else cmd
|
|
51
51
|
for i in range(len(command)-1):
|
|
52
|
-
if command[i].startswith('"'):
|
|
53
|
-
start_quote = i
|
|
52
|
+
if command[i].startswith('"'):
|
|
53
|
+
start_quote = i
|
|
54
54
|
end_quote = i+1
|
|
55
55
|
while not command[end_quote].endswith('"'): end_quote+=1
|
|
56
56
|
command[i] = " ".join(command[start_quote:end_quote+1])
|
|
57
57
|
for j in range(start_quote+1, end_quote+1): del command[j]
|
|
58
|
-
output = parse_shell_output(check_output(command, stderr=DEVNULL).decode().splitlines())
|
|
58
|
+
output = parse_shell_output(check_output(command, stderr=DEVNULL, executable='/bin/bash').decode().splitlines())
|
|
59
59
|
return output
|
|
60
60
|
def anvil(cmd: str, username=_USERNAME_) -> str | list[str]:
|
|
61
61
|
"""Send a shell command to anvil and parse the output
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|