Skip to content

Commit

Permalink
FIX: physically consistent RoI calculation for gridding; updated grid…
Browse files Browse the repository at this point in the history
…ding input parameters to mitigate smearing (#1552)

* ENH: Dimension-dependent weighting factor flexibility in gridding
(previously, weighting scaling was optional only for the z-dim)

* TST: modify tests to align with new mapping scaling factor flexibility

* FIX: dist2 bug fix + STY

* FIX: optional conversion of  h_factor and dist_factor to array (compatibility)

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

* ENH: `min_radius` smaller for ARM radars reflecting higher resolution
FIX: consistent default values in `map_to_grid`

* STY: liniting (black)

* Increase min_radius default to necessarily cover 250 m resolution fluctuations

* FIX: `try` statement for using/testing metadata information

* TST: update a few tests which were to rigid without flexibility to consider any changes to the gridding methods

* STY: linting (black)

* FIX: specific AttributeError; explicit default input parameter values
  • Loading branch information
isilber committed Apr 11, 2024
1 parent 5e48f82 commit 5328bee
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
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
17 changes: 15 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=250.0,
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,19 @@ 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
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 AttributeError:
pass

skip_transform = False
if len(radars) == 1 and grid_origin_alt is None and grid_origin is None:
skip_transform = True
Expand Down
25 changes: 20 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=250.0,
h_factor=(1.0, 1.0, 1.0),
nb=1.0,
bsp=1.0,
**kwargs
):
Expand Down Expand Up @@ -394,8 +394,10 @@ 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.
NOTE: the default `min_radius` value is smaller for ARM radars
to reflect their higher resolution relative to precipitation 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 +438,19 @@ 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
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 AttributeError:
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

0 comments on commit 5328bee

Please sign in to comment.