Metadata-Version: 2.4
Name: onefluxpro
Version: 0.13.0
Summary: Eddy Covariance Software for Python. This package provides tools for processing and analyzing Eddy Covariance data, Written by pedrohenriquecoimbra
Author-email: Pedro Henrique Coimbra <pedro-henrique.herig-coimbra@inrae.fr>
Maintainer-email: Pedro Henrique Coimbra <pedro-henrique.herig-coimbra@inrae.fr>
License-Expression: EUPL-1.2
Project-URL: Homepage, https://github.com/pedrohenriquecoimbra/ONEFluxPro
Project-URL: Repository, https://github.com/pedrohenriquecoimbra/ONEFluxPro
Keywords: eddy covariance,EC,ICOS,flux,preprocessing,reproducibility
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Other Environment
Classifier: Framework :: Jupyter
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENCE
Requires-Dist: pandas>=2.0.0
Requires-Dist: matplotlib>=3.1.0
Requires-Dist: numpy>=1.24
Requires-Dist: PyWavelets>=1.4.0
Requires-Dist: scipy>=1.10.0
Requires-Dist: scikit-learn>=1.0
Requires-Dist: PyYAML>=5.4
Requires-Dist: Pint>=0.20
Requires-Dist: pint_xarray>=0.3
Requires-Dist: xlrd>=2.0
Requires-Dist: netcdf4>=1.6
Requires-Dist: h5netcdf>=1.0
Requires-Dist: h5py>=3.0
Requires-Dist: xarray>=2023.1
Requires-Dist: configobj>=5.0
Requires-Dist: regorator>=0.2.0
Requires-Dist: ordinator<0.3,>=0.2.0
Requires-Dist: pytz
Provides-Extra: footprint
Requires-Dist: fluxprint; extra == "footprint"
Provides-Extra: cwt
Requires-Dist: pycwt; extra == "cwt"
Provides-Extra: fcwt
Requires-Dist: pycwt; extra == "fcwt"
Requires-Dist: fcwt; extra == "fcwt"
Provides-Extra: era5
Requires-Dist: cdsapi; extra == "era5"
Provides-Extra: geddysoft
Requires-Dist: diptest; extra == "geddysoft"
Requires-Dist: statsmodels; extra == "geddysoft"
Provides-Extra: test
Requires-Dist: pytest>=7.0; extra == "test"
Requires-Dist: pytest-cov>=4.0; extra == "test"
Requires-Dist: jinja2; extra == "test"
Requires-Dist: tomli; python_version < "3.11" and extra == "test"
Provides-Extra: docs
Requires-Dist: sphinx>=7.0; extra == "docs"
Requires-Dist: myst-parser>=2.0; extra == "docs"
Requires-Dist: sphinx-rtd-theme>=2.0; extra == "docs"
Provides-Extra: lint
Requires-Dist: ruff>=0.6; extra == "lint"
Dynamic: license-file

# onefluxpro

*Formerly `oneflux_preproc`.*

Eddy-covariance preprocessing for Python: reads raw high-frequency data,
applies the standard corrections, computes covariances and fluxes, runs quality
control, exports ONEFlux-compatible output.

Every processing choice (despiking, rotation, lag, spectral correction) is a
**named entry in a registry**: selected in the configuration, swappable,
recorded by the run. Comparing two analyses means comparing two lists.

