miniflux-ec 0.1.0__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.
Files changed (47) hide show
  1. miniflux_ec-0.1.0/LICENCE +287 -0
  2. miniflux_ec-0.1.0/PKG-INFO +361 -0
  3. miniflux_ec-0.1.0/README.md +341 -0
  4. miniflux_ec-0.1.0/miniflux/__init__.py +11 -0
  5. miniflux_ec-0.1.0/miniflux/__main__.py +8 -0
  6. miniflux_ec-0.1.0/miniflux/cell.py +133 -0
  7. miniflux_ec-0.1.0/miniflux/cli.py +131 -0
  8. miniflux_ec-0.1.0/miniflux/config.py +629 -0
  9. miniflux_ec-0.1.0/miniflux/constants.py +36 -0
  10. miniflux_ec-0.1.0/miniflux/despike.py +97 -0
  11. miniflux_ec-0.1.0/miniflux/detrend.py +90 -0
  12. miniflux_ec-0.1.0/miniflux/errors.py +23 -0
  13. miniflux_ec-0.1.0/miniflux/flux.py +359 -0
  14. miniflux_ec-0.1.0/miniflux/kernels.py +504 -0
  15. miniflux_ec-0.1.0/miniflux/lag.py +182 -0
  16. miniflux_ec-0.1.0/miniflux/pipeline.py +160 -0
  17. miniflux_ec-0.1.0/miniflux/qc.py +249 -0
  18. miniflux_ec-0.1.0/miniflux/read.py +559 -0
  19. miniflux_ec-0.1.0/miniflux/rotate.py +162 -0
  20. miniflux_ec-0.1.0/miniflux/spectral.py +136 -0
  21. miniflux_ec-0.1.0/miniflux/wpl.py +187 -0
  22. miniflux_ec-0.1.0/miniflux/write.py +219 -0
  23. miniflux_ec-0.1.0/miniflux/xarray_adapter.py +379 -0
  24. miniflux_ec-0.1.0/miniflux_ec.egg-info/PKG-INFO +361 -0
  25. miniflux_ec-0.1.0/miniflux_ec.egg-info/SOURCES.txt +45 -0
  26. miniflux_ec-0.1.0/miniflux_ec.egg-info/dependency_links.txt +1 -0
  27. miniflux_ec-0.1.0/miniflux_ec.egg-info/entry_points.txt +2 -0
  28. miniflux_ec-0.1.0/miniflux_ec.egg-info/requires.txt +6 -0
  29. miniflux_ec-0.1.0/miniflux_ec.egg-info/top_level.txt +1 -0
  30. miniflux_ec-0.1.0/pyproject.toml +40 -0
  31. miniflux_ec-0.1.0/setup.cfg +4 -0
  32. miniflux_ec-0.1.0/tests/test_cell.py +386 -0
  33. miniflux_ec-0.1.0/tests/test_config.py +757 -0
  34. miniflux_ec-0.1.0/tests/test_despike.py +280 -0
  35. miniflux_ec-0.1.0/tests/test_detrend.py +230 -0
  36. miniflux_ec-0.1.0/tests/test_flux.py +581 -0
  37. miniflux_ec-0.1.0/tests/test_integration.py +429 -0
  38. miniflux_ec-0.1.0/tests/test_kernels.py +447 -0
  39. miniflux_ec-0.1.0/tests/test_kernels_parity.py +317 -0
  40. miniflux_ec-0.1.0/tests/test_lag.py +376 -0
  41. miniflux_ec-0.1.0/tests/test_pipeline.py +453 -0
  42. miniflux_ec-0.1.0/tests/test_qc.py +471 -0
  43. miniflux_ec-0.1.0/tests/test_read.py +680 -0
  44. miniflux_ec-0.1.0/tests/test_rotate.py +435 -0
  45. miniflux_ec-0.1.0/tests/test_spectral.py +181 -0
  46. miniflux_ec-0.1.0/tests/test_wpl.py +398 -0
  47. miniflux_ec-0.1.0/tests/test_xr.py +552 -0
