Project

General

Profile

How to calculate eca_cwd index

Added by Guilherme Martins 6 months ago

Hello, everyone. How are you?

I would like to calculate the CWD index in Python using CDO. However, I'm not sure how to do it. Could someone please provide some guidance?

I've attached some figures with information about my file and the command line I tried to use. The issue is that I'm not sure how to pass the parameters. I don't want to create a NetCDF file. I want to create a figure.

Best regards,

Guilherme Martins.


Replies (1)

RE: How to calculate eca_cwd index - Added by Karin Meier-Fleischer 6 months ago

Hi Guilherme,

in Python CDO can return an xarray Dataset or DataArray. Here, I recommend to use the Dataset because eca_cwd returns two variables, consecutive_wet_days_index_per_time_period and number_of_cwd_periods_with_more_than_5days_per_time_period.

Example: Precipitation data has units "kg m-2 s-1" so we have to multiply it with 86400 to get "mm".

import xarray as xr
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cdo import Cdo
cdo = Cdo()

infile = 'your-input-data-file.nc'

ds_cwd = cdo.eca_cwd('1.5', input='-mulc,86400 ' + infile, returnXDataset=True)

fig, ax = plt.subplots(subplot_kw=dict(projection=ccrs.PlateCarree()))
ax.coastlines()
ax.pcolormesh(ds_cwd.lon, ds_cwd.lat, cwd.isel(time=0));

    (1-1/1)