cavapy 0.1.1__py3-none-any.whl → 0.1.3__py3-none-any.whl
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: cavapy
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: CAVA Python package. Retrive and analyze climate data.
|
|
5
5
|
Home-page: https://github.com/Risk-Team/cavapy
|
|
6
6
|
License: MIT
|
|
@@ -23,30 +23,48 @@ Requires-Dist: xclim (>=0.53.2,<0.54.0)
|
|
|
23
23
|
Project-URL: Repository, https://github.com/Risk-Team/cavapy
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
|
|
26
|
-
#
|
|
27
|
-
cavapy is a Python library that allows retrieval of climate data hosted in THREDDS servers at the University of Cantabria thanks to the [CAVA project](https://risk-team.github.io/CAVAanalytics/articles/CAVA.html).
|
|
26
|
+
# cavapy: CORDEX-CORE Climate Data Access Simplified
|
|
28
27
|
|
|
29
|
-
##
|
|
30
|
-
The climate data is available at the THREDDS data server of the University of Cantabria as part of the CAVA (Climate and Agriculture Risk Visualization and Assessment) product developed by FAO, the University of Cantabria, the University of Cape Town and Predictia.
|
|
31
|
-
CAVA has available CORDEX-CORE climate models, the high resolution (25 Km) dynamically-downscaled climate models used in the IPCC report AR5. Additionally, CAVA offers access to state-of-the-art reanalyses datasets, such as ERA5 and the observational dataset W5E5 v2.
|
|
28
|
+
## Introduction
|
|
32
29
|
|
|
33
|
-
|
|
30
|
+
`cavapy` is a Python library designed to streamline the retrieval of CORDEX-CORE climate models hosted on THREDDS servers at the University of Cantabria. Using the Open-source Project for a Network Data Access Protocol (**OPeNDAP**), users can directly access and subset datasets without the need to download large NetCDF files. This capability is part of the Climate and Agriculture Risk Visualization and Assessment (CAVA) [project](https://risk-team.github.io/CAVAanalytics/articles/CAVA.html), which focuses on providing high-resolution climate data for scientific, environmental, and agricultural applications.
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
- W5E5 and ERA5 datasets
|
|
37
|
-
|
|
38
|
-
Available variables:
|
|
32
|
+
With `cavapy`, users can efficiently integrate CORDEX-CORE data into their workflows, making it an ideal resource for hydrological and crop modeling, among other climate-sensitive analyses. Additionally, `cavapy` enables bias correction, potentially enhancing the precision and usability of the data for a wide range of applications.
|
|
39
33
|
|
|
40
|
-
|
|
41
|
-
- Daily minimum temperature (tasmin) (°C)
|
|
42
|
-
- Daily precipitation (pr) (mm)
|
|
43
|
-
- Daily relative humidity (hurs) (%)
|
|
44
|
-
- Daily wind speed (sfcWind) (2 m level m/s)
|
|
45
|
-
- Daily solar radiation (rsds) (W/m^2)
|
|
34
|
+
---
|
|
46
35
|
|
|
36
|
+
## Data Source
|
|
37
|
+
|
|
38
|
+
The climate data provided by `cavapy` is hosted on the THREDDS data server of the University of Cantabria as part of the CAVA project. CAVA is a collaborative effort by FAO, the University of Cantabria, the University of Cape Town, and Predictia, aimed at democratising accessibility and usability of climate information.
|
|
39
|
+
|
|
40
|
+
### Key Datasets:
|
|
41
|
+
- **CORDEX-CORE Simulations**: Dynamically downscaled high-resolution (25 km) climate models, used in the IPCC AR5 report, featuring simulations from:
|
|
42
|
+
- 3 Global Climate Models (GCMs)
|
|
43
|
+
- 2 Regional Climate Models (RCMs)
|
|
44
|
+
- Two Representative Concentration Pathways (RCPs: RCP4.5 and RCP8.5)
|
|
45
|
+
- **Reanalyses and Observational Datasets**:
|
|
46
|
+
- ERA5
|
|
47
|
+
- W5E5 v2
|
|
48
|
+
|
|
49
|
+
These datasets provide robust inputs for climate and environmental modeling, supporting scientific and policy-driven decision-making.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Available Variables
|
|
54
|
+
|
|
55
|
+
`cavapy` grants access to critical climate variables, enabling integration into diverse modeling frameworks. The variables currently available include:
|
|
56
|
+
|
|
57
|
+
- **Daily Maximum Temperature (tasmax)**: °C
|
|
58
|
+
- **Daily Minimum Temperature (tasmin)**: °C
|
|
59
|
+
- **Daily Precipitation (pr)**: mm
|
|
60
|
+
- **Daily Relative Humidity (hurs)**: %
|
|
61
|
+
- **Daily Wind Speed (sfcWind)**: 2 m level, m/s
|
|
62
|
+
- **Daily Solar Radiation (rsds)**: W/m²
|
|
63
|
+
|
|
64
|
+
---
|
|
47
65
|
|
|
48
66
|
## Installation
|
|
49
|
-
cavapy can be installed with pip. Ensure that you are not using a python version >
|
|
67
|
+
cavapy can be installed with pip. Ensure that you are not using a python version > 3.
|
|
50
68
|
|
|
51
69
|
```
|
|
52
70
|
conda create -n test python=3.11
|
|
@@ -69,6 +87,8 @@ Since bias-correction requires both the historical run of the CORDEX model and t
|
|
|
69
87
|
It takes about 10 minutes to run each of the tasks below. For bigger areas/country, the computational time increases. For example, for Zambia it takes about 30 minutes.
|
|
70
88
|
|
|
71
89
|
### Bias-corrected climate projections
|
|
90
|
+
**By default all available climate variables are used. You can specify a subset with the variable argument**
|
|
91
|
+
|
|
72
92
|
```
|
|
73
93
|
import cavapy
|
|
74
94
|
Togo_climate_data = cavapy.get_climate_data(country="Togo", cordex_domain="AFR-22", rcp="rcp26", gcm="MPI", rcm="REMO", years_up_to=2030, obs=False, bias_correction=True, historical=False)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
cavapy.py,sha256=i9ULBOrL4NrtG13KFl7g9JEytsXJkF0Vepudebw7MEY,24377
|
|
2
|
+
cavapy-0.1.3.dist-info/LICENSE,sha256=1etyG4_n-Tb3yoNMwQ38g_WxXFQ4E_ZCjZc-AGYPc9U,1151
|
|
3
|
+
cavapy-0.1.3.dist-info/METADATA,sha256=M2KwoqRuQFd7SAubXRnwFKSJaVci1HfU1Q-BwOoT9Vo,6002
|
|
4
|
+
cavapy-0.1.3.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
|
|
5
|
+
cavapy-0.1.3.dist-info/RECORD,,
|
cavapy.py
CHANGED
|
@@ -161,7 +161,7 @@ def get_climate_data(
|
|
|
161
161
|
else:
|
|
162
162
|
variables = VALID_VARIABLES
|
|
163
163
|
|
|
164
|
-
_validate_urls(gcm, rcm, rcp, remote, cordex_domain, obs)
|
|
164
|
+
_validate_urls(gcm, rcm, rcp, remote, cordex_domain, obs, historical, bias_correction)
|
|
165
165
|
|
|
166
166
|
bbox = _geo_localize(country, xlim, ylim, buffer, cordex_domain)
|
|
167
167
|
|
|
@@ -206,6 +206,8 @@ def _validate_urls(
|
|
|
206
206
|
remote: bool = True,
|
|
207
207
|
cordex_domain: str = None,
|
|
208
208
|
obs: bool = False,
|
|
209
|
+
historical: bool = False,
|
|
210
|
+
bias_correction: bool = False,
|
|
209
211
|
):
|
|
210
212
|
# Load the data
|
|
211
213
|
log = logger.getChild("URL-validation")
|
|
@@ -219,6 +221,11 @@ def _validate_urls(
|
|
|
219
221
|
# Set the column to use based on whether the data is remote or local
|
|
220
222
|
column_to_use = "location" if remote else "hub"
|
|
221
223
|
|
|
224
|
+
# Define which experiments we need
|
|
225
|
+
experiments = [rcp]
|
|
226
|
+
if historical or bias_correction:
|
|
227
|
+
experiments.append("historical")
|
|
228
|
+
|
|
222
229
|
# Filter the data based on the conditions
|
|
223
230
|
filtered_data = data[
|
|
224
231
|
lambda x: (
|
|
@@ -226,27 +233,19 @@ def _validate_urls(
|
|
|
226
233
|
& (x["domain"] == cordex_domain)
|
|
227
234
|
& (x["model"].str.contains(gcm, na=False))
|
|
228
235
|
& (x["rcm"].str.contains(rcm, na=False))
|
|
229
|
-
& (x["experiment"].isin(
|
|
236
|
+
& (x["experiment"].isin(experiments))
|
|
230
237
|
)
|
|
231
238
|
][["experiment", column_to_use]]
|
|
232
239
|
|
|
233
240
|
# Extract the column values as a list
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
else:
|
|
243
|
-
# Log the output for two rows
|
|
244
|
-
row1 = column_values.iloc[0]
|
|
245
|
-
row2 = column_values.iloc[1]
|
|
246
|
-
log_hist = logger.getChild("URL-validation-historical")
|
|
247
|
-
log_proj = logger.getChild("URL-validation-projections")
|
|
248
|
-
log_hist.info(f"{row1}")
|
|
249
|
-
log_proj.info(f"{row2}")
|
|
241
|
+
for _, row in filtered_data.iterrows():
|
|
242
|
+
if row["experiment"] == "historical":
|
|
243
|
+
log_hist = logger.getChild("URL-validation-historical")
|
|
244
|
+
log_hist.info(f"{row[column_to_use]}")
|
|
245
|
+
else:
|
|
246
|
+
log_proj = logger.getChild("URL-validation-projections")
|
|
247
|
+
log_proj.info(f"{row[column_to_use]}")
|
|
248
|
+
|
|
250
249
|
else: # when obs is True
|
|
251
250
|
log_obs = logger.getChild("URL-validation-observations")
|
|
252
251
|
log_obs.info(f"{ERA5_DATA_REMOTE_URL}")
|
|
@@ -417,12 +416,18 @@ def _climate_data_for_variable(
|
|
|
417
416
|
)
|
|
418
417
|
data = pd.read_csv(inventory_csv_url)
|
|
419
418
|
column_to_use = "location" if remote else "hub"
|
|
419
|
+
|
|
420
|
+
# Filter data based on whether we need historical data
|
|
421
|
+
experiments = [rcp]
|
|
422
|
+
if historical or bias_correction:
|
|
423
|
+
experiments.append("historical")
|
|
424
|
+
|
|
420
425
|
filtered_data = data[
|
|
421
426
|
lambda x: (x["activity"].str.contains("FAO", na=False))
|
|
422
427
|
& (x["domain"] == cordex_domain)
|
|
423
428
|
& (x["model"].str.contains(gcm, na=False))
|
|
424
429
|
& (x["rcm"].str.contains(rcm, na=False))
|
|
425
|
-
& (x["experiment"].isin(
|
|
430
|
+
& (x["experiment"].isin(experiments))
|
|
426
431
|
][["experiment", column_to_use]]
|
|
427
432
|
|
|
428
433
|
future_obs = None
|
|
@@ -454,12 +459,17 @@ def _climate_data_for_variable(
|
|
|
454
459
|
|
|
455
460
|
# Add the downloaded models to the DataFrame
|
|
456
461
|
filtered_data["models"] = downloaded_models
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
462
|
+
|
|
463
|
+
if historical or bias_correction:
|
|
464
|
+
hist = filtered_data[filtered_data["experiment"] == "historical"]["models"].iloc[0]
|
|
465
|
+
proj = filtered_data[filtered_data["experiment"] == rcp]["models"].iloc[0]
|
|
466
|
+
|
|
467
|
+
hist = hist.interpolate_na(dim="time", method="linear")
|
|
468
|
+
proj = proj.interpolate_na(dim="time", method="linear")
|
|
469
|
+
else:
|
|
470
|
+
proj = filtered_data["models"].iloc[0]
|
|
471
|
+
proj = proj.interpolate_na(dim="time", method="linear")
|
|
472
|
+
|
|
463
473
|
if bias_correction and historical:
|
|
464
474
|
# Load observations for bias correction
|
|
465
475
|
ref = future_obs.result()
|
|
@@ -581,6 +591,14 @@ def _download_data(
|
|
|
581
591
|
else:
|
|
582
592
|
log.info(f"Establishing connection to CORDEX data for {variable}")
|
|
583
593
|
ds_var = xr.open_dataset(url)[variable]
|
|
594
|
+
|
|
595
|
+
# Check if time dimension has a prefix, indicating variable is not available
|
|
596
|
+
time_dims = [dim for dim in ds_var.dims if dim.startswith('time_')]
|
|
597
|
+
if time_dims:
|
|
598
|
+
msg = f"Variable {variable} is not available for this model: {url}"
|
|
599
|
+
log.exception(msg)
|
|
600
|
+
raise ValueError(msg)
|
|
601
|
+
|
|
584
602
|
log.info(f"Connection to CORDEX data for {variable} has been established")
|
|
585
603
|
ds_cropped = ds_var.sel(
|
|
586
604
|
longitude=slice(bbox["xlim"][0], bbox["xlim"][1]),
|
|
@@ -636,14 +654,15 @@ def _download_data(
|
|
|
636
654
|
|
|
637
655
|
if __name__ == "__main__":
|
|
638
656
|
data = get_climate_data(
|
|
639
|
-
country="
|
|
657
|
+
country="Togo",
|
|
658
|
+
variables=["hurs"],
|
|
640
659
|
cordex_domain="AFR-22",
|
|
641
660
|
rcp="rcp26",
|
|
642
661
|
gcm="MPI",
|
|
643
|
-
rcm="
|
|
662
|
+
rcm="Reg",
|
|
644
663
|
years_up_to=2030,
|
|
645
664
|
obs=False,
|
|
646
|
-
bias_correction=
|
|
665
|
+
bias_correction=False,
|
|
647
666
|
historical=False,
|
|
648
667
|
)
|
|
649
668
|
print(data)
|
cavapy-0.1.1.dist-info/RECORD
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
cavapy.py,sha256=dYDRyrrKn560xp4gGOL73ctn8YZLqrtkMw6631YMbkI,23557
|
|
2
|
-
cavapy-0.1.1.dist-info/LICENSE,sha256=1etyG4_n-Tb3yoNMwQ38g_WxXFQ4E_ZCjZc-AGYPc9U,1151
|
|
3
|
-
cavapy-0.1.1.dist-info/METADATA,sha256=PB0uKvdF9W0vli69Vf4KKdrOaOLMFnhwtitXi0od7KE,4732
|
|
4
|
-
cavapy-0.1.1.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
|
|
5
|
-
cavapy-0.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|