diff --git a/pyart/map/gates_to_grid.py b/pyart/map/gates_to_grid.py index 95a6e88824..576afa9225 100644 --- a/pyart/map/gates_to_grid.py +++ b/pyart/map/gates_to_grid.py @@ -114,9 +114,9 @@ def map_gates_to_grid( skip_transform = True if grid_origin_alt is None: - try: - grid_origin_alt = float(radars[0].altitude["data"]) - except TypeError: + if len(radars[0].altitude["data"]) == 1: + grid_origin_alt = float(radars[0].altitude["data"].item()) + else: grid_origin_alt = np.mean(radars[0].altitude["data"]) # convert input h_factor and dist_factor from scalar, tuple, or list to array @@ -242,10 +242,10 @@ def _find_projparams(grid_origin, radars, grid_projection): # parse grid_origin if grid_origin is None: - try: - lat = float(radars[0].latitude["data"]) - lon = float(radars[0].longitude["data"]) - except TypeError: + if len(radars[0].latitude["data"]) == 1 & len(radars[0].longitude["data"]) == 1: + lat = float(radars[0].latitude["data"].item()) + lon = float(radars[0].longitude["data"].item()) + else: lat = np.mean(radars[0].latitude["data"]) lon = np.mean(radars[0].longitude["data"]) grid_origin = (lat, lon) @@ -293,10 +293,15 @@ def _find_offsets(radars, projparams, grid_origin_alt): x_disp, y_disp = geographic_to_cartesian( radar.longitude["data"], radar.latitude["data"], projparams ) - try: - z_disp = float(radar.altitude["data"]) - grid_origin_alt - offsets.append((z_disp, float(y_disp), float(x_disp))) - except TypeError: + if ( + len(radar.latitude["data"]) + == 1 & len(radar.longitude["data"]) + == 1 & len(radar.altitude["data"]) + == 1 + ): + z_disp = float(radar.altitude["data"].item()) - grid_origin_alt + offsets.append((z_disp, float(y_disp.item()), float(x_disp.item()))) + else: z_disp = np.mean(radar.altitude["data"]) - grid_origin_alt offsets.append((z_disp, np.mean(y_disp), np.mean(x_disp))) return offsets diff --git a/pyart/map/grid_mapper.py b/pyart/map/grid_mapper.py index 96c0e60487..bb4fb6e0b3 100644 --- a/pyart/map/grid_mapper.py +++ b/pyart/map/grid_mapper.py @@ -481,19 +481,19 @@ def map_to_grid( # find the grid origin if not given if grid_origin is None: - try: - lat = float(radars[0].latitude["data"]) - lon = float(radars[0].longitude["data"]) - except TypeError: + if len(radars[0].latitude["data"]) == 1 & len(radars[0].longitude["data"]) == 1: + lat = float(radars[0].latitude["data"].item()) + lon = float(radars[0].longitude["data"].item()) + else: lat = np.mean(radars[0].latitude["data"]) lon = np.mean(radars[0].longitude["data"]) grid_origin = (lat, lon) grid_origin_lat, grid_origin_lon = grid_origin if grid_origin_alt is None: - try: - grid_origin_alt = float(radars[0].altitude["data"]) - except TypeError: + if len(radars[0].altitude["data"]) == 1: + grid_origin_alt = float(radars[0].altitude["data"].item()) + else: grid_origin_alt = np.mean(radars[0].altitude["data"]) # fields which should be mapped, None for fields which are in all radars @@ -544,10 +544,15 @@ def map_to_grid( x_disp, y_disp = geographic_to_cartesian( radar.longitude["data"], radar.latitude["data"], projparams ) - try: - z_disp = float(radar.altitude["data"]) - grid_origin_alt - offsets.append((z_disp, float(y_disp), float(x_disp))) - except TypeError: + if ( + len(radar.latitude["data"]) + == 1 & len(radar.longitude["data"]) + == 1 & len(radar.altitude["data"]) + == 1 + ): + z_disp = float(radar.altitude["data"].item()) - grid_origin_alt + offsets.append((z_disp, float(y_disp.item()), float(x_disp.item()))) + else: z_disp = np.mean(radar.altitude["data"]) - grid_origin_alt offsets.append((z_disp, np.mean(y_disp), np.mean(x_disp))) diff --git a/pyart/retrieve/kdp_proc.py b/pyart/retrieve/kdp_proc.py index e5c042aa28..7818be1911 100755 --- a/pyart/retrieve/kdp_proc.py +++ b/pyart/retrieve/kdp_proc.py @@ -301,7 +301,7 @@ def _kdp_estimation_backward_fixed( p = np.dot((identity_i - np.dot(k, h_plus)), p_pred) # Fill the output - kdp[ii] = s[0] + kdp[ii] = s[0].item() kdp_error[ii] = p[0, 0] # Shift @@ -407,9 +407,9 @@ def _kdp_estimation_forward_fixed( p = np.dot((identity_i - np.dot(k, h_plus)), p_pred) # Fill the output - kdp[ii] = s[0] + kdp[ii] = s[0].item() kdp_error[ii] = p[0, 0] - phidp[ii] = s[2] + phidp[ii] = s[2].item() # Shift dummy = np.copy(kdp) diff --git a/pyart/util/radar_utils.py b/pyart/util/radar_utils.py index ba7063a98c..bc6827e83e 100644 --- a/pyart/util/radar_utils.py +++ b/pyart/util/radar_utils.py @@ -573,12 +573,12 @@ def join_radar(radar1, radar2): == 1 & len(radar2.altitude["data"]) == 1 ): - lat1 = float(radar1.latitude["data"]) - lon1 = float(radar1.longitude["data"]) - alt1 = float(radar1.altitude["data"]) - lat2 = float(radar2.latitude["data"]) - lon2 = float(radar2.longitude["data"]) - alt2 = float(radar2.altitude["data"]) + lat1 = float(radar1.latitude["data"].item()) + lon1 = float(radar1.longitude["data"].item()) + alt1 = float(radar1.altitude["data"].item()) + lat2 = float(radar2.latitude["data"].item()) + lon2 = float(radar2.longitude["data"].item()) + alt2 = float(radar2.altitude["data"].item()) if (lat1 != lat2) or (lon1 != lon2) or (alt1 != alt2): ones1 = np.ones(len(radar1.time["data"]), dtype="float32") diff --git a/tests/core/test_grid.py b/tests/core/test_grid.py index 0fedbe0450..986da33dc2 100644 --- a/tests/core/test_grid.py +++ b/tests/core/test_grid.py @@ -92,7 +92,7 @@ def test_grid_to_xarray(): time = np.array([netCDF4.num2date(grid.time["data"][0], grid.time["units"])]) # Check dimensions - assert ds.dims == {"time": 1, "z": 2, "y": 400, "x": 320, "nradar": 1} + assert ds.sizes == {"time": 1, "z": 2, "y": 400, "x": 320, "nradar": 1} # Check coordinate data assert np.array_equal(ds.x.data, grid.x["data"])