From 258fb58209d68f2bee93a40aab97e1c6266c3899 Mon Sep 17 00:00:00 2001 From: Zach Sherman <19153455+zssherman@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:28:05 -0500 Subject: [PATCH 1/3] MNT: Attempt to remove pinning and fixes for ruff errors. (#1666) * MNT: Remove pinning from requirements. * MNT: Remove pinning from environment file. * STY: PEP8 fixes. * STY: Fix for misordered imports. * STY: Revert old check. * CI: Update wheels.yml to use latest OS. --- .github/workflows/wheels.yml | 4 ++-- continuous_integration/environment-ci.yml | 2 +- examples/plotting/radar-cross-section.ipynb | 1 + pyart/graph/radarmapdisplay_basemap.py | 2 +- requirements.txt | 6 +++--- tests/io/test_cfradial.py | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 8fbc410482d..044ba2d8fe5 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -26,8 +26,8 @@ jobs: strategy: matrix: os: [ - ubuntu-20.04, - windows-2019, + ubuntu-latest, + windows-latest, macos-14, macos-13, ] diff --git a/continuous_integration/environment-ci.yml b/continuous_integration/environment-ci.yml index a0e9c5b81e2..cc74e5e51e3 100644 --- a/continuous_integration/environment-ci.yml +++ b/continuous_integration/environment-ci.yml @@ -24,7 +24,7 @@ dependencies: - cftime - setuptools - shapely - - ruff==0.4.2 + - ruff - mda-xdrlib - xradar - pooch diff --git a/examples/plotting/radar-cross-section.ipynb b/examples/plotting/radar-cross-section.ipynb index 4fe48a2ca0a..36c8cacd27f 100644 --- a/examples/plotting/radar-cross-section.ipynb +++ b/examples/plotting/radar-cross-section.ipynb @@ -7,6 +7,7 @@ "metadata": {}, "outputs": [], "source": [ + "import cartopy.crs as ccrs\n", "import matplotlib.pyplot as plt\n", "\n", "import pyart\n", diff --git a/pyart/graph/radarmapdisplay_basemap.py b/pyart/graph/radarmapdisplay_basemap.py index d0972771f3d..50582b67016 100644 --- a/pyart/graph/radarmapdisplay_basemap.py +++ b/pyart/graph/radarmapdisplay_basemap.py @@ -288,7 +288,7 @@ def plot_ppi_map( data = np.ma.masked_outside(data, vmin, vmax) # create the basemap if not provided - if type(basemap) != Basemap: + if not isinstance(basemap, Basemap): using_corners = None not in [min_lon, min_lat, max_lon, max_lat] if using_corners: basemap = Basemap( diff --git a/requirements.txt b/requirements.txt index 736c3569c00..cec082875de 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,15 @@ numpy scipy -netCDF4>=1.7.0 +netCDF4 matplotlib pooch cftime fsspec s3fs open_radar_data -xradar>=0.5.0 +xradar pandas mda-xdrlib -xarray!=0.21.0 +xarray cartopy pint diff --git a/tests/io/test_cfradial.py b/tests/io/test_cfradial.py index 443100bf5b0..6b6115dc50e 100644 --- a/tests/io/test_cfradial.py +++ b/tests/io/test_cfradial.py @@ -486,7 +486,7 @@ def attribute_equal(class1, class2, key, allow_str_case_diff=True): a1 = getattr(class1, key) a2 = getattr(class2, key) - assert type(a1) == type(a2) + assert type(a1) == type(a2) # noqa if isinstance(a1, str) and allow_str_case_diff: assert a1.upper() == a2.upper() From 716bd2e01fa2bee90bfa4e6245a08d3940a1d3e0 Mon Sep 17 00:00:00 2001 From: Max Grover Date: Wed, 23 Oct 2024 15:00:38 -0500 Subject: [PATCH 2/3] ADD: Add dask to docs environment (#1672) * ADD: Add dask to env * ADD: Add proper conda recipe * Update environment-ci.yml --- continuous_integration/environment-ci.yml | 1 - doc/environment.yml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/continuous_integration/environment-ci.yml b/continuous_integration/environment-ci.yml index cc74e5e51e3..f9973d75f8a 100644 --- a/continuous_integration/environment-ci.yml +++ b/continuous_integration/environment-ci.yml @@ -20,7 +20,6 @@ dependencies: - libnetcdf - flake8 - fsspec - - glpk - cftime - setuptools - shapely diff --git a/doc/environment.yml b/doc/environment.yml index db0249b5d02..4e6b55d32fc 100644 --- a/doc/environment.yml +++ b/doc/environment.yml @@ -36,6 +36,7 @@ dependencies: - cmweather - mda-xdrlib - xradar + - dask - pip - pip: - pooch From ec7759c31faad5467c35a11f67f8e190670a99e4 Mon Sep 17 00:00:00 2001 From: Zach Sherman <19153455+zssherman@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:27:45 -0500 Subject: [PATCH 3/3] FIX: Updates code to fix scalar warnings. (#1673) * FIX: Updates code to fix scalar warnings. I fixed this by calling .items() to pull from the array. Also checks similar to radar utils if the arrays are 1 or more (mobile radar). * FIX: Forgot to check for singular radar later on. --- pyart/map/gates_to_grid.py | 27 ++++++++++++++++----------- pyart/map/grid_mapper.py | 27 ++++++++++++++++----------- pyart/retrieve/kdp_proc.py | 6 +++--- pyart/util/radar_utils.py | 12 ++++++------ tests/core/test_grid.py | 2 +- 5 files changed, 42 insertions(+), 32 deletions(-) diff --git a/pyart/map/gates_to_grid.py b/pyart/map/gates_to_grid.py index 95a6e888248..576afa92252 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 96c0e60487a..bb4fb6e0b3c 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 e5c042aa280..7818be1911d 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 ba7063a98cb..bc6827e83e2 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 0fedbe0450e..986da33dc26 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"])