dclab 0.67.0__cp314-cp314-macosx_10_13_x86_64.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.
Potentially problematic release.
This version of dclab might be problematic. Click here for more details.
- dclab/__init__.py +41 -0
- dclab/_version.py +34 -0
- dclab/cached.py +97 -0
- dclab/cli/__init__.py +10 -0
- dclab/cli/common.py +237 -0
- dclab/cli/task_compress.py +126 -0
- dclab/cli/task_condense.py +223 -0
- dclab/cli/task_join.py +229 -0
- dclab/cli/task_repack.py +98 -0
- dclab/cli/task_split.py +154 -0
- dclab/cli/task_tdms2rtdc.py +186 -0
- dclab/cli/task_verify_dataset.py +75 -0
- dclab/definitions/__init__.py +79 -0
- dclab/definitions/feat_const.py +202 -0
- dclab/definitions/feat_logic.py +182 -0
- dclab/definitions/meta_const.py +252 -0
- dclab/definitions/meta_logic.py +111 -0
- dclab/definitions/meta_parse.py +94 -0
- dclab/downsampling.cpython-314-darwin.so +0 -0
- dclab/downsampling.pyx +230 -0
- dclab/external/__init__.py +4 -0
- dclab/external/packaging/LICENSE +3 -0
- dclab/external/packaging/LICENSE.APACHE +177 -0
- dclab/external/packaging/LICENSE.BSD +23 -0
- dclab/external/packaging/__init__.py +6 -0
- dclab/external/packaging/_structures.py +61 -0
- dclab/external/packaging/version.py +505 -0
- dclab/external/skimage/LICENSE +28 -0
- dclab/external/skimage/__init__.py +2 -0
- dclab/external/skimage/_find_contours.py +216 -0
- dclab/external/skimage/_find_contours_cy.cpython-314-darwin.so +0 -0
- dclab/external/skimage/_find_contours_cy.pyx +188 -0
- dclab/external/skimage/_pnpoly.cpython-314-darwin.so +0 -0
- dclab/external/skimage/_pnpoly.pyx +99 -0
- dclab/external/skimage/_shared/__init__.py +1 -0
- dclab/external/skimage/_shared/geometry.cpython-314-darwin.so +0 -0
- dclab/external/skimage/_shared/geometry.pxd +6 -0
- dclab/external/skimage/_shared/geometry.pyx +55 -0
- dclab/external/skimage/measure.py +7 -0
- dclab/external/skimage/pnpoly.py +53 -0
- dclab/external/statsmodels/LICENSE +35 -0
- dclab/external/statsmodels/__init__.py +6 -0
- dclab/external/statsmodels/nonparametric/__init__.py +1 -0
- dclab/external/statsmodels/nonparametric/_kernel_base.py +203 -0
- dclab/external/statsmodels/nonparametric/kernel_density.py +165 -0
- dclab/external/statsmodels/nonparametric/kernels.py +36 -0
- dclab/features/__init__.py +9 -0
- dclab/features/bright.py +81 -0
- dclab/features/bright_bc.py +93 -0
- dclab/features/bright_perc.py +63 -0
- dclab/features/contour.py +161 -0
- dclab/features/emodulus/__init__.py +339 -0
- dclab/features/emodulus/load.py +252 -0
- dclab/features/emodulus/lut_HE-2D-FEM-22.txt +16432 -0
- dclab/features/emodulus/lut_HE-3D-FEM-22.txt +1276 -0
- dclab/features/emodulus/lut_LE-2D-FEM-19.txt +13082 -0
- dclab/features/emodulus/pxcorr.py +135 -0
- dclab/features/emodulus/scale_linear.py +247 -0
- dclab/features/emodulus/viscosity.py +260 -0
- dclab/features/fl_crosstalk.py +95 -0
- dclab/features/inert_ratio.py +377 -0
- dclab/features/volume.py +242 -0
- dclab/http_utils.py +322 -0
- dclab/isoelastics/__init__.py +468 -0
- dclab/isoelastics/iso_HE-2D-FEM-22-area_um-deform.txt +2440 -0
- dclab/isoelastics/iso_HE-2D-FEM-22-volume-deform.txt +2635 -0
- dclab/isoelastics/iso_HE-3D-FEM-22-area_um-deform.txt +1930 -0
- dclab/isoelastics/iso_HE-3D-FEM-22-volume-deform.txt +2221 -0
- dclab/isoelastics/iso_LE-2D-FEM-19-area_um-deform.txt +2151 -0
- dclab/isoelastics/iso_LE-2D-FEM-19-volume-deform.txt +2250 -0
- dclab/isoelastics/iso_LE-2D-ana-18-area_um-deform.txt +1266 -0
- dclab/kde/__init__.py +1 -0
- dclab/kde/base.py +459 -0
- dclab/kde/contours.py +222 -0
- dclab/kde/methods.py +313 -0
- dclab/kde_contours.py +10 -0
- dclab/kde_methods.py +11 -0
- dclab/lme4/__init__.py +5 -0
- dclab/lme4/lme4_template.R +94 -0
- dclab/lme4/rsetup.py +204 -0
- dclab/lme4/wrapr.py +386 -0
- dclab/polygon_filter.py +398 -0
- dclab/rtdc_dataset/__init__.py +15 -0
- dclab/rtdc_dataset/check.py +902 -0
- dclab/rtdc_dataset/config.py +533 -0
- dclab/rtdc_dataset/copier.py +353 -0
- dclab/rtdc_dataset/core.py +896 -0
- dclab/rtdc_dataset/export.py +867 -0
- dclab/rtdc_dataset/feat_anc_core/__init__.py +24 -0
- dclab/rtdc_dataset/feat_anc_core/af_basic.py +75 -0
- dclab/rtdc_dataset/feat_anc_core/af_emodulus.py +160 -0
- dclab/rtdc_dataset/feat_anc_core/af_fl_max_ctc.py +133 -0
- dclab/rtdc_dataset/feat_anc_core/af_image_contour.py +113 -0
- dclab/rtdc_dataset/feat_anc_core/af_ml_class.py +102 -0
- dclab/rtdc_dataset/feat_anc_core/ancillary_feature.py +320 -0
- dclab/rtdc_dataset/feat_anc_ml/__init__.py +32 -0
- dclab/rtdc_dataset/feat_anc_plugin/__init__.py +3 -0
- dclab/rtdc_dataset/feat_anc_plugin/plugin_feature.py +329 -0
- dclab/rtdc_dataset/feat_basin.py +762 -0
- dclab/rtdc_dataset/feat_temp.py +102 -0
- dclab/rtdc_dataset/filter.py +263 -0
- dclab/rtdc_dataset/fmt_dcor/__init__.py +7 -0
- dclab/rtdc_dataset/fmt_dcor/access_token.py +52 -0
- dclab/rtdc_dataset/fmt_dcor/api.py +173 -0
- dclab/rtdc_dataset/fmt_dcor/base.py +299 -0
- dclab/rtdc_dataset/fmt_dcor/basin.py +73 -0
- dclab/rtdc_dataset/fmt_dcor/logs.py +26 -0
- dclab/rtdc_dataset/fmt_dcor/tables.py +66 -0
- dclab/rtdc_dataset/fmt_dict.py +103 -0
- dclab/rtdc_dataset/fmt_hdf5/__init__.py +6 -0
- dclab/rtdc_dataset/fmt_hdf5/base.py +192 -0
- dclab/rtdc_dataset/fmt_hdf5/basin.py +30 -0
- dclab/rtdc_dataset/fmt_hdf5/events.py +276 -0
- dclab/rtdc_dataset/fmt_hdf5/feat_defect.py +164 -0
- dclab/rtdc_dataset/fmt_hdf5/logs.py +33 -0
- dclab/rtdc_dataset/fmt_hdf5/tables.py +60 -0
- dclab/rtdc_dataset/fmt_hierarchy/__init__.py +11 -0
- dclab/rtdc_dataset/fmt_hierarchy/base.py +278 -0
- dclab/rtdc_dataset/fmt_hierarchy/events.py +146 -0
- dclab/rtdc_dataset/fmt_hierarchy/hfilter.py +140 -0
- dclab/rtdc_dataset/fmt_hierarchy/mapper.py +134 -0
- dclab/rtdc_dataset/fmt_http.py +102 -0
- dclab/rtdc_dataset/fmt_s3.py +354 -0
- dclab/rtdc_dataset/fmt_tdms/__init__.py +476 -0
- dclab/rtdc_dataset/fmt_tdms/event_contour.py +264 -0
- dclab/rtdc_dataset/fmt_tdms/event_image.py +220 -0
- dclab/rtdc_dataset/fmt_tdms/event_mask.py +62 -0
- dclab/rtdc_dataset/fmt_tdms/event_trace.py +146 -0
- dclab/rtdc_dataset/fmt_tdms/exc.py +37 -0
- dclab/rtdc_dataset/fmt_tdms/naming.py +151 -0
- dclab/rtdc_dataset/load.py +77 -0
- dclab/rtdc_dataset/meta_table.py +25 -0
- dclab/rtdc_dataset/writer.py +1019 -0
- dclab/statistics.py +226 -0
- dclab/util.py +176 -0
- dclab/warn.py +15 -0
- dclab-0.67.0.dist-info/METADATA +153 -0
- dclab-0.67.0.dist-info/RECORD +142 -0
- dclab-0.67.0.dist-info/WHEEL +6 -0
- dclab-0.67.0.dist-info/entry_points.txt +8 -0
- dclab-0.67.0.dist-info/licenses/LICENSE +283 -0
- dclab-0.67.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import numbers
|
|
2
|
+
|
|
3
|
+
from . import feat_logic, meta_const, meta_parse
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def config_key_exists(section, key):
|
|
7
|
+
"""Return `True` if the configuration key exists"""
|
|
8
|
+
valid = False
|
|
9
|
+
if section == "user":
|
|
10
|
+
if isinstance(key, str) and key.strip(): # sanity check
|
|
11
|
+
valid = True
|
|
12
|
+
elif meta_const.config_funcs.get(section, {}).get(key, False):
|
|
13
|
+
valid = True
|
|
14
|
+
elif section == "online_filter":
|
|
15
|
+
if (key.count(",")
|
|
16
|
+
and (key.endswith("soft limit")
|
|
17
|
+
or key.endswith("polygon points"))):
|
|
18
|
+
# "online_filter:area_um,deform soft limit"
|
|
19
|
+
# "online_filter:area_um,deform polygon points"
|
|
20
|
+
f1, f2 = key.split(" ", 1)[0].split(",")
|
|
21
|
+
valid = (feat_logic.scalar_feature_exists(f1)
|
|
22
|
+
and feat_logic.scalar_feature_exists(f2))
|
|
23
|
+
else:
|
|
24
|
+
feat = key.split(" ", 1)[0]
|
|
25
|
+
valid = feat_logic.scalar_feature_exists(feat)
|
|
26
|
+
return valid
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_config_value_descr(section, key):
|
|
30
|
+
"""Return the description of a config value
|
|
31
|
+
|
|
32
|
+
Returns `key` if not defined anywhere
|
|
33
|
+
"""
|
|
34
|
+
descr = key
|
|
35
|
+
if section == "user":
|
|
36
|
+
pass
|
|
37
|
+
elif meta_const.config_descr.get(section, {}).get(key, False):
|
|
38
|
+
descr = meta_const.config_descr[section][key]
|
|
39
|
+
elif section == "online_filter":
|
|
40
|
+
if (key.count(",")
|
|
41
|
+
and (key.endswith("soft limit")
|
|
42
|
+
or key.endswith("polygon points"))):
|
|
43
|
+
# "online_filter:area_um,deform soft limit"
|
|
44
|
+
# "online_filter:area_um,deform polygon points"
|
|
45
|
+
f1, f2 = key.split(" ", 1)[0].split(",")
|
|
46
|
+
# do not include units
|
|
47
|
+
l1 = feat_logic.get_feature_label(f1, with_unit=False)
|
|
48
|
+
l2 = feat_logic.get_feature_label(f2, with_unit=False)
|
|
49
|
+
if key.endswith("soft limit"):
|
|
50
|
+
descr = f"Soft limit, polygon ({l1}, {l2})"
|
|
51
|
+
elif key.endswith("polygon points"):
|
|
52
|
+
descr = f"Polygon ({l1}, {l2})"
|
|
53
|
+
else:
|
|
54
|
+
feat = key.split(" ", 1)[0]
|
|
55
|
+
if feat_logic.scalar_feature_exists(feat):
|
|
56
|
+
if key.endswith("soft limit"):
|
|
57
|
+
# "online_filter:area_um soft limit"
|
|
58
|
+
label = feat_logic.get_feature_label(feat, with_unit=False)
|
|
59
|
+
descr = f"Soft limit, {label}"
|
|
60
|
+
elif key.endswith("min"):
|
|
61
|
+
# "online_filter:area_um min"
|
|
62
|
+
descr = f"Min. {feat_logic.get_feature_label(feat)}"
|
|
63
|
+
elif key.endswith("max"):
|
|
64
|
+
# "online_filter:area_um max"
|
|
65
|
+
descr = f"Max. {feat_logic.get_feature_label(feat)}"
|
|
66
|
+
|
|
67
|
+
return descr
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def get_config_value_func(section, key):
|
|
71
|
+
"""Return configuration type converter function"""
|
|
72
|
+
func = None
|
|
73
|
+
if section == "user":
|
|
74
|
+
pass
|
|
75
|
+
elif meta_const.config_funcs.get(section, {}).get(key, False):
|
|
76
|
+
func = meta_const.config_funcs[section][key]
|
|
77
|
+
elif section == "online_filter":
|
|
78
|
+
# Note that for "min" and "max" values we do nothing (None)
|
|
79
|
+
if key.endswith("soft limit"):
|
|
80
|
+
# "online_filter:area_um,deform soft limit"
|
|
81
|
+
func = meta_parse.fbool
|
|
82
|
+
elif key.endswith("polygon points"):
|
|
83
|
+
# "online_filter:area_um,deform polygon points"
|
|
84
|
+
func = meta_parse.f2dfloatarray
|
|
85
|
+
|
|
86
|
+
if func is None:
|
|
87
|
+
return lambda x: x
|
|
88
|
+
else:
|
|
89
|
+
return func
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def get_config_value_type(section, key):
|
|
93
|
+
"""Return the expected type of a config value
|
|
94
|
+
|
|
95
|
+
Returns `None` if no type is defined
|
|
96
|
+
"""
|
|
97
|
+
typ = None
|
|
98
|
+
if section == "user":
|
|
99
|
+
pass
|
|
100
|
+
elif meta_const.config_types.get(section, {}).get(key, False):
|
|
101
|
+
typ = meta_const.config_types[section][key]
|
|
102
|
+
elif section == "online_filter":
|
|
103
|
+
if key.endswith("soft limit"):
|
|
104
|
+
# "online_filter:area_um,deform soft limit"
|
|
105
|
+
typ = meta_parse.func_types[meta_parse.fbool]
|
|
106
|
+
elif key.endswith("polygon points"):
|
|
107
|
+
typ = meta_parse.func_types[meta_parse.f2dfloatarray]
|
|
108
|
+
elif key.endswith("min") or key.endswith("max"):
|
|
109
|
+
# most-general type is a number
|
|
110
|
+
typ = numbers.Number
|
|
111
|
+
return typ
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import numbers
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def f1dfloatduple(value):
|
|
7
|
+
"""Tuple of two floats (duple)"""
|
|
8
|
+
if np.array(value).ndim != 1:
|
|
9
|
+
raise ValueError(f"Value is not 1 dimensional, got {value}!")
|
|
10
|
+
value = tuple(float(i) for i in value)
|
|
11
|
+
if len(value) != 2:
|
|
12
|
+
raise ValueError(f"Value must be of length two, "
|
|
13
|
+
f"got length {len(value)}!")
|
|
14
|
+
return value
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def f2dfloatarray(value):
|
|
18
|
+
"""numpy floating point array"""
|
|
19
|
+
return np.array(value, dtype=np.float64)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def fbool(value):
|
|
23
|
+
"""boolean"""
|
|
24
|
+
if isinstance(value, str):
|
|
25
|
+
value = value.lower()
|
|
26
|
+
if value == "false":
|
|
27
|
+
value = False
|
|
28
|
+
elif value == "true":
|
|
29
|
+
value = True
|
|
30
|
+
elif value:
|
|
31
|
+
value = bool(float(value))
|
|
32
|
+
else:
|
|
33
|
+
raise ValueError("Empty string provided for fbool!")
|
|
34
|
+
else:
|
|
35
|
+
value = bool(float(value))
|
|
36
|
+
return value
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def fboolorfloat(value):
|
|
40
|
+
"""Bool or float"""
|
|
41
|
+
if isinstance(value, (str, bool)) or value == 0:
|
|
42
|
+
return fbool(value)
|
|
43
|
+
elif isinstance(value, (int, float)):
|
|
44
|
+
return float(value)
|
|
45
|
+
else:
|
|
46
|
+
raise ValueError(f"Value could not be converted to bool "
|
|
47
|
+
f"or float, got {value}!")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def fint(value):
|
|
51
|
+
"""integer"""
|
|
52
|
+
if isinstance(value, str):
|
|
53
|
+
# strings might have been saved wrongly as booleans
|
|
54
|
+
value = value.lower()
|
|
55
|
+
if value == "false":
|
|
56
|
+
value = 0
|
|
57
|
+
elif value == "true":
|
|
58
|
+
value = 1
|
|
59
|
+
elif value:
|
|
60
|
+
value = int(float(value))
|
|
61
|
+
else:
|
|
62
|
+
raise ValueError("Empty string provided for fint!")
|
|
63
|
+
else:
|
|
64
|
+
value = int(float(value))
|
|
65
|
+
return value
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def fintlist(alist):
|
|
69
|
+
"""A list of integers"""
|
|
70
|
+
outlist = []
|
|
71
|
+
if not isinstance(alist, (list, tuple)):
|
|
72
|
+
# we have a string (comma-separated integers)
|
|
73
|
+
alist = alist.strip().strip("[] ").split(",")
|
|
74
|
+
for it in alist:
|
|
75
|
+
if it:
|
|
76
|
+
outlist.append(fint(it))
|
|
77
|
+
return outlist
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def lcstr(astr):
|
|
81
|
+
"""lower-case string"""
|
|
82
|
+
return astr.lower()
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
#: maps functions to their expected output types
|
|
86
|
+
func_types = {
|
|
87
|
+
f1dfloatduple: (tuple, np.ndarray),
|
|
88
|
+
f2dfloatarray: np.ndarray,
|
|
89
|
+
fbool: (bool, np.bool_),
|
|
90
|
+
fboolorfloat: (bool, np.bool_, float),
|
|
91
|
+
fint: numbers.Integral,
|
|
92
|
+
fintlist: list,
|
|
93
|
+
float: numbers.Number,
|
|
94
|
+
lcstr: str}
|
|
Binary file
|
dclab/downsampling.pyx
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""Content-based downsampling of ndarrays"""
|
|
2
|
+
import numpy as np
|
|
3
|
+
cimport numpy as cnp
|
|
4
|
+
|
|
5
|
+
from .cached import Cache
|
|
6
|
+
|
|
7
|
+
# We are using the numpy array API
|
|
8
|
+
cnp.import_array()
|
|
9
|
+
ctypedef cnp.uint8_t uint8
|
|
10
|
+
ctypedef cnp.uint32_t uint32
|
|
11
|
+
ctypedef cnp.int64_t int64
|
|
12
|
+
|
|
13
|
+
def downsample_rand(a, samples, remove_invalid=False, ret_idx=False):
|
|
14
|
+
"""Downsampling by randomly removing points
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
a: 1d ndarray
|
|
19
|
+
The input array to downsample
|
|
20
|
+
samples: int
|
|
21
|
+
The desired number of samples
|
|
22
|
+
remove_invalid: bool
|
|
23
|
+
Remove nan and inf values before downsampling
|
|
24
|
+
ret_idx: bool
|
|
25
|
+
Also return a boolean array that corresponds to the
|
|
26
|
+
downsampled indices in `a`.
|
|
27
|
+
|
|
28
|
+
Returns
|
|
29
|
+
-------
|
|
30
|
+
dsa: 1d ndarray of size `samples`
|
|
31
|
+
The pseudo-randomly downsampled array `a`
|
|
32
|
+
idx: 1d boolean array with same shape as `a`
|
|
33
|
+
Only returned if `ret_idx` is True.
|
|
34
|
+
A boolean array such that `a[idx] == dsa`
|
|
35
|
+
"""
|
|
36
|
+
# fixed random state for this method
|
|
37
|
+
rs = np.random.RandomState(seed=47).get_state()
|
|
38
|
+
np.random.set_state(rs)
|
|
39
|
+
|
|
40
|
+
cdef uint32 samples_int = np.uint32(samples)
|
|
41
|
+
|
|
42
|
+
if remove_invalid:
|
|
43
|
+
# slice out nans and infs
|
|
44
|
+
bad = np.isnan(a) | np.isinf(a)
|
|
45
|
+
pool = a[~bad]
|
|
46
|
+
else:
|
|
47
|
+
pool = a
|
|
48
|
+
|
|
49
|
+
if samples_int and (samples_int < pool.shape[0]):
|
|
50
|
+
keep = np.zeros_like(pool, dtype=bool)
|
|
51
|
+
keep_ids = np.random.choice(np.arange(pool.size),
|
|
52
|
+
size=samples_int,
|
|
53
|
+
replace=False)
|
|
54
|
+
keep[keep_ids] = True
|
|
55
|
+
dsa = pool[keep]
|
|
56
|
+
else:
|
|
57
|
+
keep = np.ones_like(pool, dtype=bool)
|
|
58
|
+
dsa = pool
|
|
59
|
+
|
|
60
|
+
if remove_invalid:
|
|
61
|
+
# translate the kept values back to the original array
|
|
62
|
+
idx = np.zeros(a.size, dtype=bool)
|
|
63
|
+
idx[~bad] = keep
|
|
64
|
+
else:
|
|
65
|
+
idx = keep
|
|
66
|
+
|
|
67
|
+
if ret_idx:
|
|
68
|
+
return dsa, idx
|
|
69
|
+
else:
|
|
70
|
+
return dsa
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@Cache
|
|
74
|
+
def downsample_grid(a, b, samples, remove_invalid=False, ret_idx=False):
|
|
75
|
+
"""Content-based downsampling for faster visualization
|
|
76
|
+
|
|
77
|
+
The arrays `a` and `b` make up a 2D scatter plot with high
|
|
78
|
+
and low density values. This method takes out points at
|
|
79
|
+
indices with high density.
|
|
80
|
+
|
|
81
|
+
Parameters
|
|
82
|
+
----------
|
|
83
|
+
a, b: 1d ndarrays
|
|
84
|
+
The input arrays to downsample
|
|
85
|
+
samples: int
|
|
86
|
+
The desired number of samples
|
|
87
|
+
remove_invalid: bool
|
|
88
|
+
Remove nan and inf values before downsampling; if set to
|
|
89
|
+
`True`, the actual number of samples returned might be
|
|
90
|
+
smaller than `samples` due to infinite or nan values.
|
|
91
|
+
ret_idx: bool
|
|
92
|
+
Also return a boolean array that corresponds to the
|
|
93
|
+
downsampled indices in `a` and `b`.
|
|
94
|
+
|
|
95
|
+
Returns
|
|
96
|
+
-------
|
|
97
|
+
dsa, dsb: 1d ndarrays of shape (samples,)
|
|
98
|
+
The arrays `a` and `b` downsampled by evenly selecting
|
|
99
|
+
points and pseudo-randomly adding or removing points
|
|
100
|
+
to match `samples`.
|
|
101
|
+
idx: 1d boolean array with same shape as `a`
|
|
102
|
+
Only returned if `ret_idx` is True.
|
|
103
|
+
A boolean array such that `a[idx] == dsa`
|
|
104
|
+
"""
|
|
105
|
+
cdef uint32 samples_int = np.uint32(samples)
|
|
106
|
+
|
|
107
|
+
# fixed random state for this method
|
|
108
|
+
rs = np.random.RandomState(seed=47).get_state()
|
|
109
|
+
|
|
110
|
+
keep = np.ones_like(a, dtype=bool)
|
|
111
|
+
bad = np.isnan(a) | np.isinf(a) | np.isnan(b) | np.isinf(b)
|
|
112
|
+
good = ~bad
|
|
113
|
+
|
|
114
|
+
# We are generally not interested in bad data.
|
|
115
|
+
keep[bad] = False
|
|
116
|
+
bd = b[good]
|
|
117
|
+
ad = a[good]
|
|
118
|
+
|
|
119
|
+
cdef int64 diff
|
|
120
|
+
|
|
121
|
+
if samples_int and samples_int < ad.size:
|
|
122
|
+
# 1. Produce evenly distributed samples
|
|
123
|
+
# Choosing grid-size:
|
|
124
|
+
# - large numbers tend to show actual structures of the sample,
|
|
125
|
+
# which is not desired for plotting
|
|
126
|
+
# - small numbers tend will not result in too few samples and,
|
|
127
|
+
# in order to reach the desired samples, the data must be
|
|
128
|
+
# upsampled again.
|
|
129
|
+
# 300 is about the size of the plot in marker sizes and yields
|
|
130
|
+
# good results.
|
|
131
|
+
grid_size = 300
|
|
132
|
+
# The events on the grid to process
|
|
133
|
+
toproc = np.ones((grid_size, grid_size), dtype=np.uint8)
|
|
134
|
+
|
|
135
|
+
x_discrete = np.array(norm(ad) * (grid_size - 1), dtype=np.uint32)
|
|
136
|
+
y_discrete = np.array(norm(bd) * (grid_size - 1), dtype=np.uint32)
|
|
137
|
+
|
|
138
|
+
# The events to keep
|
|
139
|
+
keepd = np.zeros_like(ad, dtype=np.uint8)
|
|
140
|
+
populate_grid(x_discrete=x_discrete,
|
|
141
|
+
y_discrete=y_discrete,
|
|
142
|
+
toproc=toproc,
|
|
143
|
+
keepd=keepd
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
keepdb = np.array(keepd, dtype=bool)
|
|
147
|
+
|
|
148
|
+
# 2. Make sure that we reach `samples` by adding or
|
|
149
|
+
# removing events.
|
|
150
|
+
diff = np.sum(keepdb) - samples_int
|
|
151
|
+
if diff > 0:
|
|
152
|
+
# Too many samples
|
|
153
|
+
rem_indices = np.where(keepdb)[0]
|
|
154
|
+
np.random.set_state(rs)
|
|
155
|
+
rem = np.random.choice(rem_indices,
|
|
156
|
+
size=diff,
|
|
157
|
+
replace=False)
|
|
158
|
+
keepdb[rem] = False
|
|
159
|
+
elif diff < 0:
|
|
160
|
+
# Not enough samples
|
|
161
|
+
add_indices = np.where(~keepdb)[0]
|
|
162
|
+
np.random.set_state(rs)
|
|
163
|
+
add = np.random.choice(add_indices,
|
|
164
|
+
size=abs(diff),
|
|
165
|
+
replace=False)
|
|
166
|
+
keepdb[add] = True
|
|
167
|
+
|
|
168
|
+
# paulmueller 2024-01-03
|
|
169
|
+
# assert np.sum(keepdb) <= samples_int, "sanity check"
|
|
170
|
+
|
|
171
|
+
keep[good] = keepdb
|
|
172
|
+
|
|
173
|
+
# paulmueller 2024-01-03
|
|
174
|
+
# assert np.sum(keep) <= samples_int, "sanity check"
|
|
175
|
+
|
|
176
|
+
if not remove_invalid:
|
|
177
|
+
diff_bad = (samples_int or keep.size) - np.sum(keep)
|
|
178
|
+
if diff_bad > 0:
|
|
179
|
+
# Add a few of the invalid values so that in the end
|
|
180
|
+
# we have the desired array size.
|
|
181
|
+
add_indices_bad = np.where(bad)[0]
|
|
182
|
+
np.random.set_state(rs)
|
|
183
|
+
add_bad = np.random.choice(add_indices_bad,
|
|
184
|
+
size=diff_bad,
|
|
185
|
+
replace=False)
|
|
186
|
+
keep[add_bad] = True
|
|
187
|
+
|
|
188
|
+
# paulmueller 2024-01-03
|
|
189
|
+
# if samples_int and not remove_invalid:
|
|
190
|
+
# assert np.sum(keep) == samples_int, "sanity check"
|
|
191
|
+
|
|
192
|
+
asd = a[keep]
|
|
193
|
+
bsd = b[keep]
|
|
194
|
+
|
|
195
|
+
if ret_idx:
|
|
196
|
+
return asd, bsd, keep
|
|
197
|
+
else:
|
|
198
|
+
return asd, bsd
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def populate_grid(x_discrete, y_discrete, keepd, toproc):
|
|
202
|
+
# Py_ssize_t is the proper C type for Python array indices.
|
|
203
|
+
cdef int iter_size = x_discrete.size
|
|
204
|
+
cdef Py_ssize_t ii
|
|
205
|
+
cdef uint32[:] x_view = x_discrete
|
|
206
|
+
cdef uint32[:] y_view = y_discrete
|
|
207
|
+
# Numpy uses uint8 internally to represent boolean arrays
|
|
208
|
+
cdef uint8[:] keepd_view = keepd
|
|
209
|
+
cdef uint8[:, :] toproc_view = toproc
|
|
210
|
+
|
|
211
|
+
for ii in range(iter_size):
|
|
212
|
+
# filter for overlapping events
|
|
213
|
+
xi = x_view[ii]
|
|
214
|
+
yi = y_view[ii]
|
|
215
|
+
if toproc_view[xi, yi]:
|
|
216
|
+
toproc_view[xi, yi] = 0
|
|
217
|
+
# include event
|
|
218
|
+
keepd_view[ii] = 1
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def valid(a, b):
|
|
222
|
+
"""Check whether `a` and `b` are not inf or nan"""
|
|
223
|
+
return ~(np.isnan(a) | np.isinf(a) | np.isnan(b) | np.isinf(b))
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def norm(a):
|
|
227
|
+
"""Normalize `a` with its min/max values"""
|
|
228
|
+
rmin = a.min()
|
|
229
|
+
rptp = a.max() - rmin
|
|
230
|
+
return (a - rmin) / rptp
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Copyright (c) Donald Stufft and individual contributors.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
|
12
|
+
documentation and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
15
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
16
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
17
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
18
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
20
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
21
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
22
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
23
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|