Extraction de données climatiques historiques (précipitations) sur des bassins sélectionnés

  • Produits utilisés : ERA5

Commencer

Pour exécuter cette analyse, exécutez toutes les cellules du bloc-notes, en commençant par la cellule « Charger les packages ».

Charger des paquets

Importez les packages Python utilisés pour l’analyse.

[1]:
%matplotlib inline

# Force GeoPandas to use Shapely instead of PyGEOS
# In a future release, GeoPandas will switch to using Shapely by default.
import os
os.environ['USE_PYGEOS'] = '0'

import datacube
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import geopandas as gpd

from deafrica_tools.spatial import xr_rasterize
from deafrica_tools.load_era5 import load_era5
from deafrica_tools.dask import create_local_dask_cluster

Paramètres d’analyse

[2]:
# Original shapefile from https://data.apps.fao.org/map/catalog/srv/api/records/57bb1c95-2f00-4def-886f
vector_file = 'data/OB_FWR_Hydrography_Okavango_Subasins_polygon.geojson'

# define time period of interest
time_range = '2013-12', '2021-05-31'

Définir les zones d’intérêt dans le bassin de l’Okavango

[3]:
# load basin polygons
# Original shapefile from https://data.apps.fao.org/map/catalog/srv/api/records/57bb1c95-2f00-4def-886f-caee3d756da9
basin = gpd.read_file(vector_file)

# upstream include Cuito and Cubango subbasins
upstream = basin[basin.Subbasin.isin(['Cuito', 'Cubango'])]

# delta is part of the Okavango subbasin
delta = basin[basin.Subbasin.isin(['Okavango'])]

print(upstream)
   CLASS_ID  Longitude   Latitude Subbasin      Sph_Area      Sph_Len  Parts  \
0         0  19.003252 -15.179938    Cuito  5.902293e+10  2285720.103    1.0
1         0  17.870032 -15.740153  Cubango  1.078813e+11  3071839.684    1.0

   Vertices                                           geometry
0    9326.0  POLYGON ((17.85205 -13.53846, 17.85205 -13.536...
1   11314.0  POLYGON ((15.99370 -13.93323, 15.99370 -13.931...

Récupérer les données historiques de précipitations sur toutes les zones d’intérêt

[4]:
# get historical rainfall for upstream and delta
bounds = pd.concat([upstream, delta]).total_bounds
lat = bounds[1], bounds[3]
lon = bounds[0], bounds[2]
[5]:
# download ERA5 rainfall and aggregate to monthly
var = 'total_precipitation_24hr'
precip_1W = load_era5(var, lat, lon, time_range, reduce_func=np.sum, resample='1W').compute()

#resample to 3 month seasons
precip = precip_1W.resample(time='3M').sum()

# fix inconsistency in axis names
precip = precip.rename({'lat':'latitude', 'lon':'longitude'})
precip_1W = precip_1W.rename({'lat':'latitude', 'lon':'longitude'})

Créer un masque de zone pour les régions en amont et en Okavango

[6]:
upstream_raster = xr_rasterize(upstream, precip)
delta_raster = xr_rasterize(delta, precip)

Calculer les précipitations totales sur chaque zone

[7]:
upstream_rainfall = precip[var].where(upstream_raster).sum(['latitude','longitude'])
okavango_rainfall = precip[var].where(delta_raster).sum(['latitude','longitude'])

upstream_rainfall_1W = precip_1W[var].where(upstream_raster).sum(['latitude','longitude'])
[8]:
upstream_rainfall_1W = precip_1W[var].where(upstream_raster).sum(['latitude','longitude'])

Exporter les résultats au format csv

[9]:
upstream_rainfall.to_dataframe().drop('spatial_ref',axis=1).rename({'total_precipitation_24hr':'cumulative 3-month rainfall (mm)'},axis=1).to_csv(f'results/upstream_rainfall_{time_range[0]}_to_{time_range[1]}.csv')
okavango_rainfall.to_dataframe().drop('spatial_ref',axis=1).rename({'total_precipitation_24hr':'cumulative 3-month rainfall (mm)'},axis=1).to_csv(f'results/okavango_rainfall_{time_range[0]}_to_{time_range[1]}.csv')

upstream_rainfall_1W.to_dataframe().drop('spatial_ref',axis=1).rename({'total_precipitation_24hr':'cumulative 1-week rainfall (mm)'},axis=1).to_csv(f'results/upstream_rainfall_1W_{time_range[0]}_to_{time_range[1]}.csv')

Visualisez les précipitations historiques et comparez-les aux changements d’étendue d’eau

[10]:
upstream_rainfall.plot(label='Cuito + Cubango', marker='o', figsize=(20,8));
okavango_rainfall.plot(label='Okavango', marker='o');
plt.legend();
../../../../_images/sandbox_notebooks_Use_cases_Okavango_3_Historical_rainfall_19_0.png

Informations Complémentaires

Licence : Le code de ce carnet est sous licence Apache, version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>. Les données de Digital Earth Africa sont sous licence Creative Commons par attribution 4.0 <https://creativecommons.org/licenses/by/4.0/>.

Contact : Si vous avez besoin d’aide, veuillez poster une question sur le canal Slack Open Data Cube <http://slack.opendatacube.org/>`__ ou sur le GIS Stack Exchange en utilisant la balise open-data-cube (vous pouvez consulter les questions posées précédemment ici). Si vous souhaitez signaler un problème avec ce bloc-notes, vous pouvez en déposer un sur Github.

Version de Datacube compatible :

[11]:
print(datacube.__version__)
1.8.15

Dernier test :

[12]:
from datetime import datetime
datetime.today().strftime('%Y-%m-%d')
[12]:
'2024-02-01'