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

ENH: grid creation function accept a single Radar object. #330

Merged
merged 1 commit into from Jul 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions pyart/map/gates_to_grid.py
Expand Up @@ -19,6 +19,7 @@

import numpy as np
from ..config import get_field_name
from ..core.radar import Radar
from ..graph.common import corner_to_point

from ._gate_to_grid_map import GateToGridMapper
Expand Down Expand Up @@ -78,6 +79,10 @@ def map_gates_to_grid(
grid point.

"""
# make a tuple if passed a radar object as the first argument
if isinstance(radars, Radar):
radars = (radars, )

if max_refl is None: # parse max_refl
max_refl = np.finfo('float32').max
if grid_origin_alt is None:
Expand Down
13 changes: 11 additions & 2 deletions pyart/map/grid_mapper.py
Expand Up @@ -31,6 +31,7 @@
from ..graph.common import corner_to_point
from ..io.common import radar_coords_to_cart
from ..core.grid import Grid
from ..core.radar import Radar
from ._load_nn_field_data import _load_nn_field_data
from .ckdtree import cKDTree
from .ball_tree import BallTree
Expand All @@ -47,7 +48,7 @@ def grid_from_radars(radars, grid_shape, grid_limits,

Parameters
----------
radars : tuple of Radar objects.
radars : Radar or tuple of Radar objects.
Radar objects which will be mapped to the Cartesian grid.
grid_shape : 3-tuple of floats
Number of points in the grid (z, y, x).
Expand All @@ -72,6 +73,10 @@ def grid_from_radars(radars, grid_shape, grid_limits,
radar fields.

"""
# make a tuple if passed a radar object as the first argument
if isinstance(radars, Radar):
radars = (radars, )

# map the radar(s) to a cartesian grid
if gridding_algo == 'map_to_grid':
grids = map_to_grid(radars, grid_shape, grid_limits, **kwargs)
Expand Down Expand Up @@ -292,7 +297,7 @@ def map_to_grid(radars, grid_shape, grid_limits, grid_origin=None,

Parameters
----------
radars : tuple of Radar objects.
radars : Radar or tuple of Radar objects.
Radar objects which will be mapped to the Cartesian grid.
grid_shape : 3-tuple of floats
Number of points in the grid (z, y, x).
Expand Down Expand Up @@ -404,6 +409,10 @@ def map_to_grid(radars, grid_shape, grid_limits, grid_origin=None,
grid_from_radars : Map to grid and return a Grid object.

"""
# make a tuple if passed a radar object as the first argument
if isinstance(radars, Radar):
radars = (radars, )

# check the parameters
if weighting_function.upper() not in ['CRESSMAN', 'BARNES']:
raise ValueError('unknown weighting_function')
Expand Down
8 changes: 8 additions & 0 deletions pyart/map/tests/test_gates_to_grid.py
Expand Up @@ -17,6 +17,14 @@
'constant_roi': 30., }


def test_map_to_grid_non_tuple():
radar = pyart.testing.make_target_radar()
grids = pyart.map.map_gates_to_grid(radar,
**COMMON_MAP_TO_GRID_ARGS)
center_slice = grids['reflectivity'][1, 4, :]
assert_array_equal(np.round(center_slice), EXPECTED_CENTER_SLICE)


def test_map_to_grid_default():
radar = pyart.testing.make_target_radar()
grids = pyart.map.map_gates_to_grid((radar,),
Expand Down
27 changes: 27 additions & 0 deletions pyart/map/tests/test_grid_mapper.py
Expand Up @@ -16,6 +16,14 @@
'roi_func': lambda z, y, x: 30, }


def test_map_to_grid_non_tuple():
radar = pyart.testing.make_target_radar()
grids = pyart.map.map_to_grid(radar,
**COMMON_MAP_TO_GRID_ARGS)
center_slice = grids['reflectivity'][1, 4, :]
assert_array_equal(np.round(center_slice), EXPECTED_CENTER_SLICE)


def test_map_to_grid_default():
radar = pyart.testing.make_target_radar()
grids = pyart.map.map_to_grid((radar,),
Expand Down Expand Up @@ -158,6 +166,25 @@ def test_grid_from_radars():
np.linspace(-400, 400, 3).astype('float64'))


def test_grid_from_radars_non_tuple():
radar = pyart.testing.make_target_radar()
grid = pyart.map.grid_from_radars(radar, **COMMON_MAP_TO_GRID_ARGS)

# check field data
center_slice = grid.fields['reflectivity']['data'][1, 4, :]
assert_array_equal(np.round(center_slice), EXPECTED_CENTER_SLICE)

# check other Grid object attributes
assert 'ROI' in grid.fields
assert np.all(grid.fields['ROI']['data'] == 30.)
assert_array_equal(grid.axes['x_disp']['data'],
np.linspace(-900, 900, 10))
assert_array_equal(grid.axes['y_disp']['data'],
np.linspace(-900, 900, 9).astype('float64'))
assert_array_equal(grid.axes['z_disp']['data'],
np.linspace(-400, 400, 3).astype('float64'))


def test_grid_from_radars_grid_origin():
radar = pyart.testing.make_target_radar()
radar.metadata.pop('instrument_name')
Expand Down