@@ -0,0 +1,287 @@
1
+ EUROPEAN UNION PUBLIC LICENCE v. 1.2
2
+ EUPL © the European Union 2007, 2016
3
+
4
+ This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined
5
+ below) which is provided under the terms of this Licence. Any use of the Work,
6
+ other than as authorised under this Licence is prohibited (to the extent such
7
+ use is covered by a right of the copyright holder of the Work).
8
+
9
+ The Work is provided under the terms of this Licence when the Licensor (as
10
+ defined below) has placed the following notice immediately following the
11
+ copyright notice for the Work:
12
+
13
+ Licensed under the EUPL
14
+
15
+ or has expressed by any other means his willingness to license under the EUPL.
16
+
17
+ 1. Definitions
18
+
19
+ In this Licence, the following terms have the following meaning:
20
+
21
+ - ‘The Licence’: this Licence.
22
+
23
+ - ‘The Original Work’: the work or software distributed or communicated by the
24
+ Licensor under this Licence, available as Source Code and also as Executable
25
+ Code as the case may be.
26
+
27
+ - ‘Derivative Works’: the works or software that could be created by the
28
+ Licensee, based upon the Original Work or modifications thereof. This Licence
29
+ does not define the extent of modification or dependence on the Original Work
30
+ required in order to classify a work as a Derivative Work; this extent is
31
+ determined by copyright law applicable in the country mentioned in Article 15.
32
+
33
+ - ‘The Work’: the Original Work or its Derivative Works.
34
+
35
+ - ‘The Source Code’: the human-readable form of the Work which is the most
36
+ convenient for people to study and modify.
37
+
38
+ - ‘The Executable Code’: any code which has generally been compiled and which is
39
+ meant to be interpreted by a computer as a program.
40
+
41
+ - ‘The Licensor’: the natural or legal person that distributes or communicates
42
+ the Work under the Licence.
43
+
44
+ - ‘Contributor(s)’: any natural or legal person who modifies the Work under the
45
+ Licence, or otherwise contributes to the creation of a Derivative Work.
46
+
47
+ - ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
48
+ the Work under the terms of the Licence.
49
+
50
+ - ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
51
+ renting, distributing, communicating, transmitting, or otherwise making
52
+ available, online or offline, copies of the Work or providing access to its
53
+ essential functionalities at the disposal of any other natural or legal
54
+ person.
55
+
56
+ 2. Scope of the rights granted by the Licence
57
+
58
+ The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
59
+ sublicensable licence to do the following, for the duration of copyright vested
60
+ in the Original Work:
61
+
62
+ - use the Work in any circumstance and for all usage,
63
+ - reproduce the Work,
64
+ - modify the Work, and make Derivative Works based upon the Work,
65
+ - communicate to the public, including the right to make available or display
66
+ the Work or copies thereof to the public and perform publicly, as the case may
67
+ be, the Work,
68
+ - distribute the Work or copies thereof,
69
+ - lend and rent the Work or copies thereof,
70
+ - sublicense rights in the Work or copies thereof.
71
+
72
+ Those rights can be exercised on any media, supports and formats, whether now
73
+ known or later invented, as far as the applicable law permits so.
74
+
75
+ In the countries where moral rights apply, the Licensor waives his right to
76
+ exercise his moral right to the extent allowed by law in order to make effective
77
+ the licence of the economic rights here above listed.
78
+
79
+ The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to
80
+ any patents held by the Licensor, to the extent necessary to make use of the
81
+ rights granted on the Work under this Licence.
82
+
83
+ 3. Communication of the Source Code
84
+
85
+ The Licensor may provide the Work either in its Source Code form, or as
86
+ Executable Code. If the Work is provided as Executable Code, the Licensor
87
+ provides in addition a machine-readable copy of the Source Code of the Work
88
+ along with each copy of the Work that the Licensor distributes or indicates, in
89
+ a notice following the copyright notice attached to the Work, a repository where
90
+ the Source Code is easily and freely accessible for as long as the Licensor
91
+ continues to distribute or communicate the Work.
92
+
93
+ 4. Limitations on copyright
94
+
95
+ Nothing in this Licence is intended to deprive the Licensee of the benefits from
96
+ any exception or limitation to the exclusive rights of the rights owners in the
97
+ Work, of the exhaustion of those rights or of other applicable limitations
98
+ thereto.
99
+
100
+ 5. Obligations of the Licensee
101
+
102
+ The grant of the rights mentioned above is subject to some restrictions and
103
+ obligations imposed on the Licensee. Those obligations are the following:
104
+
105
+ Attribution right: The Licensee shall keep intact all copyright, patent or
106
+ trademarks notices and all notices that refer to the Licence and to the
107
+ disclaimer of warranties. The Licensee must include a copy of such notices and a
108
+ copy of the Licence with every copy of the Work he/she distributes or
109
+ communicates. The Licensee must cause any Derivative Work to carry prominent
110
+ notices stating that the Work has been modified and the date of modification.
111
+
112
+ Copyleft clause: If the Licensee distributes or communicates copies of the
113
+ Original Works or Derivative Works, this Distribution or Communication will be
114
+ done under the terms of this Licence or of a later version of this Licence
115
+ unless the Original Work is expressly distributed only under this version of the
116
+ Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee
117
+ (becoming Licensor) cannot offer or impose any additional terms or conditions on
118
+ the Work or Derivative Work that alter or restrict the terms of the Licence.
119
+
120
+ Compatibility clause: If the Licensee Distributes or Communicates Derivative
121
+ Works or copies thereof based upon both the Work and another work licensed under
122
+ a Compatible Licence, this Distribution or Communication can be done under the
123
+ terms of this Compatible Licence. For the sake of this clause, ‘Compatible
124
+ Licence’ refers to the licences listed in the appendix attached to this Licence.
125
+ Should the Licensee's obligations under the Compatible Licence conflict with
126
+ his/her obligations under this Licence, the obligations of the Compatible
127
+ Licence shall prevail.
128
+
129
+ Provision of Source Code: When distributing or communicating copies of the Work,
130
+ the Licensee will provide a machine-readable copy of the Source Code or indicate
131
+ a repository where this Source will be easily and freely available for as long
132
+ as the Licensee continues to distribute or communicate the Work.
133
+
134
+ Legal Protection: This Licence does not grant permission to use the trade names,
135
+ trademarks, service marks, or names of the Licensor, except as required for
136
+ reasonable and customary use in describing the origin of the Work and
137
+ reproducing the content of the copyright notice.
138
+
139
+ 6. Chain of Authorship
140
+
141
+ The original Licensor warrants that the copyright in the Original Work granted
142
+ hereunder is owned by him/her or licensed to him/her and that he/she has the
143
+ power and authority to grant the Licence.
144
+
145
+ Each Contributor warrants that the copyright in the modifications he/she brings
146
+ to the Work are owned by him/her or licensed to him/her and that he/she has the
147
+ power and authority to grant the Licence.
148
+
149
+ Each time You accept the Licence, the original Licensor and subsequent
150
+ Contributors grant You a licence to their contributions to the Work, under the
151
+ terms of this Licence.
152
+
153
+ 7. Disclaimer of Warranty
154
+
155
+ The Work is a work in progress, which is continuously improved by numerous
156
+ Contributors. It is not a finished work and may therefore contain defects or
157
+ ‘bugs’ inherent to this type of development.
158
+
159
+ For the above reason, the Work is provided under the Licence on an ‘as is’ basis
160
+ and without warranties of any kind concerning the Work, including without
161
+ limitation merchantability, fitness for a particular purpose, absence of defects
162
+ or errors, accuracy, non-infringement of intellectual property rights other than
163
+ copyright as stated in Article 6 of this Licence.
164
+
165
+ This disclaimer of warranty is an essential part of the Licence and a condition
166
+ for the grant of any rights to the Work.
167
+
168
+ 8. Disclaimer of Liability
169
+
170
+ Except in the cases of wilful misconduct or damages directly caused to natural
171
+ persons, the Licensor will in no event be liable for any direct or indirect,
172
+ material or moral, damages of any kind, arising out of the Licence or of the use
173
+ of the Work, including without limitation, damages for loss of goodwill, work
174
+ stoppage, computer failure or malfunction, loss of data or any commercial
175
+ damage, even if the Licensor has been advised of the possibility of such damage.
176
+ However, the Licensor will be liable under statutory product liability laws as
177
+ far such laws apply to the Work.
178
+
179
+ 9. Additional agreements
180
+
181
+ While distributing the Work, You may choose to conclude an additional agreement,
182
+ defining obligations or services consistent with this Licence. However, if
183
+ accepting obligations, You may act only on your own behalf and on your sole
184
+ responsibility, not on behalf of the original Licensor or any other Contributor,
185
+ and only if You agree to indemnify, defend, and hold each Contributor harmless
186
+ for any liability incurred by, or claims asserted against such Contributor by
187
+ the fact You have accepted any warranty or additional liability.
188
+
189
+ 10. Acceptance of the Licence
190
+
191
+ The provisions of this Licence can be accepted by clicking on an icon ‘I agree’
192
+ placed under the bottom of a window displaying the text of this Licence or by
193
+ affirming consent in any other similar way, in accordance with the rules of
194
+ applicable law. Clicking on that icon indicates your clear and irrevocable
195
+ acceptance of this Licence and all of its terms and conditions.
196
+
197
+ Similarly, you irrevocably accept this Licence and all of its terms and
198
+ conditions by exercising any rights granted to You by Article 2 of this Licence,
199
+ such as the use of the Work, the creation by You of a Derivative Work or the
200
+ Distribution or Communication by You of the Work or copies thereof.
201
+
202
+ 11. Information to the public
203
+
204
+ In case of any Distribution or Communication of the Work by means of electronic
205
+ communication by You (for example, by offering to download the Work from a
206
+ remote location) the distribution channel or media (for example, a website) must
207
+ at least provide to the public the information requested by the applicable law
208
+ regarding the Licensor, the Licence and the way it may be accessible, concluded,
209
+ stored and reproduced by the Licensee.
210
+
211
+ 12. Termination of the Licence
212
+
213
+ The Licence and the rights granted hereunder will terminate automatically upon
214
+ any breach by the Licensee of the terms of the Licence.
215
+
216
+ Such a termination will not terminate the licences of any person who has
217
+ received the Work from the Licensee under the Licence, provided such persons
218
+ remain in full compliance with the Licence.
219
+
220
+ 13. Miscellaneous
221
+
222
+ Without prejudice of Article 9 above, the Licence represents the complete
223
+ agreement between the Parties as to the Work.
224
+
225
+ If any provision of the Licence is invalid or unenforceable under applicable
226
+ law, this will not affect the validity or enforceability of the Licence as a
227
+ whole. Such provision will be construed or reformed so as necessary to make it
228
+ valid and enforceable.
229
+
230
+ The European Commission may publish other linguistic versions or new versions of
231
+ this Licence or updated versions of the Appendix, so far this is required and
232
+ reasonable, without reducing the scope of the rights granted by the Licence. New
233
+ versions of the Licence will be published with a unique version number.
234
+
235
+ All linguistic versions of this Licence, approved by the European Commission,
236
+ have identical value. Parties can take advantage of the linguistic version of
237
+ their choice.
238
+
239
+ 14. Jurisdiction
240
+
241
+ Without prejudice to specific agreement between parties,
242
+
243
+ - any litigation resulting from the interpretation of this License, arising
244
+ between the European Union institutions, bodies, offices or agencies, as a
245
+ Licensor, and any Licensee, will be subject to the jurisdiction of the Court
246
+ of Justice of the European Union, as laid down in article 272 of the Treaty on
247
+ the Functioning of the European Union,
248
+
249
+ - any litigation arising between other parties and resulting from the
250
+ interpretation of this License, will be subject to the exclusive jurisdiction
251
+ of the competent court where the Licensor resides or conducts its primary
252
+ business.
253
+
254
+ 15. Applicable Law
255
+
256
+ Without prejudice to specific agreement between parties,
257
+
258
+ - this Licence shall be governed by the law of the European Union Member State
259
+ where the Licensor has his seat, resides or has his registered office,
260
+
261
+ - this licence shall be governed by Belgian law if the Licensor has no seat,
262
+ residence or registered office inside a European Union Member State.
263
+
264
+ Appendix
265
+
266
+ ‘Compatible Licences’ according to Article 5 EUPL are:
267
+
268
+ - GNU General Public License (GPL) v. 2, v. 3
269
+ - GNU Affero General Public License (AGPL) v. 3
270
+ - Open Software License (OSL) v. 2.1, v. 3.0
271
+ - Eclipse Public License (EPL) v. 1.0
272
+ - CeCILL v. 2.0, v. 2.1
273
+ - Mozilla Public Licence (MPL) v. 2
274
+ - GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
275
+ - Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
276
+ works other than software
277
+ - European Union Public Licence (EUPL) v. 1.1, v. 1.2
278
+ - Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
279
+ Reciprocity (LiLiQ-R+).
280
+
281
+ The European Commission may update this Appendix to later versions of the above
282
+ licences without producing a new version of the EUPL, as long as they provide
283
+ the rights granted in Article 2 of this Licence and protect the covered Source
284
+ Code from exclusive appropriation.
285
+
286
+ All other changes or additions to this Appendix require the production of a new
287
+ EUPL version.
@@ -0,0 +1,361 @@
1
+ Metadata-Version: 2.4
2
+ Name: miniflux-ec
3
+ Version: 0.1.0
4
+ Summary: A minimal eddy-covariance flux program: raw high-frequency data in, one flux row per averaging period out, on the standard library alone.
5
+ Author-email: Pedro Henrique Coimbra <pedro-henrique.herig-coimbra@inrae.fr>
6
+ License-Expression: EUPL-1.2
7
+ Keywords: eddy covariance,flux,micrometeorology,minimal
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENCE
15
+ Provides-Extra: fast
16
+ Requires-Dist: numpy>=1.17; extra == "fast"
17
+ Provides-Extra: xarray
18
+ Requires-Dist: xarray>=2022.11; extra == "xarray"
19
+ Dynamic: license-file
20
+
21
+ # miniflux
22
+
23
+ miniflux is a minimal eddy-covariance flux program: raw high-frequency data in, one flux row
24
+ per averaging period out. It has no dependencies — the standard library computes every
25
+ number, and numpy, when it happens to be installed, is a speed switch inside a single module.
26
+ The whole program is 3,272 lines of Python across seventeen files, about 1,800 of them
27
+ statements and the rest comment and docstring.
28
+
29
+ ```
30
+ 20 Hz raw file(s) -> despike, rotate, lag, thermodynamics, detrend, moments, assemble,
31
+ WPL, QC -> one CSV row per 30 minutes (54 columns + units sidecar)
32
+ ```
33
+
34
+ Two documents are the law, and the code is checked against them line by line:
35
+
36
+ * [`docs/ALGORITHMS.md`](docs/ALGORITHMS.md) — the mathematics: every formula, constant,
37
+ default, edge case and citation (1,656 lines).
38
+ * [`docs/CONTRACT.md`](docs/CONTRACT.md) — the plumbing: every module, signature, meta key,
39
+ config key and refusal (1,523 lines).
40
+
41
+ Python >= 3.8. EUPL-1.2. 582 tests, `unittest` only.
42
+
43
+ ## Why it exists
44
+
45
+ **To be forked.** Every step is a plain function `(period, cfg) -> period`, the pipeline is a
46
+ list of nine of them, and there is no registry, no plugin system, no provenance layer and no
47
+ units library to learn first. If you want to write your own flux software, or teach how one
48
+ works, this is a base whose whole behaviour fits in one person's head — and whose physics is
49
+ written down separately from its code, so you can disagree with a decision by reading it.
50
+
51
+ **To run where nothing can be installed.** A logger PC, an air-gapped field laptop, an old
52
+ cluster node with no wheels for its architecture: a copy of the `miniflux/` directory and a
53
+ Python interpreter is the entire install. That is enough for a preliminary flux while the
54
+ real processing happens elsewhere — a first look at yesterday's data, a sanity check on an
55
+ instrument that was serviced this morning.
56
+
57
+ **Because it can exist.** This is roughly the smallest thing that is still a real flux
58
+ program: it despikes, rotates, finds its own lags, does the thermodynamics per sample, and
59
+ applies WPL and Foken's quality tests. The Alpine of flux software. Nothing is stubbed to
60
+ make that sentence true — what is missing is listed below, with what it costs.
61
+
62
+ ## What it computes
63
+
64
+ `pipeline.STEPS`, in order. The order is normative; each line in that file says what breaks
65
+ if it moves.
66
+
67
+ | # | step | what it does | source |
68
+ |---|---|---|---|
69
+ | 1 | `despike` | median/MAD test per variable per period, spikes become NaN and are never refilled | Mauder et al. (2013) |
70
+ | 2 | `rotate` | double rotation into the mean streamline; wind speed and direction from the unrotated means | Wilczak et al. (2001) |
71
+ | 3 | `lag` | slides each scalar against `w` and keeps the shift that maximises `abs(cov)`, with a nominal fallback when the peak lands on a window edge | EddyPro `CovMax`; Aubinet et al. (2012) |
72
+ | 4 | `thermodynamics` | per-sample moist-air state (e, es, RH, densities, cp, lambda), averaged over the period; air temperature measured where finite, else sonic-derived | ALGORITHMS §8; Schotanus et al. (1983) |
73
+ | 5 | `detrend` | block average (stores the mean, leaves the samples alone) or a least-squares line removed for real | Moncrieff et al. (2004); Rannik & Vesala (1999) |
74
+ | 6 | `moments` | variances and covariances on the joint finite mask, two passes, ddof = 1; `ustar` from the full stress vector | ALGORITHMS §7 |
75
+ | 7 | `assemble` | level-0 fluxes, the Schotanus heat flux in its exact division form, Obukhov length, z/L | Schotanus et al. (1983); van Dijk et al. (2004) Eq. 3.53 |
76
+ | 8 | `wpl` | density correction for a gas reported as a molar density; a dry mixing ratio is already conserved and gets none | Webb, Pearman & Leuning (1980), Eq. 24 and 25 |
77
+ | 9 | `qc` | steady-state test on one covariance pair, plus three integral turbulence deviations | Foken & Wichura (1996); Thomas & Foken (2002) |
78
+
79
+ Reading, timestamp parsing and the period cut happen before step 1, in `read.py`. Nothing is
80
+ carried between periods: no running means, no fitted planes, no tables.
81
+
82
+ ## Quickstart
83
+
84
+ From a checkout, with nothing installed:
85
+
86
+ ```sh
87
+ cd miniflux
88
+ python -m unittest discover -s tests -t . # 582 tests, about 6 s
89
+ python examples/make_sample.py # writes ./sample_20hz.dat, 36000 samples
90
+ python -m miniflux check examples/miniflux.ini # validate and echo the config, read no data
91
+ python -m miniflux run examples/miniflux.ini # -> ./miniflux.csv + ./miniflux_units.csv
92
+ ```
93
+
94
+ `make_sample.py` prints what it planted in the synthetic file, and the run has to reproduce
95
+ it. On the shipped seed:
96
+
97
+ ```
98
+ PLANTED -> COMPUTED
99
+ N_IN 36000 36000
100
+ N_SPIKE_U 3 3 (also V 2, CO2 4, and zero elsewhere)
101
+ CO2_LAG +0.75 s 0.75 (15 samples at 20 Hz)
102
+ THETA -7.035997 -7.036 deg
103
+ COV_W_TS 0.159552027 0.159552 K m s-1
104
+ ```
105
+
106
+ The generator computes those predictions with its own forty lines of arithmetic rather than
107
+ by calling the program, so agreement means something.
108
+
109
+ `ITC_W`, `ITC_U` and `ITC_T` come out as `-9999` on that run, and the log says why: the
110
+ example config sits at `latitude = 0.0`, where the Coriolis parameter vanishes and the
111
+ neutral model would take `log(0)`. Write your real latitude.
112
+
113
+ Then a real file:
114
+
115
+ ```sh
116
+ cp examples/miniflux.ini mine.ini
117
+ # edit [files], [timestamp], [variables], [units], [gases], [site] to describe your data
118
+ python -m miniflux check mine.ini # exits 2 and names the key if it is wrong
119
+ python -m miniflux run mine.ini --limit 1 # one period, as a smoke run
120
+ python -m miniflux run mine.ini
121
+ ```
122
+
123
+ A Campbell TOA5 file needs `header_line = 2` and `first_data_line = 5`; the quoting and the
124
+ skipped preamble lines are handled. `--pure` forces the standard-library kernels for a run.
125
+ Exit codes are `0` success, `2` a config error, `3` an input error, `1` anything else, so a
126
+ wrapper script can tell "you wrote the config wrong" from "the data is not what the config
127
+ says it is" without parsing the log.
128
+
129
+ ## Configuration
130
+
131
+ One `.ini` file, every key documented in [`examples/miniflux.ini`](examples/miniflux.ini) and
132
+ specified in `CONTRACT.md` §6. The dozen that matter:
133
+
134
+ ```ini
135
+ [files]
136
+ input_glob = ./*.dat # matches are read in the order of their first sample
137
+ header_line = 1 # 1-based; TOA5 is header 2, data 5
138
+ first_data_line = 2
139
+
140
+ [period]
141
+ averaging_minutes = 30
142
+ acquisition_frequency = 20.0 # [Hz], authoritative; the observed rate is only logged
143
+ closed = right # which side of a boundary a sample on it belongs to
144
+
145
+ [timestamp]
146
+ column = TIMESTAMP
147
+ format = iso # iso | numeric — parsed, never inferred
148
+
149
+ [variables] # canonical name = exact column header; empty = absent
150
+ u = Ux
151
+ w = Uz
152
+ co2 = CO2
153
+ p_air = Press
154
+
155
+ [units] # the unit AS WRITTEN IN THE FILE
156
+ ts = K # K | degC
157
+ co2 = ppm # ppm | umol/mol | mmol/m3 | mol/m3 | mg/m3 | g/m3
158
+
159
+ [gases]
160
+ co2_measure_type = mixing_ratio # mixing_ratio (per mole of dry air) | molar_density
161
+
162
+ [site]
163
+ measurement_height = 3.0
164
+ latitude = 45.0 # used only by the ITC test
165
+ ```
166
+
167
+ **Nothing is guessed.** Where a wrong-looking-right number is the alternative, miniflux
168
+ refuses and names the key:
169
+
170
+ ```
171
+ $ python -m miniflux check nop.ini
172
+ ERROR miniflux.cli: configuration: [variables] p_air and [site] pressure_pa are both unset:
173
+ miniflux never invents a pressure. Name the pressure column in [variables] p_air, or write a
174
+ constant in [site] pressure_pa.
175
+
176
+ $ python -m miniflux run numts.ini
177
+ ERROR miniflux.cli: input: ./sample_20hz.dat line 2: timestamp '2025-09-08 19:30:00.050000'
178
+ does not have the shape declared by [timestamp] format, which is YYYYMMDDHHMMSS[.ffffff];
179
+ miniflux parses timestamps and never infers their format
180
+ ```
181
+
182
+ The same rule runs through the program: a closed-path analyser is refused rather than given
183
+ an ambient density correction, a wet mole fraction is refused rather than half-corrected, and
184
+ a flux that is owed WPL but did not get it is written as `-9999` rather than under the
185
+ corrected name. Everything else degenerate is NaN in the meta, `-9999` in the table, and a
186
+ `WARNING` in the log saying which input was not finite.
187
+
188
+ ## Extending it
189
+
190
+ A step is a function `(period, cfg) -> period`. `period` is a plain dict: `'meta'` and ten
191
+ `array('d')` series of equal length (`u v w ts co2 h2o ta p_air t_cell p_cell`), where
192
+ missing is always NaN and where there is no per-sample time at all (`CONTRACT.md` §1.2 says
193
+ why, and how to re-derive one). Adding a step means writing the function and putting its
194
+ name in `pipeline.STEPS`. There is nothing else to update.
195
+
196
+ Say you want the skewness of the vertical wind, the first half of a Vickers & Mahrt
197
+ instrument test:
198
+
199
+ ```python
200
+ # miniflux/skewness.py
201
+ """Per-period skewness of the vertical wind, a high-frequency sanity diagnostic."""
202
+
203
+ import logging
204
+ import math
205
+
206
+ from . import kernels
207
+
208
+ logger = logging.getLogger(__name__)
209
+
210
+
211
+ def skewness(period, cfg):
212
+ """Write meta['skew_w'], the skewness of w over its finite samples [-].
213
+
214
+ period: the dict of CONTRACT section 1. cfg: the Config of section 5.
215
+ Returns the same period. Never raises: a degenerate period gives NaN.
216
+ """
217
+ w = period['w']
218
+ mean = kernels.nanmean(w)
219
+ sd = kernels.nanstd(w)
220
+ if not (math.isfinite(mean) and math.isfinite(sd)) or sd == 0.0:
221
+ logger.warning('skew_w is NaN: mean=%r, sd=%r', mean, sd)
222
+ period['meta']['skew_w'] = float('nan')
223
+ return period
224
+ total = 0.0
225
+ n = 0
226
+ for value in w:
227
+ if math.isfinite(value):
228
+ total += ((value - mean) / sd) ** 3
229
+ n += 1
230
+ period['meta']['skew_w'] = total / n if n else float('nan')
231
+ return period
232
+ ```
233
+
234
+ Two lines in `miniflux/pipeline.py`, after `moments` because it wants the despiked, rotated,
235
+ detrended `w`:
236
+
237
+ ```python
238
+ from . import despike, detrend, flux, lag, qc, read, rotate, skewness, wpl
239
+ ...
240
+ ('moments', flux.moments),
241
+ ('skewness', skewness.skewness),
242
+ ```
243
+
244
+ and one line in `miniflux/write.py` to publish it, if you want it in the table:
245
+
246
+ ```python
247
+ ('SKEW_W', 'skew_w', '-'),
248
+ ```
249
+
250
+ That is the whole change. Re-run the sample and the new column is there:
251
+
252
+ ```
253
+ TIMESTAMP_END VAR_W SKEW_W USTAR
254
+ 202509082000 0.131553 0.0161974 0.32693
255
+ ```
256
+
257
+ The rules a step has to keep (`CONTRACT.md` §1.1): it must not raise on physically degenerate
258
+ data — it writes `float('nan')` and logs at `WARNING`, so one bad period never costs the run
259
+ its other rows; it must not read a config section other than its own; and it must not import
260
+ another step module. Anything shared lives in `kernels.py` (the only module that knows about
261
+ array layout, NaN bookkeeping and numpy), `constants.py`, or the helpers in `flux.py`.
262
+
263
+ If you are adding physics rather than a diagnostic, write it into `ALGORITHMS.md` first, with
264
+ its formula and citation, and pin it with a test in the same commit. That is the convention
265
+ the repo is kept under, and it is the reason the code can be checked at all.
266
+
267
+ ### Calling a step from xarray
268
+
269
+ If your data already lives in an `xarray.Dataset`, one optional file — `xarray_adapter.py`,
270
+ `pip install miniflux-ec[xarray]` — lets you run any miniflux step on it without copying ten
271
+ series and thirty meta keys by hand:
272
+
273
+ ```python
274
+ from miniflux import config, pipeline, xarray_adapter as mfx
275
+
276
+ cfg = config.load('miniflux.ini')
277
+ ds = mfx.apply('despike', ds, cfg) # any name in pipeline.STEPS, or the function
278
+ ds = mfx.apply(pipeline.run_period, ds, cfg) # or the whole pipeline at once
279
+ ```
280
+
281
+ with `to_dataset(period, cfg)` and `from_dataset(dataset, cfg)` underneath it. Each variable
282
+ carries its canonical unit as an attribute, and a Dataset that contradicts one — a declared
283
+ unit that is not the canonical one, a `datetime64` or a bool where a measurement should be —
284
+ is **refused** rather than reinterpreted: a ppm column read as `mol mol-1` looks right all
285
+ the way to the flux. Steps mutate in place, so `apply` copies by default and leaves your
286
+ Dataset untouched; `copy=False` aliases the buffers instead, and then the step's result is
287
+ in your own Dataset when `apply` returns. The time coordinate is rebuilt as
288
+ `period_start + i / freq_hz` and is a label, not a measurement (`CONTRACT.md` §22.3 lists
289
+ what that costs).
290
+
291
+ This is a boundary, not a change of heart. xarray pulls numpy **and** pandas, of the order of
292
+ a hundred megabytes, which would undo the one property the program is built around, and none
293
+ of its strengths are live on a single-axis 2.3 MB period anyway. So it sits in one file that
294
+ nothing in the core imports, exactly as numpy sits inside `kernels.py`. **miniflux does not
295
+ need xarray**: `import miniflux` still imports nothing, the CLI and the whole pipeline are
296
+ unchanged, and the suite passes on an interpreter that has neither library — the adapter's
297
+ own tests skip, and one of them proves the rest of the program does not care. Delete the
298
+ file and nothing else moves.
299
+
300
+ ## What it deliberately does not do
301
+
302
+ `ALGORITHMS.md` §13 gives the full list with the cost of each. In short:
303
+
304
+ * **No spectral / frequency-response correction.** The largest known bias in a miniflux
305
+ number: fluxes are underestimated by roughly 2–15 % depending on height, tube length and
306
+ stability, and nothing here estimates it.
307
+ * **No planar fit, no triple rotation.** Double rotation over-rotates individual low-wind
308
+ periods; a planar fit needs cross-period state that a one-period-at-a-time program does not
309
+ have.
310
+ * **No closed-path handling.** A cell needs a per-sample conversion to a dry mixing ratio
311
+ with fast cell temperature and pressure, not an ambient density correction. Closed-path
312
+ input is refused rather than mis-corrected.
313
+ * **No gap filling, no u\* filtering, no night-time partitioning.** The output has holes in
314
+ it, and annual sums cannot be computed from it without a downstream step.
315
+ * **No storage term.** Night-time NEE is too low at tall towers.
316
+ * **No footprint model.** Nothing in a row says how much of the flux came from the target
317
+ ecosystem; screening by `WD`, `ZL` and `USTAR` is left to you.
318
+ * **One gas pair only** — CO2 and H2O. No CH4, no N2O, no multi-analyser stream assembly, no
319
+ resampling.
320
+ * **No random-uncertainty estimate.** A miniflux flux has no error bar.
321
+
322
+ For work that has to stand up, use a real processing chain:
323
+ [ONEFlux_preproc](https://github.com/pedrohenriquecoimbra/ONEFlux-preproc) (the reference
324
+ miniflux was extracted from, which carries the spectral corrections, the provenance record
325
+ and the engine comparisons), **EddyPro** (LI-COR), or **GEddySoft** (B. Heinesch, ULiège —
326
+ Gembloux Agro-Bio Tech). miniflux is the small thing you read, fork, or run where those
327
+ cannot go.
328
+
329
+ ## Speed
330
+
331
+ A 36,000-sample period takes a couple of seconds end to end on the pure-Python path and about
332
+ half that with numpy on the machine this was written on — seconds per period, not minutes;
333
+ measured numbers, on real files and both paths, are in
334
+ [`docs/BENCHMARK.md`](docs/BENCHMARK.md). numpy is a speed switch and nothing else: every
335
+ decision (spike mask, selected lag, QC flag) is bit-for-bit identical between the two paths
336
+ and reductions agree within 8 ULP, which the suite asserts at 1e-12 relative. On the shipped
337
+ sample, `--pure` and the numpy path write byte-identical tables.
338
+
339
+ ## Validation
340
+
341
+ The suite pins every formula in `ALGORITHMS.md` against hand-computed test vectors, and the
342
+ eight end-to-end self-tests of §14 (rotation invariants, lag sign, WPL magnitude on a known
343
+ parcel, Schotanus contrast, numpy parity) are part of it. What has and has not been
344
+ compared against a reference implementation on real data is written up in
345
+ [`docs/VALIDATION.md`](docs/VALIDATION.md) — read it before you report a miniflux number.
346
+ Where miniflux and `ONEFlux_preproc` disagree numerically, `ONEFlux_preproc` is right and
347
+ miniflux has a bug.
348
+
349
+ ## Licence and provenance
350
+
351
+ EUPL-1.2. See [`LICENCE`](LICENCE); copyright (c) 2026 Pedro Henrique Herig Coimbra.
352
+
353
+ miniflux is a minimal reimplementation of the flux path of `oneflux_preproc` v0.10.0, by the
354
+ same author, also under the EUPL-1.2. The physics, the constants and the numerical
355
+ conventions come from that reference implementation, which is itself a reconciliation of
356
+ EddyPro 7.0.9 (LI-COR) and GEddySoft v4.1 (B. Heinesch, ULiège — Gembloux Agro-Bio Tech). The
357
+ code here is written from scratch against the standard library, and the pipeline is a plain
358
+ ordered list of functions rather than a registry. `oneflux_preproc` carries the engine
359
+ comparisons, the provenance record, the spectral corrections and the published parity against
360
+ EddyPro and GEddySoft; miniflux carries none of that on purpose. Full method citations are in
361
+ [`NOTICE`](NOTICE) and §15 of `ALGORITHMS.md`.