Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot_ppi_map with lat/lon #1245

Closed
srbrodzik opened this issue Aug 17, 2022 · 27 comments
Closed

plot_ppi_map with lat/lon #1245

srbrodzik opened this issue Aug 17, 2022 · 27 comments

Comments

@srbrodzik
Copy link

I have some code that I've been using successfully on a Debian 10 machine running pyart v1.11.2. I've tried running it on a Debian 11 machine running pyart v1.12.5 and I get plots but no lat/lon information. See my code and two attached images. Can you explain what I might be missing?

`import os
import sys
import matplotlib.pyplot as plt
import pyart
import numpy as np
from datetime import datetime
import cartopy.crs as ccrs
import warnings
warnings.filterwarnings("ignore")

fname = "/home/disk/monsoon/precip/cfradial/spol_ncar/cfradial/rate/sur/20220607/cfrad.20220607_042450.162_to_20220607_043052.364_SPOL_SUR.nc"
outdir_base = '/home/disk/monsoon/precip/radar/spol_test'

get date and time from filename

filename = os.path.basename(fname)
(prefix,start,junk,junk,junk) = filename.split('.')
start_obj = datetime. strptime(start, '%Y%m%d_%H%M%S')
start_str = start_obj.strftime('%Y/%m/%d %H:%M:%S')
datetime_str = start_obj.strftime('%Y%m%d%H%M%S')
date = start_obj.strftime('%Y%m%d')

create outdir if necessary

outdir = outdir_base+'/'+date
if not os.path.exists(outdir):
os.makedirs(outdir)

read input file & get elevation angles

radar = pyart.io.read(fname)
radar.scan_type = 'sur'
els = radar.fixed_angle['data']

get lowest elevation angle

index = 0
angle = round(els[index],1)
print('lowest angle =',angle)

check to see if image already exists

file_out = 'research.Radar_SPOL.'+datetime_str+'.ppim_rrate_'+str(angle).replace('.','')+'.png'
if not os.path.isfile(outdir+'/'+file_out):

# remove transition angle flags
subset = radar.extract_sweeps([index])
trans = subset.antenna_transition["data"]
trans[:] = 0
subset.antenna_transition["data"] = trans

# create display
# use 'subset' instead of 'radar' to define display
# then sweep will be 0 for all plots since subset contains only one sweep
display = pyart.graph.RadarMapDisplay(subset)
fig = plt.figure(figsize=(12, 4.5))
fig.tight_layout()
fig.suptitle('SPOL Rain Rates '+start_str+' UTC PPI '+str(angle)+' deg', fontsize=18)

ax = fig.add_subplot(121, projection=ccrs.PlateCarree())
display.plot_ppi_map('RATE_HYBRID', sweep=0, ax=ax, title='',
                     vmin=0,vmax=50,
                     width=400000, height=400000,
                     colorbar_label='RATE_HYBRID (mm/hr)',
                     cmap='pyart_HomeyerRainbow',
                     lat_lines = np.arange(22,27,.5),
                     lon_lines = np.arange(118, 123,1),
                     #axislabels=('', 'Distance from radar (km)'),
                     resolution = '10m')

ax = fig.add_subplot(122, projection=ccrs.PlateCarree())
display.plot_ppi_map('RATE_PID', sweep=0, ax=ax, title='',
                     vmin=0,vmax=50,
                     width=400000, height=400000,
                     colorbar_label='RATE_PID (mm/hr)',
                     #cmap='pyart_Carbone42',
                     cmap='pyart_HomeyerRainbow',
                     lat_lines = np.arange(22,27,.5),
                     lon_lines = np.arange(118, 123,1),
                     #axislabels=('', 'Distance from radar (km)'),
                     resolution = '10m')

# save plot
plt.savefig(outdir+'/'+file_out)

`
research Radar_SPOL 20220607042450 ppim_rrate_05_oldPyart
research Radar_SPOL 20220607042450 ppim_rrate_05_newPyart

@mgrover1
Copy link
Collaborator

@srbrodzik can you add embellish = True to see if that solves the issue?

@srbrodzik
Copy link
Author

I'm not familiar with that command or how to use it and couldn't find anything about it on the web, so I put it after the display and fig command and before the individual plots are defined, like this:

display = pyart.graph.RadarMapDisplay(subset)
fig = plt.figure(figsize=(12, 4.5))
fig.tight_layout()
fig.suptitle('SPOL Rain Rates '+start_str+' UTC PPI '+str(angle)+' deg', fontsize=18)
embellish = True

It made no difference.

If there's a more proper way to use the command, let me know.

@mgrover1
Copy link
Collaborator

