Plot radar ppi without dithering?

68 views
Skip to first unread message

Paddy McCarthy

unread,
Aug 10, 2021, 3:34:27 PM8/10/21
to Py-ART Users
Hi-

I'm trying to plot some NEXRAD Archive files to .png images in a way that preserves the discrete colors in my colormap. But somewhere along the line pyart or matplotlib is dithering the image so there are pixels in the image not represented in the colormap. Has anyone come across this issue, and is there a way to turn off dithering in the tool that's introducing it?

I'm using a method to plot that's like this:
radar = pyart.io.read_nexrad_archive(input_filename, include_fields=('reflectivity', 'velocity'))
display = pyart.graph.RadarMapDisplay(radar)
dbz_figure = plt.figure(figsize=[12, 10], clear=True)
dbz_ax = dbz_figure.add_subplot(111)
display.plot_ppi(
    'reflectivity', sweep=0,
    ax=dbz_ax,
    title="Radar Base Reflectivity",
    colorbar_flag=True,
    colorbar_label='dBZ',
    vmin=-40., vmax=100.,
    ticks=dbz_ticks, ticklabs=dbz_ticklabs,
    cmap=dbz_cmap,
    # embelish=True
)
plt.savefig(input_filename + '_BREF.png', dpi=200, transparent=True)

Thank you!

-Paddy McCarthy
National Center for Atmospheric Research
Message has been deleted

sherma...@gmail.com

unread,
Aug 10, 2021, 5:19:29 PM8/10/21
to Py-ART Users
Hi Paddy,

Do you have an image you can provide? I haven't encountered this before, i think in matplotlib there is an antialiasing parameter that might help,  not 100% sure, which can be plugged into the kwargs for plot_ppi. But from what I know, if the amount of colors is constrained to a specific color palette, the color information is thrown off. What does the dbz_cmap look like?

https://matplotlib-devel.narkive.com/SEreXJSL/strange-moray-patterns-with-pcolor

Zach S

Paddy McCarthy

unread,
Aug 11, 2021, 8:07:47 AM8/11/21
to Py-ART Users
Hi Zach-

Thanks for the reply. Unfortunately this problem went away while I was trying different settings. I backed everything out and was unable to replicate the problem! I'm half-convinced that the dithering may have been an artifact of one of the tools I was using to view the images on my mac.

Thanks again for your help in any case.

For completeness, and in case anyone ever wants to use a color scale with discrete color bins (mimics how the National Weather Service displays reflectivity), here it is and I've attached a sample image:
# Segmented dBZ colormap
dbz_colors=[
    (0.39, 0.39, 0.39),
    (0.39, 0.39, 0.39),
    (0.81, 1, 1),
    (0.80, 0.61, 0.80),
    (0.60, 0.41, 0.60),
    (0.40, 0.21, 0.38),
    (0.80, 0.80, 0.61),
    (0.60, 0.60, 0.41),
    (0.39, 0.39, 0.39),
    (0.16, 0.91, 0.90),
    (0.09, 0.63, 0.95),

    (0.05, 0.13, 0.94),
    (0.16, 0.98, 0.18),
    (0.12, 0.76, 0.13),
    (0.07, 0.55, 0.08),
    (0.99, 0.96, 0.22),
    (0.89, 0.73, 0.16),
    (0.98, 0.58, 0.15),
    (0.98, 0.05, 0.11),
    (0.82, 0.04, 0.08),
    (0.73, 0.03, 0.07),
    (0.96, 0.16, 0.98),
    (0.59, 0.35, 0.77),
    (0.99, 0.99, 0.99),
    (0.99, 0.99, 0.99),
    (0.99, 0.99, 0.99),
    (0.99, 0.99, 0.99),
    (0.99, 0.99, 0.99)
]
n_dbz_colors = len(dbz_colors)
dbz_cbar_limits = [0.0, 0.03571, 0.07143, 0.1429, 0.1786, 0.2143, 0.25,
                   0.2857, 0.3214, 0.3571, 0.3929, 0.4286, 0.4643, 0.5,
                   0.5357, 0.5714, 0.6071, 0.6429, 0.6786, 0.7143, 0.75,
                   0.7857, 0.8214, 0.8571, 0.8929, 0.9286, 0.9643, 1]
n_dbz_limits = len(dbz_cbar_limits)
dbz_ticks = [
    -40, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 100
]
dbz_ticklabs = [
    '-40', '-30', '-25', '-20', '-15', '-10', '-5', '0', '5', '10', '15', '20', '25', '30', '35', '40', '45', '50', '55', '60', '65', '70', '75', '100'
]
dbz_cmap = colors.LinearSegmentedColormap.from_list('test', dbz_colors, n_dbz_colors)

KPBZ_20210810_1924_BREF.png
Reply all
Reply to author
Forward
0 new messages