Adding transparency?

217 views
Skip to first unread message

Brenda Cabell

unread,
Oct 21, 2015, 7:21:54 PM10/21/15
to Py-ART Users
Hey all,

Inspired by someone's plots at the Norman radar conference (I can't remember now who), I'd like to make a plot of data where dual-Doppler radar lobes are 'highlighted' against the background reflectivity. That is, the radar reflectivity over the domain was, say, 40% transparent, while within the dual-Doppler lobes it was normal opacity (100% opaque? 0% transparent? whatever). I was thinking I could plot the 'background' reflectivity with contourf(alpha=0.4), then plot the dual-Doppler data as a masked array on top of that, which is what I've done in the attached image using gridded data. Is there a way I can make this type of plot using the PyArt built-in plotting functionality?

Cheers,

-Brenda
CPOL_dualDop_gridplot.png

Nick Guy

unread,
Oct 22, 2015, 12:58:07 PM10/22/15
to Py-ART Users
I'm curious to see the code you did the above with Brenda.

Brenda Cabell

unread,
Oct 22, 2015, 4:28:01 PM10/22/15
to Py-ART Users
Oh boy, so everyone can see my code? :) Actually in my haste yesterday, I didn't actually have the dual-Doppler area correct (see new attached fig for correct plot). I've attached my function dualdopp.py, and the rest of the code is this:


##############################
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.figure as figure
import glob
import math
from netCDF4 import Dataset
from dualdopp import dualdopp
from dualdopp import mask_dualdop

#### Read in the Netcdf gridded file
cradarfile ='CPOL20060101_040009.00000_all_calb_2kmres.cdf'
radarc = Dataset(cradarfile)

print radarc.variables.keys()

dzc = radarc.variables['DZ']
drc = radarc.variables['DR']
kdc = radarc.variables['KD']
rhc = radarc.variables['RH']

radar_z= np.arange(np.array(np.shape(radarc.variables['z'])))*radarc.zdelta+radarc.zfirst
radar_x= np.arange(np.array(np.shape(radarc.variables['x'])))*radarc.xdelta+radarc.xfirst
radar_y= np.arange(np.array(np.shape(radarc.variables['y'])))*radarc.ydelta+radarc.yfirst

#### Set up some colorbar stuff
lowdbz = 0.
highdbz = 68.
deldbz = 4.
rangedbz = highdbz-lowdbz
levels_dbz = range(0,68,4) # dbz contour levels

fig, ax = plt.subplots(1,1,figsize=(16,16))

#Plot the 'background' reflectivity with a transparancy of 0.4
dbz_hand=plt.contourf(radar_x,radar_y,dzc[2,:,:],levels_dbz,interpolation='none', cmap='RdYlBu_r',alpha=0.4)

#Define the locations of the two radars in the gridded coodrinate system
rad1=[0.0,0.0]
rad2=[-13.47,-27.99]

#Select a beam-crossling angle
beamang=30
rad1x,rad1y,rad2x,rad2y,midpoint,radius=dualdopp(rad1,rad2,beamang)

#Over plot the outline of the dual-doppler rings and the locations of the radars
plt.plot(rad1x,rad1y,color='r')
plt.plot(rad2x,rad2y,color='r')
plt.plot(rad1[0],rad1[1],marker='o',color='k')
plt.plot(rad2[0],rad2[1],marker='o',color='k')

#Find the indices of the location of the dual-Doppler lobes in our x, y from the dual-Doppler output
myx1=np.argmin(np.abs(radar_x-midpoint[0][0]))
myy1=np.argmin(np.abs(radar_y-midpoint[0][1]))

myx2=np.argmin(np.abs(radar_x-midpoint[1][0]))
myy2=np.argmin(np.abs(radar_y-midpoint[1][1]))


center_x=[myx1,myx2]
center_y=[myy1,myy2]

#Now mask out everything outside of the lobes
mynewdata=mask_dualdop(dzc[2,:,:],center_x,center_y,radius/2.)