Could you add it in the plot_ppi_map? Ex. Plot_ppi_map(embellish=True)

@mgrover1
Copy link
Collaborator

# remove transition angle flags
subset = radar.extract_sweeps([index])
trans = subset.antenna_transition["data"]
trans[:] = 0
subset.antenna_transition["data"] = trans

# create display
# use 'subset' instead of 'radar' to define display
# then sweep will be 0 for all plots since subset contains only one sweep
display = pyart.graph.RadarMapDisplay(subset)
fig = plt.figure(figsize=(12, 4.5))
fig.tight_layout()
fig.suptitle('SPOL Rain Rates '+start_str+' UTC PPI '+str(angle)+' deg', fontsize=18)

ax = fig.add_subplot(121, projection=ccrs.PlateCarree())
display.plot_ppi_map('RATE_HYBRID', sweep=0, ax=ax, title='',
                     vmin=0,vmax=50,
                     width=400000, height=400000,
                     colorbar_label='RATE_HYBRID (mm/hr)',
                     cmap='pyart_HomeyerRainbow',
                     lat_lines = np.arange(22,27,.5),
                     lon_lines = np.arange(118, 123,1),
                     #axislabels=('', 'Distance from radar (km)'),
                     embellish=True,
                     resolution = '10m')

ax = fig.add_subplot(122, projection=ccrs.PlateCarree())
display.plot_ppi_map('RATE_PID', sweep=0, ax=ax, title='',
                     vmin=0,vmax=50,
                     width=400000, height=400000,
                     colorbar_label='RATE_PID (mm/hr)',
                     #cmap='pyart_Carbone42',
                     cmap='pyart_HomeyerRainbow',
                     lat_lines = np.arange(22,27,.5),
                     lon_lines = np.arange(118, 123,1),
                     #axislabels=('', 'Distance from radar (km)'),
                     embellish=True,
                     resolution = '10m')

# save plot
plt.savefig(outdir+'/'+file_out)

@srbrodzik
Copy link
Author

srbrodzik commented Aug 19, 2022 via email

@mgrover1
Copy link
Collaborator

mgrover1 commented Aug 20, 2022

I tried troubleshooting with version 1.12.5, and was not able to reproduce the error

# remove transition angle flags
subset = radar.extract_sweeps([index])
trans = subset.antenna_transition["data"]
trans[:] = 0
subset.antenna_transition["data"] = trans

# create display
# use 'subset' instead of 'radar' to define display
# then sweep will be 0 for all plots since subset contains only one sweep
display = pyart.graph.RadarMapDisplay(subset)
fig = plt.figure(figsize=(12, 4.5))
fig.tight_layout()
fig.suptitle('SPOL Rain Rates '+start_str+' UTC PPI '+str(angle)+' deg', fontsize=18)

ax = fig.add_subplot(121, projection=ccrs.PlateCarree())
display.plot_ppi_map('RATE_HYBRID', sweep=0, ax=ax, title='',
                     vmin=0,vmax=50,
                     width=400000, height=400000,
                     colorbar_label='RATE_HYBRID (mm/hr)',
                     cmap='pyart_HomeyerRainbow',
                     lat_lines = np.arange(22,27,.5),
                     lon_lines = np.arange(118, 123,1),
                     #axislabels=('', 'Distance from radar (km)'),
                     # embellish=True,
                     resolution = '10m')

ax = fig.add_subplot(122, projection=ccrs.PlateCarree())
display.plot_ppi_map('RATE_PID', sweep=0, ax=ax, title='',
                     vmin=0,vmax=50,
                     width=400000, height=400000,
                     colorbar_label='RATE_PID (mm/hr)',
                     #cmap='pyart_Carbone42',
                     cmap='pyart_HomeyerRainbow',
                     lat_lines = np.arange(22,27,.5),
                     lon_lines = np.arange(118, 123,1),
                     #axislabels=('', 'Distance from radar (km)'),
                     # embellish=True,
                     resolution = '10m')

# save plot
plt.savefig(outdir+'/'+file_out)

Screen Shot 2022-08-20 at 9 16 47 AM

There is one way to override the grid labels, by adding

ax.gridlines(xlocs=lon_lines, ylocs=lat_lines, draw_labels=True)

When you create the plots. I added a revised code snippet similar to above, except with the added line to make sure that grid lines are added and labels are included! I hope this helps!

index = 0 

# remove transition angle flags
subset = radar.extract_sweeps([index])
trans = subset.antenna_transition["data"]
trans[:] = 0
subset.antenna_transition["data"] = trans

