import os
import pyart
import xradar
import cmweather
import numpy as np
import xarray as xr
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings("ignore")
file1 = "2021110309550500dBZ.vol"
dtree = xradar.io.open_rainbow_datatree(file1)
# Fubction to add necessaey metadata, in order to export it to cfradial1 format
def correct_cfradial2(dtree):
data = np.array('axis_z', dtype='|S32')
attributes = {
'standard_name': 'primary_axis_of_rotation',
'options': 'axis_z, axis_y, axis_x'
}
# Create the xarray DataArray
dtree['primary_axis'] = xr.DataArray(data, attrs=attributes, dims=())
fixed_angles = []
for grp in dtree.groups:
if "sweep" in grp:
fixed_angle = dtree[grp]['sweep_fixed_angle'].values
fixed_angles.append(fixed_angle)
dtree[grp]['sweep_mode'] = xr.DataArray(
np.array(dtree[grp]['sweep_mode'], dtype='|S32'),
attrs={'standard_name': 'scan_mode_for_sweep',
'options': 'sector, coplane, rhi, vertical_pointing, idle, azimuth_surveillance, \
elevation_surveillance, sunscan, pointing, calibration, manual_ppi, manual_rhi'})
fixed_angles = np.array(fixed_angles, dtype=np.float32)
sweep_groups = np.array([f'sweep_{i}' for i in range(fixed_angles.size)])
dtree['sweep_fixed_angle'] = xr.DataArray(fixed_angles, dims=('sweep'))
dtree['sweep_group_name'] = xr.DataArray(sweep_groups, dims=('sweep'))
dtree['volume_number'] = xr.DataArray(np.array(0, dtype=np.int16),
attrs={'standard_name':'data_volume_index_number'})
dtree['instrument_type'] = xr.DataArray(np.array('radar', dtype='|S32'),
attrs={'standard_name': 'type_of_instrument',
'options': 'radar, lidar',
'meta_group': 'instrument_parameters'}
)
dtree['platform_type'] = xr.DataArray(
np.array('fixed', dtype='|S32'),
attrs={'standard_name': 'platform_type',
'options':'fixed, vehicle, ship, aircraft_fore, aircraft_aft, aircraft_tail, aircraft_belly,\
aircraft_roof, aircraft_nose, satellite_orbit, satellite_geostat'})
return dtree
# Apply Correction
dtree = correct_cfradial2(dtree)
# Export to Cfradial1
xradar.io.to_cfradial1(dtree, filename=None, calibs=True)
# Now Let's create PsedudoRHI using Pyart
radar = pyart.io.read_cfradial('cfrad1_None_20211103_095505.nc')
azi = 10 # Choose any azimuth from 0 to 360
pseudorhi = pyart.util.cross_section_ppi(radar, [azi])
display = pyart.graph.RadarDisplay(pseudorhi)
fig = plt.figure(figsize=[8, 3])
ax = plt.axes()
display.plot_rhi('DBZH', ax=ax, cmap="NWSRef")
ax.set_ylim(0, 20)
ax.set_xlim(0,130)
plt.show()
For the detailed Notebook, and how I created this animation, check this Notebook