fluxscale 0.6.0__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.
- fluxscale/__init__.py +20 -0
- fluxscale/core/__init__.py +15 -0
- fluxscale/core/addons.py +128 -0
- fluxscale/core/cascade.py +952 -0
- fluxscale/core/commons.py +534 -0
- fluxscale/core/corrections.py +114 -0
- fluxscale/core/handlers.py +728 -0
- fluxscale/core/wavelet_functions.py +461 -0
- fluxscale/extra/__init__.py +7 -0
- fluxscale/extra/decomposition.py +46 -0
- fluxscale/extra/eddypro.py +289 -0
- fluxscale/extra/midi.py +244 -0
- fluxscale/extra/partitioning/__init__.py +4 -0
- fluxscale/extra/partitioning/coimbra_et_al_2025.py +298 -0
- fluxscale/extra/partitioning/zahn_et_al_2022.py +231 -0
- fluxscale/extra/sonification.py +1211 -0
- fluxscale/io/__init__.py +4 -0
- fluxscale/io/main.py +8 -0
- fluxscale/io/readers.py +50 -0
- fluxscale/main.py +421 -0
- fluxscale/version.py +6 -0
- fluxscale-0.6.0.dist-info/METADATA +307 -0
- fluxscale-0.6.0.dist-info/RECORD +27 -0
- fluxscale-0.6.0.dist-info/WHEEL +5 -0
- fluxscale-0.6.0.dist-info/entry_points.txt +7 -0
- fluxscale-0.6.0.dist-info/licenses/LICENSE +287 -0
- fluxscale-0.6.0.dist-info/top_level.txt +1 -0
fluxscale/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from . import main, version, core, extra
|
|
2
|
+
from .extra import partitioning
|
|
3
|
+
from .extra.sonification import sonify
|
|
4
|
+
from .extra.decomposition import decompose
|
|
5
|
+
from .extra.midi import export_midi
|
|
6
|
+
from .core.wavelet_functions import universal_wt as wavelet_transform
|
|
7
|
+
from .core.handlers import * # noqa: F403 # public API; see handlers.__all__
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"main",
|
|
11
|
+
"version",
|
|
12
|
+
"core",
|
|
13
|
+
"extra",
|
|
14
|
+
"partitioning",
|
|
15
|
+
"wavelet_transform",
|
|
16
|
+
"sonify",
|
|
17
|
+
"decompose",
|
|
18
|
+
"export_midi",
|
|
19
|
+
*core.handlers.__all__,
|
|
20
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from . import commons
|
|
2
|
+
from . import corrections
|
|
3
|
+
from . import wavelet_functions
|
|
4
|
+
from . import handlers
|
|
5
|
+
from . import cascade
|
|
6
|
+
from .commons import * # noqa: F403 (bounded by commons.__all__)
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"commons",
|
|
10
|
+
"corrections",
|
|
11
|
+
"wavelet_functions",
|
|
12
|
+
"handlers",
|
|
13
|
+
"cascade",
|
|
14
|
+
*commons.__all__,
|
|
15
|
+
]
|
fluxscale/core/addons.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# built-in modules
|
|
2
|
+
import re
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import warnings
|
|
6
|
+
import logging
|
|
7
|
+
from contextlib import contextmanager
|
|
8
|
+
|
|
9
|
+
# 3rd party modules
|
|
10
|
+
import pandas as pd
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"configure_warnings",
|
|
16
|
+
"patch_pandas",
|
|
17
|
+
"read_file",
|
|
18
|
+
"to_file",
|
|
19
|
+
"columnstartswith",
|
|
20
|
+
"columnsmatch",
|
|
21
|
+
"columnsconditioned",
|
|
22
|
+
"suppress_stdout",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Add-ons
|
|
27
|
+
def _warning(
|
|
28
|
+
message,
|
|
29
|
+
category = UserWarning,
|
|
30
|
+
filename = '',
|
|
31
|
+
lineno = -1,
|
|
32
|
+
file = None,
|
|
33
|
+
line = None):
|
|
34
|
+
logger.warning("%s: %s", category.__name__, message)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def configure_warnings():
|
|
38
|
+
"""Route Python warnings through this module's logger.
|
|
39
|
+
|
|
40
|
+
Not applied on import; call explicitly (e.g. from an application entry
|
|
41
|
+
point) if you want ``warnings.showwarning`` overridden.
|
|
42
|
+
"""
|
|
43
|
+
warnings.showwarning = _warning
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# --- DataFrame helpers (module-level; opt into pandas methods via patch_pandas) ---
|
|
47
|
+
|
|
48
|
+
def columnstartswith(df, prefix):
|
|
49
|
+
"""Return columns of *df* whose names start with *prefix*."""
|
|
50
|
+
return [c for c in df.columns if c.startswith(prefix)]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def columnsmatch(df, pattern):
|
|
54
|
+
"""Return columns of *df* whose names match the regex *pattern*."""
|
|
55
|
+
return [c for c in df.columns if re.findall(pattern, c)]
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def columnsconditioned(df, start, *patterns):
|
|
59
|
+
"""Return columns matching ``^{start}[^_]+$`` and every regex in *patterns*."""
|
|
60
|
+
columns = columnsmatch(df, f'^{start}[^_]+$')
|
|
61
|
+
for pattern in patterns:
|
|
62
|
+
columns = [c for c in columns if re.findall(pattern, c)]
|
|
63
|
+
return columns
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
_TO_WRITERS = {'csv': pd.DataFrame.to_csv,
|
|
67
|
+
'xlsx': pd.DataFrame.to_excel,
|
|
68
|
+
'txt': pd.DataFrame.to_csv,
|
|
69
|
+
'parquet': pd.DataFrame.to_parquet,
|
|
70
|
+
'temporary': pd.DataFrame.to_parquet,
|
|
71
|
+
'json': pd.DataFrame.to_json}
|
|
72
|
+
_READERS = {'csv': pd.read_csv,
|
|
73
|
+
'xlsx': pd.read_excel,
|
|
74
|
+
'txt': pd.read_csv,
|
|
75
|
+
'parquet': pd.read_parquet,
|
|
76
|
+
'temporary': pd.read_parquet,
|
|
77
|
+
'json': pd.read_json}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def to_file(df, file_name, *args, **kwargs):
|
|
81
|
+
"""Write *df* to *file_name*, dispatching on the file-name extension.
|
|
82
|
+
|
|
83
|
+
Returns the writer's result, or ``None`` (with a warning) if the extension
|
|
84
|
+
is unrecognized. A trailing ``.part`` suffix is ignored when matching.
|
|
85
|
+
"""
|
|
86
|
+
file_str = file_name if isinstance(file_name, str) else file_name.name
|
|
87
|
+
if file_str.endswith('.part'):
|
|
88
|
+
file_str = file_str.replace('.part', '')
|
|
89
|
+
for ext, writer in _TO_WRITERS.items():
|
|
90
|
+
if file_str.endswith(ext):
|
|
91
|
+
return writer(df, file_name, *args, **kwargs)
|
|
92
|
+
logger.warning("File extension not recognized: %s", file_str)
|
|
93
|
+
return None
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def read_file(file_name, *args, **kwargs):
|
|
97
|
+
"""Read *file_name* into a DataFrame, dispatching on the file-name extension.
|
|
98
|
+
|
|
99
|
+
Returns ``None`` if the extension is unrecognized.
|
|
100
|
+
"""
|
|
101
|
+
for ext, reader in _READERS.items():
|
|
102
|
+
if file_name.endswith(ext):
|
|
103
|
+
return reader(file_name, *args, **kwargs)
|
|
104
|
+
return None
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def patch_pandas():
|
|
108
|
+
"""Attach the helpers above onto pandas as methods/functions.
|
|
109
|
+
|
|
110
|
+
Opt-in convenience, **not** applied on import. After calling this you can
|
|
111
|
+
use ``df.to_file(...)``, ``pd.read_file(...)``, ``df.columnsmatch(...)``,
|
|
112
|
+
etc. Library code should prefer the module-level functions directly.
|
|
113
|
+
"""
|
|
114
|
+
pd.DataFrame.columnstartswith = lambda self, prefix: columnstartswith(self, prefix)
|
|
115
|
+
pd.DataFrame.columnsmatch = lambda self, pattern: columnsmatch(self, pattern)
|
|
116
|
+
pd.DataFrame.columnsconditioned = lambda self, start, *patterns: columnsconditioned(self, start, *patterns)
|
|
117
|
+
pd.DataFrame.to_file = lambda self, *args, **kwargs: to_file(self, *args, **kwargs)
|
|
118
|
+
pd.read_file = read_file
|
|
119
|
+
|
|
120
|
+
@contextmanager
|
|
121
|
+
def suppress_stdout():
|
|
122
|
+
with open(os.devnull, "w") as devnull:
|
|
123
|
+
old_stdout = sys.stdout
|
|
124
|
+
sys.stdout = devnull
|
|
125
|
+
try:
|
|
126
|
+
yield
|
|
127
|
+
finally:
|
|
128
|
+
sys.stdout = old_stdout
|