Extract A Radar Column Along a Line of Azimuth

Using the attached figure as an example, I want to extract column data along a 242 degree azimuth black dotted line from radar (0 -125 km) volume PPI plot (0.8 deg elevation). The file is in NC format. How can I go about it using Py-ART? I’m aiming to plot these data (dBZ) against the radar range 125 km.


Thanks for the question @Gitbix - I would suggest using xradar here, which enables you to do this!

Here is a sample code block, using some sample data.

import xradar as xd
from open_radar_data import DATASETS

# Load in a sample file from the Southern Great Plains ARM Site
file = DATASETS.fetch('sample_sgp_data.nc')

# Read the data using xradar
dtree = xd.io.open_cfradial1_datatree(

# Select the lowest sweep (0), and the closes azimuth to 242 degrees, and plot it!
dtree['sweep_1'].sel(azimuth=242, method='nearest')['corrected_reflectivity_horizontal'].plot()

Here is the result (note, there are some missing values, and we did not explicitly interpolate):

1 Like

Hey, Thanks Max. I’d be using this xradar method for the first time. What if I want to plot only some dBZ data in a fixed range say between 40 to 50 Km and not all?

@Gitbix you could add another selection here (note range units are meters):

ds.sel(range=slice(40_000, 50_000))

or the full line:

dtree['sweep_1'].sel(azimuth=242, method='nearest').sel(range=slice(40_000, 50_000))['corrected_reflectivity_horizontal'].plot()

Thank you very much.

How can the dataset in ‘file’ be read with “dtree = xd.io.open_cfradial1_datatree(file)” if the dataset contains variable “nsweep” and not ‘sweep_number’? Error from the line above is seen below.

Are you sure the data you are reading is a cfradial file? Can you rename the variable using netCDF? The reader is assuming the cfradial1 standard, which uses the name sweep_number.

Yes, the data is a cfradial NC file having the variable sweep_number. The version from metadata is CF-Radial 1.4. Also, I’m not sure the data type exist in the datasets module above.

Can you share a copy of the code block you are running?

Yes, here is it. Having installed and imported all modules.

@Gitbix it looks like that file is missing sweep_number still - using following fixes the read in, by adding a new sweep_number variable to the dataset using the existing sweep variable, writing to disk, then reading back in using xradar

# Open the original file
ds = xr.open_dataset('cfrad.20211211_120304.494_to_20211211_120801.176_KBSI_SUR.nc')

# Make sure that sweep number is one of the variables in the dataset
ds['sweep_number'] = ds.sweep

# Write this new netcdf file to disk

# Read the data back in using xradar
tree = xd.io.open_cfradial1_datatree('cfrad.20211211_120304.494_to_20211211_120801.176_KBSI_SUR.nc')

Oh really. So, the solution is to ingest the sweep_number variable into the same file?
Would try check it out. Thank you.

I plotted the data but it seems to be empty. What could be wrong?

@Gitbix it looks like there was a bug with the way dask vs. numpy arrays were saved to disk - this should resolve that issue, and I opened an issue on the xradar side to reflect these issues

# Open the original file
file = 'cfrad.20211211_120304.494_to_20211211_120801.176_KBSI_SUR.nc'
ds = xr.open_dataset(file)

# Make sure that sweep number is one of the variables in the dataset
ds['sweep_number'] = ('sweep', ds.sweep.values)

# Make sure the full dataset is loaded, which ensures values are passed correctly
ds = ds.compute()

# Write this new netcdf file to disk

# Read the data back in using xradar
tree = xd.io.open_cfradial1_datatree(file)

# Plot the second sweep, using the closest azimuth
tree['sweep_1'].sel(azimuth=242, method='nearest').sel(range=slice(40_000, 50_000))['corrected_reflectivity'].plot()

Which resulted in this plot

Oh really. I would check the opened issue. Thank you sir

1 Like