meteosynth 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 (33) hide show
  1. meteosynth-0.1.0/.github/workflows/docs.yml +34 -0
  2. meteosynth-0.1.0/.github/workflows/publish.yml +58 -0
  3. meteosynth-0.1.0/.gitignore +56 -0
  4. meteosynth-0.1.0/.python-version +1 -0
  5. meteosynth-0.1.0/LICENSE +21 -0
  6. meteosynth-0.1.0/PKG-INFO +176 -0
  7. meteosynth-0.1.0/README.md +151 -0
  8. meteosynth-0.1.0/cloudflare-workers-recommended.md +266 -0
  9. meteosynth-0.1.0/docs/Makefile +20 -0
  10. meteosynth-0.1.0/docs/make.bat +35 -0
  11. meteosynth-0.1.0/docs/source/_static/.gitkeep +0 -0
  12. meteosynth-0.1.0/docs/source/api.rst +49 -0
  13. meteosynth-0.1.0/docs/source/conf.py +40 -0
  14. meteosynth-0.1.0/docs/source/examples.md +93 -0
  15. meteosynth-0.1.0/docs/source/index.rst +30 -0
  16. meteosynth-0.1.0/docs/source/quickstart.md +106 -0
  17. meteosynth-0.1.0/docs/source/theory.md +149 -0
  18. meteosynth-0.1.0/examples/example_exploratory_analysis.py +102 -0
  19. meteosynth-0.1.0/examples/example_markov_generation.py +100 -0
  20. meteosynth-0.1.0/pyproject.toml +57 -0
  21. meteosynth-0.1.0/src/meteosynth/__init__.py +15 -0
  22. meteosynth-0.1.0/src/meteosynth/generators.py +190 -0
  23. meteosynth-0.1.0/src/meteosynth/markov_chain_simulator_kde2d.py +655 -0
  24. meteosynth-0.1.0/src/meteosynth/markov_implementations/markov_chain_simulator_continuous.py +287 -0
  25. meteosynth-0.1.0/src/meteosynth/markov_implementations/markov_chain_simulator_discrete.py +170 -0
  26. meteosynth-0.1.0/src/meteosynth/met_data_processor.py +90 -0
  27. meteosynth-0.1.0/src/meteosynth/metdata_pvgis.py +134 -0
  28. meteosynth-0.1.0/src/meteosynth/py.typed +0 -0
  29. meteosynth-0.1.0/src/meteosynth/sup_plot_lib.py +148 -0
  30. meteosynth-0.1.0/tests/test_markov_chain_simulator_kde2d.py +121 -0
  31. meteosynth-0.1.0/tests/test_markov_chain_simulator_singularity.py +53 -0
  32. meteosynth-0.1.0/uv.lock +3953 -0
  33. meteosynth-0.1.0/wrangler.jsonc +8 -0
