cavapy 0.1.1__py3-none-any.whl → 0.1.2__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.1
3
+ Version: 0.1.2
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
- # Introduction
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
- ## Data source
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
- The currently available data is:
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
- - CORDEX-CORE simulations (3 GCMs donwscaled with 2 RCMs for two RCPs)
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
- - Daily maximum temperature (tasmax) (°C)
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 > 13.
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=hie9HYVNepHlAiUF7zT0I1Y6Yghf-8WiVm2LLKddeB0,23903
2
+ cavapy-0.1.2.dist-info/LICENSE,sha256=1etyG4_n-Tb3yoNMwQ38g_WxXFQ4E_ZCjZc-AGYPc9U,1151
3
+ cavapy-0.1.2.dist-info/METADATA,sha256=zig0HriF0p6YpEAOAyy07vOCD33lt7sv9ZRUSzVQJ_0,6002
4
+ cavapy-0.1.2.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
5
+ cavapy-0.1.2.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([rcp, "historical"]))
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
- num_rows = filtered_data.shape[0]
235
- column_values = filtered_data[column_to_use]
236
-
237
- if num_rows == 1:
238
- # Log the output for one row
239
- row1 = column_values.iloc[0]
240
- log_proj = logger.getChild("URL-validation-projections")
241
- log_proj.info(f"{row1}")
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([rcp, "historical"]))
430
+ & (x["experiment"].isin(experiments))
426
431
  ][["experiment", column_to_use]]
427
432
 
428
433
  future_obs = None
@@ -454,12 +459,13 @@ def _climate_data_for_variable(
454
459
 
455
460
  # Add the downloaded models to the DataFrame
456
461
  filtered_data["models"] = downloaded_models
457
- hist = (
458
- filtered_data["models"].iloc[0].interpolate_na(dim="time", method="linear")
459
- )
460
- proj = (
461
- filtered_data["models"].iloc[1].interpolate_na(dim="time", method="linear")
462
- )
462
+
463
+ if historical or bias_correction:
464
+ hist = filtered_data[filtered_data["experiment"] == "historical"]["models"].iloc[0].interpolate_na(dim="time", method="linear")
465
+ proj = filtered_data[filtered_data["experiment"] == rcp]["models"].iloc[0].interpolate_na(dim="time", method="linear")
466
+ else:
467
+ proj = filtered_data["models"].iloc[0].interpolate_na(dim="time", method="linear")
468
+
463
469
  if bias_correction and historical:
464
470
  # Load observations for bias correction
465
471
  ref = future_obs.result()
@@ -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