AttributeError : pyart.feature_detection

when iam plotting this

import numpy as np
import matplotlib.pyplot as plt
import as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import glob
import pyart
import as ma
import wradlib as wrl

grid_files = glob.glob(“D:\radar_data\radinout\gridded_20_jun_2022\gridded_20_jun_2022grid_ZDR_*nc”)

total_rain_rate = np.zeros((len(grid_files), 250, 250))

for i, file in enumerate(grid_files):
grid_data =
feature_detection=pyart.feature_detection(grid_data,xg_files[‘lon’].values, xg_files[‘lat’].values,field=“REF”,always_core_thres=40,bkg_rad_km=20,use_cosine=True,max_diff=5,zero_diff_cos_val=55,weak_echo_thres=10,max_rad_km=2,)

ref_data = grid_data.fields['REF']['data']
ref_values_greater_than_40 = ma.masked_less(ref_data, 40)  # Filter reflectivity >= 40 dBZ

grid_data.fields['REF']['data'] = ref_values_greater_than_40
grid_data.fields['REF']['long_name'] = 'Reflectivity'
grid_data.fields['REF']['units'] = 'dBZ'

xg_files = grid_data.to_xarray()
Z = wrl.trafo.idecibel(xg_files.REF[0, 0, :, :].values)
rain_rate = wrl.zr.z_to_r(Z, a=200, b=1.5)
total_rain_rate[i, :, :] = rain_rate

missing_mask = np.isnan(total_rain_rate)
valid_data =, mask=missing_mask)
daily_aggregated_rain = np.sum(valid_data, axis=0)

Apply limit to rainfall values

masked_rainfall = < 0) | (daily_aggregated_rain > 120), daily_aggregated_rain)

Define the Plate Carree projection

proj = ccrs.PlateCarree()

Create the axes instance

plt.figure(figsize=(10, 8))
ax = plt.axes(projection=proj)

Plot the contourf

im = ax.contourf(xg_files[‘lon’].values, xg_files[‘lat’].values, masked_rainfall, levels=np.linspace(10, 120, 10),cmap=‘jet’, origin=“lower”)

Add colorbar

cbar = plt.colorbar(im, ax=ax, label=‘Accumulated Rainfall (mm)’, ticks=np.arange(10, 120, 10))

Add gridlines

gl = ax.gridlines(crs=proj, draw_labels=True, color=‘none’)
gl.yformatter = LATITUDE_FORMATTER

Add basemap

ax.add_feature(cfeature.BORDERS, linewidth=1)
ax.add_feature(cfeature.STATES, linewidth=1)

Plot the marker

plt.plot(75.8175, 26.8207, marker=“x”, color=“black”, markersize=15, markeredgewidth=2)

Set labels and title

plt.title(‘Accumulated Rainfall (mm)/IMD JPR/20-6-2022 (mm)’)

Show the plot

AttributeError Traceback (most recent call last)
Cell In[4], line 17
** 15 for i, file in enumerate(grid_files):**
** 16 grid_data =**
—> 17 feature_detection=pyart.feature_detection(grid_data,xg_files[‘lon’].values, xg_files[‘lat’].values,field=“REF”,always_core_thres=40,bkg_rad_km=20,use_cosine=True,max_diff=5,zero_diff_cos_val=55,weak_echo_thres=10,max_rad_km=2,)
** 19 ref_data = grid_data.fields[‘REF’][‘data’]**
** 20 ref_values_greater_than_40 = ma.masked_less(ref_data, 40) # Filter reflectivity >= 40 dBZ**

AttributeError: module ‘pyart’ has no attribute ‘feature_detection’

@ankithva You need to call the submodule for it to work. In this case, pyart.retrieve.feature_detection

Not it is showing: module pyart.retrieve has no attribute feature_detection

Which version of Py-ART are you using?

import pyart


iam using pyart version 1.16.1

Are you working through the example on the example gallery?

import pyart

# get dx dy
dx = grid.x["data"][1] - grid.x["data"][0]
dy = grid.y["data"][1] - grid.y["data"][0]

pyart.retrieve.feature_detection(grid_data,  dx, dy,field=“REF”,always_core_thres=40,bkg_rad_km=20,use_cosine=True,max_diff=5,zero_diff_cos_val=55,weak_echo_thres=10,max_rad_km=2,)

I would really encourage you to follow through that example on the documentation as a guide.

1 Like

@ankithva Also to add, the feature detection code was added in 1.17, you’ll need to update your Py-ART to use the feature detection code.

1 Like

Thanks ,it worked