Read [PHILOSOPHY.md](https://github.com/pedrohenriquecoimbra/ONEFluxPro/blob/main/PHILOSOPHY.md), the design rules, and
[ordinator's](https://github.com/pedrohenriquecoimbra/ordinator/blob/main/PHILOSOPHY.md), which they extend, before contributing;
[ROADMAP.md](https://github.com/pedrohenriquecoimbra/ONEFluxPro/blob/main/ROADMAP.md) says what is planned next.

## Engines

A method can run this package's transcription of it or the engine's own code,
selected by name in the configuration (`double_rotation@geddysoft`). Each
engine is pinned as a submodule, and its methods and bindings are declared in
`engines/descriptors/<engine>.json` rather than written in Python.

<!-- begin: engines -- generated by `onefluxpro compatibility` -->

| engine | pinned at | declared without Python | what the count means |
|---|---|---|---|
| EddyPro | `3cabe63` | n/a | nothing of it is importable, so none of its methods carry a binding; its constants are read from source. |
| fluxmethods | `645f0dd` | 32 of 32 | 32 of 32 functions we bind from it are declared in JSON alone; 0 need an adapter. |
| GEddySoft | `79df6b3` | 13 of 19 | 13 of 19 functions we bind from it are declared in JSON alone; 6 need an adapter. |
| miniflux | `6f23394` | 1 of 2 | 1 of 2 functions we bind from it are declared in JSON alone; 1 need an adapter. |

The **declared without Python** column counts the functions **this package
binds**, not what the engine offers: a method nobody has tried to bind is in
neither term. An adapter is not a failure -- every binding is held to the
same equivalence test -- it means our role vocabulary did not stretch that far.

<!-- end: engines -->

## Steps in R or Julia

A step does not have to be Python. A method written in R or in Julia is declared
the same way, selected the same way, and runs in the same pipeline:

```ini
[Corrections]
    [[despiking]]
        method = mad_perperiod@fluxmethods              # Python
    [[axis_rotation]]
        method = double_rotation@fluxmethods_r          # R
    [[detrending]]
        method = block_average@fluxmethods_julia        # Julia
```

Each language runs in one persistent child process, with every number crossing
in memory as raw float64: no file and no process per call, and the run records
the file of the language that computed each step. On the FR-Gri sample, the
chain above and the same chain in Python alone:

| run | despiking | rotation | detrending | identical to the Python-only run |
|---|---|---|---|---|
| Python only | Python | Python | Python | 135 of 135 variables |
| three languages | Python | R | Julia | 119 of 135, the rest to 1.3e-14 |
| the other way | Python | Julia | R | 119 of 135, the rest to 1.3e-14 |

R and Julia are bit-identical to each other. The 16 variables that differ from
Python do so by one bit of the rotation angle, and the cause is on the Python
side: with `math.atan2` in place of `numpy.arctan2`, all three runs are
identical in all 135 variables.

**[examples/languages.ipynb](https://github.com/pedrohenriquecoimbra/ONEFluxPro/blob/main/examples/languages.ipynb)** walks through it with
its outputs: one method in three files, one pipeline run three times, the
explanation, and one run with a language at each step.
[docs/meta/other_languages.md](https://github.com/pedrohenriquecoimbra/ONEFluxPro/blob/main/docs/meta/other_languages.md) has the set-up and
the measurements. R (`Rscript`, with `jsonlite`) and Julia are optional: without
one, its steps refuse at the first call and say what to install.

## Install

Python 3.10+. Install the latest release from PyPI:

```bash
pip install onefluxpro
```

Or the development tree from GitHub:

```bash
pip install git+https://github.com/pedrohenriquecoimbra/ONEFluxPro
```

Or from a checkout:

```bash
git clone https://github.com/pedrohenriquecoimbra/ONEFluxPro
git -C ONEFluxPro submodule update --init third_party/fluxmethods
pip install -e ONEFluxPro
```

The second line is not optional. The methods themselves (despiking, rotation,
lag, spectral, density) are kept in
[`fluxmethods`](https://github.com/pedrohenriquecoimbra/fluxmethods), a
collection of plain functions pinned here as a submodule, and the package runs
those files rather than a copy of them. It is not on PyPI: a wheel carries the
pinned tree inside it, so `pip install onefluxpro` needs nothing more.

Optional extras:

```bash
pip install -e "ONEFluxPro[era5]"        # ERA5 reanalysis download (cdsapi)
pip install -e "ONEFluxPro[geddysoft]"   # GEddySoft instrument-problem test (diptest, statsmodels)
pip install -e "ONEFluxPro[test]"        # the test suite, and `reproduce`'s tables
pip install -e "ONEFluxPro[docs]"        # sphinx-build
```

## Run it

From the repository root:

```python
import os
import onefluxpro as o
from configobj import ConfigObj

setup = ConfigObj("examples/FR-Gri_20220514/config_L0.txt")
setup["Options"]["datetimerange"] = "202205130000-202205130030"

os.chdir("data")                      # the config's input paths resolve here
data = o.standard_run(setup)          # -> xarray.Dataset
print(data[["ustar", "wind_dir", "FC"]])
```

`standard_run` returns the dataset and writes nothing. To also write NetCDF,
ONEFlux CSV and provenance manifest, still from `data/`:

```python
o.main("../examples/FR-Gri_20220514/config_L0.txt", dst="output/")
```

Config input paths are relative to the working directory; the example reads
`sample/FR-Gri_20220514/FLUX`, which lives under `data/`. On the command line pass
`--workdir`; `-o` resolves there too.

## Command line and web UI

The package installs `onefluxpro`. `list`, `describe` and `validate` read
the live registry, so a registered method appears at once:

```bash
onefluxpro tutorial                                # getting-started walkthrough
onefluxpro list                                    # registered methods (--all adds internal and deprecated ones)
onefluxpro describe despiking mad_perperiod@fluxmethods  # scope, references, signature, docs
onefluxpro engines                                 # processing engines, and which are runnable here
onefluxpro import --engine eddypro \
    --setup FR-Gri.eddypro --metadata FR-Gri.metadata my_config_L0.txt   # a foreign setup, as a config of ours
onefluxpro validate -c examples/FR-Gri_20220514/config_L0.txt
onefluxpro install-plugins -c examples/FR-Gri_20220514/config_L0.txt   # pip-install the plugins a config declares
onefluxpro run -c examples/FR-Gri_20220514/config_L0.txt \
    --from 202205130000 --to 202205130030 -o output/ --workdir data
onefluxpro gui                                     # http://localhost:8765/
```

`run` also takes `--set KEY=VALUE` (a dotted path into the config, repeatable,
for this run only — every override is recorded in the manifest),
`--diagnostic` (keep the high-frequency series so before/after diagnostics
exist; use a short window; without it the config's `Options.keep_raw` decides) and `--permissive` (a refusing step is skipped and
the waiver recorded, rather than stopping the run). Two more subcommands serve
narrower needs: `reproduce` re-runs the published engine comparisons and
rebuilds their tables, and `engine-spec` emits this package's engine-manifest
descriptor (`--cwl` for a CWL CommandLineTool instead).

The web UI renders the catalogue and the run form from the same registry. Runs are
cancellable child processes with a live log; results offer a NetCDF download, a
diagnostics gallery and a history that reopens past runs. An engine picker
selects which engine runs — this package by default, EddyPro-RP and GEddySoft
when their programs are there, the same choice `run --engine` offers on the
command line — and the Setup editor opens a foreign configuration (EddyPro
`.eddypro` + `.metadata`, GEddySoft `.ini`) as its own sections, writing back
only the keys that changed. Any run with an output directory writes a
provenance manifest (code and library versions, config hash, inputs, seeds,
warnings) beside its NetCDF.

`scripts/gui.cmd` (Windows) and `scripts/gui.sh` (Unix) start the UI from
`./.conda`.

## Where things are

| directory | what it holds |
|---|---|
| `src/` | the `onefluxpro` package: the kinds, the facades, the readers and the record. Its kernel, `ordinator`, is a package and a repository of its own, and its methods are `third_party/fluxmethods` |
| `examples/` | one folder per site: the configurations the published comparisons run, and the scripts that derive them |
| `data/` | the data root: `sample/<site>/` and run outputs. Git-ignored, distributed separately, and the directory you mount at `/data` |
| `third_party/` | git submodules (`git submodule update --init`): `fluxmethods`, which holds this package's methods and is required, and the engine sources the comparisons read and the bridged methods call; `third_party/README.md` says what each is, where it is pinned and under which licence |
| `tests/` | the suite, including the comparisons that carry the published assertions |
| `docs/` | the Sphinx sources: `user_guide/` for readers, `meta/` for implementation detail |
| `scripts/` | launchers and one-off helpers |

## Documentation

Start with **[the pipeline](https://github.com/pedrohenriquecoimbra/ONEFluxPro/blob/main/docs/user_guide/pipeline.md)**: a run from files
to fluxes, in one page; then
[configuration](https://github.com/pedrohenriquecoimbra/ONEFluxPro/blob/main/docs/user_guide/configuration.md) and
[the interfaces](https://github.com/pedrohenriquecoimbra/ONEFluxPro/blob/main/docs/user_guide/interface.md).
[Docker](https://github.com/pedrohenriquecoimbra/ONEFluxPro/blob/main/docs/user_guide/docker.md),
[the VOC setup](https://github.com/pedrohenriquecoimbra/ONEFluxPro/blob/main/docs/user_guide/voc.md) and
[reproducing the comparisons](https://github.com/pedrohenriquecoimbra/ONEFluxPro/blob/main/docs/user_guide/reproducing_comparisons.md)
cover the rest.

## Development

One self-contained conda env at `./.conda` covers development, the tests and the UI:

```bash
conda create --prefix ./.conda python=3.11 pip -y
./.conda/bin/python -m pip install -e ".[test]"   # Windows: .\.conda\python

conda activate ./.conda
pytest                              # run the test suite
onefluxpro gui                 # launch the web UI
```

The `docs` extra (`.[test,docs]`) enables `sphinx-build -b html docs public`.
The end-to-end regression test runs on the FR-Gri sample when present and
skips otherwise, as do the engine comparisons.

Or a plain virtualenv:
`python -m venv .venv && .venv/bin/pip install -e ".[test]"` (Windows: `.venv\Scripts\pip`).

## Docker

One image carries the pipeline, the web UI and the reproduction of the
published comparisons. It starts the UI by default:

```bash
docker pull ghcr.io/pedrohenriquecoimbra/onefluxpro:latest
docker run --rm -p 127.0.0.1:8765:8765 -v /path/to/data:/data ghcr.io/pedrohenriquecoimbra/onefluxpro:latest
```

Mount the directory holding `sample/` at `/data`;
[docs/user_guide/docker.md](https://github.com/pedrohenriquecoimbra/ONEFluxPro/blob/main/docs/user_guide/docker.md) covers the data-volume
contract, batch runs and `reproduce`.

## License

EUPL-1.2, see `LICENCE`.
