perfectdays 0.0.1__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 (68) hide show
  1. perfectdays-0.0.1/CITATION.cff +12 -0
  2. perfectdays-0.0.1/LICENSE +201 -0
  3. perfectdays-0.0.1/MANIFEST.in +29 -0
  4. perfectdays-0.0.1/PKG-INFO +196 -0
  5. perfectdays-0.0.1/README.md +159 -0
  6. perfectdays-0.0.1/perfectdays/__init__.py +14 -0
  7. perfectdays-0.0.1/perfectdays/api/__init__.py +13 -0
  8. perfectdays-0.0.1/perfectdays/api/formats/__init__.py +42 -0
  9. perfectdays-0.0.1/perfectdays/api/formats/reho.py +126 -0
  10. perfectdays-0.0.1/perfectdays/api/frontend.py +91 -0
  11. perfectdays-0.0.1/perfectdays/api/reho.py +120 -0
  12. perfectdays-0.0.1/perfectdays/api/routing.py +101 -0
  13. perfectdays-0.0.1/perfectdays/clusteringfactory/__init__.py +6 -0
  14. perfectdays-0.0.1/perfectdays/clusteringfactory/clustering.py +230 -0
  15. perfectdays-0.0.1/perfectdays/clusteringfactory/kmedoids.py +110 -0
  16. perfectdays-0.0.1/perfectdays/clusteringfactory/metrics.py +71 -0
  17. perfectdays-0.0.1/perfectdays/clusteringfactory/periods.py +106 -0
  18. perfectdays-0.0.1/perfectdays/clusteringfactory/quality.py +230 -0
  19. perfectdays-0.0.1/perfectdays/clusteringfactory/result.py +63 -0
  20. perfectdays-0.0.1/perfectdays/sources/__init__.py +10 -0
  21. perfectdays-0.0.1/perfectdays/sources/base.py +121 -0
  22. perfectdays-0.0.1/perfectdays/sources/files.py +68 -0
  23. perfectdays-0.0.1/perfectdays/sources/pvgis.py +64 -0
  24. perfectdays-0.0.1/perfectdays/sources/swiss.py +115 -0
  25. perfectdays-0.0.1/perfectdays/swissweathergrid/__init__.py +10 -0
  26. perfectdays-0.0.1/perfectdays/swissweathergrid/cell_access/__init__.py +8 -0
  27. perfectdays-0.0.1/perfectdays/swissweathergrid/cell_access/ch2025.py +200 -0
  28. perfectdays-0.0.1/perfectdays/swissweathergrid/cell_access/query.py +421 -0
  29. perfectdays-0.0.1/perfectdays/swissweathergrid/cell_access/zenodo.py +131 -0
  30. perfectdays-0.0.1/perfectdays/swissweathergrid/core/__init__.py +8 -0
  31. perfectdays-0.0.1/perfectdays/swissweathergrid/core/ch2025.py +82 -0
  32. perfectdays-0.0.1/perfectdays/swissweathergrid/core/fetch.py +57 -0
  33. perfectdays-0.0.1/perfectdays/swissweathergrid/core/geo.py +218 -0
  34. perfectdays-0.0.1/perfectdays/swissweathergrid/core/wsl.py +259 -0
  35. perfectdays-0.0.1/perfectdays/swissweathergrid/data/at_meta.json +1 -0
  36. perfectdays-0.0.1/perfectdays/swissweathergrid/data/imis_meta.txt +129 -0
  37. perfectdays-0.0.1/perfectdays/swissweathergrid/data/lakes_osm.json +116311 -0
  38. perfectdays-0.0.1/perfectdays/swissweathergrid/data/smn_meta.csv +159 -0
  39. perfectdays-0.0.1/perfectdays/swissweathergrid/data/swiss_border_osm.json +57493 -0
  40. perfectdays-0.0.1/perfectdays/swissweathergrid/data/switzerland.geojson +9684 -0
  41. perfectdays-0.0.1/perfectdays/swissweathergrid/data/wsl_change_iswr.csv +41581 -0
  42. perfectdays-0.0.1/perfectdays/swissweathergrid/data/wsl_delta_tas.csv +43849 -0
  43. perfectdays-0.0.1/perfectdays/swissweathergrid/grid_building/__init__.py +8 -0
  44. perfectdays-0.0.1/perfectdays/swissweathergrid/grid_building/__main__.py +4 -0
  45. perfectdays-0.0.1/perfectdays/swissweathergrid/grid_building/builder.py +276 -0
  46. perfectdays-0.0.1/perfectdays/swissweathergrid/grid_building/pipeline.py +500 -0
  47. perfectdays-0.0.1/perfectdays/swissweathergrid/grid_building/postgres.py +497 -0
  48. perfectdays-0.0.1/perfectdays/swissweathergrid/grid_building/scenarios.py +415 -0
  49. perfectdays-0.0.1/perfectdays/swissweathergrid/grid_building/solution.py +150 -0
  50. perfectdays-0.0.1/perfectdays/swissweathergrid/grid_building/storage.py +111 -0
  51. perfectdays-0.0.1/perfectdays/swissweathergrid/interpolation_method/__init__.py +11 -0
  52. perfectdays-0.0.1/perfectdays/swissweathergrid/interpolation_method/covariants_computation.py +795 -0
  53. perfectdays-0.0.1/perfectdays/swissweathergrid/interpolation_method/interpolation.py +244 -0
  54. perfectdays-0.0.1/perfectdays/swissweathergrid/interpolation_method/stations.py +694 -0
  55. perfectdays-0.0.1/perfectdays/swissweathergrid/interpolation_method/validation.py +550 -0
  56. perfectdays-0.0.1/perfectdays/swissweathergrid/paths.py +25 -0
  57. perfectdays-0.0.1/perfectdays.egg-info/PKG-INFO +196 -0
  58. perfectdays-0.0.1/perfectdays.egg-info/SOURCES.txt +66 -0
  59. perfectdays-0.0.1/perfectdays.egg-info/dependency_links.txt +1 -0
  60. perfectdays-0.0.1/perfectdays.egg-info/requires.txt +17 -0
  61. perfectdays-0.0.1/perfectdays.egg-info/top_level.txt +1 -0
  62. perfectdays-0.0.1/pyproject.toml +69 -0
  63. perfectdays-0.0.1/setup.cfg +4 -0
  64. perfectdays-0.0.1/tests/test_api.py +182 -0
  65. perfectdays-0.0.1/tests/test_clustering.py +208 -0
  66. perfectdays-0.0.1/tests/test_import.py +11 -0
  67. perfectdays-0.0.1/tests/test_reho_parity.py +98 -0
  68. perfectdays-0.0.1/tests/test_sources.py +235 -0
@@ -0,0 +1,12 @@
1
+ cff-version: "1.2.0"
2
+ title: "SwissWeatherGrid: Hourly weather for any point in Switzerland on a 1 km grid"
3
+ message: If you use SwissWeatherGrid in your research or applications, please cite it.
4
+ authors:
5
+ - family-names: Loustau
6
+ given-names: Joseph
7
+ orcid: "https://orcid.org/0009-0005-5830-225X"
8
+ contact:
9
+ - family-names: Loustau
10
+ given-names: Joseph
11
+ license: Apache-2.0
12
+ repository-code: "https://gitlab.epfl.ch/ipese/urban-systems/swissweathergrid"
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2021] [IPESE]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,29 @@
1
+ include README.md
2
+ include LICENSE
3
+ include CHANGELOG.md
4
+ include CITATION.cff
5
+
6
+ # Ship the derived products, never the inputs. `data/` holds ~3.7 GB of station
7
+ # archives and DEM tiles that every loader re-downloads on demand; shipping them
8
+ # would put gigabytes in the wheel to no purpose.
9
+ include perfectdays/swissweathergrid/data/wsl_delta_tas.csv
10
+ include perfectdays/swissweathergrid/data/wsl_change_iswr.csv
11
+ include perfectdays/swissweathergrid/data/imis_meta.txt
12
+ include perfectdays/swissweathergrid/data/smn_meta.csv
13
+ include perfectdays/swissweathergrid/data/at_meta.json
14
+ include perfectdays/swissweathergrid/data/lakes_osm.json
15
+ include perfectdays/swissweathergrid/data/swiss_border_osm.json
16
+ include perfectdays/swissweathergrid/data/switzerland.geojson
17
+
18
+ prune perfectdays/swissweathergrid/cache
19
+ prune perfectdays/swissweathergrid/data/hourly
20
+ prune perfectdays/swissweathergrid/data/grid
21
+ prune perfectdays/swissweathergrid/data/france
22
+ prune perfectdays/swissweathergrid/data/dwd
23
+ prune perfectdays/swissweathergrid/data/smn
24
+ prune perfectdays/swissweathergrid/data/austria
25
+ prune perfectdays/swissweathergrid/data/aosta
26
+ prune perfectdays/swissweathergrid/data/italy
27
+ prune perfectdays/swissweathergrid/data/imis
28
+ prune solutions
29
+ prune docs/_build
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.4
2
+ Name: perfectdays
3
+ Version: 0.0.1
4
+ Summary: perfectdays - Hourly temperature and irradiance anywhere in Europe, clustered into typical periods for energy-system models
5
+ Author-email: Joseph Loustau <joseph.loustau@epfl.ch>
6
+ Maintainer-email: IPESE-IT <it.ipese@epfl.ch>
7
+ License: Apache-2.0
8
+ Project-URL: Documentation, https://swissweathergrid.readthedocs.io/
9
+ Project-URL: Repository, https://gitlab.epfl.ch/ipese/urban-systems/swissweathergrid
10
+ Project-URL: Download, https://pypi.org/project/perfectdays
11
+ Keywords: weather data,kriging,climate scenarios,typical days,clustering,Switzerland,Europe,energy systems
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
18
+ Classifier: Topic :: Scientific/Engineering :: GIS
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: certifi
23
+ Requires-Dist: netCDF4
24
+ Requires-Dist: numpy
25
+ Requires-Dist: pandas
26
+ Requires-Dist: scipy
27
+ Provides-Extra: postgres
28
+ Requires-Dist: psycopg2-binary<3.0.0; extra == "postgres"
29
+ Requires-Dist: sqlalchemy>=2.0.0; extra == "postgres"
30
+ Provides-Extra: plotting
31
+ Requires-Dist: matplotlib; extra == "plotting"
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest; extra == "dev"
34
+ Requires-Dist: build; extra == "dev"
35
+ Requires-Dist: twine; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # perfectdays
39
+
40
+ **`perfectdays`** retrieves the hourly temperature and irradiance for any point in Europe, and compress it into typical periods, ideal to reduce data dimensionality in modelling.
41
+
42
+ ![_Landscape_, Qian Du](https://swissweathergrid.readthedocs.io/en/latest/_images/landscape_qian_du.jpg)
43
+
44
+ It is developed by EPFL (Switzerland), within the *Industrial Process and Energy Systems Engineering (IPESE)* group.
45
+
46
+ This package is the weather module of models developed within the laboratory, such as [REHO](https://reho.readthedocs.io/en/main/) or [PinchSmall](https://pinchsmall.epfl.ch/docs/) - that you are encouraged to explore as well. Indeed, those models help taking decisions in the planning of energy systems - at the district-scale for _REHO_ - where external conditions are critical. Moreover, those decisions span over several long period of time, from 20 to 40 years, and therefore need forecasting of those conditions.
47
+
48
+ To this end the package has two purposes: providing reliable weather data, now and in the future, and compact them into typical periods.
49
+
50
+ This first aspect addresses:
51
+ * the lack of precision unveiled from common sources such as ERA5, a project where the grid resolution is at 30 km, which is not sufficient in the Alpine terrain where the temperature elevation gradient can change drastically within that distance.
52
+ * the absence of data at short time horizon (until 2050).
53
+
54
+ > **_SwissWeatherGrid_**
55
+ >
56
+ > This package gives therefore the possibility to build a 1km grid, _SwissWeatherGrid_, now or under a climate scenario (_RCPs_), reusing the interpolation methodology from MeteoSwiss [[1]](#references). This interpolation method is then reused to create a grid for the climate change scenarios from CH2025 and WSL's downscaling [[2]](#references).
57
+
58
+
59
+
60
+ ## Documentation
61
+
62
+ <https://swissweathergrid.readthedocs.io/>
63
+
64
+ ## Use
65
+
66
+ #### 1. Install
67
+
68
+ ```bash
69
+ pip install perfectdays
70
+ ```
71
+
72
+ To read grids from PostgreSQL, install the optional extra:
73
+
74
+ ```bash
75
+ pip install "perfectdays[postgres]"
76
+ ```
77
+
78
+ #### 2. Typical periods anywhere in Europe
79
+
80
+ ```python
81
+ from perfectdays import get_typical_periods
82
+
83
+ tp = get_typical_periods(46.52, 6.63, periods=10) # Lausanne
84
+ tp, quality = get_typical_periods(48.85, 2.35, years=[2019, 2020],
85
+ periods=10, clustering_evaluation=True)
86
+ quality.stability.plot()
87
+ ```
88
+
89
+ See the *Typical periods* page of the documentation.
90
+
91
+ #### 3. Hourly data for one Swiss point
92
+
93
+ ```python
94
+ from perfectdays.swissweathergrid import get_cell_weather
95
+
96
+ df = get_cell_weather(46.52, 6.63, 2023) # Lausanne, 8760 rows
97
+ ```
98
+
99
+ Coordinates are WGS84 degrees; the point is snapped to the 1 km cell containing
100
+ it. You get an hourly frame for the whole calendar year — 8760 rows, 8784 in a
101
+ leap year:
102
+
103
+ | column | unit | source |
104
+ |---|---|---|
105
+ | `temperature` | °C | the KED grid |
106
+ | `beam`, `diffuse` | W/m² | PVGIS, for the plane you asked for |
107
+ | `global_horizontal` | W/m² | `beam + diffuse` |
108
+
109
+ Pass `irradiance=False` for temperature only, or `slope=` and `azimuth=` for a
110
+ tilted plane.
111
+
112
+ #### 4. Choose a scenario
113
+
114
+ ```python
115
+ df = get_cell_weather(46.52, 6.63, 2023, scenario="rcp45_2045")
116
+ ```
117
+
118
+ A scenario is named `{pathway}_{year}`. A pathway says how the world gets warmer, a year says when you are
119
+ looking. Neither alone fixes a climate.
120
+
121
+ | part | values | meaning |
122
+ |---|---|---|
123
+ | pathway | `rcp26`, `rcp45`, `rcp85` | CH2018 emission pathway, 12 / 25 / 31 model chains |
124
+ | year | 1990–2100 | resolved to the WSL decade containing it |
125
+
126
+ `"current"` is the observed year, unwarmed.
127
+
128
+ The `year` argument stays the **base year** — the observed year being warmed.
129
+ So `scenario="rcp45_2045", year=2023` means "2023's weather, moved to the
130
+ climate of the 2040s under RCP4.5". The change is measured between the decade
131
+ containing your base year and the decade containing the scenario year, taken
132
+ from the same model chains, so the historical record cancels and only the
133
+ climate signal survives.
134
+
135
+
136
+ #### 5. What a scenario series may be used for
137
+
138
+ Each delivered year is a **continuous 8760-hour series** with real day-to-day
139
+ persistence, because the scenario warms an observed year rather than
140
+ synthesising one. What it is not is a moment in a trajectory.
141
+
142
+ **No transient series.** WSL provides decade snapshots, not a continuous run
143
+ through the century. The authors: "only snapshots for the future are provided
144
+ with discontinuities between them." Two scenario years are two separate
145
+ stationary climates, not two points on a path.
146
+
147
+ **No climate signal in the sub-daily cycle.** The delta is applied to a
148
+ historical hourly record, so the diurnal *shape* is inherited from the past.
149
+ What the method gets right is leaving that shape undistorted; what it cannot
150
+ tell you is how the shape itself changes.
151
+
152
+ **Only the change is usable.** The signal is a difference taken *inside* WSL,
153
+ between two decades of the same model chain, which cancels the bias of the
154
+ underlying record. Absolute scenario values do not carry over; differences and
155
+ ratios do.
156
+
157
+ In practice:
158
+
159
+ | you want | do |
160
+ |---|---|
161
+ | typical days, duration curves, monthly or seasonal statistics | fine — these use the distribution |
162
+ | a design day, a heating or cooling degree-hour total | fine |
163
+ | "what does 14 July 2045 look like" | **no** — the day order carries no information |
164
+ | a 2030 → 2040 → 2050 trajectory | **no** — the decades are separate stationary climates |
165
+ | a change in the shape of the daily cycle | **no** — inherited from the historical record |
166
+
167
+
168
+ ## Structure
169
+
170
+ | folder | what it does |
171
+ |---|---|
172
+ | `perfectdays/sources/` | hourly years from the Swiss grid, PVGIS or your files, in one shape |
173
+ | `perfectdays/clusteringfactory/` | typical periods by k-medoids (PAM), and their quality |
174
+ | `perfectdays/api/` | `get_weather`, `get_typical_periods`: source choice, fallback, output formats |
175
+ | `perfectdays/api/reho.py` | REHO's weather step, with REHO's arguments |
176
+ | `perfectdays/swissweathergrid/core/` | HTTP caching, LV95 coordinates, elevation, grid definition |
177
+ | `perfectdays/swissweathergrid/interpolation_method/` | rebuilds and validates the method of Frey & Frei (2025) |
178
+ | `perfectdays/swissweathergrid/grid_building/` | applies it to produce national grids per scenario and year |
179
+ | `perfectdays/swissweathergrid/cell_access/` | queries a grid for one location, and adds irradiance |
180
+
181
+
182
+ ## References
183
+
184
+ 1. Frey, L. & Frei, C. (2025). Interpolation of Hourly Surface Air Temperature — Application of a Spatio-Temporal Statistical Model in Complex Terrain. *International Journal of Climatology*, 45(7). <https://doi.org/10.1002/joc.8796>
185
+ 2. Michel, A., Sharma, V., Lehning, M. & Huwald, H. (2021). Climate change scenarios at hourly time-step over Switzerland from an enhanced temporal downscaling approach. *International Journal of Climatology*, 41(6), 3503–3522. <https://doi.org/10.1002/joc.7032>
186
+ 3. Loustau, J. (2026). SwissWeatherGrid: hourly air temperature on a 1 km grid for Switzerland [Dataset, CC BY 4.0]. Zenodo. <https://doi.org/10.5281/zenodo.23674731>
187
+
188
+
189
+ ## Main contributors
190
+
191
+ * Joseph **Loustau**, IPESE, EPFL
192
+
193
+ ## License
194
+
195
+ Code: Apache License 2.0 — see [LICENSE](LICENSE). Data: CC BY 4.0, see
196
+ [the Zenodo record](https://doi.org/10.5281/zenodo.23674731).
@@ -0,0 +1,159 @@
1
+ # perfectdays
2
+
3
+ **`perfectdays`** retrieves the hourly temperature and irradiance for any point in Europe, and compress it into typical periods, ideal to reduce data dimensionality in modelling.
4
+
5
+ ![_Landscape_, Qian Du](https://swissweathergrid.readthedocs.io/en/latest/_images/landscape_qian_du.jpg)
6
+
7
+ It is developed by EPFL (Switzerland), within the *Industrial Process and Energy Systems Engineering (IPESE)* group.
8
+
9
+ This package is the weather module of models developed within the laboratory, such as [REHO](https://reho.readthedocs.io/en/main/) or [PinchSmall](https://pinchsmall.epfl.ch/docs/) - that you are encouraged to explore as well. Indeed, those models help taking decisions in the planning of energy systems - at the district-scale for _REHO_ - where external conditions are critical. Moreover, those decisions span over several long period of time, from 20 to 40 years, and therefore need forecasting of those conditions.
10
+
11
+ To this end the package has two purposes: providing reliable weather data, now and in the future, and compact them into typical periods.
12
+
13
+ This first aspect addresses:
14
+ * the lack of precision unveiled from common sources such as ERA5, a project where the grid resolution is at 30 km, which is not sufficient in the Alpine terrain where the temperature elevation gradient can change drastically within that distance.
15
+ * the absence of data at short time horizon (until 2050).
16
+
17
+ > **_SwissWeatherGrid_**
18
+ >
19
+ > This package gives therefore the possibility to build a 1km grid, _SwissWeatherGrid_, now or under a climate scenario (_RCPs_), reusing the interpolation methodology from MeteoSwiss [[1]](#references). This interpolation method is then reused to create a grid for the climate change scenarios from CH2025 and WSL's downscaling [[2]](#references).
20
+
21
+
22
+
23
+ ## Documentation
24
+
25
+ <https://swissweathergrid.readthedocs.io/>
26
+
27
+ ## Use
28
+
29
+ #### 1. Install
30
+
31
+ ```bash
32
+ pip install perfectdays
33
+ ```
34
+
35
+ To read grids from PostgreSQL, install the optional extra:
36
+
37
+ ```bash
38
+ pip install "perfectdays[postgres]"
39
+ ```
40
+
41
+ #### 2. Typical periods anywhere in Europe
42
+
43
+ ```python
44
+ from perfectdays import get_typical_periods
45
+
46
+ tp = get_typical_periods(46.52, 6.63, periods=10) # Lausanne
47
+ tp, quality = get_typical_periods(48.85, 2.35, years=[2019, 2020],
48
+ periods=10, clustering_evaluation=True)
49
+ quality.stability.plot()
50
+ ```
51
+
52
+ See the *Typical periods* page of the documentation.
53
+
54
+ #### 3. Hourly data for one Swiss point
55
+
56
+ ```python
57
+ from perfectdays.swissweathergrid import get_cell_weather
58
+
59
+ df = get_cell_weather(46.52, 6.63, 2023) # Lausanne, 8760 rows
60
+ ```
61
+
62
+ Coordinates are WGS84 degrees; the point is snapped to the 1 km cell containing
63
+ it. You get an hourly frame for the whole calendar year — 8760 rows, 8784 in a
64
+ leap year:
65
+
66
+ | column | unit | source |
67
+ |---|---|---|
68
+ | `temperature` | °C | the KED grid |
69
+ | `beam`, `diffuse` | W/m² | PVGIS, for the plane you asked for |
70
+ | `global_horizontal` | W/m² | `beam + diffuse` |
71
+
72
+ Pass `irradiance=False` for temperature only, or `slope=` and `azimuth=` for a
73
+ tilted plane.
74
+
75
+ #### 4. Choose a scenario
76
+
77
+ ```python
78
+ df = get_cell_weather(46.52, 6.63, 2023, scenario="rcp45_2045")
79
+ ```
80
+
81
+ A scenario is named `{pathway}_{year}`. A pathway says how the world gets warmer, a year says when you are
82
+ looking. Neither alone fixes a climate.
83
+
84
+ | part | values | meaning |
85
+ |---|---|---|
86
+ | pathway | `rcp26`, `rcp45`, `rcp85` | CH2018 emission pathway, 12 / 25 / 31 model chains |
87
+ | year | 1990–2100 | resolved to the WSL decade containing it |
88
+
89
+ `"current"` is the observed year, unwarmed.
90
+
91
+ The `year` argument stays the **base year** — the observed year being warmed.
92
+ So `scenario="rcp45_2045", year=2023` means "2023's weather, moved to the
93
+ climate of the 2040s under RCP4.5". The change is measured between the decade
94
+ containing your base year and the decade containing the scenario year, taken
95
+ from the same model chains, so the historical record cancels and only the
96
+ climate signal survives.
97
+
98
+
99
+ #### 5. What a scenario series may be used for
100
+
101
+ Each delivered year is a **continuous 8760-hour series** with real day-to-day
102
+ persistence, because the scenario warms an observed year rather than
103
+ synthesising one. What it is not is a moment in a trajectory.
104
+
105
+ **No transient series.** WSL provides decade snapshots, not a continuous run
106
+ through the century. The authors: "only snapshots for the future are provided
107
+ with discontinuities between them." Two scenario years are two separate
108
+ stationary climates, not two points on a path.
109
+
110
+ **No climate signal in the sub-daily cycle.** The delta is applied to a
111
+ historical hourly record, so the diurnal *shape* is inherited from the past.
112
+ What the method gets right is leaving that shape undistorted; what it cannot
113
+ tell you is how the shape itself changes.
114
+
115
+ **Only the change is usable.** The signal is a difference taken *inside* WSL,
116
+ between two decades of the same model chain, which cancels the bias of the
117
+ underlying record. Absolute scenario values do not carry over; differences and
118
+ ratios do.
119
+
120
+ In practice:
121
+
122
+ | you want | do |
123
+ |---|---|
124
+ | typical days, duration curves, monthly or seasonal statistics | fine — these use the distribution |
125
+ | a design day, a heating or cooling degree-hour total | fine |
126
+ | "what does 14 July 2045 look like" | **no** — the day order carries no information |
127
+ | a 2030 → 2040 → 2050 trajectory | **no** — the decades are separate stationary climates |
128
+ | a change in the shape of the daily cycle | **no** — inherited from the historical record |
129
+
130
+
131
+ ## Structure
132
+
133
+ | folder | what it does |
134
+ |---|---|
135
+ | `perfectdays/sources/` | hourly years from the Swiss grid, PVGIS or your files, in one shape |
136
+ | `perfectdays/clusteringfactory/` | typical periods by k-medoids (PAM), and their quality |
137
+ | `perfectdays/api/` | `get_weather`, `get_typical_periods`: source choice, fallback, output formats |
138
+ | `perfectdays/api/reho.py` | REHO's weather step, with REHO's arguments |
139
+ | `perfectdays/swissweathergrid/core/` | HTTP caching, LV95 coordinates, elevation, grid definition |
140
+ | `perfectdays/swissweathergrid/interpolation_method/` | rebuilds and validates the method of Frey & Frei (2025) |
141
+ | `perfectdays/swissweathergrid/grid_building/` | applies it to produce national grids per scenario and year |
142
+ | `perfectdays/swissweathergrid/cell_access/` | queries a grid for one location, and adds irradiance |
143
+
144
+
145
+ ## References
146
+
147
+ 1. Frey, L. & Frei, C. (2025). Interpolation of Hourly Surface Air Temperature — Application of a Spatio-Temporal Statistical Model in Complex Terrain. *International Journal of Climatology*, 45(7). <https://doi.org/10.1002/joc.8796>
148
+ 2. Michel, A., Sharma, V., Lehning, M. & Huwald, H. (2021). Climate change scenarios at hourly time-step over Switzerland from an enhanced temporal downscaling approach. *International Journal of Climatology*, 41(6), 3503–3522. <https://doi.org/10.1002/joc.7032>
149
+ 3. Loustau, J. (2026). SwissWeatherGrid: hourly air temperature on a 1 km grid for Switzerland [Dataset, CC BY 4.0]. Zenodo. <https://doi.org/10.5281/zenodo.23674731>
150
+
151
+
152
+ ## Main contributors
153
+
154
+ * Joseph **Loustau**, IPESE, EPFL
155
+
156
+ ## License
157
+
158
+ Code: Apache License 2.0 — see [LICENSE](LICENSE). Data: CC BY 4.0, see
159
+ [the Zenodo record](https://doi.org/10.5281/zenodo.23674731).
@@ -0,0 +1,14 @@
1
+ """Hourly weather anywhere in Europe, shaped into typical periods.
2
+
3
+ Three layers: `sources` (with `swissweathergrid`, the 1 km Swiss grid, and
4
+ PVGIS elsewhere) provides hourly years, `clusteringfactory` reduces them to
5
+ typical periods, and `api` picks a source for a location and returns the
6
+ shape a model asks for, REHO's included (`perfectdays.api.reho`).
7
+ """
8
+ from .api import reho
9
+ from .api.frontend import get_typical_periods, get_weather
10
+ from .clusteringfactory import ClusterQuality, TypicalPeriods, cluster_periods
11
+ from .sources import SourceUnavailable
12
+
13
+ __all__ = ["get_weather", "get_typical_periods", "cluster_periods",
14
+ "TypicalPeriods", "ClusterQuality", "SourceUnavailable", "reho"]
@@ -0,0 +1,13 @@
1
+ """The entry points other tools call: weather or typical periods for a place.
2
+
3
+ `get_weather` and `get_typical_periods` are the general entry points;
4
+ `reho` speaks REHO's arguments and writes REHO's files.
5
+ """
6
+ from . import reho
7
+ from .frontend import get_typical_periods, get_weather
8
+ from .reho import generate_weather_data, get_cluster_file_ID
9
+ from .routing import default_sources, load_weather
10
+
11
+ __all__ = ["get_weather", "get_typical_periods", "load_weather",
12
+ "default_sources", "reho", "generate_weather_data",
13
+ "get_cluster_file_ID"]
@@ -0,0 +1,42 @@
1
+ """Output shapes for typical periods."""
2
+ from __future__ import annotations
3
+
4
+ from pathlib import Path
5
+
6
+ import pandas as pd
7
+
8
+ from ...clusteringfactory.result import TypicalPeriods
9
+ from .reho import write_reho
10
+
11
+ FORMATS = ("typical", "dataframe", "reho", "csv")
12
+
13
+
14
+ def shape(tp: TypicalPeriods, output_format: str, weather: pd.DataFrame,
15
+ output_dir: str | Path | None = None):
16
+ """Typical periods in the requested shape.
17
+
18
+ - `"typical"`: the `TypicalPeriods` object itself.
19
+ - `"dataframe"`: one long frame, (period, hour) rows with a frequency.
20
+ - `"reho"`: REHO's weather files in `output_dir`; returns the directory.
21
+ - `"csv"`: `typical_periods.csv` and `assignment.csv` in `output_dir`;
22
+ returns the directory.
23
+ """
24
+ if output_format not in FORMATS:
25
+ raise ValueError(f"unknown output_format {output_format!r}: choose "
26
+ f"among {', '.join(map(repr, FORMATS))}")
27
+ if output_format == "typical":
28
+ return tp
29
+ if output_format == "dataframe":
30
+ return tp.to_frame()
31
+ if output_dir is None:
32
+ raise ValueError(f"output_format {output_format!r} needs output_dir")
33
+ if output_format == "reho":
34
+ return write_reho(tp, output_dir, weather)
35
+ directory = Path(output_dir)
36
+ directory.mkdir(parents=True, exist_ok=True)
37
+ tp.to_frame().to_csv(directory / "typical_periods.csv")
38
+ tp.assignment.to_csv(directory / "assignment.csv")
39
+ return directory
40
+
41
+
42
+ __all__ = ["shape", "write_reho", "FORMATS"]