@@ -0,0 +1,34 @@
1
+ name: Deploy Documentation
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ build-and-deploy:
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: read
14
+ steps:
15
+ - name: Checkout repository
16
+ uses: actions/checkout@v4
17
+
18
+ - name: Set up uv
19
+ uses: astral-sh/setup-uv@v5
20
+ with:
21
+ enable-cache: true
22
+ python-version: "3.11"
23
+
24
+ - name: Build documentation
25
+ run: |
26
+ uv run --group dev sphinx-build -b html docs/source docs/build/html
27
+
28
+ - name: Deploy to Cloudflare Workers
29
+ uses: cloudflare/wrangler-action@v3
30
+ with:
31
+ apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
32
+ accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
33
+ command: deploy
34
+ wranglerVersion: "4"
@@ -0,0 +1,58 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ test-and-build:
11
+ name: Build distribution and run tests
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Checkout Repository
15
+ uses: actions/checkout@v4
16
+
17
+ - name: Set up uv
18
+ uses: astral-sh/setup-uv@v5
19
+ with:
20
+ enable-cache: true
21
+ python-version: "3.11"
22
+
23
+ - name: Install dependencies
24
+ run: |
25
+ uv sync --all-extras --dev
26
+
27
+ - name: Run tests
28
+ run: |
29
+ uv run pytest
30
+
31
+ - name: Build package
32
+ run: |
33
+ uv build
34
+
35
+ - name: Upload dist artifacts
36
+ uses: actions/upload-artifact@v4
37
+ with:
38
+ name: python-package-distributions
39
+ path: dist/
40
+
41
+ publish-to-pypi:
42
+ name: Publish Python distribution to PyPI
43
+ needs: test-and-build
44
+ runs-on: ubuntu-latest
45
+ environment:
46
+ name: pypi
47
+ url: https://pypi.org/p/meteosynth
48
+ permissions:
49
+ id-token: write # MANDATORY for Trusted Publishing OIDC authentication
50
+ steps:
51
+ - name: Download dist artifacts
52
+ uses: actions/download-artifact@v4
53
+ with:
54
+ name: python-package-distributions
55
+ path: dist/
56
+
57
+ - name: Publish package distribution to PyPI
58
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,56 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ share/python-wheels/
20
+ *.egg-info/
21
+ .installed.cfg
22
+ *.egg
23
+ MANIFEST
24
+
25
+ # Virtual environments
26
+ .venv/
27
+ venv/
28
+ ENV/
29
+ env/
30
+
31
+ # IDEs
32
+ .vscode/
33
+ .idea/
34
+ *.suo
35
+ *.ntvs*
36
+ *.njsproj
37
+ *.sln
38
+ *.swp
39
+
40
+ # Testing / coverage
41
+ .pytest_cache/
42
+ .coverage
43
+ htmlcov/
44
+
45
+ # Documentation
46
+ docs/build/
47
+ docs/_build/
48
+ docs/generated/
49
+
50
+ # Data and OS files
51
+ .DS_Store
52
+ Thumbs.db
53
+ *.xlsx
54
+ *.csv
55
+ *.nc
56
+ data/
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nikolaos Papadakis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,176 @@
1
+ Metadata-Version: 2.4
2
+ Name: meteosynth
3
+ Version: 0.1.0
4
+ Summary: A package for generating synthetic environmental time-series using Markov Chain models and PVGIS data integration.
5
+ Project-URL: Homepage, https://github.com/npapnet/meteosynth
6
+ Project-URL: Repository, https://github.com/npapnet/meteosynth.git
7
+ Project-URL: Documentation, https://meteosynth-docs.npapnet-cloudflare.workers.dev
8
+ Author-email: "N.Papadakis (hmuQ)" <npap@hmu.gr>
9
+ License-File: LICENSE
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: matplotlib>=3.5.0
16
+ Requires-Dist: numpy>=1.22.0
17
+ Requires-Dist: openpyxl>=3.0.0
18
+ Requires-Dist: pandas>=1.4.0
19
+ Requires-Dist: pvlib>=0.9.0
20
+ Requires-Dist: scipy>=1.8.0
21
+ Provides-Extra: plot
22
+ Requires-Dist: plotnine>=0.10.0; extra == 'plot'
23
+ Requires-Dist: seaborn>=0.11.0; extra == 'plot'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # meteosynth
27
+
28
+ `meteosynth` is a Python package designed to generate synthetic environmental time-series data (such as solar radiation, air temperature, wind speed) based on historical data. It implements a variety of Markov Chain models and includes utilities to interface with the PVGIS (Photovoltaic Geographical Information System) database.
29
+
30
+ Its primary target is **Monte-Carlo simulation of energy-project output and requirements**, where many statistically-plausible weather realisations are needed rather than a single deterministic profile.
31
+
32
+ ## Features
33
+
34
+ - **Markov Chain Simulators** (shared `get_next_state` / `generate_sequence` interface):
35
+ - `MarkovChainSimulator2dKDE`: Continuous state simulation using 2D Kernel Density Estimation with handling for various singularity cases (CC, CN, NC, NN).
36
+ - `ContinuousMarkovChainSimulator`: Binned continuous state simulation using 1D Kernel Density Estimation.
37
+ - `MarkovChainSimulatorDiscrete`: Discrete state transition modeling.
38
+ - **Daily Series Generators** (`meteosynth.generators`):
39
+ - `EnvSeriesGenerator`: chains 24 hourly simulators into complete 24-hour profiles and draws Monte-Carlo ensembles via `generate_ensemble`.
40
+ - **Meteorological Data Processing**:
41
+ - Pivoting hourly data into daily wide formats.
42
+ - Subsetting and filtering datasets by month/year.
43
+ - **PVGIS Integration**:
44
+ - Retrieve hourly or Typical Meteorological Year (TMY) data directly using the `pvlib` API (`meteosynth.metdata_pvgis`).
45
+
46
+ ---
47
+
48
+ ## Installation & Setup
49
+
50
+ This package is managed using the `uv` tool. To install the package and its dependencies:
51
+
52
+ ```bash
53
+ # Sync core dependencies (numpy, pandas, scipy, pvlib, matplotlib) + dev group
54
+ uv sync
55
+
56
+ # Add the extra statistical-plotting helpers (seaborn, plotnine)
57
+ uv sync --extra plot
58
+ ```
59
+
60
+ `matplotlib` is a core dependency (the simulators expose plotting helpers directly).
61
+ The `dev` dependency group — installed by default with `uv sync` — provides the
62
+ documentation toolchain (Sphinx, furo, Mermaid, MyST) and an interactive
63
+ workflow (`jupyter`, `notebook`, `ipykernel`) for VS Code / JupyterLab.
64
+
65
+ ---
66
+
67
+ ## Usage Example
68
+
69
+ Draw a single transition or a full Markov trajectory:
70
+
71
+ ```python
72
+ import pandas as pd
73
+ from meteosynth import MarkovChainSimulator2dKDE
74
+
75
+ # Load your historical training data (containing 'previous' and 'current' columns)
76
+ data = pd.DataFrame({
77
+ 'previous': [1.2, 1.5, 1.8, 2.1],
78
+ 'current': [1.5, 1.9, 2.0, 2.3]
79
+ })
80
+
81
+ # Initialize the 2D KDE simulator
82
+ simulator = MarkovChainSimulator2dKDE(data)
83
+
84
+ # Generate the next state from a current value of 1.7 ...
85
+ next_state = simulator.get_next_state(1.7, seed=42)
86
+ print("Next state:", next_state)
87
+
88
+ # ... or a whole reproducible sequence
89
+ print(simulator.generate_sequence(start_state=1.7, length=10, seed=42))
90
+ ```
91
+
92
+ ### Monte-Carlo daily ensemble
93
+
94
+ Chain 24 hourly simulators into synthetic days and draw an ensemble for
95
+ downstream energy analysis:
96
+
97
+ ```python
98
+ from meteosynth import MetDataProcessor, EnvSeriesGenerator
99
+
100
+ # `df` is a processed PVGIS hourly frame (year, month, day, hour, poa_direct, ...)
101
+ mdp = MetDataProcessor(df)
102
+ may = mdp.get_month_subset(5) # train on one month
103
+
104
+ gen = EnvSeriesGenerator(may, attr_str="poa_direct", bandwidth=0.1)
105
+
106
+ # 500 independent synthetic days -> shape (500, 24)
107
+ ensemble = gen.generate_ensemble(n_days=500, start_value=0.0, seed=1)
108
+ daily_energy = ensemble.sum(axis=1) # per-day yield proxy
109
+ print(daily_energy.mean(), daily_energy.std())
110
+ ```
111
+
112
+ Fetch real data from PVGIS with `meteosynth.metdata_pvgis`:
113
+
114
+ ```python
115
+ from meteosynth.metdata_pvgis import fetch_pvgis_hourly, SITE_PARIS, save_hourly
116
+
117
+ df = fetch_pvgis_hourly(start_year=2011, end_year=2012, **SITE_PARIS)
118
+ save_hourly(df) # caches to data/pvgis_hourly_data.xlsx
119
+ ```
120
+
121
+ ---
122
+
123
+ ## Examples
124
+
125
+ Two runnable scripts live under `examples/`. On first run they fetch data from
126
+ PVGIS and cache it to `data/pvgis_hourly_data.xlsx`, so subsequent runs are
127
+ offline and fast.
128
+
129
+ ```bash
130
+ # Exploratory analysis: fetch, process, and plot PVGIS data
131
+ uv run python examples/example_exploratory_analysis.py
132
+
133
+ # Synthetic generation: build hourly simulators and plot synthetic daily profiles
134
+ uv run python examples/example_markov_generation.py
135
+ ```
136
+
137
+ See the **Examples** page in the documentation for a full walk-through.
138
+
139
+ ---
140
+
141
+ ## Running Tests
142
+
143
+ Verify the installation by running the test suite (`MPLBACKEND=Agg` keeps
144
+ matplotlib headless):
145
+
146
+ ```bash
147
+ # Linux/macOS
148
+ MPLBACKEND=Agg uv run pytest
149
+
150
+ # Windows (PowerShell)
151
+ $env:MPLBACKEND = "Agg"; uv run pytest
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Building Documentation
157
+
158
+ The documentation uses the standard Sphinx layout (`docs/source/` for sources,
159
+ `docs/build/` for output, with `Makefile`/`make.bat` at the `docs/` root) and
160
+ the `furo` theme, with Mermaid diagrams and Markdown (MyST) support.
161
+
162
+ ```bash
163
+ # From the docs/ directory (Windows)
164
+ cd docs
165
+ uv run .\make.bat html
166
+
167
+ # ...or on Linux/macOS
168
+ cd docs && uv run make html
169
+
170
+ # ...or invoke sphinx-build directly from the project root
171
+ uv run sphinx-build -b html docs/source docs/build/html
172
+ ```
173
+
174
+ Open `docs/build/html/index.html` in your web browser to view it. The docs
175
+ include a **Quickstart**, a **Theory** section explaining the KDE Markov method
176
+ (with diagrams), an **Examples** walk-through, and the full **API reference**.
@@ -0,0 +1,151 @@
1
+ # meteosynth
2
+
3
+ `meteosynth` is a Python package designed to generate synthetic environmental time-series data (such as solar radiation, air temperature, wind speed) based on historical data. It implements a variety of Markov Chain models and includes utilities to interface with the PVGIS (Photovoltaic Geographical Information System) database.
4
+
5
+ Its primary target is **Monte-Carlo simulation of energy-project output and requirements**, where many statistically-plausible weather realisations are needed rather than a single deterministic profile.
6
+
7
+ ## Features
8
+
9
+ - **Markov Chain Simulators** (shared `get_next_state` / `generate_sequence` interface):
10
+ - `MarkovChainSimulator2dKDE`: Continuous state simulation using 2D Kernel Density Estimation with handling for various singularity cases (CC, CN, NC, NN).
11
+ - `ContinuousMarkovChainSimulator`: Binned continuous state simulation using 1D Kernel Density Estimation.
12
+ - `MarkovChainSimulatorDiscrete`: Discrete state transition modeling.
13
+ - **Daily Series Generators** (`meteosynth.generators`):
14
+ - `EnvSeriesGenerator`: chains 24 hourly simulators into complete 24-hour profiles and draws Monte-Carlo ensembles via `generate_ensemble`.
15
+ - **Meteorological Data Processing**:
16
+ - Pivoting hourly data into daily wide formats.
17
+ - Subsetting and filtering datasets by month/year.
18
+ - **PVGIS Integration**:
19
+ - Retrieve hourly or Typical Meteorological Year (TMY) data directly using the `pvlib` API (`meteosynth.metdata_pvgis`).
20
+
21
+ ---
22
+
23
+ ## Installation & Setup
24
+
25
+ This package is managed using the `uv` tool. To install the package and its dependencies:
26
+
27
+ ```bash
28
+ # Sync core dependencies (numpy, pandas, scipy, pvlib, matplotlib) + dev group
29
+ uv sync
30
+
31
+ # Add the extra statistical-plotting helpers (seaborn, plotnine)
32
+ uv sync --extra plot
33
+ ```
34
+
35
+ `matplotlib` is a core dependency (the simulators expose plotting helpers directly).
36
+ The `dev` dependency group — installed by default with `uv sync` — provides the
37
+ documentation toolchain (Sphinx, furo, Mermaid, MyST) and an interactive
38
+ workflow (`jupyter`, `notebook`, `ipykernel`) for VS Code / JupyterLab.
39
+
40
+ ---
41
+
42
+ ## Usage Example
43
+
44
+ Draw a single transition or a full Markov trajectory:
45
+
46
+ ```python
47
+ import pandas as pd
48
+ from meteosynth import MarkovChainSimulator2dKDE
49
+
50
+ # Load your historical training data (containing 'previous' and 'current' columns)
51
+ data = pd.DataFrame({
52
+ 'previous': [1.2, 1.5, 1.8, 2.1],
53
+ 'current': [1.5, 1.9, 2.0, 2.3]
54
+ })
55
+
56
+ # Initialize the 2D KDE simulator
57
+ simulator = MarkovChainSimulator2dKDE(data)
58
+
59
+ # Generate the next state from a current value of 1.7 ...
60
+ next_state = simulator.get_next_state(1.7, seed=42)
61
+ print("Next state:", next_state)
62
+
63
+ # ... or a whole reproducible sequence
64
+ print(simulator.generate_sequence(start_state=1.7, length=10, seed=42))
65
+ ```
66
+
67
+ ### Monte-Carlo daily ensemble
68
+
69
+ Chain 24 hourly simulators into synthetic days and draw an ensemble for
70
+ downstream energy analysis:
71
+
72
+ ```python
73
+ from meteosynth import MetDataProcessor, EnvSeriesGenerator
74
+
75
+ # `df` is a processed PVGIS hourly frame (year, month, day, hour, poa_direct, ...)
76
+ mdp = MetDataProcessor(df)
77
+ may = mdp.get_month_subset(5) # train on one month
78
+
79
+ gen = EnvSeriesGenerator(may, attr_str="poa_direct", bandwidth=0.1)
80
+
81
+ # 500 independent synthetic days -> shape (500, 24)
82
+ ensemble = gen.generate_ensemble(n_days=500, start_value=0.0, seed=1)
83
+ daily_energy = ensemble.sum(axis=1) # per-day yield proxy
84
+ print(daily_energy.mean(), daily_energy.std())
85
+ ```
86
+
87
+ Fetch real data from PVGIS with `meteosynth.metdata_pvgis`:
88
+
89
+ ```python
90
+ from meteosynth.metdata_pvgis import fetch_pvgis_hourly, SITE_PARIS, save_hourly
91
+
92
+ df = fetch_pvgis_hourly(start_year=2011, end_year=2012, **SITE_PARIS)
93
+ save_hourly(df) # caches to data/pvgis_hourly_data.xlsx
94
+ ```
95
+
96
+ ---
97
+
98
+ ## Examples
99
+
100
+ Two runnable scripts live under `examples/`. On first run they fetch data from
101
+ PVGIS and cache it to `data/pvgis_hourly_data.xlsx`, so subsequent runs are
102
+ offline and fast.
103
+
104
+ ```bash
105
+ # Exploratory analysis: fetch, process, and plot PVGIS data
106
+ uv run python examples/example_exploratory_analysis.py
107
+
108
+ # Synthetic generation: build hourly simulators and plot synthetic daily profiles
109
+ uv run python examples/example_markov_generation.py
110
+ ```
111
+
112
+ See the **Examples** page in the documentation for a full walk-through.
113
+
114
+ ---
115
+
116
+ ## Running Tests
117
+
118
+ Verify the installation by running the test suite (`MPLBACKEND=Agg` keeps
119
+ matplotlib headless):
120
+
121
+ ```bash
122
+ # Linux/macOS
123
+ MPLBACKEND=Agg uv run pytest
124
+
125
+ # Windows (PowerShell)
126
+ $env:MPLBACKEND = "Agg"; uv run pytest
127
+ ```
128
+
129
+ ---
130
+
131
+ ## Building Documentation
132
+
133
+ The documentation uses the standard Sphinx layout (`docs/source/` for sources,
134
+ `docs/build/` for output, with `Makefile`/`make.bat` at the `docs/` root) and
135
+ the `furo` theme, with Mermaid diagrams and Markdown (MyST) support.
136
+
137
+ ```bash
138
+ # From the docs/ directory (Windows)
139
+ cd docs
140
+ uv run .\make.bat html
141
+
142
+ # ...or on Linux/macOS
143
+ cd docs && uv run make html
144
+
145
+ # ...or invoke sphinx-build directly from the project root
146
+ uv run sphinx-build -b html docs/source docs/build/html
147
+ ```
148
+
149
+ Open `docs/build/html/index.html` in your web browser to view it. The docs
150
+ include a **Quickstart**, a **Theory** section explaining the KDE Markov method
151
+ (with diagrams), an **Examples** walk-through, and the full **API reference**.