# create display
# use 'subset' instead of 'radar' to define display
# then sweep will be 0 for all plots since subset contains only one sweep
display = pyart.graph.RadarMapDisplay(subset)
fig = plt.figure(figsize=(12, 4.5))
fig.tight_layout()
fig.suptitle('SPOL Rain Rates '+start_str+' UTC PPI '+str(angle)+' deg', fontsize=18)
lat_lines = np.arange(22,27,.5)
lon_lines = np.arange(118, 123,1)

ax = fig.add_subplot(121, projection=ccrs.PlateCarree())
display.plot_ppi_map('RATE_HYBRID', sweep=0, ax=ax, title='',
                     fig=None,
                     vmin=0,vmax=50,
                     width=400000, height=400000,
                     colorbar_label='RATE_HYBRID (mm/hr)',
                     cmap='pyart_HomeyerRainbow',
                     lat_lines = lat_lines,
                     lon_lines = lon_lines,
                     #axislabels=('', 'Distance from radar (km)'),
                     embellish=True,
                     resolution = '10m')

# Add grid labels to the first plot
gl = ax.gridlines(xlocs=lon_lines, ylocs=lat_lines, draw_labels=True)
gl.top_labels = False
gl.right_labels = False

ax2 = fig.add_subplot(122, projection=ccrs.PlateCarree())
display.plot_ppi_map('RATE_PID', sweep=0, ax=ax2, title='',
                     fig=None,
                     vmin=0,vmax=50,
                     width=400000, height=400000,
                     colorbar_label='RATE_PID (mm/hr)',
                     #cmap='pyart_Carbone42',
                     cmap='pyart_HomeyerRainbow',
                     lat_lines = lat_lines,
                     lon_lines = lon_lines,
                     #axislabels=('', 'Distance from radar (km)'),
                     embellish=True,
                     resolution = '10m')

# Add grid labels to the other plot
gl2 = ax2.gridlines(xlocs=lon_lines, ylocs=lat_lines, draw_labels=True)
gl2.top_labels = False
gl2.right_labels = False

@srbrodzik
Copy link
Author

srbrodzik commented Aug 22, 2022 via email

@mgrover1
Copy link
Collaborator

@srbrodzik can you run conda list and post the output here?

@srbrodzik
Copy link
Author

srbrodzik commented Aug 23, 2022 via email

@mgrover1
Copy link
Collaborator

Ahh okay - I am not seeing the dpkg list...

Can you try updating matplotlib to a recent version? That might fix it or is at least worth a try.

@srbrodzik
Copy link
Author

srbrodzik commented Aug 23, 2022 via email

@mgrover1
Copy link
Collaborator

Okay! Let me know how that goes... fingers crossed that fixes it!

@srbrodzik
Copy link
Author

srbrodzik commented Aug 29, 2022 via email

@kmuehlbauer
Copy link
Contributor

Welcome to dependency hell, @srbrodzik. This was fixed in cartopy here: SciTools/cartopy#2054

But I do not know if this is already in their latest release.

@kmuehlbauer
Copy link
Contributor

Ok, looks like we have to wait for the next cartopy release: SciTools/cartopy#2054 (comment)

@mgrover1
Copy link
Collaborator

mgrover1 commented Aug 30, 2022

Yeah - @srbrodzik for some reason your environment has the new experimental version of matplotlib, which causes some serious carroty (geo-plotting) issues... It looks like the maintainers of Cartopy are prioritizing getting a release out to fix this very soon.

One thing you could try right now to fix this is to specify

conda install -c conda-forge matplotlib=3.5.2

or

pip install matplotlib==3.5.2

@srbrodzik
Copy link
Author

srbrodzik commented Aug 30, 2022 via email

@srbrodzik
Copy link
Author

srbrodzik commented Aug 30, 2022 via email

@mgrover1
Copy link
Collaborator

mgrover1 commented Sep 1, 2022

I will try to recreate this environment - thanks for sharing which packages you used.

@srbrodzik
Copy link
Author

srbrodzik commented Sep 2, 2022 via email

@mgrover1
Copy link
Collaborator

@srbrodzik - I tracked down the issue. You will need to update your version of cartopy to use the new version of matplotlib

see this discussion SciTools/cartopy#2054

@srbrodzik
Copy link
Author

srbrodzik commented Sep 22, 2022 via email

@mgrover1
Copy link
Collaborator

@srbrodzik any updates here? Did this solve the issue?

@srbrodzik
Copy link
Author

srbrodzik commented Sep 29, 2022 via email

@srbrodzik
Copy link
Author

srbrodzik commented Oct 12, 2022 via email

@zssherman
Copy link
Collaborator

@srbrodzik Apologizes, late response, but just wanted to follow up, were you able to get the issue solved?

@srbrodzik
Copy link
Author

srbrodzik commented May 14, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants