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

FIX: physically consistent RoI calculation for gridding; updated gridding input parameters to mitigate smearing #1552

Merged
merged 14 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pyart/map/_gate_to_grid_map.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ cdef class DistBeamRoI(RoIFunction):
z_offset = self.offsets[i, 0]
y_offset = self.offsets[i, 1]
x_offset = self.offsets[i, 2]
roi = (self.h_factor[0] * ((z - z_offset) / 20.0) +
sqrt((self.h_factor[1] * (y - y_offset))**2 +
roi = (sqrt((self.h_factor[0] * (z - z_offset))**2 +
(self.h_factor[1] * (y - y_offset))**2 +
(self.h_factor[2] * (x - x_offset))**2) *
self.beam_factor)
self.beam_factor
)
if roi < self.min_radius:
roi = self.min_radius
if roi < min_roi:
Expand Down
19 changes: 17 additions & 2 deletions pyart/map/gates_to_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def map_gates_to_grid(
constant_roi=None,
z_factor=0.05,
xy_factor=0.02,
min_radius=500.0,
min_radius=None,
h_factor=(1.0, 1.0, 1.0),
nb=1.5,
nb=1.0,
bsp=1.0,
dist_factor=(1.0, 1.0, 1.0),
**kwargs
Expand Down Expand Up @@ -95,6 +95,21 @@ def map_gates_to_grid(
if len(radars) == 0:
raise ValueError("Length of radars tuple cannot be zero")

# set min_radius depending on whether processing ARM radars
if min_radius is None:
min_radius = 250.0
try:
if "platform_id" in radars[0].metadata.keys():
if np.any(
[
x in radars[0].metadata["platform_id"].lower()
for x in ["sacr", "sapr"]
]
):
min_radius = 100.0
except:
mgrover1 marked this conversation as resolved.
Show resolved Hide resolved
pass

skip_transform = False
if len(radars) == 1 and grid_origin_alt is None and grid_origin is None:
skip_transform = True
Expand Down
26 changes: 21 additions & 5 deletions pyart/map/grid_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ def map_to_grid(
constant_roi=None,
z_factor=0.05,
xy_factor=0.02,
min_radius=500.0,
h_factor=1.0,
nb=1.5,
min_radius=None,
mgrover1 marked this conversation as resolved.
Show resolved Hide resolved
h_factor=(1.0, 1.0, 1.0),
nb=1.0,
bsp=1.0,
**kwargs
):
Expand Down Expand Up @@ -394,8 +394,9 @@ def map_to_grid(
h_factor, nb, bsp, min_radius : float
Radius of influence parameters for the built in 'dist_beam' function.
The parameter correspond to the height scaling, virtual beam width,
virtual beam spacing, and minimum radius of influence. These
parameters are only used when `roi_func` is 'dist_mean'.
virtual beam spacing, and minimum radius of influence (default value
smaller for ARM radars).
These parameters are only used when `roi_func` is 'dist_mean'.
copy_field_data : bool
True to copy the data within the radar fields for faster gridding,
the dtype for all fields in the grid will be float64. False will not
Expand Down Expand Up @@ -436,6 +437,21 @@ def map_to_grid(
if len(radars) == 0:
raise ValueError("Length of radars tuple cannot be zero")

# set min_radius depending on whether processing ARM radars
if min_radius is None:
min_radius = 250.0
try:
if "platform_id" in radars[0].metadata.keys():
if np.any(
[
x in radars[0].metadata["platform_id"].lower()
for x in ["sacr", "sapr"]
]
):
min_radius = 100.0
except:
pass

skip_transform = False
if len(radars) == 1 and grid_origin_alt is None and grid_origin is None:
skip_transform = True
Expand Down
4 changes: 2 additions & 2 deletions tests/map/test_gates_to_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ def test_map_to_grid_tiny_grid():
grids = pyart.map.map_gates_to_grid(
(radar,),
grid_shape=(1, 1, 1),
grid_limits=((-400.0, 400.0), (-900.0, 900.0), (-900, 900)),
grid_limits=((0.0, 300.0), (-800.0, 800.0), (-800, 800)),
fields=["reflectivity"],
)
assert grids["reflectivity"].shape == (1, 1, 1)
assert abs(np.round(grids["reflectivity"][0]) - 40.0) < 0.01
assert abs(np.round(grids["reflectivity"][0]) - 40.0) < 5.0


def test_grid_from_radars_gates_to_grid():
Expand Down
4 changes: 2 additions & 2 deletions tests/map/test_grid_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ def test_map_to_grid_tiny_grid():
grids = pyart.map.map_to_grid(
(radar,),
grid_shape=(1, 1, 1),
grid_limits=((-400.0, 400.0), (-900.0, 900.0), (-900, 900)),
grid_limits=((0.0, 300.0), (-800.0, 800.0), (-800, 800)),
fields=["reflectivity"],
)
assert grids["reflectivity"].shape == (1, 1, 1)
assert int(grids["reflectivity"][0]) == 40
assert abs(np.round(grids["reflectivity"][0]) - 40.0) < 5.0


def test_map_to_grid_errors():
Expand Down
4 changes: 1 addition & 3 deletions tests/xradar/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ def test_grid(filename=filename):
fields=["DBZ"],
)
assert_allclose(grid.x["data"], np.arange(-100_000, 120_000, 20_000))
assert_allclose(
grid.fields["DBZ"]["data"][0, -1, 0], np.array(0.4243435), rtol=1e-03
)
assert_allclose(grid.fields["DBZ"]["data"][0, -1, 0], np.array(-0.511), rtol=1e-03)


def _check_attrs_similar(grid1, grid2, attr):
Expand Down