Skip to content

Commit

Permalink
Merge branch 'main' into add-pyglpk
Browse files Browse the repository at this point in the history
  • Loading branch information
zssherman authored Nov 19, 2024
2 parents 6fee3ff + 473318d commit 2e79da8
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 59 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ jobs:

# Create environment using micromamba
- name: Install Conda environment with Micromamba
uses: mamba-org/[email protected].0
uses: mamba-org/[email protected].1
with:
environment-file: doc/environment.yml
micromamba-version: '2.0.0-0'
environment-name: pyart-docs
cache-downloads: true
cache-downloads: false

- name: Fetch all history for all tags and branches
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
os: [macos, ubuntu, windows]

steps:
- uses: actions/checkout@v4

# Install dependencies
- name: Setup Conda Environment
uses: mamba-org/[email protected].0
uses: mamba-org/[email protected].1
with:
environment-file: continuous_integration/environment-ci.yml
micromamba-version: '2.0.0-0'
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
python -m pytest -v --cov=./ --cov-report=xml
- name: Upload code coverage to Codecov
uses: codecov/codecov-action@v4.6.0
uses: codecov/codecov-action@v5.0.2
with:
file: ./coverage.xml
flags: unittests
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
strategy:
matrix:
os: [
ubuntu-20.04,
windows-2019,
ubuntu-latest,
windows-latest,
macos-14,
macos-13,
]
Expand All @@ -49,7 +49,7 @@ jobs:
with:
output-dir: dist
env:
CIBW_BUILD: "cp39-* cp310-* cp311-* cp312*"
CIBW_BUILD: "cp310-* cp311-* cp312*"
CIBW_SKIP: "*-musllinux_*" # numpy doesn't have wheels for musllinux so we can't build some quickly and without bloating
CIBW_ARCHS_LINUX: "x86_64"
MACOSX_DEPLOYMENT_TARGET: "10.9" # as of CIBW 2.9, this is the default value, pin it so it can't be bumped silently
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
merge-multiple: true

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.10.3
uses: pypa/gh-action-pypi-publish@v1.12.2
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
7 changes: 3 additions & 4 deletions continuous_integration/environment-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
- wradlib
- cartopy
- cvxopt
- xarray
- xarray>=2024.10.0
- metpy
- pytest-cov
- pytest-mpl
Expand All @@ -24,11 +24,10 @@ dependencies:
- cftime
- setuptools
- shapely
- ruff==0.4.2
- ruff
- mda-xdrlib
- xradar
- xradar>=0.8.0
- pooch
- versioneer
- black
- open-radar-data
- glpk
10 changes: 5 additions & 5 deletions doc/environment.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: pyart-docs
channels:
- conda-forge
- defaults
dependencies:
- gdal
- numpy
Expand All @@ -14,8 +13,8 @@ dependencies:
- metpy
- cartopy
- cvxopt
- xarray
- sphinx<7.2
- xarray>=2024.10.0
- sphinx==7.1.2
- ipython
- pandoc
- pkg-config
Expand All @@ -35,10 +34,11 @@ dependencies:
- pre_commit
- cmweather
- mda-xdrlib
- xradar
- xradar>=0.8.0
- dask
- ablog
- pip
- pip:
- pooch
- versioneer
- ablog
- -e ..
1 change: 1 addition & 0 deletions examples/plotting/radar-cross-section.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"metadata": {},
"outputs": [],
"source": [
"import cartopy.crs as ccrs\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import pyart\n",
Expand Down
2 changes: 1 addition & 1 deletion pyart/graph/radarmapdisplay_basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
27 changes: 16 additions & 11 deletions pyart/map/gates_to_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
27 changes: 16 additions & 11 deletions pyart/map/grid_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))

Expand Down
6 changes: 3 additions & 3 deletions pyart/retrieve/kdp_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions pyart/util/radar_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 16 additions & 4 deletions pyart/xradar/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@

import copy

import datatree
import numpy as np
import pandas as pd
from datatree import DataTree, formatting, formatting_html
from datatree.treenode import NodePath

try:
from xarray.core import formatting, formatting_html
from xarray.core.datatree import DataTree
from xarray.core.extensions import register_datatree_accessor
from xarray.core.treenode import NodePath
except ImportError:
from datatree import (
DataTree,
formatting,
formatting_html,
)
from datatree.extensions import register_datatree_accessor
from datatree.treenode import NodePath

from xarray import DataArray, Dataset, concat
from xarray.core import utils
from xradar.accessors import XradarAccessor
Expand Down Expand Up @@ -807,7 +819,7 @@ def _point_altitude_data():
return _point_altitude_data


@datatree.register_datatree_accessor("pyart")
@register_datatree_accessor("pyart")
class XradarDataTreeAccessor(XradarAccessor):
"""Adds a number of pyart specific methods to datatree.DataTree objects."""

Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
numpy
scipy
netCDF4>=1.7.0
netCDF4
matplotlib
pooch
cftime
fsspec
s3fs
open_radar_data
xradar>=0.5.0
xradar>=0.8.0
pandas
mda-xdrlib
xarray!=0.21.0
xarray>=2024.10.0
cartopy
pint
2 changes: 1 addition & 1 deletion tests/core/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_cfradial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2e79da8

Please sign in to comment.