Attenuation Correction - Workflow#
import datetime as dt
import os
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
start_process_time = dt.datetime.now()
import radarpolarimetry as rp
Load Data and Plot Initial Situation#
# recent boxpol event
start_time = dt.datetime(2017, 8, 10, 10, 0)
stop_time = dt.datetime(2017, 8, 10, 12, 0)
# choose radar specific parameters
scan = "n_ppi_010deg"
path = rp.get_xpol_path(start_time=start_time)
file_path = os.path.join(path, scan)
print(file_path)
/radar/rp-data/scans/2017/2017-08/2017-08-10/n_ppi_010deg
flist = list(rp.create_filelist(os.path.join(file_path, "*"), start_time, stop_time))
fnames = []
for fpath in flist:
with rp.rpol_data.open(fpath) as f:
fnames.append(f.name)
display(fnames)
['/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/5ae8a24d698f7c8d7b235b3feb45da7e1ba8f92165d8ddc109efec5ea420b8e1',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/f70fea4027302f6b7c9753d25aae48348161447d65a3449f8056995081b8e802',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/fd02d0a546504eb86870012c7d2d30d5f7dc8634aef9c31b36bd95797a4fff22',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/ef91314a1671358c5d0132831850e0ccd755129c341c1eb2057ffb7043a24503',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/330c33682bfd45abd300950ad9ee3a1493526c897816f6833e7c3902348f4939',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/65bb556110b892557e5d776b600f14b1f578c78386073f966c2ae63590ccebfe',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/0542758fa2525403ef27c6d15340eb5747c79724adff12f3965aac3784c6068c',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/bf7897126d47595821f83821faa3003d3883651d49b28c9c3af282b1ff3bd32b',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/d1d635dc8ffa3753371bae77077f0034220fbf52bf8cd251a972304c7ff65e21',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/2d98416f0ab09ed822838e03ef3193daec722588d71265284ca1871e0b0af8bc',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/38d3b275099670f795832f0df71fc40683f1453a253f6aa8beaf73c8b6766437',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/98182b88d979883f73e0488635d437953a62cf7b6d7b49189735aa8288f17535',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/03d8f3cea5e54d53d857132e488f3707e1fccfe2576d7b0c3b043ee2ed1fb748',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/e7ab80ccfa2da70a38a7d7ed5a0c972d90130346084cb109b06935fb7b746248',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/1be9fc90e53ec4cfabd97ad7adaac695f6111162a1f63bc988df5e0c9c3d4a3d',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/2f10a8aa55b8ee0b7a0a428481cb852cfb0e56c3e446a355ad2db44ea95975fe',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/877a566490b67fa4139909206d4b7776320489b7017fa54e6553970f5c4f757a',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/9fe6bad53850a9ee512eba5d45483489cab435cf614662417cdd1d8387297666',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/763637ea3f07f329a583ccab4bdfee4dc7511c0fe316838f1dde6bfbd4e071ff',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/45d241184a047c0b2788a27dce4c03c5300708b5e91792118b012961fadce608',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/e52e9ff623435e29fc8b2cd773d3644991acb17790db88a613c7a88eeb7a1375',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/d1c132bd7ddb4a5f4e8471e7bfbea008d2404d5fdc4d7069173c55d3e26f4055',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/c2945c7b8e0c1bc68465aa3bb46d69ca007515dae7f65e6de09055c001f54426',
'/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/.cache/ftp.meteo.uni-bonn.de/7fb21486e0059ee055b090c4e84df34167bd99c8eba11e9498b07e36a68e7c48']
reindex_angle = dict(start_angle=0, stop_angle=360, angle_res=1.0, direction=1)
def preprocess(ds):
ds = ds.set_coords("sweep_mode")
ds = ds.assign_coords(time2=ds.time.values.min())
el_median = ds.elevation.load().median("azimuth", skipna=True)
elevation = xr.where(ds.elevation != el_median, el_median, ds.elevation)
ds = ds.assign_coords(elevation=elevation)
return ds
sweep_ts = xr.open_mfdataset(
fnames,
concat_dim="time2",
combine="nested",
engine="gamic",
group="sweep_0",
reindex_angle=reindex_angle,
preprocess=preprocess,
)
display(sweep_ts)
<xarray.Dataset> Size: 337MB
Dimensions: (time2: 24, azimuth: 360, range: 750)
Coordinates:
* time2 (time2) datetime64[ns] 192B 2017-08-10T10:03:32.922000...
* azimuth (azimuth) float64 3kB 0.5 1.5 2.5 ... 357.5 358.5 359.5
elevation (azimuth) float64 3kB 0.9998 0.9998 ... 0.9998 0.9998
time (time2, azimuth) datetime64[ns] 69kB 2017-08-10T10:03:...
* range (range) float32 3kB 100.0 300.0 ... 1.497e+05 1.499e+05
sweep_mode <U20 80B 'azimuth_surveillance'
longitude float64 8B 7.072
latitude float64 8B 50.73
altitude float64 8B 99.5
Data variables: (12/18)
DBZH (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBZV (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
KDP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
RHOHV (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
CMAP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBTH (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
... ...
PHIDP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
sweep_number (time2) int64 192B 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0
prt_mode (time2) <U7 672B 'not_set' 'not_set' ... 'not_set'
follow_mode (time2) <U7 672B 'not_set' 'not_set' ... 'not_set'
sweep_fixed_angle (time2) float64 192B 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0
nyquist_velocity (time2) float64 192B 5.623 5.623 5.623 ... 5.623 5.623
Attributes:
source: gamic
ant_gain_h: 44.0
ant_gain_v: 44.0
noise_power_h: -1.39495
noise_power_v: -1.09706
rx_loss_h: 0.73
rx_loss_v: 0.73sweep_ts = sweep_ts.wrl.georef.georeference()
display(sweep_ts)
<xarray.Dataset> Size: 349MB
Dimensions: (time2: 24, azimuth: 360, range: 750)
Coordinates: (12/16)
* time2 (time2) datetime64[ns] 192B 2017-08-10T10:03:32.922000...
* azimuth (azimuth) float64 3kB 0.5 1.5 2.5 ... 357.5 358.5 359.5
elevation (azimuth) float64 3kB 0.9998 0.9998 ... 0.9998 0.9998
time (time2, azimuth) datetime64[ns] 69kB 2017-08-10T10:03:...
* range (range) float32 3kB 100.0 300.0 ... 1.497e+05 1.499e+05
x (azimuth, range) float64 2MB 0.8725 2.618 ... -1.307e+03
... ...
bins (azimuth, range) float32 1MB 100.0 300.0 ... 1.499e+05
sweep_mode <U20 80B 'azimuth_surveillance'
longitude float64 8B 7.072
latitude float64 8B 50.73
altitude float64 8B 99.5
crs_wkt int64 8B 0
Data variables: (12/18)
DBZH (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBZV (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
KDP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
RHOHV (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
CMAP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBTH (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
... ...
PHIDP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
sweep_number (time2) int64 192B 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0
prt_mode (time2) <U7 672B 'not_set' 'not_set' ... 'not_set'
follow_mode (time2) <U7 672B 'not_set' 'not_set' ... 'not_set'
sweep_fixed_angle (time2) float64 192B 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0
nyquist_velocity (time2) float64 192B 5.623 5.623 5.623 ... 5.623 5.623
Attributes:
source: gamic
ant_gain_h: 44.0
ant_gain_v: 44.0
noise_power_h: -1.39495
noise_power_v: -1.09706
rx_loss_h: 0.73
rx_loss_v: 0.73swp = sweep_ts.isel(time2=0)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(
nrows=2,
ncols=2,
figsize=(12, 10),
sharex=True,
sharey=True,
squeeze=True,
constrained_layout=True,
)
rp.plot_moment(swp.DBTH, ax=ax1)
rp.plot_moment(swp.ZDR, ax=ax2)
rp.plot_moment(swp.RHOHV, ax=ax3)
rp.plot_moment(swp.PHIDP, ax=ax4)
t = fig.suptitle(
f"sweep at {swp.sweep_fixed_angle.values:.1f} deg elevation at {swp.time.min().values.astype('<M8[s]')}",
fontsize=18,
)
DEM processing#
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, sharey=True, figsize=(12, 4))
# Get DEM-data
rasterfile = rp.rpol_data.open("/radar/wradlib-data/geo/bonn_dem.tif").name
dem = xr.open_dataset(rasterfile, engine="rasterio")
# DEM-data on radar grid
sweep_ts = sweep_ts.pipe(rp.interpolate_dem, dem.band_data[0])
sweep_ts.DEM.wrl.vis.plot(ax=ax1)
# Beamblockage
sweep_ts = sweep_ts.pipe(rp.get_beamblockage)
sweep_ts.CBB.wrl.vis.plot(ax=ax2)
# QI(BBF)
sweep_ts = sweep_ts.pipe(rp.get_qbbf)
sweep_ts.QBBF.wrl.vis.plot(ax=ax3)
plt.tight_layout()
Clutter and Noise Correction#
bit = 0x001
sweep_ts.DBTH.where((sweep_ts.CMAP.astype("uint16") & bit) != bit).isel(
time2=12
).wrl.vis.plot()
# plt.gca().set_xlim(-20e3, 20e3)
# plt.gca().set_ylim(-20e3, 20e3)
<matplotlib.collections.QuadMesh at 0x7f2b72db2490>
start_time_day = dt.datetime(start_time.year, start_time.month, start_time.day)
delta = dt.timedelta(days=1)
sweep_ts_day = rp.load_timeseries_sweep(start_time_day, delta, scan)
DBTH = sweep_ts_day.DBTH.sum("time2")
loading 288 files
%%time
sweep_ts = sweep_ts.pipe(
rp.estimate_cmap, DBTH, upper_frequency=0.05, lower_frequency=0.01, name="CMAP2"
)
CPU times: user 12.1 s, sys: 887 ms, total: 13 s
Wall time: 10.4 s
display(sweep_ts)
<xarray.Dataset> Size: 361MB
Dimensions: (time2: 24, azimuth: 360, range: 750)
Coordinates: (12/20)
* time2 (time2) datetime64[ns] 192B 2017-08-10T10:03:32.922000...
* azimuth (azimuth) float64 3kB 0.5 1.5 2.5 ... 357.5 358.5 359.5
elevation (azimuth) float64 3kB 0.9998 0.9998 ... 0.9998 0.9998
time (time2, azimuth) datetime64[ns] 69kB 2017-08-10T10:03:...
* range (range) float32 3kB 100.0 300.0 ... 1.497e+05 1.499e+05
x (azimuth, range) float64 2MB 0.8725 2.618 ... -1.307e+03
... ...
longitude float64 8B 7.072
latitude float64 8B 50.73
altitude float64 8B 99.5
crs_wkt int64 8B 0
band int64 8B 1
spatial_ref int64 8B 0
Data variables: (12/23)
DBZH (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBZV (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
KDP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
RHOHV (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
CMAP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBTH (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
... ...
nyquist_velocity (time2) float64 192B 5.623 5.623 5.623 ... 5.623 5.623
DEM (azimuth, range) float32 1MB 71.22 64.67 ... 56.64 56.04
PBB (azimuth, range) float64 2MB 0.0 0.0 0.0 ... 0.0 0.0 0.0
CBB (azimuth, range) float64 2MB 0.0 0.0 0.0 ... 0.0 0.0 0.0
QBBF (azimuth, range) float64 2MB 1.0 1.0 1.0 ... 1.0 1.0 1.0
CMAP2 (azimuth, range) uint8 270kB 1 1 0 1 0 1 ... 0 0 0 0 0 0
Attributes:
source: gamic
ant_gain_h: 44.0
ant_gain_v: 44.0
noise_power_h: -1.39495
noise_power_v: -1.09706
rx_loss_h: 0.73
rx_loss_v: 0.73sweep_ts.isel(time2=0).CMAP2.wrl.vis.plot()
<matplotlib.collections.QuadMesh at 0x7f2af81b6710>
noise = (-40, -10, 1)
hist = rp.noise_hist(sweep_ts.DBZH, sweep_ts.RHOHV, noise=noise)
nl = rp.noise_level(hist)
[ ] | 0% Completed | 928.48 us
[ ] | 0% Completed | 130.53 ms
[ ] | 0% Completed | 265.81 ms
[ ] | 0% Completed | 368.21 ms
[ ] | 0% Completed | 472.80 ms
[ ] | 0% Completed | 574.22 ms
[ ] | 0% Completed | 676.24 ms
[ ] | 0% Completed | 779.64 ms
[ ] | 1% Completed | 883.40 ms
[ ] | 1% Completed | 989.31 ms
[ ] | 1% Completed | 1.10 s
[ ] | 1% Completed | 1.20 s
[ ] | 1% Completed | 1.31 s
[ ] | 2% Completed | 1.41 s
[ ] | 2% Completed | 1.51 s
[# ] | 2% Completed | 1.62 s
[# ] | 3% Completed | 1.72 s
[# ] | 3% Completed | 1.82 s
[# ] | 3% Completed | 1.92 s
[# ] | 4% Completed | 2.03 s
[# ] | 4% Completed | 2.13 s
[# ] | 4% Completed | 2.23 s
[## ] | 5% Completed | 2.34 s
[## ] | 5% Completed | 2.44 s
[## ] | 5% Completed | 2.54 s
[## ] | 6% Completed | 2.65 s
[## ] | 6% Completed | 2.75 s
[## ] | 6% Completed | 2.86 s
[## ] | 7% Completed | 2.96 s
[## ] | 7% Completed | 3.07 s
[### ] | 7% Completed | 3.17 s
[### ] | 7% Completed | 3.60 s
[### ] | 8% Completed | 3.71 s
[### ] | 8% Completed | 3.81 s
[### ] | 8% Completed | 3.92 s
[### ] | 9% Completed | 4.02 s
[### ] | 9% Completed | 4.13 s
[### ] | 9% Completed | 4.24 s
[#### ] | 10% Completed | 4.35 s
[#### ] | 10% Completed | 4.46 s
[#### ] | 10% Completed | 4.56 s
[#### ] | 11% Completed | 4.66 s
[#### ] | 11% Completed | 4.77 s
[#### ] | 11% Completed | 4.87 s
[#### ] | 12% Completed | 4.98 s
[##### ] | 12% Completed | 5.08 s
[##### ] | 13% Completed | 5.18 s
[##### ] | 13% Completed | 5.29 s
[##### ] | 13% Completed | 5.39 s
[##### ] | 14% Completed | 5.50 s
[##### ] | 14% Completed | 5.60 s
[##### ] | 14% Completed | 5.71 s
[###### ] | 15% Completed | 5.81 s
[###### ] | 15% Completed | 5.92 s
[###### ] | 15% Completed | 6.02 s
[###### ] | 16% Completed | 6.12 s
[###### ] | 16% Completed | 6.23 s
[###### ] | 16% Completed | 6.33 s
[###### ] | 17% Completed | 6.44 s
[###### ] | 17% Completed | 6.54 s
[####### ] | 17% Completed | 6.65 s
[####### ] | 17% Completed | 6.75 s
[####### ] | 18% Completed | 6.85 s
[####### ] | 18% Completed | 6.96 s
[####### ] | 18% Completed | 7.06 s
[####### ] | 19% Completed | 7.17 s
[####### ] | 19% Completed | 7.27 s
[######## ] | 20% Completed | 7.38 s
[######## ] | 20% Completed | 7.49 s
[######## ] | 20% Completed | 7.59 s
[######## ] | 21% Completed | 7.69 s
[######## ] | 21% Completed | 7.80 s
[######## ] | 21% Completed | 7.90 s
[######## ] | 22% Completed | 8.01 s
[######## ] | 22% Completed | 8.11 s
[######### ] | 22% Completed | 8.21 s
[######### ] | 23% Completed | 8.32 s
[######### ] | 23% Completed | 8.43 s
[######### ] | 23% Completed | 8.53 s
[######### ] | 24% Completed | 8.64 s
[######### ] | 24% Completed | 8.74 s
[######### ] | 24% Completed | 8.84 s
[########## ] | 25% Completed | 8.95 s
[########## ] | 25% Completed | 9.05 s
[########## ] | 25% Completed | 9.16 s
[########## ] | 26% Completed | 9.26 s
[########## ] | 26% Completed | 9.37 s
[########## ] | 27% Completed | 9.48 s
[########## ] | 27% Completed | 9.59 s
[########### ] | 27% Completed | 9.69 s
[########### ] | 28% Completed | 9.79 s
[########### ] | 28% Completed | 9.90 s
[########### ] | 28% Completed | 10.01 s
[########### ] | 29% Completed | 10.11 s
[########### ] | 29% Completed | 10.22 s
[########### ] | 29% Completed | 10.32 s
[############ ] | 30% Completed | 10.42 s
[############ ] | 30% Completed | 10.53 s
[############ ] | 30% Completed | 10.63 s
[############ ] | 31% Completed | 10.74 s
[############ ] | 31% Completed | 10.84 s
[############ ] | 31% Completed | 10.94 s
[############ ] | 32% Completed | 11.05 s
[############ ] | 32% Completed | 11.15 s
[############# ] | 32% Completed | 11.26 s
[############# ] | 33% Completed | 11.36 s
[############# ] | 33% Completed | 11.47 s
[############# ] | 33% Completed | 11.58 s
[############# ] | 34% Completed | 11.68 s
[############# ] | 34% Completed | 11.79 s
[############# ] | 34% Completed | 11.89 s
[############## ] | 35% Completed | 12.00 s
[############## ] | 35% Completed | 12.10 s
[############## ] | 35% Completed | 12.21 s
[############## ] | 36% Completed | 12.32 s
[############## ] | 36% Completed | 12.42 s
[############## ] | 36% Completed | 12.53 s
[############## ] | 37% Completed | 12.63 s
[############## ] | 37% Completed | 12.73 s
[############### ] | 37% Completed | 12.83 s
[############### ] | 38% Completed | 12.94 s
[############### ] | 38% Completed | 13.04 s
[############### ] | 38% Completed | 13.14 s
[############### ] | 38% Completed | 13.25 s
[############### ] | 39% Completed | 13.36 s
[############### ] | 39% Completed | 13.46 s
[################ ] | 40% Completed | 13.56 s
[################ ] | 40% Completed | 13.67 s
[################ ] | 40% Completed | 13.77 s
[################ ] | 40% Completed | 13.87 s
[################ ] | 41% Completed | 13.98 s
[################ ] | 41% Completed | 14.08 s
[################ ] | 41% Completed | 14.19 s
[################ ] | 42% Completed | 14.29 s
[################# ] | 42% Completed | 14.39 s
[################# ] | 42% Completed | 14.50 s
[################# ] | 43% Completed | 14.60 s
[################# ] | 43% Completed | 14.71 s
[################# ] | 43% Completed | 14.81 s
[################# ] | 44% Completed | 14.92 s
[################# ] | 44% Completed | 15.02 s
[################# ] | 44% Completed | 15.12 s
[################## ] | 45% Completed | 15.23 s
[################## ] | 45% Completed | 15.33 s
[################## ] | 45% Completed | 15.44 s
[################## ] | 46% Completed | 15.54 s
[################## ] | 46% Completed | 15.64 s
[################## ] | 46% Completed | 15.75 s
[################## ] | 47% Completed | 15.86 s
[################### ] | 47% Completed | 15.97 s
[################### ] | 47% Completed | 16.07 s
[################### ] | 48% Completed | 16.17 s
[################### ] | 48% Completed | 16.28 s
[################### ] | 48% Completed | 16.38 s
[################### ] | 49% Completed | 16.48 s
[################### ] | 49% Completed | 16.59 s
[################### ] | 49% Completed | 16.69 s
[#################### ] | 50% Completed | 16.80 s
[#################### ] | 50% Completed | 16.90 s
[#################### ] | 50% Completed | 17.00 s
[#################### ] | 51% Completed | 17.10 s
[#################### ] | 51% Completed | 17.21 s
[#################### ] | 52% Completed | 17.31 s
[#################### ] | 52% Completed | 17.42 s
[##################### ] | 52% Completed | 17.52 s
[##################### ] | 53% Completed | 17.62 s
[##################### ] | 53% Completed | 17.73 s
[##################### ] | 53% Completed | 17.83 s
[##################### ] | 53% Completed | 17.94 s
[##################### ] | 54% Completed | 18.04 s
[##################### ] | 54% Completed | 18.14 s
[##################### ] | 54% Completed | 18.25 s
[###################### ] | 55% Completed | 18.35 s
[###################### ] | 55% Completed | 18.46 s
[###################### ] | 55% Completed | 18.56 s
[###################### ] | 56% Completed | 18.67 s
[###################### ] | 56% Completed | 18.77 s
[###################### ] | 56% Completed | 18.88 s
[###################### ] | 57% Completed | 18.98 s
[###################### ] | 57% Completed | 19.08 s
[####################### ] | 57% Completed | 19.19 s
[####################### ] | 58% Completed | 19.29 s
[####################### ] | 58% Completed | 19.40 s
[####################### ] | 58% Completed | 19.50 s
[####################### ] | 59% Completed | 19.61 s
[####################### ] | 59% Completed | 19.71 s
[####################### ] | 59% Completed | 19.81 s
[######################## ] | 60% Completed | 19.92 s
[######################## ] | 60% Completed | 20.02 s
[######################## ] | 60% Completed | 20.13 s
[######################## ] | 61% Completed | 20.23 s
[######################## ] | 61% Completed | 20.33 s
[######################## ] | 61% Completed | 20.43 s
[######################## ] | 62% Completed | 20.54 s
[######################## ] | 62% Completed | 20.65 s
[######################### ] | 62% Completed | 20.75 s
[######################### ] | 63% Completed | 20.86 s
[######################### ] | 63% Completed | 20.98 s
[######################### ] | 63% Completed | 21.08 s
[######################### ] | 64% Completed | 21.19 s
[######################### ] | 64% Completed | 21.29 s
[######################### ] | 64% Completed | 21.39 s
[########################## ] | 65% Completed | 21.50 s
[########################## ] | 65% Completed | 21.60 s
[########################## ] | 65% Completed | 21.70 s
[########################## ] | 66% Completed | 21.81 s
[########################## ] | 66% Completed | 21.91 s
[########################## ] | 66% Completed | 22.01 s
[########################## ] | 67% Completed | 22.12 s
[########################## ] | 67% Completed | 22.22 s
[########################### ] | 67% Completed | 22.32 s
[########################### ] | 67% Completed | 22.43 s
[########################### ] | 68% Completed | 22.53 s
[########################### ] | 68% Completed | 22.64 s
[########################### ] | 68% Completed | 22.74 s
[########################### ] | 69% Completed | 22.85 s
[########################### ] | 69% Completed | 22.95 s
[############################ ] | 70% Completed | 23.06 s
[############################ ] | 70% Completed | 23.16 s
[############################ ] | 70% Completed | 23.26 s
[############################ ] | 70% Completed | 23.36 s
[############################ ] | 71% Completed | 23.47 s
[############################ ] | 71% Completed | 23.57 s
[############################ ] | 71% Completed | 23.67 s
[############################ ] | 72% Completed | 23.78 s
[############################# ] | 72% Completed | 23.89 s
[############################# ] | 73% Completed | 23.99 s
[############################# ] | 73% Completed | 24.09 s
[############################# ] | 73% Completed | 24.20 s
[############################# ] | 73% Completed | 24.30 s
[############################# ] | 74% Completed | 24.40 s
[############################# ] | 74% Completed | 24.51 s
[############################# ] | 74% Completed | 24.61 s
[############################## ] | 75% Completed | 24.71 s
[############################## ] | 75% Completed | 24.82 s
[############################## ] | 75% Completed | 24.92 s
[############################## ] | 76% Completed | 25.03 s
[############################## ] | 76% Completed | 25.15 s
[############################## ] | 76% Completed | 25.25 s
[############################## ] | 77% Completed | 25.36 s
[############################### ] | 77% Completed | 25.47 s
[############################### ] | 77% Completed | 25.57 s
[############################### ] | 78% Completed | 25.68 s
[############################### ] | 78% Completed | 25.78 s
[############################### ] | 78% Completed | 25.88 s
[############################### ] | 79% Completed | 25.99 s
[############################### ] | 79% Completed | 26.09 s
[############################### ] | 79% Completed | 26.20 s
[################################ ] | 80% Completed | 26.31 s
[################################ ] | 80% Completed | 26.41 s
[################################ ] | 80% Completed | 26.51 s
[################################ ] | 81% Completed | 26.61 s
[################################ ] | 81% Completed | 26.72 s
[################################ ] | 81% Completed | 26.82 s
[################################ ] | 81% Completed | 26.92 s
[################################ ] | 82% Completed | 27.02 s
[################################ ] | 82% Completed | 27.12 s
[################################# ] | 82% Completed | 27.23 s
[################################# ] | 83% Completed | 27.34 s
[################################# ] | 83% Completed | 27.44 s
[################################# ] | 83% Completed | 27.54 s
[################################# ] | 84% Completed | 27.65 s
[################################# ] | 84% Completed | 27.76 s
[################################# ] | 84% Completed | 27.86 s
[################################## ] | 85% Completed | 27.97 s
[################################## ] | 85% Completed | 28.07 s
[################################## ] | 85% Completed | 28.17 s
[################################## ] | 86% Completed | 28.28 s
[################################## ] | 86% Completed | 28.39 s
[################################## ] | 86% Completed | 28.49 s
[################################## ] | 87% Completed | 28.59 s
[################################### ] | 87% Completed | 28.70 s
[################################### ] | 87% Completed | 28.80 s
[################################### ] | 88% Completed | 28.90 s
[################################### ] | 88% Completed | 29.01 s
[################################### ] | 88% Completed | 29.11 s
[################################### ] | 89% Completed | 29.22 s
[################################### ] | 89% Completed | 29.32 s
[################################### ] | 89% Completed | 29.43 s
[#################################### ] | 90% Completed | 29.53 s
[#################################### ] | 90% Completed | 29.63 s
[#################################### ] | 90% Completed | 29.74 s
[#################################### ] | 91% Completed | 29.84 s
[#################################### ] | 91% Completed | 29.94 s
[#################################### ] | 91% Completed | 30.05 s
[#################################### ] | 92% Completed | 30.15 s
[##################################### ] | 92% Completed | 30.25 s
[##################################### ] | 92% Completed | 30.36 s
[##################################### ] | 93% Completed | 30.46 s
[##################################### ] | 93% Completed | 30.57 s
[##################################### ] | 93% Completed | 30.70 s
[##################################### ] | 94% Completed | 30.80 s
[##################################### ] | 94% Completed | 30.90 s
[##################################### ] | 94% Completed | 31.01 s
[###################################### ] | 95% Completed | 31.11 s
[###################################### ] | 95% Completed | 31.21 s
[###################################### ] | 95% Completed | 31.32 s
[###################################### ] | 96% Completed | 31.43 s
[###################################### ] | 96% Completed | 31.53 s
[###################################### ] | 96% Completed | 31.64 s
[###################################### ] | 97% Completed | 31.74 s
[###################################### ] | 97% Completed | 31.84 s
[####################################### ] | 97% Completed | 31.95 s
[####################################### ] | 98% Completed | 32.05 s
[####################################### ] | 98% Completed | 32.15 s
[####################################### ] | 98% Completed | 32.26 s
[####################################### ] | 99% Completed | 32.36 s
[####################################### ] | 99% Completed | 32.47 s
[####################################### ] | 99% Completed | 32.57 s
[####################################### ] | 99% Completed | 32.68 s
[####################################### ] | 99% Completed | 32.78 s
[####################################### ] | 99% Completed | 32.88 s
[####################################### ] | 99% Completed | 32.98 s
[####################################### ] | 99% Completed | 33.08 s
[####################################### ] | 99% Completed | 33.19 s
[########################################] | 100% Completed | 33.29 s
[ ] | 0% Completed | 416.17 us
[ ] | 0% Completed | 116.76 ms
[ ] | 0% Completed | 224.11 ms
[ ] | 1% Completed | 327.43 ms
[# ] | 3% Completed | 433.32 ms
[# ] | 4% Completed | 540.49 ms
[## ] | 5% Completed | 643.27 ms
[## ] | 6% Completed | 747.23 ms
[## ] | 7% Completed | 849.50 ms
[### ] | 8% Completed | 952.19 ms
[### ] | 9% Completed | 1.06 s
[#### ] | 10% Completed | 1.16 s
[#### ] | 11% Completed | 1.27 s
[##### ] | 13% Completed | 1.37 s
[##### ] | 14% Completed | 1.47 s
[###### ] | 15% Completed | 1.57 s
[###### ] | 16% Completed | 1.68 s
[###### ] | 17% Completed | 1.79 s
[####### ] | 18% Completed | 1.89 s
[####### ] | 19% Completed | 1.99 s
[######## ] | 20% Completed | 2.10 s
[######## ] | 22% Completed | 2.20 s
[######### ] | 23% Completed | 2.31 s
[######### ] | 23% Completed | 2.41 s
[########## ] | 25% Completed | 2.51 s
[########## ] | 26% Completed | 2.62 s
[########## ] | 27% Completed | 2.73 s
[########### ] | 28% Completed | 2.83 s
[########### ] | 29% Completed | 2.94 s
[############ ] | 30% Completed | 3.04 s
[############ ] | 31% Completed | 3.15 s
[############# ] | 33% Completed | 3.25 s
[############# ] | 34% Completed | 3.35 s
[############## ] | 35% Completed | 3.46 s
[############## ] | 36% Completed | 3.56 s
[############## ] | 37% Completed | 3.66 s
[############### ] | 38% Completed | 3.77 s
[############### ] | 39% Completed | 3.87 s
[################ ] | 40% Completed | 3.97 s
[################ ] | 41% Completed | 4.08 s
[################# ] | 42% Completed | 4.18 s
[################# ] | 44% Completed | 4.29 s
[################## ] | 45% Completed | 4.39 s
[################## ] | 46% Completed | 4.49 s
[################## ] | 47% Completed | 4.60 s
[################### ] | 48% Completed | 4.70 s
[################### ] | 49% Completed | 4.80 s
[#################### ] | 50% Completed | 4.91 s
[#################### ] | 51% Completed | 5.01 s
[##################### ] | 52% Completed | 5.12 s
[##################### ] | 53% Completed | 5.22 s
[###################### ] | 55% Completed | 5.32 s
[###################### ] | 56% Completed | 5.43 s
[###################### ] | 57% Completed | 5.53 s
[####################### ] | 58% Completed | 5.63 s
[####################### ] | 59% Completed | 5.73 s
[######################## ] | 60% Completed | 5.84 s
[######################## ] | 61% Completed | 5.94 s
[######################### ] | 62% Completed | 6.05 s
[######################### ] | 63% Completed | 6.15 s
[######################### ] | 64% Completed | 6.26 s
[########################## ] | 66% Completed | 6.36 s
[########################## ] | 67% Completed | 6.46 s
[########################### ] | 67% Completed | 6.57 s
[########################### ] | 68% Completed | 6.67 s
[############################ ] | 70% Completed | 6.78 s
[############################ ] | 71% Completed | 6.89 s
[############################ ] | 72% Completed | 6.99 s
[############################# ] | 73% Completed | 7.10 s
[############################# ] | 74% Completed | 7.20 s
[############################## ] | 75% Completed | 7.30 s
[############################## ] | 76% Completed | 7.41 s
[############################### ] | 77% Completed | 7.51 s
[############################### ] | 78% Completed | 7.62 s
[############################### ] | 79% Completed | 7.73 s
[################################ ] | 80% Completed | 7.83 s
[################################ ] | 81% Completed | 7.93 s
[################################# ] | 82% Completed | 8.04 s
[################################# ] | 83% Completed | 8.14 s
[################################## ] | 85% Completed | 8.24 s
[################################## ] | 86% Completed | 8.35 s
[################################## ] | 87% Completed | 8.45 s
[################################### ] | 88% Completed | 8.56 s
[################################### ] | 89% Completed | 8.66 s
[#################################### ] | 90% Completed | 8.77 s
[#################################### ] | 91% Completed | 8.87 s
[##################################### ] | 92% Completed | 8.98 s
[##################################### ] | 94% Completed | 9.08 s
[###################################### ] | 95% Completed | 9.18 s
[###################################### ] | 96% Completed | 9.28 s
[####################################### ] | 97% Completed | 9.39 s
[####################################### ] | 99% Completed | 9.49 s
[####################################### ] | 99% Completed | 9.59 s
[####################################### ] | 99% Completed | 9.70 s
[####################################### ] | 99% Completed | 9.80 s
[####################################### ] | 99% Completed | 9.90 s
[####################################### ] | 99% Completed | 10.01 s
[####################################### ] | 99% Completed | 10.11 s
[########################################] | 100% Completed | 10.21 s
[ ] | 0% Completed | 380.94 us
[ ] | 0% Completed | 112.05 ms
[ ] | 1% Completed | 217.84 ms
[ ] | 2% Completed | 320.23 ms
[# ] | 2% Completed | 425.85 ms
[# ] | 3% Completed | 528.02 ms
[# ] | 4% Completed | 629.72 ms
[## ] | 5% Completed | 733.20 ms
[## ] | 6% Completed | 836.28 ms
[### ] | 7% Completed | 939.42 ms
[### ] | 8% Completed | 1.05 s
[### ] | 9% Completed | 1.15 s
[#### ] | 10% Completed | 1.25 s
[#### ] | 11% Completed | 1.35 s
[#### ] | 12% Completed | 1.46 s
[##### ] | 13% Completed | 1.56 s
[##### ] | 14% Completed | 1.66 s
[###### ] | 15% Completed | 1.77 s
[###### ] | 16% Completed | 1.88 s
[###### ] | 17% Completed | 1.98 s
[####### ] | 18% Completed | 2.08 s
[####### ] | 19% Completed | 2.19 s
[####### ] | 19% Completed | 2.29 s
[######## ] | 20% Completed | 2.40 s
[######## ] | 21% Completed | 2.50 s
[######### ] | 22% Completed | 2.61 s
[######### ] | 23% Completed | 2.71 s
[######### ] | 24% Completed | 2.81 s
[########## ] | 25% Completed | 2.92 s
[########## ] | 26% Completed | 3.03 s
[########### ] | 27% Completed | 3.13 s
[########### ] | 28% Completed | 3.24 s
[########### ] | 29% Completed | 3.34 s
[############ ] | 30% Completed | 3.44 s
[############ ] | 31% Completed | 3.55 s
[############ ] | 31% Completed | 3.65 s
[############# ] | 32% Completed | 3.75 s
[############# ] | 33% Completed | 3.86 s
[############# ] | 34% Completed | 3.96 s
[############## ] | 35% Completed | 4.06 s
[############## ] | 36% Completed | 4.17 s
[############### ] | 37% Completed | 4.28 s
[############### ] | 38% Completed | 4.39 s
[############### ] | 39% Completed | 4.49 s
[################ ] | 40% Completed | 4.59 s
[################ ] | 41% Completed | 4.70 s
[################ ] | 42% Completed | 4.80 s
[################# ] | 43% Completed | 4.90 s
[################# ] | 44% Completed | 5.01 s
[################## ] | 45% Completed | 5.11 s
[################## ] | 46% Completed | 5.21 s
[################## ] | 46% Completed | 5.32 s
[################### ] | 47% Completed | 5.42 s
[################### ] | 48% Completed | 5.53 s
[################### ] | 49% Completed | 5.64 s
[#################### ] | 50% Completed | 5.74 s
[#################### ] | 51% Completed | 5.84 s
[#################### ] | 52% Completed | 5.95 s
[##################### ] | 53% Completed | 6.05 s
[##################### ] | 54% Completed | 6.15 s
[###################### ] | 55% Completed | 6.26 s
[###################### ] | 55% Completed | 6.36 s
[###################### ] | 56% Completed | 6.46 s
[###################### ] | 57% Completed | 6.57 s
[####################### ] | 58% Completed | 6.67 s
[####################### ] | 59% Completed | 6.77 s
[######################## ] | 60% Completed | 6.88 s
[######################## ] | 61% Completed | 6.98 s
[######################## ] | 62% Completed | 7.09 s
[######################### ] | 63% Completed | 7.19 s
[######################### ] | 64% Completed | 7.30 s
[######################### ] | 64% Completed | 7.40 s
[########################## ] | 65% Completed | 7.52 s
[########################## ] | 66% Completed | 7.62 s
[########################## ] | 67% Completed | 7.72 s
[########################### ] | 68% Completed | 7.83 s
[########################### ] | 69% Completed | 7.93 s
[############################ ] | 70% Completed | 8.03 s
[############################ ] | 71% Completed | 8.14 s
[############################ ] | 72% Completed | 8.24 s
[############################# ] | 72% Completed | 8.34 s
[############################# ] | 73% Completed | 8.45 s
[############################# ] | 74% Completed | 8.55 s
[############################## ] | 75% Completed | 8.66 s
[############################## ] | 76% Completed | 8.76 s
[############################## ] | 77% Completed | 8.86 s
[############################### ] | 78% Completed | 8.96 s
[############################### ] | 79% Completed | 9.06 s
[################################ ] | 80% Completed | 9.17 s
[################################ ] | 81% Completed | 9.27 s
[################################ ] | 81% Completed | 9.38 s
[################################ ] | 82% Completed | 9.49 s
[################################# ] | 83% Completed | 9.59 s
[################################# ] | 84% Completed | 9.69 s
[################################## ] | 85% Completed | 9.79 s
[################################## ] | 86% Completed | 9.90 s
[################################## ] | 86% Completed | 10.00 s
[################################### ] | 87% Completed | 10.10 s
[################################### ] | 88% Completed | 10.21 s
[################################### ] | 89% Completed | 10.32 s
[#################################### ] | 90% Completed | 10.42 s
[#################################### ] | 91% Completed | 10.53 s
[##################################### ] | 92% Completed | 10.63 s
[##################################### ] | 93% Completed | 10.74 s
[##################################### ] | 94% Completed | 10.84 s
[###################################### ] | 95% Completed | 10.94 s
[###################################### ] | 96% Completed | 11.05 s
[###################################### ] | 97% Completed | 11.15 s
[####################################### ] | 98% Completed | 11.25 s
[####################################### ] | 99% Completed | 11.36 s
[####################################### ] | 99% Completed | 11.46 s
[####################################### ] | 99% Completed | 11.57 s
[####################################### ] | 99% Completed | 11.67 s
[####################################### ] | 99% Completed | 11.77 s
[####################################### ] | 99% Completed | 11.87 s
[####################################### ] | 99% Completed | 11.97 s
[########################################] | 100% Completed | 12.07 s
sweep_ts = sweep_ts.pipe(rp.noise_correction, "DBZH", "RHOHV", nl)
System PhiDP#
CMAP = sweep_ts.CMAP.astype("uint16")
bit = 0
cmp = (CMAP >> bit) & 0x1
# mask phase
no_clutter_bb = (cmp == 0) & (sweep_ts.CMAP2 == 0)
phimask = sweep_ts.PHIDP.where(no_clutter_bb & (sweep_ts.RHOHV >= 0.9))
# create binary array
phib = xr.where(np.isnan(phimask), 0, 1)
display(phib)
<xarray.DataArray 'PHIDP' (time2: 24, azimuth: 360, range: 750)> Size: 52MB
dask.array<where, shape=(24, 360, 750), dtype=int64, chunksize=(1, 360, 750), chunktype=numpy.ndarray>
Coordinates: (12/21)
* time2 (time2) datetime64[ns] 192B 2017-08-10T10:03:32.922000 ... 2...
* azimuth (azimuth) float64 3kB 0.5 1.5 2.5 3.5 ... 357.5 358.5 359.5
elevation (azimuth) float64 3kB 0.9998 0.9998 0.9998 ... 0.9998 0.9998
time (time2, azimuth) datetime64[ns] 69kB 2017-08-10T10:03:48.503...
* range (range) float32 3kB 100.0 300.0 500.0 ... 1.497e+05 1.499e+05
x (azimuth, range) float64 2MB 0.8725 2.618 ... -1.307e+03
... ...
latitude float64 8B 50.73
altitude float64 8B 99.5
crs_wkt int64 8B 0
band int64 8B 1
spatial_ref int64 8B 0
NOISE_LEVEL float64 8B -24.7Version 1#
rng = 2000.0
N = swp.pipe(rp.get_bins_from_range, rng)
print(N)
# take N range bins and calculate sum, for finding N consecutive bins
phib_sum = phib.rolling(range=N, center=True).sum(skipna=True)
# get maximum along range
smax = phib_sum.max(dim="range", skipna=True)
# if smax == N, we've identified the first consecutive range of valid phase values
# derive start_range and stop_range
rstep = rp.get_range_step(phib_sum)
start_range = phib_sum.idxmax(dim="range").where(smax == N) - smax // 2 * rstep
stop_range = start_range + N * rstep
phi_1 = phimask.where((phimask.range >= start_range) & (phimask.range <= stop_range))
phi_1m = phi_1.median("range", skipna=True)
10
display(phi_1m)
<xarray.DataArray 'PHIDP' (time2: 24, azimuth: 360)> Size: 35kB
dask.array<nanmedian, shape=(24, 360), dtype=float32, chunksize=(1, 360), chunktype=numpy.ndarray>
Coordinates:
* time2 (time2) datetime64[ns] 192B 2017-08-10T10:03:32.922000 ... 2...
* azimuth (azimuth) float64 3kB 0.5 1.5 2.5 3.5 ... 357.5 358.5 359.5
elevation (azimuth) float64 3kB 0.9998 0.9998 0.9998 ... 0.9998 0.9998
time (time2, azimuth) datetime64[ns] 69kB 2017-08-10T10:03:48.503...
sweep_mode <U20 80B 'azimuth_surveillance'
longitude float64 8B 7.072
latitude float64 8B 50.73
altitude float64 8B 99.5
crs_wkt int64 8B 0
band int64 8B 1
spatial_ref int64 8B 0
NOISE_LEVEL float64 8B -24.7
Attributes:
format: UV16
is_dft: 0
unit: deg
standard_name: radar_differential_phase_hv
long_name: Differential phase HV
units: degrees
_Undetect: 0.0phi_1m_sort = xr.apply_ufunc(
np.sort,
phi_1m,
input_core_dims=[["azimuth"]],
output_core_dims=[["azimuth"]],
dask="parallelized",
)
sysphi_1 = phi_1m_sort.isel(azimuth=slice(0, 30)).median("azimuth", skipna=True)
Version 2#
rng = 2000.0
N = sweep_ts.pipe(rp.get_bins_from_range, rng)
print(N)
10
# take N range bins and calculate sum, for finding N consecutive bins
phib_sum = phib.rolling(range=N, center=True).sum(skipna=True)
# get the maximum along the ray
# derive start_range and stop_range
rstep = rp.get_range_step(phib_sum)
start_range = phib_sum.idxmax(dim="range") - N // 2 * rstep
stop_range = start_range + N * rstep
phi_2 = phimask.where((phimask.range >= start_range) & (phimask.range <= stop_range))
# phi_2.plot(x="azimuth")
phi_2m = phi_2.median("range", skipna=True)
phi_2m_sort = xr.apply_ufunc(
np.sort,
phi_2m,
input_core_dims=[["azimuth"]],
output_core_dims=[["azimuth"]],
dask="parallelized",
)
sysphi_2 = phi_2m_sort.isel(azimuth=slice(0, 30)).median("azimuth", skipna=True)
Version 3#
N = 10
# cumulative sum, for finding first N valid bins
phib_cumsum = phib.cumsum("range", skipna=True)
# select only values until N is reached
phi_3 = phimask.where(phib_cumsum <= N)
# phi_3.plot(x="azimuth", vmin=75, vmax=95)
phi_3m = phi_3.median("range", skipna=True)
phi_3m_sort = xr.apply_ufunc(
np.sort,
phi_3m,
input_core_dims=[["azimuth"]],
output_core_dims=[["azimuth"]],
dask="parallelized",
)
sysphi_3 = phi_3m_sort.isel(azimuth=slice(0, 30)).median("azimuth", skipna=True)
Version 4#
from xhistogram.xarray import histogram as xhist
hlist = []
phase_res = 0.1
bins = np.arange(-180, 180, phase_res)
phi_hist = xhist(sweep_ts.PHIDP, dim=("range",), bins=[bins])
display(phi_hist)
<xarray.DataArray 'histogram_PHIDP' (time2: 24, azimuth: 360, PHIDP_bin: 3599)> Size: 249MB dask.array<sum-aggregate, shape=(24, 360, 3599), dtype=int64, chunksize=(1, 360, 3599), chunktype=numpy.ndarray> Coordinates: * time2 (time2) datetime64[ns] 192B 2017-08-10T10:03:32.922000 ... 201... * azimuth (azimuth) float64 3kB 0.5 1.5 2.5 3.5 ... 356.5 357.5 358.5 359.5 * PHIDP_bin (PHIDP_bin) float64 29kB -179.9 -179.9 -179.8 ... 179.7 179.8
phi_hist_smooth = phi_hist.rolling(PHIDP_bin=5, center=True).mean()
pmax = phi_hist_smooth.idxmax("PHIDP_bin").compute()
phi_hist_smooth_cut = phi_hist_smooth.where(
(phi_hist.PHIDP_bin > (pmax - 5)) & (phi_hist.PHIDP_bin < (pmax + 5)), drop=True
)
phi_hist_smooth_cut = phi_hist_smooth_cut / phi_hist_smooth_cut.max()
sysphi_4 = (
phi_hist_smooth_cut.differentiate("PHIDP_bin")
.rolling(PHIDP_bin=11, center=True)
.mean()
.idxmax("PHIDP_bin")
)
with xr.set_options(keep_attrs=True):
sweep_ts = sweep_ts.assign({"SYSPHI1": sysphi_1})
sweep_ts = sweep_ts.assign({"PHIDP_OC1": swp.PHIDP - sysphi_1})
sweep_ts = sweep_ts.assign({"SYSPHI2": sysphi_2})
sweep_ts = sweep_ts.assign({"PHIDP_OC2": swp.PHIDP - sysphi_2})
sweep_ts = sweep_ts.assign({"SYSPHI3": sysphi_3})
sweep_ts = sweep_ts.assign({"PHIDP_OC3": swp.PHIDP - sysphi_3})
sweep_ts = sweep_ts.assign({"SYSPHI4": sysphi_4})
sweep_ts = sweep_ts.assign({"PHIDP_OC4": swp.PHIDP - sysphi_4})
display(sweep_ts)
<xarray.Dataset> Size: 594MB
Dimensions: (time2: 24, azimuth: 360, range: 750)
Coordinates: (12/21)
* time2 (time2) datetime64[ns] 192B 2017-08-10T10:03:32.922000...
* azimuth (azimuth) float64 3kB 0.5 1.5 2.5 ... 357.5 358.5 359.5
elevation (azimuth) float64 3kB 0.9998 0.9998 ... 0.9998 0.9998
time (time2, azimuth) datetime64[ns] 69kB 2017-08-10T10:03:...
* range (range) float32 3kB 100.0 300.0 ... 1.497e+05 1.499e+05
x (azimuth, range) float64 2MB 0.8725 2.618 ... -1.307e+03
... ...
latitude float64 8B 50.73
altitude float64 8B 99.5
crs_wkt int64 8B 0
band int64 8B 1
spatial_ref int64 8B 0
NOISE_LEVEL float64 8B -24.7
Data variables: (12/33)
DBZH (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBZV (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
KDP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
RHOHV (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
CMAP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBTH (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
... ...
SYSPHI2 (time2) float32 96B dask.array<chunksize=(1,), meta=np.ndarray>
PHIDP_OC2 (azimuth, range, time2) float32 26MB dask.array<chunksize=(360, 750, 1), meta=np.ndarray>
SYSPHI3 (time2) float32 96B dask.array<chunksize=(1,), meta=np.ndarray>
PHIDP_OC3 (azimuth, range, time2) float32 26MB dask.array<chunksize=(360, 750, 1), meta=np.ndarray>
SYSPHI4 (time2, azimuth) float64 69kB dask.array<chunksize=(1, 360), meta=np.ndarray>
PHIDP_OC4 (azimuth, range, time2) float64 52MB dask.array<chunksize=(360, 750, 1), meta=np.ndarray>
Attributes:
source: gamic
ant_gain_h: 44.0
ant_gain_v: 44.0
noise_power_h: -1.39495
noise_power_v: -1.09706
rx_loss_h: 0.73
rx_loss_v: 0.73Phase Processing#
Phase processing was already done in the prior lectures. So we just use the corrected phase moments from the dataset.
CMAP = sweep_ts.CMAP.astype("uint16")
noise = ((CMAP >> 0) & 0x1).astype(bool)
clutter = ((CMAP >> 2) & 0x1).astype(bool)
masked = noise | clutter
valid = ~masked
CMAP2 = sweep_ts.CMAP2
clutter2 = CMAP2 == 1
bb = CMAP == 2
masked2 = clutter2 | bb
valid2 = ~masked2
val = valid & valid2
sweep_ts_masked = (
sweep_ts.where(val).where(sweep_ts.RHOHV >= 0.95).where(sweep_ts.DBZH >= 0)
)
sweep_ts_masked = sweep_ts_masked.assign(
RHOHV_SMOOTH=sweep_ts_masked.RHOHV.rolling(
range=11, min_periods=2, center=True
).median(skipna=True)
)
medwin = 41
PHIDP_OC = "PHIDP_OC1"
# median filtering 2d
phimed = sweep_ts_masked[PHIDP_OC].copy()
with xr.set_options(keep_attrs=True):
phimed = phimed.pipe(rp.filter_data, medwin)
# gaussian convolution 1d - smoothing
# play with sigma and kwidth
kwidth = 41
sigma = 10
gkern = rp.gauss_kernel(kwidth, sigma)
with xr.set_options(keep_attrs=True):
phiclean = phimed.pipe(rp.smooth_data, gkern)
%%time
window = 41
window2 = 3
with xr.set_options(keep_attrs=True):
phi_median = (
sweep_ts_masked[PHIDP_OC]
.copy()
.pipe(
rp.xr_rolling,
window,
window2=window2,
method="median",
skipna=True,
min_periods=3,
)
.transpose("time2", ...)
)
# gaussian convolution 1d - smoothing
# play with sigma and kwidth
kwidth = 41
sigma = 10
gkern = rp.gauss_kernel(kwidth, sigma)
phi_clean = phi_median.pipe(rp.smooth_data, gkern)
CPU times: user 611 ms, sys: 88.4 ms, total: 700 ms
Wall time: 698 ms
sweep_ts_masked = sweep_ts_masked.assign(
{
"PHIDP_CORR1": phimed,
"PHIDP_CORR2": phi_median,
"PHIDP_CORR3": phiclean,
"PHIDP_CORR4": phi_clean,
}
)
PHIDP_CORR = "PHIDP_CORR1"
L = 11
sweep_ts_masked[PHIDP_CORR]
<xarray.DataArray 'PHIDP_CORR1' (time2: 24, azimuth: 360, range: 750)> Size: 52MB
dask.array<transpose, shape=(24, 360, 750), dtype=float64, chunksize=(1, 360, 750), chunktype=numpy.ndarray>
Coordinates: (12/21)
* time2 (time2) datetime64[ns] 192B 2017-08-10T10:03:32.922000 ... 2...
* azimuth (azimuth) float64 3kB 0.5 1.5 2.5 3.5 ... 357.5 358.5 359.5
elevation (azimuth) float64 3kB 0.9998 0.9998 0.9998 ... 0.9998 0.9998
time (time2, azimuth) datetime64[ns] 69kB 2017-08-10T10:03:48.503...
* range (range) float32 3kB 100.0 300.0 500.0 ... 1.497e+05 1.499e+05
x (azimuth, range) float64 2MB 0.8725 2.618 ... -1.307e+03
... ...
latitude float64 8B 50.73
altitude float64 8B 99.5
crs_wkt int64 8B 0
band int64 8B 1
spatial_ref int64 8B 0
NOISE_LEVEL float64 8B -24.7
Attributes:
format: UV16
is_dft: 0
unit: deg
standard_name: radar_differential_phase_hv
long_name: Differential phase HV
units: degrees
_Undetect: 0.0%%time
kdp_lanczos = sweep_ts_masked[PHIDP_CORR].wrl.dp.kdp_from_phidp(winlen=L, min_periods=2)
phidp_v, kdp_vulpiani = sweep_ts_masked[PHIDP_CORR].wrl.dp.phidp_kdp_vulpiani(winlen=L)
CPU times: user 6.97 ms, sys: 0 ns, total: 6.97 ms
Wall time: 6.86 ms
swp = swp.assign({"KDP_LANC": kdp_lanczos, "KDP_VULP": kdp_vulpiani})
Attenuation Correction#
Standard Method#
uh = "DBTH"
zh = "DBZH"
zdr = "ZDR"
phi_list = [f"PHIDP_CORR{i}" for i in range(1, 5)]
alphax = 0.28
betax = 0.05
with xr.set_options(keep_attrs=True):
for phi in phi_list:
uhcorr = sweep_ts_masked[uh] + alphax * sweep_ts_masked[phi]
uhcorr.name = (
f"{sweep_ts_masked[uh].name}_{sweep_ts_masked[phi].name.split('_')[-1]}"
)
zhcorr = sweep_ts_masked[zh] + alphax * sweep_ts_masked[phi]
zhcorr.name = (
f"{sweep_ts_masked[zh].name}_{sweep_ts_masked[phi].name.split('_')[-1]}"
)
zdrcorr = sweep_ts_masked[zdr] + betax * sweep_ts_masked[phi]
zdrcorr.name = (
f"{sweep_ts_masked[zdr].name}_{sweep_ts_masked[phi].name.split('_')[-1]}"
)
sweep_ts_masked = sweep_ts_masked.assign(
{uhcorr.name: uhcorr, zhcorr.name: zhcorr, zdrcorr.name: zdrcorr}
)
ZPHI-Method#
CMAP = sweep_ts_masked.CMAP.astype("uint16")
noise = ((CMAP >> 0) & 0x1).astype(bool)
clutter = ((CMAP >> 2) & 0x1).astype(bool)
masked = noise | clutter
valid = ~masked
phi = sweep_ts_masked.PHIDP.where(
(sweep_ts_masked.CMAP2 == 0) & valid & (sweep_ts_masked.RHOHV > 0.9)
)
rng = 2000.0
zh = sweep_ts_masked.DBZH.where(
(sweep_ts_masked.CMAP2 == 0) & valid & (sweep_ts_masked.RHOHV > 0.9)
)
ah = rp.zphi(phi, zh, rng=2000, alphax=np.array([0.28])).squeeze()
range res [km]: 0.2
kdp_ah = ah.fillna(0) / ah.alpha
kdp_ah.attrs = swp.KDP.attrs
phical = kdp_ah.wrl.dp.phidp_from_kdp()
phical = phical.rename("PHICAL")
phical.attrs = swp.PHIDP.attrs
sweep_ts_masked = sweep_ts_masked.assign(
AH=ah,
KDP_AH=kdp_ah,
PHIDP_CORR5=phical,
)
uh = "DBTH"
zh = "DBZH"
zdr = "ZDR"
phi = "PHIDP_CORR5"
with xr.set_options(keep_attrs=True):
uhcorr = sweep_ts_masked[uh] + sweep_ts_masked.alpha * sweep_ts_masked[phi]
uhcorr.name = (
f"{sweep_ts_masked[uh].name}_{sweep_ts_masked[phi].name.split('_')[-1]}"
)
zhcorr = sweep_ts_masked[zh] + sweep_ts_masked.alpha * sweep_ts_masked[phi]
zhcorr.name = (
f"{sweep_ts_masked[zh].name}_{sweep_ts_masked[phi].name.split('_')[-1]}"
)
zdrcorr = sweep_ts_masked[zdr] + betax * sweep_ts_masked[phi]
zdrcorr.name = (
f"{sweep_ts_masked[zdr].name}_{sweep_ts_masked[phi].name.split('_')[-1]}"
)
sweep_ts_masked = sweep_ts_masked.assign(
{uhcorr.name: uhcorr, zhcorr.name: zhcorr, zdrcorr.name: zdrcorr}
)
display(sweep_ts_masked)
<xarray.Dataset> Size: 2GB
Dimensions: (time2: 24, azimuth: 360, range: 750)
Coordinates: (12/22)
* time2 (time2) datetime64[ns] 192B 2017-08-10T10:03:32.922000...
* azimuth (azimuth) float64 3kB 0.5 1.5 2.5 ... 357.5 358.5 359.5
elevation (azimuth) float64 3kB 0.9998 0.9998 ... 0.9998 0.9998
time (time2, azimuth) datetime64[ns] 69kB 2017-08-10T10:03:...
* range (range) float32 3kB 100.0 300.0 ... 1.497e+05 1.499e+05
x (azimuth, range) float64 2MB 0.8725 2.618 ... -1.307e+03
... ...
altitude float64 8B 99.5
crs_wkt int64 8B 0
band int64 8B 1
spatial_ref int64 8B 0
NOISE_LEVEL float64 8B -24.7
alpha float64 8B 0.28
Data variables: (12/56)
DBZH (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBZV (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
KDP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
RHOHV (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
CMAP (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBTH (time2, azimuth, range) float32 26MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
... ...
AH (time2, azimuth, range) float64 52MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
KDP_AH (time2, azimuth, range) float64 52MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
PHIDP_CORR5 (time2, azimuth, range) float64 52MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBTH_CORR5 (time2, azimuth, range) float64 52MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
DBZH_CORR5 (time2, azimuth, range) float64 52MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
ZDR_CORR5 (time2, azimuth, range) float64 52MB dask.array<chunksize=(1, 360, 750), meta=np.ndarray>
Attributes:
source: gamic
ant_gain_h: 44.0
ant_gain_v: 44.0
noise_power_h: -1.39495
noise_power_v: -1.09706
rx_loss_h: 0.73
rx_loss_v: 0.73Save data#
%%time
dtime_min = (
sweep_ts_masked.time.min().dt.floor("5min").dt.strftime("%Y%m%dT%H%M").values
)
dtime_max = sweep_ts_masked.time.max().dt.ceil("5min").dt.strftime("%Y%m%dT%H%M").values
fname = rp.data_path() / "lecture" / f"tmp_{dtime_min}_{dtime_max}_attcorr_workflow.nc"
print(fname)
sweep_ts_masked.to_netcdf(fname)
/builds/_NRRzFk9l/0/grp_meteo/radar/radarpolarimetry/data/lecture/tmp_20170810T1000_20170810T1200_attcorr_workflow.nc
CPU times: user 2min 18s, sys: 1min 15s, total: 3min 33s
Wall time: 1min 30s
elapsed_time = dt.datetime.now() - start_process_time
# Print the elapsed time
print("Elapsed time:", elapsed_time.total_seconds(), "seconds")
Elapsed time: 320.73959 seconds