Skip to content

Commit

Permalink
Merge branch 'Unidata:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
winash12 committed Jul 15, 2024
2 parents 66ab624 + 021123d commit 2401d47
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 12 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/automerge-dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Auto-merge Dependabot PRs

on:
pull_request_target:

jobs:
#
# Automatically review dependabot PRs and set them to automerge (on successful checks)
#
Automerge:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
env:
GH_TOKEN: ${{ github.token }}

permissions:
contents: write
pull-requests: write

steps:
- name: Set auto-merge
run: gh pr merge -R ${{ github.repository }} --merge --auto ${{ github.event.pull_request.number }}
- name: Review PR
run: gh pr review -R ${{ github.repository }} --approve ${{ github.event.pull_request.number }}
3 changes: 3 additions & 0 deletions .github/workflows/tests-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ jobs:
for dep in src:
dep = dep.split(';')[0]
out.write(dep.replace('>=', '==') + '\n')
# Only needed while we support numpy 1.20
if fname == 'requirements.txt':
out.write('pillow!=10.4.0\n')
EOF
- name: Install from PyPI
Expand Down
2 changes: 1 addition & 1 deletion ci/doc_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sphinx==7.3.7
pydata-sphinx-theme==0.15.2
sphinx-design==0.5.0
sphinx-design==0.6.0
sphinx-gallery==0.16.0
myst-parser==3.0.1
netCDF4==1.7.1
Expand Down
2 changes: 1 addition & 1 deletion ci/linting_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ruff==0.4.10
ruff==0.5.1

flake8==7.1.0
pycodestyle==2.12.0
Expand Down
2 changes: 1 addition & 1 deletion ci/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
matplotlib==3.8.4
matplotlib==3.9.1
numpy==1.26.4
pandas==2.2.2
pooch==1.8.2
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ preview = true

[tool.ruff.lint]
select = ["A", "B", "C", "CPY001", "D", "E", "E226", "F", "G", "I", "N", "NPY", "Q", "R", "S", "SIM", "T", "U", "W"]
ignore = ["F405", "I001", "RET504", "RET505", "RET506", "RET507", "RUF100"]
# NPY201 ignores the use of 'trapz' false alarm
ignore = ["F405", "I001", "NPY201", "RET504", "RET505", "RET506", "RET507", "RUF100"]
explicit-preview-rules = true

[tool.ruff.lint.per-file-ignores]
Expand Down
6 changes: 1 addition & 5 deletions src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4591,18 +4591,14 @@ def galvez_davison_index(pressure, temperature, mixing_ratio, surface_pressure,
<Quantity(-8.78797532, 'dimensionless')>
"""
if np.any(np.max(pressure, axis=vertical_dim) < 950 * units.hectopascal):
indices_without_950 = np.where(
np.max(pressure, axis=vertical_dim) < 950 * units.hectopascal
)
raise ValueError(
f'Data not provided for 950hPa or higher pressure. '
f'GDI requires 950hPa temperature and dewpoint data, '
f'see referenced paper section 3.d. in docstring for discussion of'
f' extrapolating sounding data below terrain surface in high-'
f'elevation regions.\nIndices without a 950hPa or higher datapoint'
f':\n{indices_without_950}'
f'\nMax provided pressures:'
f'\n{np.max(pressure, axis=0)[indices_without_950]}'
f'\n{np.max(pressure, axis=0)}'
)

potential_temp = potential_temperature(pressure, temperature)
Expand Down
11 changes: 9 additions & 2 deletions src/metpy/io/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,22 @@ def _decode_coords(coordinates):
(-119.3, 47.3)
"""
# Define latitude orientation
flip = 1

if coordinates[0] == '-':
coordinates = coordinates[1:]
# Flip latitude to Southern Hemisphere
flip = -1

# Based on the number of digits, find the correct place to split between lat and lon
# Hires bulletins provide 7 digits for coordinates; regular bulletins provide 4 or 5 digits
split_pos = int(len(coordinates) / 2)
lat, lon = coordinates[:split_pos], coordinates[split_pos:]

# Insert decimal point at the correct place and convert to float
lat = float(f'{lat[:2]}.{lat[2:]}')
lat = float(f'{lat[:2]}.{lat[2:]}') * flip
lon = -float(f'{lon[:3]}.{lon[3:]}')

return lon, lat


Expand Down
18 changes: 18 additions & 0 deletions tests/calc/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,24 @@ def test_gdi_no_950_raises_valueerror(index_xarray_data):
)


def test_gdi_no_950_by_simplevalue():
"""GDI requires a 950hPa or higher measurement."""
with pytest.raises(ValueError):
pressure = np.array([922., 850., 700., 600., 500., 400., 300., 250.,
200., 150.]) * units.hPa
temperature = np.array([22.6, 18.6, 8.6, 2.8, -4.6, -15.5, -30.6, -40.4,
-52.9, -67.8]) * units.degC
relative_humidity = np.array([71.12, 71.16, 70.79, 50.33, 28.22, 4.80, 3.68, 5.82,
18.18, 27.33]) * units.percent
mixrat = mixing_ratio_from_relative_humidity(pressure, temperature, relative_humidity)
galvez_davison_index(
pressure,
temperature,
mixrat,
pressure[0]
)


def test_gradient_richardson_number():
"""Test gradient Richardson number calculation."""
theta = units('K') * np.asarray([254.5, 258.3, 262.2])
Expand Down
37 changes: 37 additions & 0 deletions tests/io/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,40 @@ def test_parse_wpc_surface_bulletin():
[-102, 32], [-103, 31]])

assert all(df.valid == datetime(2021, 6, 28, 18, 0, 0))


@needs_module('shapely')
def test_negative_lat_highres():
"""Test decoding of high res coordinates with negative latitude."""
from io import BytesIO

import shapely.geometry as sgeom

sample = BytesIO(b"""
178
ASUS02 KWBC 281800
CODSUS
CODED SURFACE FRONTAL POSITIONS
NWS WEATHER PREDICTION CENTER COLLEGE PARK MD
342 PM EDT MON JUN 28 2021
VALID 062818Z
HIGHS 1022 -3961069 1020 -3851069 1026 3750773 1022 4430845 1019 5520728 1018
""")
df = parse_wpc_surface_bulletin(sample)
assert df.geometry[0] == sgeom.Point([-106.9, -39.6])


@needs_module('shapely')
def test_negative_lat():
"""Test decoding of coordinates with negative latitude."""
from io import BytesIO

import shapely.geometry as sgeom

sample = BytesIO(b"""12HR PROG VALID xxxxxxZ
HIGHS -351 -3985 -4046 -38117 -7510
""")
df = parse_wpc_surface_bulletin(sample)
assert df.geometry[0] == sgeom.Point([-51, -3])
Binary file modified tests/plots/baseline/test_declarative_events.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion tests/plots/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ def test_declarative_contour_convert_units():
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.276)
@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=2.731 if version_check('matplotlib<3.9') else 0.246)
@needs_cartopy
def test_declarative_events():
"""Test that resetting traitlets properly propagates."""
Expand Down

0 comments on commit 2401d47

Please sign in to comment.