#Over plot the masked data in 'full' opacity
plt.contourf(radar_x,radar_y,mynewdata,levels_dbz,interpolation='none',cmap='RdYlBu_r')

#Add some lables
plt.xlabel('E-W Distance (km)')
plt.ylabel('N-S Distance (km)')
plt.title('CPOL 20060101 0400 UTC dual-Doppler lobes beamcrossing: {:2.1f}'.format(beamang))

plt.savefig('CPOL_dualDop_gridplot_{}.png'.format(beamang),dpi=200)



On Wednesday, October 21, 2015 at 5:21:54 PM UTC-6, Brenda Cabell wrote:
CPOL_dualDop_gridplot_30.png
dualdopp.py

Scott Collis

unread,
Oct 22, 2015, 6:32:04 PM10/22/15
to pyart...@googlegroups.com
Hmm Interesting.. I also assume you would only ever really want to do this on a grid object?

Now you can access the basemap object tied to a GridMapDisplay object
http://arm-doe.github.io/pyart-docs-travis/user_reference/generated/pyart.graph.GridMapDisplay.html#pyart.graph.GridMapDisplay
in display.basemap

you could plot a non-alpha version and the one with alpha later.. I will have a play.. I hope to be getting back to multi-doppler soon and Kirk I know is doing work in it so a display like this would be very nice.
--
You received this message because you are subscribed to the Google Groups "Py-ART Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyart-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brenda Cabell

unread,
Oct 22, 2015, 6:52:55 PM10/22/15
to Py-ART Users
Well, honestly I wanted to use this for case selection, so ideally read in the polar data and plot the (approximate) dual-Doppler coverage to make sure the storms of interest are actually passing through our domain before spending too much time processing. :)

-Brenda

Jonathan Helmus

unread,
Oct 23, 2015, 4:15:57 PM10/23/15
to pyart...@googlegroups.com
I don't think Py-ART has the needed functionality to create such a plot yet...

Next week I'll see if I can't put something together that can created something close to this with Py-ART's various display classes.  That is if Scott doesn't get to it first.

Cheers,

    - Jonathan Helmus

Brenda Cabell

unread,
Nov 5, 2015, 6:47:39 PM11/5/15
to Py-ART Users
Wahoo! I figured out how to do this in PPI / radar space! If I just use a black and white color bar for the 'background' then color over it, it accomplishes the same thing. :) I still mask the reflectivity outside the dual-Doppler area and save it back to the radar object as a new variable.

However, for some reason (in ipython notebook) I can't get it to plot the x and y labels (e.g. nice lat and lons)? Incidentally, I'm having the same problem when I grid the data then use  pyart.graph.GridMapDisplay(grids).  What am I missing?? 

display = pyart.graph.RadarMapDisplay(radar)

---plotting snippet---

my_figure = plt.figure(figsize=[16, 12])
display.plot_ppi_map('CZ',0,vmin=-8,vmax=64,cmap='Greys_r')
display.plot_ppi_map('DD', 0, vmin=-8, vmax=64,cmap='RdYlBu_r')

plt.savefig('CPOL_20060101_0400_DD_polarcoord.png',dpi=200)

----------------------------

Thanks,

-Brenda
CPOL_20060101_0400_DD_polarcoord.png

Brenda Cabell

unread,
Nov 5, 2015, 6:49:16 PM11/5/15
to Py-ART Users
And again I attached the wrong file...Ugh.

Heres the correct one.

-Brenda
CPOL_20060101_0400_DD_polarcoord.png

Brenda Cabell

unread,
Nov 5, 2015, 7:09:06 PM11/5/15
to Py-ART Users
Sorry for spamming the list today, but I have 2 more questions:

1) Anyone know where the heck the Tiwi islands went on my map?? Melville Island should be about where that convection is firing north of the radar.

2) I would like to add dual-Doppler rings on here for an outline. How do I plot things on top of the plot? (Can I use an axis command or something?) I'm still pretty new to all this....

Thanks!

-Brenda

Scott Collis

unread,
Nov 5, 2015, 7:21:15 PM11/5/15
to Py-ART Users
All good! No need for sorry!

Take a look here:
http://arm-doe.github.io/pyart/dev/auto_examples/plotting/plot_grid_three_panel.html
You will see that each map instance has a basemap method attached
x
, y = display.basemap(lons, lats)
So you can use this to calculate X,Y's and plot what you need..
Oh.. And I need to dig up some code, but yeah.. using your own shapefiles is some time needed

November 5, 2015 at 6:09 PM
November 5, 2015 at 5:49 PM
And again I attached the wrong file...Ugh.

Heres the correct one.

-Brenda


On Thursday, November 5, 2015 at 4:47:39 PM UTC-7, Brenda Cabell wrote:
--
You received this message because you are subscribed to the Google Groups "Py-ART Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyart-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
November 5, 2015 at 5:47 PM
Wahoo! I figured out how to do this in PPI / radar space! If I just use a black and white color bar for the 'background' then color over it, it accomplishes the same thing. :) I still mask the reflectivity outside the dual-Doppler area and save it back to the radar object as a new variable.

However, for some reason (in ipython notebook) I can't get it to plot the x and y labels (e.g. nice lat and lons)? Incidentally, I'm having the same problem when I grid the data then use  pyart.graph.GridMapDisplay(grids).  What am I missing?? 

display = pyart.graph.RadarMapDisplay(radar)

---plotting snippet---

my_figure = plt.figure(figsize=[16, 12])
display.plot_ppi_map('CZ',0,vmin=-8,vmax=64,cmap='Greys_r')
display.plot_ppi_map('DD', 0, vmin=-8, vmax=64,cmap='RdYlBu_r')

plt.savefig('CPOL_20060101_0400_DD_polarcoord.png',dpi=200)

----------------------------

Thanks,

-Brenda


On Friday, October 23, 2015 at 2:15:57 PM UTC-6, Jonathan Helmus wrote:
--
You received this message because you are subscribed to the Google Groups "Py-ART Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyart-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
October 23, 2015 at 3:14 PM
I don't think Py-ART has the needed functionality to create such a plot yet...

Next week I'll see if I can't put something together that can created something close to this with Py-ART's various display classes.  That is if Scott doesn't get to it first.

Cheers,

    - Jonathan Helmus

On 10/22/2015 05:52 PM, Brenda Cabell wrote:

--
You received this message because you are subscribed to the Google Groups "Py-ART Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyart-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
October 22, 2015 at 5:52 PM

Jonathan Helmus

unread,
Nov 5, 2015, 7:24:11 PM11/5/15
to pyart...@googlegroups.com
Brenda,

    Check out the documentation on the plot_ppi_map function [1] and some of the other methods of the RadarMapDisplay class [2] for customizing the plot.  Also the ppi with basemap example [3].  A few of the key parameters to plot_ppi_map:

    lat_lines, lon_lines : Specifies where to draw latitude and longitude lines are drawn and the ticks.
     resolution : 'h' or 'f' for high or full resolution, this might get you the missing islands.
    area_thresh : set this to something low to not skip drawing the islands if upping the resolution does not help.
    colorbar_flag : False to not draw the colorbar... for example in the B/W plot.

The plot_range_ring method will let you draw a circle at a given distance from the radar, if your dual-Doppler ring fits that criteria you are in luck. If not you may need to plot directly onto the basemap instance which is stored in as radar.basemap.

Cheers,

    - Jonathan Helmus

   


[1] http://arm-doe.github.io/pyart-docs-travis/user_reference/generated/pyart.graph.RadarMapDisplay.plot_ppi_map.html
[2] http://arm-doe.github.io/pyart-docs-travis/user_reference/generated/pyart.graph.RadarMapDisplay.html
[3] http://arm-doe.github.io/pyart/dev/auto_examples/plotting/plot_ppi_basemap_with_rings.html
Reply all
Reply to author
Forward
0 new messages