cavapy 2.0.2__tar.gz → 2.0.4__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.
Potentially problematic release.
This version of cavapy might be problematic. Click here for more details.
- cavapy-2.0.4/LICENSE +202 -0
- cavapy-2.0.4/PKG-INFO +342 -0
- cavapy-2.0.4/README.md +311 -0
- {cavapy-2.0.2 → cavapy-2.0.4}/cavapy/__init__.py +1 -1
- {cavapy-2.0.2 → cavapy-2.0.4}/cavapy/cava_config.py +1 -0
- {cavapy-2.0.2 → cavapy-2.0.4}/pyproject.toml +1 -1
- cavapy-2.0.2/LICENSE +0 -674
- cavapy-2.0.2/PKG-INFO +0 -285
- cavapy-2.0.2/README.md +0 -254
- {cavapy-2.0.2 → cavapy-2.0.4}/cavapy/cava_bias.py +0 -0
- {cavapy-2.0.2 → cavapy-2.0.4}/cavapy/cava_download.py +0 -0
- {cavapy-2.0.2 → cavapy-2.0.4}/cavapy/cava_plot.py +0 -0
- {cavapy-2.0.2 → cavapy-2.0.4}/cavapy/cava_validation.py +0 -0
- {cavapy-2.0.2 → cavapy-2.0.4}/cavapy/cavapy.py +0 -0
cavapy-2.0.4/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.
|
cavapy-2.0.4/PKG-INFO
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cavapy
|
|
3
|
+
Version: 2.0.4
|
|
4
|
+
Summary: CAVA Python package. Retrive climate data.
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: Riccardo Soldan
|
|
8
|
+
Author-email: riccardosoldan@hotmail.it
|
|
9
|
+
Requires-Python: >=3.11,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Requires-Dist: bottleneck
|
|
18
|
+
Requires-Dist: cartopy
|
|
19
|
+
Requires-Dist: dask
|
|
20
|
+
Requires-Dist: llvmlite
|
|
21
|
+
Requires-Dist: matplotlib
|
|
22
|
+
Requires-Dist: netcdf4
|
|
23
|
+
Requires-Dist: pydap
|
|
24
|
+
Requires-Dist: seaborn
|
|
25
|
+
Requires-Dist: tqdm
|
|
26
|
+
Requires-Dist: xclim
|
|
27
|
+
Requires-Dist: xsdba
|
|
28
|
+
Project-URL: Repository, https://github.com/Risk-Team/cavapy
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
<p align="center">
|
|
32
|
+
<img src="figures/cavapy_logo.svg" alt="cavapy logo" width="760">
|
|
33
|
+
</p>
|
|
34
|
+
|
|
35
|
+
<p align="center">
|
|
36
|
+
<a href="https://pypi.org/project/cavapy/"><img src="https://img.shields.io/pypi/v/cavapy?label=PyPI&style=for-the-badge" alt="PyPI version"></a>
|
|
37
|
+
<a href="https://pepy.tech/project/cavapy"><img src="https://img.shields.io/pepy/dt/cavapy?style=for-the-badge&label=Downloads" alt="Total downloads"></a>
|
|
38
|
+
<img src="https://img.shields.io/badge/Python-3.11%2B-1f6feb?style=for-the-badge" alt="Python 3.11+">
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
<p align="center">
|
|
42
|
+
Retrieve, subset, and process CORDEX-CORE and ERA5 climate data directly from THREDDS/OPeNDAP.
|
|
43
|
+
</p>
|
|
44
|
+
|
|
45
|
+
<p align="center">
|
|
46
|
+
<a href="https://github.com/risk-team/cavapy/stargazers">Star this project on GitHub</a>
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## What is cavapy?
|
|
52
|
+
|
|
53
|
+
Working with CORDEX-CORE climate projections normally means downloading terabytes of raw NetCDF files, reprojecting from rotated polar coordinates to regular lat/lon, writing boilerplate to handle non-Gregorian calendars, converting units, subsetting grids, wrangling multi-model ensembles, and layering bias correction on top. All before you can run a single analysis.
|
|
54
|
+
|
|
55
|
+
`cavapy` collapses all of that into one function call.
|
|
56
|
+
|
|
57
|
+
It streams only the spatial slice you need over OPeNDAP (no local archive required) and returns analysis-ready `xarray.DataArray` objects with consistent units, a standard Gregorian calendar, and optional bias correction already applied.
|
|
58
|
+
|
|
59
|
+
It is part of the [CAVA](https://risk-team.github.io/CAVAanalytics/articles/CAVA.html) (Climate and Agriculture Risk Visualization and Assessment) ecosystem, a joint initiative of FAO, the University of Cantabria, the University of Cape Town, and Predictia.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## What gets handled automatically
|
|
64
|
+
|
|
65
|
+
A single `get_climate_data()` call orchestrates a full pipeline:
|
|
66
|
+
|
|
67
|
+
| Step | What happens |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| **Inventory lookup** | Resolves the correct OPeNDAP URL(s) for your GCM/RCM/RCP/domain combination from a live THREDDS inventory |
|
|
70
|
+
| **Spatial subsetting** | Streams only the grid cells inside your country or bounding box — no full-file downloads |
|
|
71
|
+
| **Country → bbox** | Converts a country name to a precise bounding box using Natural Earth shapefiles |
|
|
72
|
+
| **Unit conversion** | K → °C for temperature; kg m⁻² s⁻¹ → mm/day for precipitation; J/m² → W/m² for solar radiation; 10 m → 2 m for wind speed |
|
|
73
|
+
| **Regridding** | CORDEX outputs are natively in rotated polar coordinates; the data served here has already been regridded to a regular lat/lon grid, so standard spatial operations work out of the box |
|
|
74
|
+
| **Calendar harmonization** | Converts 360-day and other non-Gregorian CORDEX calendars to Gregorian, filling gaps with NaN |
|
|
75
|
+
| **Parallelization** | Variables are fetched in parallel processes; within each process, threaded downloads handle multi-file retrieval |
|
|
76
|
+
| **Fault tolerance** | OPeNDAP connections retry up to 3 times with backoff; C-level noise is suppressed on intermediate attempts |
|
|
77
|
+
| **Bias correction** | ERA5 is automatically fetched as the reference; EQM is trained and applied — no external tools needed |
|
|
78
|
+
| **Domain validation** | If your bounding box falls outside the chosen CORDEX domain, a corrected domain is suggested |
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Data Coverage
|
|
83
|
+
|
|
84
|
+
### Sources
|
|
85
|
+
|
|
86
|
+
- CORDEX-CORE regional climate simulations (25 km)
|
|
87
|
+
- ERA5 reanalysis (used directly and as the reference for bias correction)
|
|
88
|
+
|
|
89
|
+
Data is hosted on the University of Cantabria THREDDS infrastructure.
|
|
90
|
+
|
|
91
|
+
### Available datasets
|
|
92
|
+
|
|
93
|
+
- **`CORDEX-CORE`** — original model outputs. Use this when you want raw projections or when you will apply your own post-processing.
|
|
94
|
+
- **`CORDEX-CORE-BC`** — pre-bias-corrected outputs. The full CORDEX-CORE archive was corrected against ERA5 reanalysis using the [ISIMIP3 methodology](https://www.isimip.org/documents/413/ISIMIP3b_bias_adjustment_fact_sheet_GCMs_v2.pdf) (trend-preserving quantile mapping). Use this dataset when you need a consistent, ready-to-use ensemble with no additional processing.
|
|
95
|
+
|
|
96
|
+
### Available variables
|
|
97
|
+
|
|
98
|
+
| Variable | Description | Units |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| `tas` | Daily mean temperature | °C |
|
|
101
|
+
| `tasmax` | Daily maximum temperature | °C |
|
|
102
|
+
| `tasmin` | Daily minimum temperature | °C |
|
|
103
|
+
| `pr` | Daily precipitation | mm/day |
|
|
104
|
+
| `hurs` | Daily relative humidity | % |
|
|
105
|
+
| `sfcWind` | Daily wind speed at 2 m | m/s |
|
|
106
|
+
| `rsds` | Daily solar radiation | W/m² |
|
|
107
|
+
|
|
108
|
+
### Supported domains and scenario/model options
|
|
109
|
+
|
|
110
|
+
- **Domains**: `NAM-22`, `EUR-22`, `AFR-22`, `EAS-22`, `SEA-22`, `WAS-22`, `AUS-22`, `SAM-22`, `CAM-22`
|
|
111
|
+
- **RCPs**: `rcp26`, `rcp85`
|
|
112
|
+
- **GCMs**: `MOHC`, `MPI`, `NCC`
|
|
113
|
+
- **RCMs**: `REMO`, `Reg`
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Installation
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
conda create -n cavapy "python>=3.11"
|
|
121
|
+
conda activate cavapy
|
|
122
|
+
pip install cavapy
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Quick Start
|
|
128
|
+
|
|
129
|
+
### 1) Pre-bias-corrected projections (recommended)
|
|
130
|
+
|
|
131
|
+
Uses `CORDEX-CORE-BC`: the full CORDEX archive already corrected against ERA5 using the ISIMIP3 methodology. No further correction is applied at download time.
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
import cavapy
|
|
135
|
+
|
|
136
|
+
togo = cavapy.get_climate_data(
|
|
137
|
+
country="Togo",
|
|
138
|
+
variables=["tasmax", "pr"],
|
|
139
|
+
cordex_domain="AFR-22",
|
|
140
|
+
rcp="rcp26",
|
|
141
|
+
gcm="MPI",
|
|
142
|
+
rcm="REMO",
|
|
143
|
+
years_up_to=2030,
|
|
144
|
+
dataset="CORDEX-CORE-BC",
|
|
145
|
+
)
|
|
146
|
+
# Returns: {"tasmax": xr.DataArray, "pr": xr.DataArray}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 2) Original CORDEX-CORE with on-the-fly bias correction
|
|
150
|
+
|
|
151
|
+
When `bias_correction=True`, cavapy automatically fetches ERA5 for the historical period and applies **Empirical Quantile Mapping (EQM)** via [xsdba](https://xsdba.readthedocs.io). Historical bias correction uses leave-one-out cross-validation to avoid overfitting. Multiplicative scaling is applied for precipitation, wind, and radiation; additive for temperature and humidity. This is useful when you need custom period or region coverage beyond the pre-corrected archive.
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
import cavapy
|
|
155
|
+
|
|
156
|
+
togo = cavapy.get_climate_data(
|
|
157
|
+
country="Togo",
|
|
158
|
+
variables=["tasmax", "pr"],
|
|
159
|
+
cordex_domain="AFR-22",
|
|
160
|
+
rcp="rcp26",
|
|
161
|
+
gcm="MPI",
|
|
162
|
+
rcm="REMO",
|
|
163
|
+
years_up_to=2030,
|
|
164
|
+
bias_correction=True,
|
|
165
|
+
dataset="CORDEX-CORE",
|
|
166
|
+
)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 3) ERA5 observations only
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
import cavapy
|
|
173
|
+
|
|
174
|
+
era5 = cavapy.get_climate_data(
|
|
175
|
+
country="Togo",
|
|
176
|
+
variables=["tasmax", "pr"],
|
|
177
|
+
obs=True,
|
|
178
|
+
years_obs=range(1980, 2019),
|
|
179
|
+
)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Core Workflows
|
|
185
|
+
|
|
186
|
+
### Projections + historical baseline
|
|
187
|
+
|
|
188
|
+
Setting `historical=True` fetches the 1980–2005 historical simulation run and concatenates it with the projection period, giving a continuous time series.
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
import cavapy
|
|
192
|
+
|
|
193
|
+
data = cavapy.get_climate_data(
|
|
194
|
+
country="Afghanistan",
|
|
195
|
+
variables=["tasmax", "pr"],
|
|
196
|
+
cordex_domain="WAS-22",
|
|
197
|
+
rcp="rcp85",
|
|
198
|
+
gcm="NCC",
|
|
199
|
+
rcm="REMO",
|
|
200
|
+
years_up_to=2030,
|
|
201
|
+
historical=True,
|
|
202
|
+
dataset="CORDEX-CORE-BC",
|
|
203
|
+
)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Multi-model ensemble
|
|
207
|
+
|
|
208
|
+
Pass lists (or `None` for all) to `rcp`, `gcm`, and `rcm`. Invalid combinations for the domain are skipped automatically with a warning, rather than raising an error.
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
import cavapy
|
|
212
|
+
|
|
213
|
+
multi = cavapy.get_climate_data(
|
|
214
|
+
country="Togo",
|
|
215
|
+
cordex_domain="AFR-22",
|
|
216
|
+
rcp=["rcp26", "rcp85"],
|
|
217
|
+
gcm=["MPI", "MOHC"],
|
|
218
|
+
rcm=["Reg", "REMO"],
|
|
219
|
+
years_up_to=2030,
|
|
220
|
+
historical=True,
|
|
221
|
+
dataset="CORDEX-CORE-BC",
|
|
222
|
+
)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The return structure for multi-combination requests is a nested dict:
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
multi[rcp][f"{gcm}-{rcm}"][variable] # -> xarray.DataArray
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Custom bounding box
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
import cavapy
|
|
235
|
+
|
|
236
|
+
data = cavapy.get_climate_data(
|
|
237
|
+
country=None,
|
|
238
|
+
xlim=(30.0, 42.0),
|
|
239
|
+
ylim=(3.0, 15.0),
|
|
240
|
+
cordex_domain="AFR-22",
|
|
241
|
+
rcp="rcp85",
|
|
242
|
+
gcm="MPI",
|
|
243
|
+
rcm="REMO",
|
|
244
|
+
years_up_to=2050,
|
|
245
|
+
buffer=1, # expand bbox by 1 degree on each side
|
|
246
|
+
)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## Parallelization
|
|
252
|
+
|
|
253
|
+
`get_climate_data()` uses two levels of concurrency:
|
|
254
|
+
|
|
255
|
+
- **Single model/scenario**: variables are processed in parallel across processes (default: one per variable), with threaded downloads inside each process
|
|
256
|
+
- **Multiple models/scenarios**: combo × variable tasks are distributed across a global process pool (default cap: 6 processes); a live progress bar tracks completion
|
|
257
|
+
- Sequential mode is used when `num_processes <= 1` or only one variable is requested
|
|
258
|
+
|
|
259
|
+
### macOS and Windows scripts
|
|
260
|
+
|
|
261
|
+
On macOS and Windows, Python starts multiprocessing workers with the `spawn` method. This means each worker imports the script again before running its task. If `get_climate_data()` is called at the top level of a `.py` script, that import re-runs the same call while Python is still starting the worker process, which can raise a multiprocessing bootstrapping `RuntimeError`.
|
|
262
|
+
|
|
263
|
+
When using multiple variables or multi-model requests in a script on macOS or Windows, put the call behind Python's standard multiprocessing entry-point guard:
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
import cavapy
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def main():
|
|
270
|
+
togo = cavapy.get_climate_data(
|
|
271
|
+
country="Togo",
|
|
272
|
+
variables=["tasmax", "pr"],
|
|
273
|
+
cordex_domain="AFR-22",
|
|
274
|
+
rcp="rcp26",
|
|
275
|
+
gcm="MPI",
|
|
276
|
+
rcm="REMO",
|
|
277
|
+
years_up_to=2030,
|
|
278
|
+
dataset="CORDEX-CORE-BC",
|
|
279
|
+
)
|
|
280
|
+
return togo
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
if __name__ == "__main__":
|
|
284
|
+
main()
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
For a quick unguarded script, use `num_processes=1` or request a single variable to run sequentially.
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Plotting
|
|
292
|
+
|
|
293
|
+
`cavapy` includes built-in plotting helpers that work directly on the returned DataArrays.
|
|
294
|
+
|
|
295
|
+
### Spatial map
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
import cavapy
|
|
299
|
+
|
|
300
|
+
data = cavapy.get_climate_data(country="Togo", obs=True, years_obs=range(1990, 2011))
|
|
301
|
+
|
|
302
|
+
fig = cavapy.plot_spatial_map(
|
|
303
|
+
data["tasmax"],
|
|
304
|
+
time_period=(2000, 2010),
|
|
305
|
+
title="Mean Max Temperature 2000-2010",
|
|
306
|
+
cmap="Reds",
|
|
307
|
+
)
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+

|
|
311
|
+
|
|
312
|
+
### Time series
|
|
313
|
+
|
|
314
|
+
```python
|
|
315
|
+
fig = cavapy.plot_time_series(
|
|
316
|
+
data["pr"],
|
|
317
|
+
title="Precipitation Time Series - Togo (1990-2011)",
|
|
318
|
+
trend_line=True,
|
|
319
|
+
ylabel="Annual Precipitation (mm)",
|
|
320
|
+
aggregation="sum",
|
|
321
|
+
figsize=(12, 6),
|
|
322
|
+
)
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+

|
|
326
|
+
|
|
327
|
+
For advanced visualization and reporting, see [CAVAanalytics](https://risk-team.github.io/CAVAanalytics/).
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## Operational Notes
|
|
332
|
+
|
|
333
|
+
- Check [GitHub issues](https://github.com/risk-team/cavapy/issues) for data server outages or announcements. cavapy fetches these automatically at startup.
|
|
334
|
+
- Set `CAVAPY_NO_ANNOUNCEMENTS=1` to disable startup announcements in scripts or production runs.
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## Citation and License
|
|
339
|
+
|
|
340
|
+
- License: [MIT](LICENSE)
|
|
341
|
+
- Package metadata and build details: [pyproject.toml](pyproject.toml)
|
|
342
|
+
|