0% found this document useful (0 votes)
9 views

Code Calculus

The document provides Python code examples using the Py-ART library to visualize radar data, including PPI (Plan Position Indicator) images for reflectivity, velocity, and spectrum width. It also includes CMAX (Composite Maximum) visualizations for these fields, as well as CAPPI (Constant Altitude Plan Position Indicator) images at a specified altitude. Each section demonstrates reading radar data, processing it, and displaying the results using Matplotlib.

Uploaded by

thanh.lelog2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Code Calculus

The document provides Python code examples using the Py-ART library to visualize radar data, including PPI (Plan Position Indicator) images for reflectivity, velocity, and spectrum width. It also includes CMAX (Composite Maximum) visualizations for these fields, as well as CAPPI (Constant Altitude Plan Position Indicator) images at a specified altitude. Each section demonstrates reading radar data, processing it, and displaying the results using Matplotlib.

Uploaded by

thanh.lelog2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

PPI Reflectivity

import pyart
import matplotlib.pyplot as plt

# Path to sample radar data from Py-ART


file_path = r"[file_path]"

# Read radar data from file


radar = pyart.io.read(file_path)

# Specify displayed field


field_name = 'reflectivity'
# Reflectivity is specified

# PPI (Plan Position Indicator) image creation


display = pyart.graph.RadarDisplay(radar)
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111)
display.plot_ppi(field_name, 0, ax=ax, title='Radar Reflectivity',
colorbar_label='dBZ', axislabels=(None, 'East-West distance (km)'))
plt.show()
PPI Velocity
import pyart
import matplotlib.pyplot as plt

# Path to sample radar data from Py-ART


file_path = r"[file_path]"

# Read radar data from file


radar = pyart.io.read(file_path)

# Specify displayed field


field_name = 'velocity' # Velocity is specified

# PPI (Plan Position Indicator) image creation


