meteoraster 2.5__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.
- meteoraster-2.5/LICENSE +202 -0
- meteoraster-2.5/MANIFEST.in +3 -0
- meteoraster-2.5/NOTICE +18 -0
- meteoraster-2.5/PKG-INFO +419 -0
- meteoraster-2.5/README.md +367 -0
- meteoraster-2.5/meteoraster/__init__.py +5 -0
- meteoraster-2.5/meteoraster/meteoraster.py +1267 -0
- meteoraster-2.5/meteoraster/resample.py +269 -0
- meteoraster-2.5/meteoraster/utils.py +359 -0
- meteoraster-2.5/meteoraster.egg-info/PKG-INFO +419 -0
- meteoraster-2.5/meteoraster.egg-info/SOURCES.txt +20 -0
- meteoraster-2.5/meteoraster.egg-info/dependency_links.txt +1 -0
- meteoraster-2.5/meteoraster.egg-info/requires.txt +30 -0
- meteoraster-2.5/meteoraster.egg-info/top_level.txt +1 -0
- meteoraster-2.5/pyproject.toml +76 -0
- meteoraster-2.5/setup.cfg +4 -0
- meteoraster-2.5/tests/conftest.py +149 -0
- meteoraster-2.5/tests/test_deprecations.py +29 -0
- meteoraster-2.5/tests/test_meteo_raster_base.py +217 -0
- meteoraster-2.5/tests/test_meteo_raster_extra.py +69 -0
- meteoraster-2.5/tests/test_meteo_raster_plots.py +154 -0
- meteoraster-2.5/tests/test_resample.py +32 -0
meteoraster-2.5/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
meteoraster-2.5/NOTICE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
meteoraster
|
|
2
|
+
Copyright 2025-2026 Jose Pedro Matos and contributors
|
|
3
|
+
|
|
4
|
+
This product includes software developed at FORESIGHT,
|
|
5
|
+
Instituto Superior Tecnico, Universidade de Lisboa
|
|
6
|
+
(https://foresight.tecnico.ulisboa.pt/).
|
|
7
|
+
|
|
8
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
you may not use this file except in compliance with the License.
|
|
10
|
+
You may obtain a copy of the License at
|
|
11
|
+
|
|
12
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
|
|
14
|
+
Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
See the License for the specific language governing permissions and
|
|
18
|
+
limitations under the License.
|
meteoraster-2.5/PKG-INFO
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: meteoraster
|
|
3
|
+
Version: 2.5
|
|
4
|
+
Summary: Module for handling distributed ensemble and probabilistic forecast data (5-D meteorological rasters)
|
|
5
|
+
Author-email: Jose Pedro Matos <jose.matos@tecnico.ulisboa.pt>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/FORESIGHT-ULisboa/Tethys-meteoraster
|
|
8
|
+
Project-URL: Repository, https://github.com/FORESIGHT-ULisboa/Tethys-meteoraster
|
|
9
|
+
Project-URL: Issues, https://github.com/FORESIGHT-ULisboa/Tethys-meteoraster/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/FORESIGHT-ULisboa/Tethys-meteoraster/releases
|
|
11
|
+
Project-URL: FORESIGHT, https://foresight.tecnico.ulisboa.pt/
|
|
12
|
+
Keywords: meteorology,forecast,ensemble,raster,netcdf,ERA5,GFS,C3S,CORDEX
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
License-File: NOTICE
|
|
24
|
+
Requires-Dist: numpy<2
|
|
25
|
+
Requires-Dist: scipy
|
|
26
|
+
Requires-Dist: pandas
|
|
27
|
+
Requires-Dist: xarray
|
|
28
|
+
Requires-Dist: netcdf4
|
|
29
|
+
Requires-Dist: h5netcdf
|
|
30
|
+
Requires-Dist: cfgrib
|
|
31
|
+
Requires-Dist: cdsapi
|
|
32
|
+
Requires-Dist: scikit-learn
|
|
33
|
+
Requires-Dist: matplotlib
|
|
34
|
+
Requires-Dist: seaborn
|
|
35
|
+
Requires-Dist: statsmodels
|
|
36
|
+
Requires-Dist: cartopy
|
|
37
|
+
Requires-Dist: beautifulsoup4
|
|
38
|
+
Requires-Dist: openpyxl
|
|
39
|
+
Provides-Extra: test
|
|
40
|
+
Requires-Dist: pytest; extra == "test"
|
|
41
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
42
|
+
Provides-Extra: build
|
|
43
|
+
Requires-Dist: build; extra == "build"
|
|
44
|
+
Requires-Dist: twine; extra == "build"
|
|
45
|
+
Provides-Extra: dev
|
|
46
|
+
Requires-Dist: pytest; extra == "dev"
|
|
47
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
48
|
+
Requires-Dist: build; extra == "dev"
|
|
49
|
+
Requires-Dist: twine; extra == "dev"
|
|
50
|
+
Requires-Dist: jupyterlab; extra == "dev"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
<p align="center">
|
|
54
|
+
<img src="images/foresight.png" alt="FORESIGHT" width="320">
|
|
55
|
+
</p>
|
|
56
|
+
|
|
57
|
+
# Tethys meteoraster
|
|
58
|
+
|
|
59
|
+
<p align="center">
|
|
60
|
+
<a href="https://pypi.org/project/meteoraster/"><img src="https://img.shields.io/pypi/v/meteoraster.svg" alt="PyPI version"></a>
|
|
61
|
+
<a href="https://pypi.org/project/meteoraster/"><img src="https://img.shields.io/pypi/pyversions/meteoraster.svg" alt="Supported Python versions"></a>
|
|
62
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-blue.svg" alt="License: Apache-2.0"></a>
|
|
63
|
+
</p>
|
|
64
|
+
|
|
65
|
+
**`meteoraster`** is a Python library, developed by [FORESIGHT — Forecasting and
|
|
66
|
+
Optimization for Resilient Environmental Systems through Investigation with
|
|
67
|
+
Groundbreaking Hydrological Tools](https://foresight.tecnico.ulisboa.pt/), for
|
|
68
|
+
**handling distributed ensemble and probabilistic meteorological forecasts**.
|
|
69
|
+
|
|
70
|
+
Its core data structure, `MeteoRaster`, holds a single **5-D** array indexed by
|
|
71
|
+
`[production_datetime, ensemble_member, leadtime, latitude, longitude]`, and
|
|
72
|
+
wraps it with everything you need to turn raw reanalysis/forecast files into
|
|
73
|
+
report-ready time series, maps and aggregated statistics:
|
|
74
|
+
|
|
75
|
+
- read ERA5, ERA5-Land, GFS, C3S (seasonal) and CORDEX files into a common model,
|
|
76
|
+
- crop, join, trim, resample and check the completeness of the data,
|
|
77
|
+
- extract point time series or **catchment/zone aggregates from KML polygons**
|
|
78
|
+
(area-weighted, missing-data aware),
|
|
79
|
+
- persist to compressed NetCDF (`h5netcdf`) and reload losslessly,
|
|
80
|
+
- and plot means, seasonal cycles, coordinates and availability with `cartopy`.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Features
|
|
85
|
+
|
|
86
|
+
| Category | What you get |
|
|
87
|
+
|---|---|
|
|
88
|
+
| **Data model** | `MeteoRaster` — 5-D `[production_datetime, ensemble_member, leadtime, lat, lon]`; 2-D lat/lon grids; automatic Greenwich (0–360 → −180–180) fix and latitude flip |
|
|
89
|
+
<!-- | **Format readers** | `readERA5_monthly`, `readERA5Land_monthly`, `read_ERA5Land_hourly`, `read_GFS`, `read_C3S`, `readCORDEX_monthly` | -->
|
|
90
|
+
| **Subsetting / merging** | `get_cropped`, `join`, `trim`, `adjust_leadtimes` |
|
|
91
|
+
| **Resampling** | `resample_timestep` (pandas rules) and the standalone `Resample` class |
|
|
92
|
+
| **Extraction** | `get_values_from_latlon`, `get_values_from_KML`, `get_quantiles_from_KML`*, `get_values_from_latlon_by_event` |
|
|
93
|
+
| **Spatial aggregation** | area-weighted coverage matrices from KML polygons, missing-data aware |
|
|
94
|
+
| **Quality / diagnostics** | `is_complete`, `get_complete_index`, `get_missing`, `get_completeness` |
|
|
95
|
+
| **I/O** | `save` / `load` (compressed NetCDF via `h5netcdf`), `to_xarray` |
|
|
96
|
+
| **Visualisation** | `plot_mean`, `plot_mean_projected`, `plot_seasonal`, `plot_coordinates`, `plot_availability`, `add_shapefile`, `add_shape` |
|
|
97
|
+
|
|
98
|
+
\* `get_quantiles_from_KML` is currently under review and not functional — see
|
|
99
|
+
[AGENTS.md](AGENTS.md).
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Installation
|
|
104
|
+
|
|
105
|
+
`meteoraster` relies on a geospatial stack (**GDAL/`osgeo`**, `cartopy`, `cfgrib`)
|
|
106
|
+
that is most reliably installed with **conda**. Two paths follow: install the
|
|
107
|
+
**released package from PyPI** on top of a conda environment (use the package), or
|
|
108
|
+
install **from source** (develop / run the tests).
|
|
109
|
+
|
|
110
|
+
### A · Install from PyPI
|
|
111
|
+
|
|
112
|
+
Create a conda environment that provides the geospatial libraries, then install
|
|
113
|
+
[`meteoraster`](https://pypi.org/project/meteoraster/) into it:
|
|
114
|
+
|
|
115
|
+
```bat
|
|
116
|
+
conda env create -f environment.yml
|
|
117
|
+
conda activate tethys_rasters
|
|
118
|
+
pip install meteoraster
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Upgrading later needs no URL — `pip install --upgrade meteoraster` always picks up
|
|
122
|
+
the newest release.
|
|
123
|
+
|
|
124
|
+
> The package declares its pure-Python dependencies, but **GDAL is intentionally
|
|
125
|
+
> not** a pip dependency (it is a system/conda package). The conda environment
|
|
126
|
+
> above provides it. If you only need the point/plotting features and already
|
|
127
|
+
> have GDAL, you can `pip install meteoraster` into any environment.
|
|
128
|
+
|
|
129
|
+
Every release is also attached to the
|
|
130
|
+
[GitHub releases page](https://github.com/FORESIGHT-ULisboa/Tethys-meteoraster/releases),
|
|
131
|
+
which is useful to pin an exact build without going through PyPI:
|
|
132
|
+
|
|
133
|
+
```bat
|
|
134
|
+
pip install https://github.com/FORESIGHT-ULisboa/Tethys-meteoraster/releases/download/v2.5/meteoraster-2.5-py3-none-any.whl
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### B · Install from source (development)
|
|
138
|
+
|
|
139
|
+
#### 1 · Create the conda environment
|
|
140
|
+
|
|
141
|
+
```bat
|
|
142
|
+
conda env create -f environment.yml
|
|
143
|
+
conda activate tethys_rasters
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
#### 2 · Install the package (editable) with the dev extras
|
|
147
|
+
|
|
148
|
+
From the repository root:
|
|
149
|
+
|
|
150
|
+
```bat
|
|
151
|
+
pip install -e ".[dev]"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
That adds `pytest`, `pytest-cov`, `build`, `twine` and `jupyterlab` on top of the
|
|
155
|
+
runtime dependencies.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Quick start
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
import numpy as np
|
|
163
|
+
import pandas as pd
|
|
164
|
+
from meteoraster import MeteoRaster
|
|
165
|
+
|
|
166
|
+
# data axes: [production_datetime, ensemble_member, leadtime, lat, lon]
|
|
167
|
+
data = np.random.rand(2, 3, 2, 4, 5)
|
|
168
|
+
|
|
169
|
+
mr = MeteoRaster(
|
|
170
|
+
data=data,
|
|
171
|
+
latitudes=np.linspace(40, 30, 4), # 1-D is auto-meshed to 2-D
|
|
172
|
+
longitudes=np.linspace(-10, 10, 5),
|
|
173
|
+
production_datetime=pd.to_datetime(["2023-01-01", "2023-01-02"]).values,
|
|
174
|
+
leadtimes=np.array([pd.Timedelta(days=1), pd.Timedelta(days=2)]),
|
|
175
|
+
units="mm",
|
|
176
|
+
variable="precip",
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Read a real dataset
|
|
181
|
+
|
|
182
|
+
The readers live in `meteoraster.utils` and return a ready-to-use `MeteoRaster`:
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
from meteoraster.utils import readERA5Land_monthly, read_C3S
|
|
186
|
+
|
|
187
|
+
era5 = readERA5Land_monthly("era5land_tp.grib", "tp") # total precipitation
|
|
188
|
+
c3s = read_C3S("seasonal_t2m.grib", "t2m") # seasonal 2 m temperature
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Extract a point time series
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
# DataFrame: index = production_datetime, columns = MultiIndex(leadtime, ensemble_member)
|
|
195
|
+
ts = mr.get_values_from_latlon(lat=35.0, lon=0.0)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Aggregate over KML zones (e.g. catchments)
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
# agg: DataFrame indexed by production date, columns MultiIndex(zone, leadtime, ensemble_member)
|
|
202
|
+
# centroids: DataFrame of zone centroids (x, y)
|
|
203
|
+
agg, centroids = mr.get_values_from_KML("zones.kml", nameField="zone_id")
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Crop, save and reload
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
sub = mr.get_cropped(from_lat=32, to_lat=38, from_lon=-2, to_lon=7,
|
|
210
|
+
from_prod_date=pd.Timestamp("2023-01-02"))
|
|
211
|
+
|
|
212
|
+
sub.save("forecast.nc") # compressed NetCDF (h5netcdf)
|
|
213
|
+
reloaded = MeteoRaster.load("forecast.nc")
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Resample in time
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
import numpy as np
|
|
220
|
+
|
|
221
|
+
mr.resample_timestep("MS", fun=np.nanmean) # to month start, ensemble-wise
|
|
222
|
+
|
|
223
|
+
# Or resample a production×leadtime DataFrame with the standalone helper:
|
|
224
|
+
from meteoraster import Resample
|
|
225
|
+
resampled = Resample.resample(df, timestep_frequency="1D", resamplingType="sum")
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Plot
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
ax, cbar = mr.plot_mean(central_longitude=0, coastline=True, borders=True,
|
|
232
|
+
colorbar=True, cmap="viridis")
|
|
233
|
+
mr.add_shapefile(ax, "basin.shp")
|
|
234
|
+
mr.plot_seasonal(lat=35.0, lon=0.0)
|
|
235
|
+
mr.plot_availability()
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Project structure
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
Tethys-meteoraster/
|
|
244
|
+
├── meteoraster/
|
|
245
|
+
│ ├── __init__.py # exports MeteoRaster, Resample
|
|
246
|
+
│ ├── meteoraster.py # MeteoRaster core class
|
|
247
|
+
│ ├── resample.py # Resample (time-step resampling of DataFrames)
|
|
248
|
+
│ └── utils.py # ERA5 / ERA5-Land / GFS / C3S / CORDEX readers
|
|
249
|
+
├── tests/ # pytest suite + fixtures (conftest.py)
|
|
250
|
+
├── images/foresight.png # README header
|
|
251
|
+
├── environment.yml # conda environment (tethys_rasters)
|
|
252
|
+
├── pyproject.toml # packaging + pytest configuration
|
|
253
|
+
├── AGENTS.md # canonical guidance for humans & AI agents
|
|
254
|
+
├── CLAUDE.md # → points to AGENTS.md
|
|
255
|
+
├── .github/copilot-instructions.md # → points to AGENTS.md
|
|
256
|
+
├── .github/workflows/release.yml # build + publish to PyPI on tag push
|
|
257
|
+
├── .github/scripts/check_version.py # release guard: version declared consistently
|
|
258
|
+
├── LICENSE # Apache 2.0
|
|
259
|
+
├── NOTICE # attribution required by Apache 2.0
|
|
260
|
+
└── README.md
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Running the tests
|
|
266
|
+
|
|
267
|
+
```bat
|
|
268
|
+
conda activate tethys_rasters
|
|
269
|
+
pip install -e ".[dev]"
|
|
270
|
+
pytest -ra
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
The suite covers construction, cropping, point/KML extraction, NetCDF
|
|
274
|
+
round-trips, completeness checks, resampling and the deprecated-alias warnings.
|
|
275
|
+
Tests that need real GRIB/NetCDF inputs (the format readers) are out of scope and
|
|
276
|
+
not included.
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Building a distribution (wheel + sdist)
|
|
281
|
+
|
|
282
|
+
The package builds with the standard [PEP 517](https://peps.python.org/pep-0517/)
|
|
283
|
+
toolchain:
|
|
284
|
+
|
|
285
|
+
```bat
|
|
286
|
+
conda activate tethys_rasters
|
|
287
|
+
pip install -e ".[build]"
|
|
288
|
+
python -m build
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
This produces both artifacts in `dist/`:
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
dist/
|
|
295
|
+
├── meteoraster-2.5-py3-none-any.whl
|
|
296
|
+
└── meteoraster-2.5.tar.gz
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Install the wheel anywhere (provided GDAL is available):
|
|
300
|
+
|
|
301
|
+
```bat
|
|
302
|
+
pip install dist/meteoraster-2.5-py3-none-any.whl
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Notes:
|
|
306
|
+
- The version lives in [pyproject.toml](pyproject.toml) (`project.version`) and is
|
|
307
|
+
mirrored in `MeteoRaster.VERSION` — bump both together.
|
|
308
|
+
[.github/scripts/check_version.py](.github/scripts/check_version.py) enforces
|
|
309
|
+
that at release time.
|
|
310
|
+
- Building by hand is only needed to inspect an artifact locally. Actual releases
|
|
311
|
+
are produced by CI — see [Releasing](#releasing) below.
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
## Releasing
|
|
316
|
+
|
|
317
|
+
Releases are automated by
|
|
318
|
+
[.github/workflows/release.yml](.github/workflows/release.yml). To cut version
|
|
319
|
+
`X.Y`:
|
|
320
|
+
|
|
321
|
+
1. Bump the version in **both** [pyproject.toml](pyproject.toml) and
|
|
322
|
+
`MeteoRaster.VERSION`, then commit.
|
|
323
|
+
2. Tag and push:
|
|
324
|
+
|
|
325
|
+
```bat
|
|
326
|
+
git tag vX.Y
|
|
327
|
+
git push origin vX.Y
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
The workflow then verifies the two version declarations agree with the tag, builds
|
|
331
|
+
the wheel and sdist, runs `twine check --strict`, publishes to
|
|
332
|
+
[PyPI](https://pypi.org/project/meteoraster/), and attaches both artifacts to the
|
|
333
|
+
GitHub release.
|
|
334
|
+
|
|
335
|
+
To rehearse without touching PyPI, run the workflow manually from the **Actions**
|
|
336
|
+
tab and leave the target as `testpypi`; it builds and uploads to
|
|
337
|
+
[TestPyPI](https://test.pypi.org/project/meteoraster/) with no tag required.
|
|
338
|
+
|
|
339
|
+
> **PyPI uploads are immutable** — a version number can never be reused, even
|
|
340
|
+
> after deletion. Get the version right before pushing the tag.
|
|
341
|
+
|
|
342
|
+
Authentication uses [PyPI Trusted Publishing](https://docs.pypi.org/trusted-publishers/)
|
|
343
|
+
(OIDC), so no API tokens are stored in the repository. The one-time setup is
|
|
344
|
+
described in [AGENTS.md](AGENTS.md).
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## API reference
|
|
349
|
+
|
|
350
|
+
### `MeteoRaster`
|
|
351
|
+
|
|
352
|
+
**Construction & conversion**
|
|
353
|
+
|
|
354
|
+
| Member | Description |
|
|
355
|
+
|---|---|
|
|
356
|
+
| `MeteoRaster(data, latitudes, longitudes, production_datetime, leadtimes, units='unknown', variable='unknown', …)` | Build from a 5-D array (or a dict with the same keys). 1-D lat/lon are auto-meshed to 2-D; longitudes are wrapped to [−180, 180] and latitudes flipped if needed. |
|
|
357
|
+
| `copy()` | Deep copy. |
|
|
358
|
+
| `to_xarray()` | Convert to a labelled `xarray.DataArray`. |
|
|
359
|
+
|
|
360
|
+
**Subsetting, merging & resampling**
|
|
361
|
+
|
|
362
|
+
| Member | Description |
|
|
363
|
+
|---|---|
|
|
364
|
+
| `get_cropped(from_prod_date, to_prod_date, from_lat, to_lat, from_lon, to_lon, from_leadtime, to_leadtime)` | Crop in time and space; returns a new `MeteoRaster`. |
|
|
365
|
+
| `join(meteoRaster, strickt=False, trim=False)` | Concatenate another raster along production dates (aligns ensembles/leadtimes). |
|
|
366
|
+
| `trim()` | Drop leading/trailing all-NaN production dates. |
|
|
367
|
+
| `adjust_leadtimes(period='months')` | Align leadtimes to relative periods (experimental). |
|
|
368
|
+
| `resample_timestep(rule, fun=np.mean)` | Resample production dates with pandas rules (experimental). |
|
|
369
|
+
|
|
370
|
+
**Extraction & aggregation**
|
|
371
|
+
|
|
372
|
+
| Member | Description |
|
|
373
|
+
|---|---|
|
|
374
|
+
| `get_values_from_latlon(lat, lon)` | Time series from the nearest pixel as a `DataFrame`. |
|
|
375
|
+
| `get_values_from_KML(kml, nameField=None, …)` | Area-weighted aggregate over KML polygons → `(agg, centroids)`. |
|
|
376
|
+
| `get_quantiles_from_KML(...)` | Spatial quantiles over KML zones — **under review, not functional**. |
|
|
377
|
+
| `get_values_from_latlon_by_event(production_date_dataframe)` | *(static)* Reindex a production-date frame by event date. |
|
|
378
|
+
|
|
379
|
+
**Quality & diagnostics**
|
|
380
|
+
|
|
381
|
+
| Member | Description |
|
|
382
|
+
|---|---|
|
|
383
|
+
| `is_complete(full_ensemble=True, space_completeness=False)` | Whether every production×leadtime slice has finite data. |
|
|
384
|
+
| `get_complete_index(full_ensemble=True, space_completeness=False)` | Boolean `DataFrame` (production × leadtime) of completeness. |
|
|
385
|
+
| `get_missing()` | Fraction of missing pixels per leadtime/ensemble member. |
|
|
386
|
+
| `get_completeness(file)` | *(classmethod)* Read the `complete` flag from a saved file. |
|
|
387
|
+
|
|
388
|
+
**I/O**
|
|
389
|
+
|
|
390
|
+
| Member | Description |
|
|
391
|
+
|---|---|
|
|
392
|
+
| `save(file, complevel=1, complete=None)` | Write compressed NetCDF via `h5netcdf`. |
|
|
393
|
+
| `load(file, verbose=None)` | *(classmethod)* Reload a NetCDF written by `save`. |
|
|
394
|
+
|
|
395
|
+
**Visualisation**
|
|
396
|
+
|
|
397
|
+
| Member | Description |
|
|
398
|
+
|---|---|
|
|
399
|
+
| `create_plot(central_longitude, …)` | Create a `cartopy` axes. |
|
|
400
|
+
| `plot_mean(ax=None, coastline=False, borders=False, colorbar=True, cmap='viridis', …)` | Map of the ensemble/temporal mean → `(ax, cbar)`. |
|
|
401
|
+
| `plot_mean_projected`, `plot_coordinates`, `plot_seasonal`, `plot_availability` | Projected mean, grid coordinates, seasonal cycle, data availability. |
|
|
402
|
+
| `add_shapefile(ax, shapefile_path, …)` / `add_shape(ax, path, …)` | Overlay shapefile geometries/boundaries. |
|
|
403
|
+
|
|
404
|
+
> Deprecated camelCase aliases (`getCropped`, `getValuesFromKML`,
|
|
405
|
+
> `getDataFromLatLon`, `getQuantilesFromKML`, `resampleTimeStep`) still work but
|
|
406
|
+
> emit a `DeprecationWarning`; use the snake_case names above.
|
|
407
|
+
|
|
408
|
+
### `Resample`
|
|
409
|
+
|
|
410
|
+
| Member | Description |
|
|
411
|
+
|---|---|
|
|
412
|
+
| `Resample.resample(data, timestep_frequency, resamplingType, date_from=None, date_to=None, print_func=None)` | *(classmethod)* Resample a production×leadtime `DataFrame`. `resamplingType` ∈ {`'sum'`, `'mean'`, `'linear'`, `'max'`}. |
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
## License
|
|
417
|
+
|
|
418
|
+
Licensed under the **Apache License, Version 2.0** — see [LICENSE](LICENSE) and
|
|
419
|
+
[NOTICE](NOTICE).
|