display = pyart.graph.RadarDisplay(radar)
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111)
display.plot_ppi(field_name, 0, ax=ax, title='Radar Velocity',
colorbar_label='Velocity (m/s)', axislabels=(None, 'East-West distance
(km)'))
plt.show()
PPI Spectrum Width
import pyart
import matplotlib.pyplot as plt

# Path to sample radar data from Py-ART


file_path = r"[file_path]"

# Read radar data from file


radar = pyart.io.read(file_path)

# Specify displayed field


field_name = 'spectrum_width'
# spectrum_width is specified

# PPI (Plan Position Indicator) image creation


display = pyart.graph.RadarDisplay(radar)
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111)
display.plot_ppi(field_name, 0, ax=ax, title='Radar Spectrum Width',
colorbar_label='Spectrum Width (m)', axislabels=(None, 'East-West
distance (km)'))
plt.show()
CMAX Reflectivity
import pyart
import matplotlib.pyplot as plt
import numpy as np

# Path to sample radar data from Py-ART


file_path = r"[file_path]"

# Read radar data from file


radar = pyart.io.read(file_path)

# Check if Reflectivity exists


if 'reflectivity' not in radar.fields:
raise KeyError("The radar data does not contain a 'reflectivity' field.")

reflectivity = radar.fields['reflectivity']['data']

# Check for data size


print(f"Reflectivity shape: {reflectivity.shape}")

# Emulate data as 3D if initially 2D


if len(reflectivity.shape) == 2:
num_levels = 10 # Number of emulated levellevels
reflectivity_3d = np.repeat(reflectivity[np.newaxis, :, :], num_levels, axis=0)
print(f"Reflectivity 3D shape: {reflectivity_3d.shape}")
else:
reflectivity_3d = reflectivity

# Calculate CMAX (maximum reflectivity value along the vertical axis)


cmax = np.nanmax(reflectivity_3d, axis=0)

# Display CMAX image


plt.figure(figsize=(10, 8))
plt.imshow(
cmax, origin='lower', cmap='pyart_NWSRef',
extent=(-120, 120, -120, 120),
# Adjust radar spatial range
vmin=-10, vmax=60
# dBZ value
)
plt.title('CMAX Reflectivity (Composite Maximum Reflectivity)')
plt.colorbar(label='Reflectivity (dBZ)')
plt.xlabel('East-West distance (km)')
plt.ylabel('North-South distance (km)')
plt.grid(True)
plt.show()
CMAX Velocity
import pyart
import matplotlib.pyplot as plt
import numpy as np

# Path to sample radar data from Py-ART


file_path = r"[file_path]"

# Read radar data from file


radar = pyart.io.read(file_path)

# Check if Velocity exists


if 'velocity' not in radar.fields:
raise KeyError("The radar data does not contain a 'velocity' field.")

velocity = radar.fields['velocity']['data']

# Check for data size


print(f"Velocity shape: {velocity.shape}")

# Emulate data as 3D if initially 2D


if len(velocity.shape) == 2:
num_levels = 10 # Number of emulated levels
velocity_3d = np.repeat(velocity[np.newaxis, :, :], num_levels, axis=0)
print(f"Velocity 3D shape: {velocity_3d.shape}")
else:
velocity_3d = velocity

# Calculate CMAX (maximum reflectivity value along the vertical axis)


vmax = np.nanmax(velocity_3d, axis=0)

# Display image of CMAX Velocity


plt.figure(figsize=(10, 8))
plt.imshow(
vmax, origin='lower', cmap='pyart_NWSVel', # Specify suitable colors for Velocity
extent=(-120, 120, -120, 120), # Adjust radar spatial range
vmin=-30, vmax=30 # Range of velocity values (m/s)
)
plt.title('CMAX Velocity (Composite Maximum Velocity)')
plt.colorbar(label='Velocity (m/s)')
plt.xlabel('East-West distance (km)')
plt.ylabel('North-South distance (km)')
plt.grid(True)
plt.show()
CMAX Spectrum Width
import pyart
import matplotlib.pyplot as plt
import numpy as np

# Path to sample radar data from Py-ART


file_path = r"[file_path]"

# Read radar data from file


radar = pyart.io.read(file_path)

# Check if Spectrum Width exists


if 'spectrum_width' not in radar.fields:
raise KeyError("The radar data does not contain a 'spectrum_width' field.")

spectrum_width = radar.fields['spectrum_width']['data']

# Check for data size


print(f"Spectrum Width shape: {spectrum_width.shape}")

# Emulate data as 3D if initially 2D


if len(spectrum_width.shape) == 2:
num_levels = 10 # Number of emulated levels
spectrum_width_3d = np.repeat(spectrum_width[np.newaxis, :, :], num_levels,
axis=0)
print(f"Spectrum Width 3D shape: {spectrum_width_3d.shape}")
else:
spectrum_width_3d = spectrum_width

# Calculate CMAX (maximum reflectivity value along the vertical axis)


smax = np.nanmax(spectrum_width_3d, axis=0)

# Display CMAX Spectrum Width image


plt.figure(figsize=(10, 8))
plt.imshow(
smax, origin='lower', cmap='pyart_NWS_SPW', # Specify suitable colors for
Spectrum Width
extent=(-120, 120, -120, 120), # Adjust radar spatial range
vmin=0, vmax=10 # Range of spectral values (m)
)
plt.title('CMAX Spectrum Width (Composite Maximum Spectrum Width)')
plt.colorbar(label='Spectrum Width (m)')
plt.xlabel('East-West distance (km)')
plt.ylabel('North-South distance (km)')
plt.grid(True)
plt.show()
CAPPI Reflectivity
import pyart
import matplotlib.pyplot as plt

# Path to sample radar data from Py-ART


file_path = r"d:\Project Calculus\T5\Pro-Raw-01-11-T05-2022\01\60.RAW1ME7"

# Read radar data from file


radar = pyart.io.read(file_path)

# Specify displayed field


field_name = 'reflectivity'

grid = pyart.map.grid_from_radars(
radar,
grid_shape=(1, 241, 241), # Number of height levels and grid size
grid_limits=((2000, 2000), (-120000.0, 120000.0), (-120000.0, 120000.0)), # Height
(m) và Width (km)
fields=['reflectivity']
# Displayed field
)
# Extract reflectivity data at a fixed altitude (CAPPI)
reflectivity = grid.fields['reflectivity']['data'][0]

# Render a CAPPI image


plt.figure(figsize=(10, 8))
plt.imshow(
reflectivity, origin='lower', extent=(-120, 120, -120, 120),
cmap='pyart_NWSRef', vmin=-10, vmax=60
)
plt.title('CAPPI Reflectivity (dBZ) at 2 km Altitude')
plt.xlabel('East-West distance (km)')
plt.ylabel('North-South distance (km)')
plt.colorbar(label='Reflectivity (dBZ)')
plt.show()
CAPPI Velocity
import pyart
import matplotlib.pyplot as plt

# Path to sample radar data from Py-ART


file_path = r"[file_path]"

# Read radar data from file


radar = pyart.io.read(file_path)

# Specify displayed field


field_name = 'velocity'

# Create grid from radar data


grid = pyart.map.grid_from_radars(
radar,
grid_shape=(1, 241, 241), # Number of height levels and grid size
grid_limits=((2000, 2000), (-120000.0, 120000.0), (-120000.0, 120000.0)),
# Height(m) and Width (km)
fields=['velocity']
# Displayed field
)

# Extract reflectivity data at a fixed altitude (CAPPI)


velocity = grid.fields['velocity']['data'][0]

# Render a CAPPI image


plt.figure(figsize=(10, 8))
plt.imshow(
velocity, origin='lower', extent=(-120, 120, -120, 120),
cmap='pyart_NWSVel', vmin=-30, vmax=30
# Range of velocity values (m/s)
)
plt.title('CAPPI Velocity (m/s) at 2 km Altitude')
plt.xlabel('East-West distance (km)')
plt.ylabel('North-South distance (km)')
plt.colorbar(label='Velocity (m/s)')
plt.show()
CAPPI Spectrum Width
import pyart
import matplotlib.pyplot as plt

# Path to sample radar data from Py-ART


file_path = r"[file_path]"

# Read radar data from file


radar = pyart.io.read(file_path)

# Specify displayed field


field_name = 'spectrum_width' # spectrum_width is specified

# Create grid from radar data


grid = pyart.map.grid_from_radars(
radar,
grid_shape=(1, 241, 241), # Number of height levels and grid size
grid_limits=((2000, 2000), (-120000.0, 120000.0), (-120000.0, 120000.0)),
# Height (m) and Width (km)
fields=[field_name] # Displayed field
)

# Extract reflectivity data at a fixed altitude (CAPPI)


spectrum_width = grid.fields[field_name]['data'][0]

# Render CAPPI spectrum width image


plt.figure(figsize=(10, 8))
plt.imshow(
spectrum_width, origin='lower', extent=(-120, 120, -120, 120),
cmap='pyart_NWSVel', vmin=0, vmax=10 # Adjust range of Spectrum Width
values (m/s)
)
plt.title('CAPPI Spectrum Width (m) at 2 km Altitude')
plt.xlabel('East-West distance (km)')
plt.ylabel('North-South distance (km)')
plt.colorbar(label='Spectrum Width (m)')
plt.show()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy